* Adding keywords for font-lock experts
@ 2009-03-09 13:45 Sébastien Vauban
2009-03-12 10:14 ` Sébastien Vauban
0 siblings, 1 reply; 2+ messages in thread
From: Sébastien Vauban @ 2009-03-09 13:45 UTC (permalink / raw
To: help-gnu-emacs-mXXj517/zsQ
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Adding keywords for font-lock experts
2009-03-09 13:45 Adding keywords for font-lock experts Sébastien Vauban
@ 2009-03-12 10:14 ` Sébastien Vauban
0 siblings, 0 replies; 2+ messages in thread
From: Sébastien Vauban @ 2009-03-12 10:14 UTC (permalink / raw
To: help-gnu-emacs-mXXj517/zsQ
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-12 10:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-09 13:45 Adding keywords for font-lock experts Sébastien Vauban
2009-03-12 10:14 ` Sébastien Vauban
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.