Recently, using fic-mode
as reference, I implemented a way for words like TODO
, etc. to be highlighted. Here is the code:
(defun todo/pos-in-doc-or-comment-region-p (pos)
(memq (get-char-property pos 'face)
'(font-lock-doc-face font-lock-comment-face)))
(defun todo/search-for-keyword (limit)
(let ((original-match-data nil))
(save-match-data
(while (and (null original-match-data)
(re-search-forward "\\<\\(\\(\\(TODO(\\)\\([^)]+?\\)\\():\\)\\)\\|\\(\\(NOTE(\\)\\([^)]+?\\)\\():\\)\\)\\|\\(\\(FIXME(\\)\\([^)]+?\\)\\():\\)\\)\\|\\(\\(IMPORTANT(\\)\\([^)]+?\\)\\():\\)\\)\\)" limit t))
(if (and (todo/pos-in-doc-or-comment-region-p (match-beginning 0))
(todo/pos-in-doc-or-comment-region-p (match-end 0)))
(setq original-match-data (match-data)))))
(when original-match-data
(set-match-data original-match-data)
(goto-char (match-end 0))
t)))
(defvar todo/keywords
'((todo/search-for-keyword (3 font-lock-warning-face t t)
(4 font-lock-constant-face t t)
(5 font-lock-warning-face t t)
(7 font-lock-string-face t t)
(8 font-lock-constant-face t t)
(9 font-lock-string-face t t)
(11 font-lock-warning-face t t)
(12 font-lock-constant-face t t)
(13 font-lock-warning-face t t)
(15 font-lock-variable-name-face t t)
(16 font-lock-constant-face t t)
(17 font-lock-variable-name-face t t)
)))
(add-hook 'prog-mode-hook
(lambda () (font-lock-add-keywords nil todo/keywords 'append)))
This was supposed to enable me to write things like TODO(name): something
and have it properly highlighted like this:
However, if I enable hl-line-mode
using (global-hl-line-mode 1)
, the highlighting only happens if the point (cursor) is on a line different from the one on which the TODO...
was typed. If I am on the same line, even doing font-lock-fontify-buffer
does not refreshes syntax highlighting.
Also, once the highlighting has been "activated" (by pressing Enter, for example), if I come back to that line and edit something, the highlighting goes away once again.
Can someone help as to how can I stop this clashing with hl-line-mode
?
PS. I have set the line highlighting color using
(set-face-background hl-line-face theme/color/woodsmoke) ; hl-line
------------------------------------------------------------
Solution
Using the selected answer, putting
(set-face-attribute 'hl-line nil :inherit nil :background theme/color/woodsmoke)
before
(global-hl-line-mode 1)
fixes it.