unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 69511@debbugs.gnu.org
Subject: bug#69511: Restore any state after revert-buffer
Date: Sun, 03 Mar 2024 09:59:24 +0200	[thread overview]
Message-ID: <864jdnpw83.fsf@mail.linkov.net> (raw)
In-Reply-To: <867cikpkpm.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 02 Mar 2024 20:11:49 +0200")

>> 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.





  reply	other threads:[~2024-03-03  7:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 17:55 bug#69511: Restore any state after revert-buffer Juri Linkov
2024-03-02 18:11 ` Eli Zaretskii
2024-03-03  7:59   ` Juri Linkov [this message]
2024-03-03  9:04     ` Eli Zaretskii
2024-03-03 17:28       ` Juri Linkov
2024-03-03 17:43         ` Eli Zaretskii
2024-03-03 17:55           ` Juri Linkov
2024-03-03 18:46             ` Eli Zaretskii
2024-06-03  6:35               ` Juri Linkov
2024-06-03 16:55                 ` Juri Linkov
2024-03-03  2:46 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-03  7:55   ` Juri Linkov
2024-03-03  9:03     ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-04  6:37 ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=864jdnpw83.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=69511@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).