[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Adding keywords for font-lock experts
From: |
Sébastien Vauban |
Subject: |
Adding keywords for font-lock experts |
Date: |
Mon, 09 Mar 2009 14:45:39 +0100 |
User-agent: |
Gnus/5.110009 (No Gnus v0.9) Emacs/23.0.60 (gnu/linux) |
Hello,
This question has already been answered several times, but never in a fully
satisfactory way. So, I ask it now, once again, but in a much more detailed
way.
My goal is to highlight some words in (almost) all modes.
As an example, I would like to see the word `Warning' highlighted in the
following buffers:
o any text buffer or programming buffer,
o the Gnus article buffer (`gnus-article-mode'),
o the LaTeX log buffer (`fundamental-mode'?).
To do such a thing, I've found on the Web 3 slightly different solutions,
displayed below:
--8<---------------cut here---------------start------------->8---
(make-face 'special-words)
(set-face-attribute 'special-words nil :foreground "White" :background
"Firebrick")
;; solution 1
(dolist (mode '(fundamental-mode gnus-article-mode org-mode shell-mode
muse-mode))
(font-lock-add-keywords mode
'(("\\<\\(BUGS\\|FIXME\\|TODO\\)"
0 'font-lock-warning-face t)
("\\<\\(Firefox\\|Warning\\|WARNING\\)"
0 'special-words t))))
;; solution 2
(defun highlighting-install ()
(interactive)
(font-lock-mode -1)
(font-lock-mode 1)
(font-lock-add-keywords nil
`(("\\(BUGS\\|FIXME\\|Firefox\\|TODO\\|Warning\\|WARNING\\)"
(1 'font-lock-warning-face prepend)))))
(dolist (hook '(fundamental-mode-hook
gnus-article-mode-hook
org-mode-hook
shell-mode-hook
muse-mode-hook))
(add-hook hook 'highlighting-install))
;; solution 3
(let ((pattern "\\<\\(BUGS\\|FIXME\\|Firefox\\|TODO\\|Warning\\|WARNING\\)"))
(mapc
(lambda (mode)
(font-lock-add-keywords mode `((,pattern 1 'special-words prepend))))
'(fundamental-mode gnus-article-mode org-mode shell-mode muse-mode)))
--8<---------------cut here---------------end--------------->8---
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.)?
Though, I have 2 problems:
o solution 2 is different from solutions 1 and 3 for the Gnus article
buffer:
- in solution 2, the word `Warning' is highlighted but the rest
of the buffer isn't anymore (mail headers);
- with solutions 1 and 3, the article buffer is highlighted like
always, but the word `Warning' is not.
o none of the solutions highlights the word `Warning' in the LaTeX log
(`C-c C-c LaTeX' from AUCTeX), though I've included `fundamental-mode'
in the above codes.
Can someone help me/us getting this working? Thanks a lot in advance!
Best regards,
Seb
--
Sébastien Vauban
- Adding keywords for font-lock experts,
Sébastien Vauban <=