Related to this question.
Here's my current font lock setup for python-mode
:
(require 'org)
(defconst lpy-font-lock-keywords
'(("^#\\(\\* .*\\)$" 1 'org-level-1 prepend)
("^#\\(\\*\\* .*\\)$" 1 'org-level-2 prepend)
("^#\\(\\*\\*\\* .*\\)$" 1 'org-level-3 prepend)
("^#\\(\\*\\*\\*\\* .*\\)$" 1 'org-level-4 prepend)
("^#\\(\\*\\*\\*\\*\\* .*\\)$" 1 'org-level-5 prepend)
(lpy-outline-comment-highlight 1 'default prepend)
("`\\([^\n']+\\)'" 1 font-lock-constant-face prepend)))
(font-lock-add-keywords 'python-mode lpy-font-lock-keywords)
(defun lpy-outline-comment-highlight (limit)
(when (re-search-forward "^#\\(?:[^*]\\|$\\)" limit t)
(let* ((pt (point))
(success (save-excursion
(and (re-search-backward "^#\\*" nil t)
(null (re-search-forward "^[^#]" pt t))))))
(when success
(set-match-data (list (line-beginning-position) (line-end-position)
(point) (line-end-position)))
(end-of-line)
t))))
The code appears to do what I want (have comment bodies, but not
starters, in default
face for comments that belong to outlines), but
only for small buffers, or places that I modify.
For larger buffers (larger than one screen), font-lock
will be lazy
and not apply the required faces. However, if I modify the text
around that region, it will be highlighted correctly.
In the image above, font-lock
is being lazy in the "Multi-dimensional indexing outline".
So I moved a point there and entered a space - the highlight became correct.
How do I force font-lock
to highlight every line on the screen?
(elisp)Font Lock Multiline
node of the manual?