[Top][All Lists]

[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)


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

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 

;; solution 1
(dolist (mode '(fundamental-mode gnus-article-mode org-mode shell-mode 
  (font-lock-add-keywords mode
                             0 'font-lock-warning-face t)
                             0 'special-words t))))

;; solution 2
(defun highlighting-install ()
  (font-lock-mode -1)
  (font-lock-mode 1)
  (font-lock-add-keywords nil
     (1 'font-lock-warning-face prepend)))))
(dolist (hook '(fundamental-mode-hook
  (add-hook hook 'highlighting-install))

;; solution 3
(let ((pattern "\\<\\(BUGS\\|FIXME\\|Firefox\\|TODO\\|Warning\\|WARNING\\)"))
   (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

            -   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,

Sébastien Vauban

reply via email to

[Prev in Thread] Current Thread [Next in Thread]