Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

OnStyle callback is never called (confirmed also in the example file)

オープン
#108 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
c, lua
領域
tooling

調査の方向性

examples/StyleCustom.lua と .abc のサンプルドキュメントを使い、説明されている print 文を使用して callback のフローを再現します。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
  1. This source defines a function for callback OnSwitchFile. It declares to call CustomStyle for the event OnStyle if the file extension is abc.
  2. My understanding is that editor:Colourise(0, -1) should lead to invocation of callback OnStyle.
  3. Handling the callback OnStyle and thus calling CustomStyle should colorize the document as a consequence.
  4. By adding print() statements and opening the Lua Console, one can observe which functions are actually run.

Expected behavior:

  1. Callback OnSwitchFile is handled.
  2. Callback OnStyle is handled.

Actual behavior:

  1. Callback OnSwitchFile is handled.
  2. Callback OnStyle is never handled, thus the function CustomStyle is 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:

clip

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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dail8859/LuaScript のほかの issue

dail8859/LuaScript の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。