[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding keywords for font-lock experts
From: |
Sébastien Vauban |
Subject: |
Re: Adding keywords for font-lock experts |
Date: |
Thu, 12 Mar 2009 11:14:42 +0100 |
User-agent: |
Gnus/5.110009 (No Gnus v0.9) Emacs/23.0.60 (gnu/linux) |
Hello,
> My goal is to highlight some words [like `Warning'] in (almost) all modes.
>
> To do such a thing, I've found on the Web [...] different solutions.
>
> (font-lock-add-keywords nil
> `(("\\(BUGS\\|FIXME\\|Firefox\\|TODO\\|Warning\\|WARNING\\)"
> 1 'font-lock-warning-face prepend))))
>
> [...]
>
> (font-lock-add-keywords mode
> `((,pattern
> 1 'special-words prepend))))
>
> They almost behave the same from a user perspective, but is one of them
> superior to the others from a technical perspective (better coding regarding
> different versions of Emacs, portability, etc.)?
I've found good documentation
(http://www.gnu.org/software/emacs/elisp/html_node/Customizing-Keywords.html#Customizing-Keywords)
explaining the differences between the exposed solutions:
o one is to add fontification patterns for _one major mode only_;
o the other affects _all derived modes_ as well.
I've now rewritten the codes as follows:
--8<---------------cut here---------------start------------->8---
;; special words
(setq keywords-level-1-pattern "\\(BUGS\\|FIXME\\|TODO\\)")
(make-face 'keywords-level-1)
(set-face-attribute 'keywords-level-1 nil :foreground "red")
(setq keywords-level-2-pattern "\\(WARNING\\)")
(make-face 'keywords-level-2)
(set-face-attribute 'keywords-level-2 nil :foreground "purple")
;; set up highlighting of special words for proper selected major modes only
(dolist (mode '(fundamental-mode
gnus-article-mode
message-mode
text-mode)) ; no interference with org-mode (which derives
; from text-mode)
(font-lock-add-keywords mode
`((,keywords-level-1-pattern 1 'keywords-level-1 prepend)
(,keywords-level-2-pattern 1 'keywords-level-2 prepend))))
--8<---------------cut here---------------end--------------->8---
Though:
o it still does not work with _LaTeX logs_ (generated on the fly in
buffers that are *not* associated with a file), such as `*test output'
-- whose major mode is `fundamental-mode';
o it still does not work with Gnus (for messages that I'm _reading_ as
well as for messages that I'm _composing_).
Can some expert please help me on this? I'm now totally blocked at this
stage...
Best regards,
Seb
--
Sébastien Vauban