* buff-menu and revert-buffer-restore-functions
@ 2024-06-03 17:49 Stefan Monnier
2024-06-03 18:13 ` Juri Linkov
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2024-06-03 17:49 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
In the recent
commit a525cfb3af0c49c5c64e8af548ab23d086348fed
Author: Juri Linkov <juri@linkov.net>
Date: Mon Jun 3 19:55:47 2024 +0300
New variable 'revert-buffer-restore-functions' (bug#69511)
* doc/lispref/backups.texi (Reverting):
Add documentation for 'revert-buffer-restore-functions'.
* lisp/files.el (revert-buffer-restore-functions): New variable.
(revert-buffer-restore-read-only): New function.
(revert-buffer): Use 'revert-buffer-restore-functions' with
the default value 'revert-buffer-restore-read-only' (bug#69511).
* lisp/buff-menu.el (Buffer-menu-mode): Add hook
'revert-buffer-restore-functions' to restore
outline-minor-mode highlighting.
Why is it the responsability of buff-menu to setup outline minor
mode's rehighlighting? Wouldn't the same apply to several other modes
and should be handled directly by outline minor mode?
What's special about buff-menu in this respect?
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: buff-menu and revert-buffer-restore-functions
2024-06-03 17:49 buff-menu and revert-buffer-restore-functions Stefan Monnier
@ 2024-06-03 18:13 ` Juri Linkov
2024-06-04 16:52 ` Juri Linkov
0 siblings, 1 reply; 3+ messages in thread
From: Juri Linkov @ 2024-06-03 18:13 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
> Why is it the responsability of buff-menu to setup outline minor
> mode's rehighlighting? Wouldn't the same apply to several other modes
> and should be handled directly by outline minor mode?
> What's special about buff-menu in this respect?
I was unsure about the applicability of this outline rehighlighting
in the general case. But now I see that the right place would be in
outline-minor-mode. So this is fixed now.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: buff-menu and revert-buffer-restore-functions
2024-06-03 18:13 ` Juri Linkov
@ 2024-06-04 16:52 ` Juri Linkov
0 siblings, 0 replies; 3+ messages in thread
From: Juri Linkov @ 2024-06-04 16:52 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
>> Why is it the responsability of buff-menu to setup outline minor
>> mode's rehighlighting? Wouldn't the same apply to several other modes
>> and should be handled directly by outline minor mode?
>> What's special about buff-menu in this respect?
>
> I was unsure about the applicability of this outline rehighlighting
> in the general case. But now I see that the right place would be in
> outline-minor-mode. So this is fixed now.
Then the right place to rehighlight hi-lock patterns would be
hi-lock-mode:
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 516bee67dd0..8cbe3155b93 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -376,7 +376,9 @@ hi-lock-mode
(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 @@ hi-lock-mode
(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,18 @@ hi-lock-font-lock-hook
(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 (or hi-lock-interactive-lighters
+ hi-lock-interactive-patterns)))
+ (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.")
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-04 16:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-03 17:49 buff-menu and revert-buffer-restore-functions Stefan Monnier
2024-06-03 18:13 ` Juri Linkov
2024-06-04 16:52 ` Juri Linkov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.