Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs mode: how to specify that thing in square brackets should be colored

Tags:

emacs

mode

elisp

I write a simple emacs mode. How do I explicitly specify that all things in e.g. square brackets should be colored. Must be smth like that:

( (if thing is in square brackets) . font-lock-string-face)
like image 630
Adobe Avatar asked Sep 13 '11 12:09

Adobe


1 Answers

I assume you're writing a major mode, but font-lock-add-keywords works also in minor modes. Check out its documentation with C-h f RET font-lock-add-keywords.

(define-derived-mode my-mode text-mode "mymode"
  ;; some init code
  (font-lock-add-keywords nil '(("\\[\\(.*\\)\\]"
                                 1 font-lock-warning-face prepend)))
  ;; some more init code
)
like image 193
Joao Tavora Avatar answered Sep 20 '22 12:09

Joao Tavora