Skip to content

Commit

Permalink
hl-todo-mode: Fontify using hl-todo--regexp only
Browse files Browse the repository at this point in the history
Previously we used `font-lock-flush' and `font-lock-ensure' instead.
Most built-in minor-modes that call `font-lock-add-keywords' (with
`nil' as MODE), only call the former, which doesn't appear to always
get the job done.  Additionally calling `font-lock-ensure' as we did
isn't much; it re-fontifies the complete buffer, which can be costly
and it has been reported that it sometimes fails to actually do so.

Directly fontifying just our own keyword using `hl-todo--regexp' for
the complete buffer seems to be a good compromise and should also be
more reliable.
  • Loading branch information
tarsius committed Oct 3, 2018
1 parent bbccf4a commit 38d8b57
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions hl-todo.el
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,11 @@ including alphanumeric characters, cannot be used here."
(hl-todo--setup)
(font-lock-remove-keywords nil hl-todo--keywords))
(when font-lock-mode
(if (and (fboundp 'font-lock-flush)
(fboundp 'font-lock-ensure))
(save-restriction
(widen)
(font-lock-flush)
(font-lock-ensure))
(with-no-warnings
(font-lock-fontify-buffer)))))
(save-excursion
(goto-char (point-min))
(while (re-search-forward hl-todo--regexp nil t)
(save-excursion
(font-lock-fontify-region (match-beginning 0) (match-end 0) nil))))))

;;;###autoload
(define-globalized-minor-mode global-hl-todo-mode
Expand Down

0 comments on commit 38d8b57

Please sign in to comment.