Font lock with org-agenda not working

569 views Asked by At

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 :

  • M-x emacs-version is GNU Emacs 24.4.1 (i686-pc-mingw32)
  • M-x org-version is Org-mode version 8.2.10
2

There are 2 answers

2
Rafael Ibraim On BEST ANSWER

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.

2
fniessen On

I don't have the time to try and understand what's wrong in your code, but you can have a look at my Emacs-Leuven.el file (L976-1015): I do the same for the words "FIXME", "XXX" and "BUG".

https://github.com/fniessen/emacs-leuven/blob/master/emacs-leuven.el