0

With latex-mode, is there any way to obtain more than three (3) levels of highlighting?

I would like to control more than three levels of highlighting, however, it appears as though latex-mode may be limited to three (3) levels. I say this because Emacs complains when attempting a fourth level -- Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument listp prepend). The following is just an example of an attempt to control four (4) levels, which gave the error message listed above.

(defvar lawlist-face-a (make-face 'lawlist-face-a))
(set-face-attribute 'lawlist-face-a nil :foreground "orange")

(defvar lawlist-face-b (make-face 'lawlist-face-b))
(set-face-attribute 'lawlist-face-b nil :foreground "cyan")

(defvar lawlist-face-c (make-face 'lawlist-face-c))
(set-face-attribute 'lawlist-face-c nil :foreground "blue")

(defvar lawlist-face-d (make-face 'lawlist-face-d))
(set-face-attribute 'lawlist-face-d nil :foreground "red")


(font-lock-add-keywords 'latex-mode '(

("\\(\\\\begin\\|\\\\end\\)\\(\{\\)\\(document\\)\\(\}\\)" (1 lawlist-face-a) (2 lawlist-face-b) (3 lawlist-face-c) (4 lawlist-face-d) prepend)

))

I tried adding (setq font-lock-support-mode 'lazy-lock-mode), which caused a freeze. I also tried adding (setq font-lock-maximum-decoration t), which didn't seem to have any appreciable effect.

Drew
  • 29,895
  • 7
  • 74
  • 104
lawlist
  • 13,099
  • 3
  • 49
  • 158

1 Answers1

2

The prepend atom needs to be outside the quoted list, as the last argument to font-lock-add-keywords:

(font-lock-add-keywords
 'latex-mode
 '(("\\(\\\\begin\\|\\\\end\\)\\(\{\\)\\(document\\)\\(\}\\)" (1 lawlist-face-a) (2 lawlist-face-b) (3 lawlist-face-c) (4 lawlist-face-d)))
 'prepend)
legoscia
  • 39,593
  • 22
  • 116
  • 167
  • I've noticed today that adding the letter `t` following each custom face is necessary sometimes if there are other definitions that potentially conflict -- e.g., `begin` is, of course, one of the most common commands and the custom colors needed that extra `t` to make everything work correctly. – lawlist May 20 '13 at 02:22
  • 1
    You're confusing two things here. The third argument to `font-lock-add-keywords` controls how these keywords are added to the existing ones. By using a non-nil (and not `set`) the keywords are *appended* to the existing set, i.e. the opposite of *prepend*. On the other hand, `prepend` can be used *inside* a rule to tell font-lock to add it's colors in front of other existing colors, however, you need to specify it for each highlight rule as in `(1 lawlist-face-a prepend) (2 lawlist-face-b prepend) ...`. – Lindydancer May 20 '13 at 09:26