Rehighlight hi-lock patterns after reverting the buffer.
* lisp/hi-lock.el (hi-lock-revert-buffer-rehighlight): New function. (hi-lock-mode): Add hi-lock-revert-buffer-rehighlight to revert-buffer-restore-functions, and remove after mode is disabled. https://lists.gnu.org/archive/html/emacs-devel/2024-06/msg00044.html
This commit is contained in:
parent
a2b6e18d60
commit
870100a8b7
1 changed files with 17 additions and 2 deletions
|
@ -376,7 +376,9 @@ use (hi-lock-mode 1) for individual buffers.")))
|
|||
(hi-lock-find-patterns)
|
||||
(add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t)
|
||||
;; Remove regexps from font-lock-keywords (bug#13891).
|
||||
(add-hook 'change-major-mode-hook (lambda () (hi-lock-mode -1)) nil t))
|
||||
(add-hook 'change-major-mode-hook (lambda () (hi-lock-mode -1)) nil t)
|
||||
(add-hook 'revert-buffer-restore-functions
|
||||
#'hi-lock-revert-buffer-rehighlight nil t))
|
||||
;; Turned off.
|
||||
(when (or hi-lock-interactive-patterns
|
||||
hi-lock-file-patterns)
|
||||
|
@ -390,7 +392,9 @@ use (hi-lock-mode 1) for individual buffers.")))
|
|||
(remove-overlays nil nil 'hi-lock-overlay t)
|
||||
(font-lock-flush))
|
||||
(define-key-after menu-bar-edit-menu [hi-lock] nil)
|
||||
(remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t)))
|
||||
(remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t)
|
||||
(remove-hook 'revert-buffer-restore-functions
|
||||
#'hi-lock-revert-buffer-rehighlight t)))
|
||||
|
||||
;;;###autoload
|
||||
(define-globalized-minor-mode global-hi-lock-mode
|
||||
|
@ -859,6 +863,17 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search."
|
|||
(font-lock-add-keywords nil hi-lock-file-patterns t)
|
||||
(font-lock-add-keywords nil hi-lock-interactive-patterns t)))
|
||||
|
||||
(defun hi-lock-revert-buffer-rehighlight ()
|
||||
"Rehighlight hi-lock patterns after `revert-buffer'.
|
||||
Apply the previous patterns after reverting the buffer."
|
||||
(when-let ((patterns hi-lock-interactive-lighters))
|
||||
(lambda ()
|
||||
(setq hi-lock-interactive-lighters nil
|
||||
hi-lock-interactive-patterns nil)
|
||||
(let ((hi-lock-auto-select-face t))
|
||||
(dolist (pattern (reverse patterns))
|
||||
(highlight-regexp (car pattern) (hi-lock-read-face-name)))))))
|
||||
|
||||
(defvar hi-lock--hashcons-hash
|
||||
(make-hash-table :test 'equal :weakness t)
|
||||
"Hash table used to hash cons regexps.")
|
||||
|
|
Loading…
Add table
Reference in a new issue