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.bugs Subject: bug#69511: Restore any state after revert-buffer Date: Sun, 03 Mar 2024 09:59:24 +0200 Organization: LINKOV.NET Message-ID: <864jdnpw83.fsf@mail.linkov.net> References: <86y1b0r00p.fsf@mail.linkov.net> <867cikpkpm.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19034"; 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: 69511@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 03 09:19:55 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rgh4d-0004pn-Ho for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Mar 2024 09:19:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgh4M-0001Ni-PF; Sun, 03 Mar 2024 03:19:38 -0500 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 1rgh4I-0001KW-P5 for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 03:19:34 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgh4I-0003rw-Gn for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 03:19:34 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rgh4l-0006IC-Ab for bug-gnu-emacs@gnu.org; Sun, 03 Mar 2024 03:20:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Mar 2024 08:20:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69511 X-GNU-PR-Package: emacs Original-Received: via spool by 69511-submit@debbugs.gnu.org id=B69511.170945397324128 (code B ref 69511); Sun, 03 Mar 2024 08:20:03 +0000 Original-Received: (at 69511) by debbugs.gnu.org; 3 Mar 2024 08:19:33 +0000 Original-Received: from localhost ([127.0.0.1]:39732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rgh4G-0006H6-QY for submit@debbugs.gnu.org; Sun, 03 Mar 2024 03:19:33 -0500 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:39399) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rgh4E-0006Gs-9W for 69511@debbugs.gnu.org; Sun, 03 Mar 2024 03:19:31 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id E9D0060004; Sun, 3 Mar 2024 08:18:34 +0000 (UTC) In-Reply-To: <867cikpkpm.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 02 Mar 2024 20:11:49 +0200") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280924 Archived-At: >> This patch adds a new variable 'revert-buffer-state-functions' >> that will allow any state to be saved and restored, >> not only the currently hard-coded 'read-only' state: > > It isn't clear what you mean by "state" here. It seems like you are > talking about functions to be called after reverting a buffer in order > to do whatever is appropriate after reverting. And if so, why > "state"? For example, one of your examples, with > outline-minor-mode-highlight-buffer, is not about "state", but about > re-highlighting the buffer after reverting it. "state" here is in the same sense as is already used in 'revert-buffer': (let ((state (and (boundp 'read-only-mode--state) (list read-only-mode--state)))) (prog1 (funcall (or revert-buffer-function #'revert-buffer--default) ignore-auto noconfirm) (when state (setq buffer-read-only (car state)) (setq-local read-only-mode--state (car state))))) > So I would suggest calling this "revert-buffer-post-revert-functions", > and updating the doc string to make it clear that the purpose is more > general. "post" can't be used because these functions are called before 'revert-buffer-function'. "pre" would be better but still has no hint that the returned lambdas will be called after 'revert-buffer-function' to restore a state. >> +(defvar-local revert-buffer-state-functions nil >> + "Functions to save and restore any state during `revert-buffer'. >> +This variable is a list of functions that are called before >> +reverting the buffer. These functions should return a lambda >> +that will be called after reverting the buffer >> +to restore a previous state saved in that lambda.") > > The last sentence needs to be reworded, because it is not clear how > functions (in plural) can return a lambda (in singular). Also, the > doc string should describe how the function is called (with no > arguments, I guess?), and that all those functions will be called one > by one in the order of the list. Here is an improved docstring: (defvar-local revert-buffer-state-functions nil "Functions to save and restore any state during `revert-buffer'. This variable is a list of functions that are called before reverting the buffer. Each of these functions are called without arguments and should return a lambda that can restore a previous state of the buffer. Then after reverting the buffer each of these lambdas will be called one by one in the order of the list to restore previous states of the buffer. An example of the buffer state is keeping the buffer read-only, or keeping minor modes, etc.") > Finally, this needs to be documented in NEWS and the ELisp reference > manual. If this docstring is ok, then it could be adapted to the ELisp reference manual.