Skip to content

Commit

Permalink
Refresh font-lock rather than recomputing from defaults
Browse files Browse the repository at this point in the history
We can use font-lock-flush now to simply refresh the fontification of
the current part of the buffer.  Previously, we needed to use the more
heavy-handed font-lock-refresh-defaults, because we were regenerating
the list of font-lock-keywords from scratch and reloading each time.
Now, keywords are added and removed as needed, or else are based on
functions with feature-specific conditionals.

We also don’t need to check that font-lock-mode is enabled, because
font-lock-flush does that already.

The result is that user-defined keywords such as these are not
clobbered:

(font-lock-add-keywords nil '(("\\W@\\w+" . font-lock-variable-name-face)))

Closes GH-222.
  • Loading branch information
jrblevin committed Nov 11, 2017
1 parent a01883f commit 2dde7b3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8701,8 +8701,7 @@ or span."
(interactive)
(when (member major-mode '(markdown-mode gfm-mode))
;; Refontify buffer
(when (and font-lock-mode (fboundp 'font-lock-refresh-defaults))
(font-lock-refresh-defaults))
(font-lock-flush)
;; Add or remove hooks related to extensions
(markdown-setup-wiki-link-hooks)))

Expand Down

0 comments on commit 2dde7b3

Please sign in to comment.