From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: buff-menu and revert-buffer-restore-functions Date: Tue, 04 Jun 2024 19:52:27 +0300 Organization: LINKOV.NET Message-ID: <86le3klkwd.fsf@mail.linkov.net> References: <86a5k1evxc.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8086"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 04 18:54:08 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sEXQG-0001xE-3m for ged-emacs-devel@m.gmane-mx.org; Tue, 04 Jun 2024 18:54:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEXPO-0007W4-Bj; Tue, 04 Jun 2024 12:53:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEXPM-0007Vj-Lh for emacs-devel@gnu.org; Tue, 04 Jun 2024 12:53:12 -0400 Original-Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEXPK-0005ik-5Z for emacs-devel@gnu.org; Tue, 04 Jun 2024 12:53:12 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id AA91840007; Tue, 4 Jun 2024 16:53:03 +0000 (UTC) In-Reply-To: <86a5k1evxc.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 03 Jun 2024 21:13:51 +0300") X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::222; envelope-from=juri@linkov.net; helo=relay2-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319822 Archived-At: >> 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.")