From e1409379f7ce60eb845a0b9c3a614af4f5fac694 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 30 Oct 2019 13:08:55 +0100 Subject: [PATCH] Add a convenience function to be used when working on font locking * doc/lispref/modes.texi (Font Lock Basics): Document it. * lisp/font-lock.el (font-lock-refontify): New convenience command. --- doc/lispref/modes.texi | 6 ++++++ etc/NEWS | 6 ++++++ lisp/font-lock.el | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index 2e0c9e4655e..fda5a106bbe 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi @@ -2737,6 +2737,12 @@ This function should make sure the region between @var{beg} and @var{end} default to the beginning and the end of the buffer's accessible portion. Calls the function specified by @code{font-lock-ensure-function}. + +@item font-lock-refontify +This is a convenience command meant to be used when developing font +locking for a mode, and should not be called from Lisp code. It +recomputes all the relevant variables and then calls +@code{font-lock-ensure} on the entire buffer. @end ftable There are several variables that control how Font Lock mode highlights diff --git a/etc/NEWS b/etc/NEWS index daf9e0e1f0c..3df50154e3e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -575,6 +575,12 @@ current and the previous or the next line, as before. * Changes in Specialized Modes and Packages in Emacs 27.1 ++++ +** New command 'font-lock-refontify'. +This is an interactive convenience function to be used when developing +font locking for a mode. It recomputes the font locking data and then +re-fontifies the buffer. + --- ** The 'C' command in 'tar-mode' will now preserve the timestamp of the extracted file if the new user option 'tar-copy-preserve-time' is diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 9ae082736cc..971e37309e9 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -1100,6 +1100,15 @@ accessible portion of the current buffer." "Function to make sure a region has been fontified. Called with two arguments BEG and END.") +(defun font-lock-refontify () + "Reinitialise the font-lock machinery and re-fontify the buffer. +This functions is a convenience functions when developing font +locking for a mode, and is not meant to be called from lisp functions." + (interactive) + (declare (interactive-only t)) + (setq font-lock-major-mode nil) + (font-lock-ensure)) + (defun font-lock-ensure (&optional beg end) "Make sure the region BEG...END has been fontified. If the region is not specified, it defaults to the entire accessible -- 2.39.5