OnStyle callback is never called (confirmed also in the example file)
還沒有人認領這個 Issue。
評估
研究方向
使用 examples/StyleCustom.lua 和 .abc 範例文件重現回呼流程,並按照描述使用 print 陳述式。閱讀 src/LuaScript.cpp 第 308 行附近的程式碼,追蹤 editor:Colourise(0, -1) 與 SCN_STYLENEEDED 通知之間的關係。當收到 OnStyle 並呼叫 CustomStyle,使文件獲得預期的自訂樣式時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
CustomStyle.lua example file
--[[ An example file
proc clip(int a)
« Clip into the positive zone »
if (a > 0) a
0
end
]]
-- Define style numbers
S_DEFAULT = 0
S_IDENTIFIER = 1
S_KEYWORD = 2
S_UNICODECOMMENT = 3
-- Anytime a file is switched, check to see if it needs styled
npp.AddEventHandler("OnSwitchFile", function(filename, bufferid)
if npp:GetExtPart() == ".abc" then
-- Add the event handler for our custom style function
npp.AddEventHandler("OnStyle", CustomStyle)
-- Make sure to set the lexer as a custom container
editor.Lexer = SCLEX_CONTAINER
-- Set up the styles as appropriate
editor.StyleFore[S_DEFAULT] = 0x7f007f
editor.StyleBold[S_DEFAULT] = true
editor.StyleFore[S_IDENTIFIER] = 0x000000
editor.StyleFore[S_KEYWORD] = 0x800000
editor.StyleBold[S_KEYWORD] = true
editor.StyleFore[S_UNICODECOMMENT] = 0x008000
editor.StyleFont[S_UNICODECOMMENT] = "Georgia"
editor.StyleItalic[S_UNICODECOMMENT] = true
editor.StyleSize[S_UNICODECOMMENT] = 9
-- Clear any style and re-lex the entire document
editor:ClearDocumentStyle()
editor:Colourise(0, -1)
else
-- Can remove the handler if it's not needed
npp.RemoveEventHandler("OnStyle", CustomStyle)
end
return false
end)
-- Style the document. Handles UTF-8 characters
function CustomStyle(styler)
identifierCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
styler:StartStyling(styler.startPos, styler.lengthDoc, styler.initStyle)
while styler:More() do
-- Exit state if needed
if styler:State() == S_IDENTIFIER then
if not identifierCharacters:find(styler:Current(), 1, true) then
identifier = styler:Token()
if identifier == "if" or identifier == "end" then
styler:ChangeState(S_KEYWORD)
end
styler:SetState(S_DEFAULT)
end
elseif styler:State() == S_UNICODECOMMENT then
if styler:Match("»") then
styler:ForwardSetState(S_DEFAULT)
end
end
-- Enter state if needed
if styler:State() == S_DEFAULT then
if styler:Match("«") then
styler:SetState(S_UNICODECOMMENT)
elseif identifierCharacters:find(styler:Current(), 1, true) then
styler:SetState(S_IDENTIFIER)
end
end
styler:Forward()
end
styler:EndStyling()
end
- This source defines a function for callback
OnSwitchFile. It declares to callCustomStylefor the eventOnStyleif the file extension isabc. - My understanding is that
editor:Colourise(0, -1)should lead to invocation of callbackOnStyle. - Handling the callback
OnStyleand thus callingCustomStyleshould colorize the document as a consequence. - By adding
print()statements and opening the Lua Console, one can observe which functions are actually run.
Expected behavior:
- Callback
OnSwitchFileis handled. - Callback
OnStyleis handled.
Actual behavior:
- Callback
OnSwitchFileis handled. - Callback
OnStyleis never handled, thus the functionCustomStyleis never called.
This can be confirmed by the resulting styling. The given example document (stored with a filepath ending with .abc) leads to the following coloring:
This coloring (every foreground text color is purple) can be explained by the editor.StyleFore[S_DEFAULT] = 0x7f007f which is run and sets the default color to purple. But the actual styling function CustomStyle is not run.
Environment:
- Windows 10
- LuaScript v0.12 (64 bit). Lua 5.3.5
- Seems like the OnStyle handling should be triggered here but SCN_STYLENEEDED does not seem to be a received Scintilla notification.
- 主要語言
- C
- 星號
- 130
- 分支
- 24
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
dail8859/LuaScript 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 52/100
-
難度 2/5 1-3 小時 新手友好度 35/100
-
難度 5/5 一週以上 新手友好度 20/100
-
難度 1/5 1 小時以內 新手友好度 55/100
-
難度 3/5 1-2 天 新手友好度 35/100
查看 dail8859/LuaScript 的全部 Issue
相似的 Issue
-
vim.filetype.match() prefixes a URL buffer name with the cwd before passing it to filetype functions未關閉
難度 2/5 1-3 小時 新手友好度 73/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
COVESA/dlt-daemon#925 · 1 個 reaction ·
-
stream_curl: retry_count never resets after a successful reconnect, so long sequential streams die after 5 drops可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 70/100
mpv-player/mpv#18728 ·
維護者通常 1 天內回覆
-
followup Prio 📌
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
cyrusimap/cyrus-imapd#6640 ·
維護者通常 2 天內回覆