Pregunta

I am trying to set up a major mode in Emacs where I would like to highlight certain keywords. Using a template from this page: http://ergoemacs.org/emacs/elisp_syntax_coloring.html I tried:

(setq testing-font-lock-keywords
  `((font-lock-keyword-face)
))

(define-derived-mode testing-mode fundamental-mode
  "testing file mode"
  "Major mode for editing test files"

  (setq font-lock-defaults '(testing-font-lock-keywords))
  (setq mode-name "testing")
)

(provide 'testing-mode)

If I use this mode on a simple test file, and type "hello" the text hello is marked in different color. That is, any text within double quotes is highlighted. Why is this happening?

I think it is related to the variable font-lock-keyword-face. But if I type C-h v and font-lock-keyword-face it says:

font-lock-keyword-face is a variable defined in `font-lock.el'.
Its value is font-lock-keyword-face

Update

It seems like it is not related to font-lock-keyword-face anyway, since defining testing-font-lock-keywords like:

(setq test-keywords '("TEST"))
(setq testing-font-lock-keywords
  `((,test-keywords)))

gives the same behavior.

¿Fue útil?

Solución

This is directed by variable `font-lock-syntactic-face-function'

Otros consejos

Emacs fontifies two things: 1) Syntactic, this includes comments and strings as declared in the syntax table. 2) Keywords.

Typically, you want the first phase to run, but you might need to update your syntax table to match the syntax of the language.

In addition, font-lock keywords can be written so that they overwrite existing colors, so that you can highlight text inside pre-colored comments and string. See the OVERRIDE flag in font-lock-keywords.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top