When I evaluate (highlight-regexp "todo" "hi-blue") in a buffer, “todo” gets highlighted in that buffer. I’d like “todo” to be highlighted in any buffer, always.

I’ve tried putting the following code in my Aquamacs Preferences.el file (equivalent to Emacs’ .emacs), based on what I read here:

(global-hi-lock-mode 1)
(setq hi-lock-file-patterns-policy (lambda (dummy) t))
(highlight-regexp "todo" "hi-blue")

But “todo” doesn’t get highlighted. What am I missing?

  • 1
    You can remove the #'.
    – Drew
    Mar 18, 2023 at 15:31
  • 1
    @drew Thanks, I removed it so as not to set a bad example. Mar 21, 2023 at 11:13

2 Answers 2


I am not sure why the hihglight-regexp does not work, but to get TODO highlighted in any buffer I recommend using the hl-todo package.

You do not have to 'sharp quote' a lambda expression as it is self-quoting (see 'lambda' docstring).


highlight-regexp does its thing in the current buffer which likely is not set when Preferences.el is read. To achieve the desired effect in every buffer, you need to call it in some hook that is fired when buffers are created but I do not know a good candidate.

  • find-file-hook perhaps?
    – NickD
    Mar 18, 2023 at 20:53
  • You probably had found this question and answers already, but I think indeed after-change-major-mode-hook probably makes a good choice. However, I would still recommend to use the hl-todo package. Mar 20, 2023 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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