高亮註釋中的關鍵字

寫代碼時,經常會在註釋中註明一些有待未來完成的事項.例如

┌────

│ # 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)

└────


當然,這種方法並不完美,它會高亮這個代碼中的關鍵字,而不僅僅是註釋中的.


[fic-mode] https://github.com/lewang/fic-mode/blob/master/fic-mode.el


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章