Download
(defgroup fic-ext-mode nil
"Highlight FIXME/TODO(...) in comments"
:tag "FIC"
:group 'tools
:group 'font-lock
:group 'faces)
(defcustom fic-highlighted-words '("FIXME" "TODO" "BUG")
"Words to highlight"
:group 'fic-ext-mode)
(defcustom fic-author-name-regexp "[a-zA-Z0-9_\\.]+"
"Regexp describing FIXME/TODO author name"
:group 'fic-ext-mode)
(defconst font-lock-fic-face 'font-lock-fic-face
"Face to fontify FIXME/TODO words")
(defface font-lock-fic-face
'((((class color))
(:background "white" :foreground "red" :weight bold))
(t (:weight bold)))
"Face to fontify FIXME/TODO words"
:group 'fic-ext-mode)
(defconst font-lock-fic-author-face 'font-lock-fic-author-face
"Face to fontify author/assignee of FIXME/TODO")
(defface font-lock-fic-author-face
'((((class color))
(:background "white" :foreground "orangered" :underline t))
(t (:underline t)))
"Face to fontify author/assignee of FIXME/TODO"
:group 'fic-ext-mode)
(defun fic-search-re ()
"Regexp to search for"
(let ((fic-words-re (regexp-opt fic-highlighted-words t)))
(concat fic-words-re "\\(?:(\\(" fic-author-name-regexp "\\))\\)?")))
(defun fic-in-doc/comment-region (pos)
(memq (get-char-property pos 'face)
(list font-lock-doc-face font-lock-string-face font-lock-comment-face)))
(defun fic-search-for-keyword (limit)
(let ((match-data-to-set nil)
found)
(save-match-data
(while (and (null match-data-to-set)
(re-search-forward (fic-search-re) limit t))
(if (and (fic-in-doc/comment-region (match-beginning 0))
(fic-in-doc/comment-region (match-end 0)))
(setq match-data-to-set (match-data)))))
(when match-data-to-set
(set-match-data match-data-to-set)
(goto-char (match-end 0))
t)))
(defun fic-ext-mode-font-lock-keywords ()
"Font Lock keywords for fic-ext-mode"
`((fic-search-for-keyword
(1 ,font-lock-fic-face t)
(2 ,font-lock-fic-author-face t t))))
(define-minor-mode fic-ext-mode
"Fic mode -- minor mode for highlighting FIXME/TODO in comments"
:lighter " FIC" :group 'fic-ext-mode
(let ((kwlist (fic-ext-mode-font-lock-keywords)))
(if fic-ext-mode
(font-lock-add-keywords nil kwlist 'append)
(font-lock-remove-keywords nil kwlist))))
(provide 'fic-ext-mode)