I would like to be able to highlight a particular phrase (in my case: @dakrone) in every emacs buffer, regardless of the mode (it's fine if it doesn't work in fundamental-mode). I know of something like:

(defun eos/add-watchwords ()
  "Highlight FIXME and TODO in code"
   nil '(("\\<\\(TODO\\(?:(.*)\\)?:?\\)\\>"  1 'warning prepend)
         ("\\<\\(FIXME\\(?:(.*)\\)?:?\\)\\>" 1 'error prepend))))

(add-hook 'prog-mode-hook #'eos/add-watchwords)

But I haven't gotten something like that to be applied globally instead of having to manually add every mode I want to highlight in. Is there a way do do this?

  • Not all modes use font-lock; e.g., org-agenda-mode uses text-properties. Font-lock and text-properties do not play well together. A third option is to use overlays. – lawlist Jan 8 '18 at 17:51

You can use library highlight.el to highlight any text in any buffer, using either text properties or overlays. The highlighting can be independent of font-locking or be controlled by font-lock-mode.

There are many ways to highlight, and your question is not very specific. See Highlight Library for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.