emacselisporg-modefont-lock

Font lock with org-agenda not working


I have a org file with the following content:

* My Heading
** TODO Make a FOO
** TODO Take action on bar and FOO
** TODO Check if FOO is working

My objective is to highlight the word FOO from the task headings in org-agenda-mode. To achieve this, I've tried:

(add-hook 'org-agenda-mode-hook
  (lambda ()
    (font-lock-add-keywords nil
                            '(("\\(FOO\\)" 1 '(:background "red"))))))

But nothing changes. My hook is running and if I try C-h v font-lock-keywords inside the agenda view, the value returned is

(t
 (("\\(FOO\\)" 1
   '(:background "red")))
 ("\\(FOO\\)"
  (1
   '(:background "red"))))

Apart from showing the same item two times, I can't see why this isn't working. Does ignore font-lock-mode settings? If so, how could I add a "custom" keyword hightlight to org-agenda-mode?

EDIT :


Solution

  • As @lawlist suggested, the *Org-Agenda* buffer does not use font-lock-mode. The easiest way to achieve what I want in the agenda view is to use HiLock as suggested in this question:

    (defface my-hi-lock-face '((t (:background  "red"
                                   :foreground  "yellow"
                                   :bold t)))
                              "my-hi-lock-face")
    
    (add-hook 'org-finalize-agenda-hook
              (lambda ()
                (highlight-regexp "\\(FOO\\)" "my-hi-lock-face")))
    

    Note the hook I'm using: this one runs again everytime I redraw my agenda buffer.