emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: font-lock-fontify-block


From: Gregory Heytings
Subject: Re: font-lock-fontify-block
Date: Sat, 13 Mar 2021 08:15:04 +0000


Because font-lock-fontify-region changes point. It seems that it doesn't change mark, but I'm not sure it never will, so I've used save-mark-and-excursion just in case.

It never will so you can use `save-excursion`.


Okay, thanks:

(defun font-lock-update (&optional arg)
  "Updates the syntax highlighting in this buffer.
Refontify the accessible portion of this buffer, or enable Font Lock mode
in this buffer if it is currently disabled.  With prefix ARG, toggle Font
Lock mode."
  (interactive "P")
  (save-excursion
    (if (and (not arg) font-lock-mode)
        (font-lock-fontify-region (point-min) (point-max))
      (font-lock-unfontify-region (point-min) (point-max))
      (font-lock-mode 'toggle))))
(global-set-key (kbd "C-x x f") 'font-lock-update)

The "C-x x f" binding is less convenient than the "M-o M-o" one, but this regression is compensated by the fact that font-lock-update works correctly, unlike font-lock-fontify-block. It is also more general, as it can be used to toggle Font Lock mode. All in all, it seems to me that this is a progress.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]