emacscommentselisphighlightingtodo

Emacs: highlighting TODO *only* in comments


This question is related to another one, Emacs :TODO indicator at left side. I recently came across a minor mode I like a lot called FixmeMode. It supports auto highlighting of TODO marks, and navigating between them. However, I think it makes more sense to recognize the "TODO" strings only in comments, rather than polluting the whole file. Is it possible?


Solution

  • Check out the library fic-mode.el, it has been verified in C++ and Emacs-Lisp.

    It was written specifically to answer this question.

    The installation is like any standard package:

    (require 'fic-mode)
    (add-hook 'c++-mode-hook 'turn-on-fic-mode) 
    

    Though Wei Hu did ask for an easy way to add it to multiple modes, so here goes:

    (defun add-something-to-mode-hooks (mode-list something)
      "helper function to add a callback to multiple hooks"
      (dolist (mode mode-list)
        (add-hook (intern (concat (symbol-name mode) "-mode-hook")) something)))
    
    (add-something-to-mode-hooks '(c++ tcl emacs-lisp) 'turn-on-fic-mode)