[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Highlighting words in every possible buffer

From: harven
Subject: Re: Highlighting words in every possible buffer
Date: Mon, 25 Aug 2008 06:49:40 -0700 (PDT)
User-agent: G2/1.0

On Aug 25, 10:12 am, Sébastien Vauban <address@hidden>
> Hello,
> I would like to have some words highlighted in every possible
> buffer -- even in mail buffers, I'd like them highlighted
> everywhere, always!
> For example:
>     o   get `error', `failed', `missing', etc. in bold red;
>     o   get `warning', `insufficient', etc. in bold orange.
> I tried something like:
> --8<---------------cut here---------------start------------->8---
>     (dolist (mode '(c-mode
>                     text-mode
>                     java-mode
>                     cperl-mode
>                     html-mode-hook
>                     css-mode-hook
>                     emacs-lisp-mode
>                     nuweb-mode
>                     latex-mode))
>       (font-lock-add-keywords mode
>        '(("\\<\\(XXX\\|FIXME\\|TODO\\|[eE][rR][rR][oO][rR]\\|BUG\\)"
>           0 font-lock-warning-face t)
> ("\\<\\([wW][aA][rR][nN][iI][nN][gG]\\|[mM][iI][sS][sS][iI][nN][gG]\\|[iI][nN][vV][aA][lL][iI][dD]\\|[fF][aA][iI][lL][eE][dD]\\)"
>           0 font-lock-warning-face t))))
> --8<---------------cut here---------------end--------------->8---
> But it does not work like expected...
>     o   the words are not highlighted in *LaTeX* compilation
>         buffer -- or, only after I manually ask for reverting
>         the buffer;
>     o   the words are not highlighted in shell outputs and the
>         like (*grep* output, etc.).
> Can you help?
> Best regards,
>   Seb
> --
> Sébastien Vauban

The following should work in most cases.

(add-hook 'after-change-major-mode-hook
  (lambda ()
   (font-lock-add-keywords nil
    '(("myword" . font-lock-warning-face)))))

Beware that in certain circumstances, the mode may choose to overwrite
your face specification. This happens, for example, in occur mode. It
also happens in grep mode if your word is a substring of a longer word
(e.g. mywords), in which case the matched substring will be
highlighted with some particular face
that will overwrite yours.

reply via email to

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