larsbrinkhoff / forth-mode

Wants to be the SLIME of Forth
GNU General Public License v3.0
61 stars 17 forks source link

How to customize forth-syntax--font-lock-keywords? #102

Closed dcnorris closed 3 months ago

dcnorris commented 3 months ago

I can of course modify forth-syntax.el as follows,

(defvar forth-syntax--font-lock-keywords
  '("if" "else" "then"
    "for" "next" "[i" "i]" ";i" ; <-- added by DCN to support FlashForth
    "?do" "do" "unloop" "exit" "leave" "loop" "+loop"
    "begin" "while" "repeat" "again" "until"
    "case" "?of" "of" "endof" "endcase"
    ":noname" ";" "does>" "immediate"
    "is" "to"
    "literal" "2literal" "fliteral" "sliteral"
    "begin-structure" "end-structure"))

But is there a less 'invasive' approach to adding fontified keywords, similar to the provisions made via forth-smie-bnf-extensions which we can specify in a .dir-locals.el as follows?

((forth-mode . ((forth-smie-bnf-extensions
                 . ((control ("for" words "next")
                             ("[i" words "i]")
                             (":" words ";i")
                             ))))))
larsbrinkhoff commented 3 months ago

No, there is nothing less invasive.

dcnorris commented 3 months ago

I've managed to achieve the desired effect adding these lines to the forth-mode hook:

  (dolist (w '("for" "next" "[i" "i]" ";i"))
    (forth-syntax--define w #'forth-syntax--state-font-lock-keyword))

Admittedly, this calls a -- function; but is less invasive than editing the original source.