寫代碼時,經常會在注釋中注明一些有待未來完成的事項.例如
┌────
│ # REFACTOR: Decouple and clean up this crap.
│
│ # crappy code omitted
└────
正常情況下,除非使用了類似[fic-mode]這樣的mode,否則Emacs不會去高亮注釋中
的REFACTOR這類關鍵字.
有一個簡單的辦法可以做到這一點:
│ (defun font-lock-comment-annotations ()
│ "Highlight a bunch of well known comment annotations.
│ This functions should be added to the hooks of major modes for programming."
│ (font-lock-add-keywords
│ nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|OPTIMIZE\\|HACK\\|REFACTOR\\):"
│ 1 font-lock-warning-face t))))
│ (add-hook 'prog-mode-hook 'font-lock-comment-annotations)
當然,這種方法并不完美,它會高亮這個代碼中的關鍵字,而不僅僅是注釋中的.