GNU bug report logs - #79065
31.0.50; [PATCH] Allow inverting the meaning of 'quit-window-kill-buffer'

Previous Next

Package: emacs;

Reported by: Jim Porter <jporterbugs <at> gmail.com>

Date: Mon, 21 Jul 2025 05:24:02 UTC

Severity: normal

Tags: patch

Found in version 31.0.50

To reply to this bug, email your comments to 79065 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to rudalics <at> gmx.at, bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 21 Jul 2025 05:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jim Porter <jporterbugs <at> gmail.com>:
New bug report received and forwarded. Copy sent to rudalics <at> gmx.at, bug-gnu-emacs <at> gnu.org. (Mon, 21 Jul 2025 05:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Sun, 20 Jul 2025 22:22:53 -0700
[Message part 1 (text/plain, inline)]
X-Debbugs-Cc: rudalics <at> gmx.at

For a long time, I've had a bit of code in my config to invert the 
default behavior of 'quit-window', so that it normally kills the buffer, 
but buries it with the prefix arg. With bug#76248, I now have almost 
what I want in Emacs proper (thanks!), except without the prefix arg 
behavior.

Attached is a patch to do this. Hopefully the documentation is ok, but 
I'm open to other wordings. I fear my current wording might be a bit 
convoluted...
[0001-Allow-inverting-the-meaning-of-quit-window-kill-buff.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 21 Jul 2025 08:29:02 GMT) Full text and rfc822 format available.

Message #8 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Jim Porter <jporterbugs <at> gmail.com>, 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 21 Jul 2025 10:28:18 +0200
> For a long time, I've had a bit of code in my config to invert the
> default behavior of 'quit-window', so that it normally kills the
> buffer, but buries it with the prefix arg. With bug#76248, I now have
> almost what I want in Emacs proper (thanks!), except without the
> prefix arg behavior.
>
> Attached is a patch to do this. Hopefully the documentation is ok, but
> I'm open to other wordings. I fear my current wording might be a bit
> convoluted...

IIUC the current behavior has the prefix argument simply ignore
'quit-window-kill-buffer'.  With your patch it inverts whatever that
option prescribed till now.  Right?  If so, this would constitute an
incompatible change and we probably should convey the behavior you want
via a new value for 'quit-window-kill-buffer' itself.  In either case,
the doc-string of 'quit-window-kill-buffer' would have to be amended
accordingly and the new behavior be called out in NEWS.

Thanks, martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 21 Jul 2025 11:58:02 GMT) Full text and rfc822 format available.

Message #11 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: rudalics <at> gmx.at, 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50;
 [PATCH] Allow inverting the meaning of 'quit-window-kill-buffer'
Date: Mon, 21 Jul 2025 14:57:10 +0300
> Cc: rudalics <at> gmx.at
> Date: Sun, 20 Jul 2025 22:22:53 -0700
> From: Jim Porter <jporterbugs <at> gmail.com>
> 
> +If @var{kill} is the special value @code{invert}, or when calling
> +interactively with the prefix argument, then @code{quit-window} inverts
> +the meaning of @code{quit-window-kill-buffer}, so that when it would
> +normally kill the buffer, it buries it instead, and vice versa.

'invert' is a problematic symbol for this purpose, because it doesn't
tell what will happen.  I prefer to use 2 symbols with explicit names,
'kill' and 'bury', instead, and have the prefix argument compute the
value by looking at the value of quit-window-kill-buffer.  This way, a
Lisp program will tell explicitly what it does, and interactive usage
still "inverts" the value of the option.

>  (defun quit-window (&optional kill window)
>    "Quit WINDOW and bury its buffer.
> -WINDOW must be a live window and defaults to the selected one.
> -With prefix argument KILL non-nil, kill the buffer instead of
> -burying it.
> +WINDOW must be a live window and defaults to the selected one.  Kill the
> +buffer instead according to `quit-window-kill-buffer' (which see).
> +
> +If KILL is `invert' (interactively, with the prefix argument), then

When you mention literal symbols in doc strings, please use

  If KILL is the symbol `invert', ....

This prevents Emacs from accidentally creating a false link leading
nowhere relevant.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 21 Jul 2025 12:03:02 GMT) Full text and rfc822 format available.

Message #14 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: jporterbugs <at> gmail.com, 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50;
 [PATCH] Allow inverting the meaning of 'quit-window-kill-buffer'
Date: Mon, 21 Jul 2025 15:02:32 +0300
> Date: Mon, 21 Jul 2025 10:28:18 +0200
> From:  martin rudalics via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
>  > For a long time, I've had a bit of code in my config to invert the
>  > default behavior of 'quit-window', so that it normally kills the
>  > buffer, but buries it with the prefix arg. With bug#76248, I now have
>  > almost what I want in Emacs proper (thanks!), except without the
>  > prefix arg behavior.
>  >
>  > Attached is a patch to do this. Hopefully the documentation is ok, but
>  > I'm open to other wordings. I fear my current wording might be a bit
>  > convoluted...
> 
> IIUC the current behavior has the prefix argument simply ignore
> 'quit-window-kill-buffer'.  With your patch it inverts whatever that
> option prescribed till now.  Right?  If so, this would constitute an
> incompatible change and we probably should convey the behavior you want
> via a new value for 'quit-window-kill-buffer' itself.  In either case,
> the doc-string of 'quit-window-kill-buffer' would have to be amended
> accordingly and the new behavior be called out in NEWS.

The user option quit-window-kill-buffer is new in Emacs 31, so I don't
think we need to mark any changes in it as incompatible.  Or did I
miss something?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 21 Jul 2025 13:58:02 GMT) Full text and rfc822 format available.

Message #17 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jporterbugs <at> gmail.com, 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 21 Jul 2025 15:56:50 +0200
> The user option quit-window-kill-buffer is new in Emacs 31, so I don't
> think we need to mark any changes in it as incompatible.  Or did I
> miss something?

The doc-string of 'quit-window-kill-buffer' would still have to be
rewritten from scratch.  Or did I miss something?

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 21 Jul 2025 14:16:01 GMT) Full text and rfc822 format available.

Message #20 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: jporterbugs <at> gmail.com, 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 21 Jul 2025 17:15:06 +0300
> Date: Mon, 21 Jul 2025 15:56:50 +0200
> Cc: jporterbugs <at> gmail.com, 79065 <at> debbugs.gnu.org
> From: martin rudalics <rudalics <at> gmx.at>
> 
>  > The user option quit-window-kill-buffer is new in Emacs 31, so I don't
>  > think we need to mark any changes in it as incompatible.  Or did I
>  > miss something?
> 
> The doc-string of 'quit-window-kill-buffer' would still have to be
> rewritten from scratch.  Or did I miss something?

Not from scratch, but it will need to be updated, yes.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 28 Jul 2025 06:18:03 GMT) Full text and rfc822 format available.

Message #23 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Jim Porter <jporterbugs <at> gmail.com>, 79065 <at> debbugs.gnu.org, rudalics <at> gmx.at
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 28 Jul 2025 09:14:52 +0300
>> +If @var{kill} is the special value @code{invert}, or when calling
>> +interactively with the prefix argument, then @code{quit-window} inverts
>> +the meaning of @code{quit-window-kill-buffer}, so that when it would
>> +normally kill the buffer, it buries it instead, and vice versa.
>
> 'invert' is a problematic symbol for this purpose, because it doesn't
> tell what will happen.  I prefer to use 2 symbols with explicit names,
> 'kill' and 'bury', instead, and have the prefix argument compute the
> value by looking at the value of quit-window-kill-buffer.  This way, a
> Lisp program will tell explicitly what it does, and interactive usage
> still "inverts" the value of the option.

For example, 'windmove-display-no-select' has the same purpose,
but avoids the symbol 'invert' by using:

  (xor (consp arg) windmove-display-no-select)

Would it be possible to use the same logic here?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 28 Jul 2025 07:20:02 GMT) Full text and rfc822 format available.

Message #26 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> linkov.net>, Eli Zaretskii <eliz <at> gnu.org>
Cc: Jim Porter <jporterbugs <at> gmail.com>, 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 28 Jul 2025 09:18:42 +0200
> For example, 'windmove-display-no-select' has the same purpose,
> but avoids the symbol 'invert' by using:
>
>    (xor (consp arg) windmove-display-no-select)
>
> Would it be possible to use the same logic here?

The problem with 'quit-window-kill-buffer' is that it also can be a list
of major modes.  What should 'invert' or 'xor' with or without a prefix
argument produce in such a case?  Kill the buffer if it is a member of
that list, kill it if it not a member of that list ...

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 28 Jul 2025 17:19:02 GMT) Full text and rfc822 format available.

Message #29 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Jim Porter <jporterbugs <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>,
 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 28 Jul 2025 20:17:42 +0300
>> For example, 'windmove-display-no-select' has the same purpose,
>> but avoids the symbol 'invert' by using:
>>
>>    (xor (consp arg) windmove-display-no-select)
>>
>> Would it be possible to use the same logic here?
>
> The problem with 'quit-window-kill-buffer' is that it also can be a list
> of major modes.  What should 'invert' or 'xor' with or without a prefix
> argument produce in such a case?  Kill the buffer if it is a member of
> that list, kill it if it not a member of that list ...

Usually a per-mode value is defined by mode hooks like

  (add-hook 'Info-mode-hook (lambda () (setq-local quit-window-kill-buffer t)))

Then the prefix argument will invert the buffer-local value.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Mon, 28 Jul 2025 18:57:02 GMT) Full text and rfc822 format available.

Message #32 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>, Juri Linkov <juri <at> linkov.net>,
 Eli Zaretskii <eliz <at> gnu.org>
Cc: 79065 <at> debbugs.gnu.org
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Mon, 28 Jul 2025 11:56:26 -0700
On 7/28/2025 12:18 AM, martin rudalics via Bug reports for GNU Emacs, 
the Swiss army knife of text editors wrote:
> The problem with 'quit-window-kill-buffer' is that it also can be a list
> of major modes.  What should 'invert' or 'xor' with or without a prefix
> argument produce in such a case?  Kill the buffer if it is a member of
> that list, kill it if it not a member of that list ...

My reasoning was that the prefix argument means, "Do the opposite of 
what quit-window' would otherwise do." (Hence the name 'invert'.)

However, another way to do this would be a tri-state:

* no prefix: obey 'quit-window-kill-buffer'
* C-u: always kill
* C--: always bury

This avoids the 'invert' symbol entirely, and also avoids the additional 
mental complexity of trying to predict what will happen when using the 
prefix argument while 'quit-window-kill-buffer' is a list. (That 
complexity is still there to a degree even without the prefix arg, but 
it might be clearer for users to have a way of saying, "I want this 
behavior," rather than just, "I want the opposite of the default.")

The above tri-state is something I do fairly often in my own Emacs 
config, though I'm not sure how common it is in Emacs itself. In this 
scheme, C-u means (very roughly) to do something "more" (e.g. more 
strongly), and C-- means the opposite: to do something "less", or in a 
diminished way. Since "C-u quit-window" in Emacs 30 is a stronger form 
of the default (quit the window *and* kill the buffer), "C-- 
quit-window" could mean the weaker form (quit the window and *never* 
kill the buffer).

From my PoV, I'd be happy with this scheme or the one I originally 
proposed. It would just involve relearning a bit of muscle memory.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Tue, 29 Jul 2025 10:45:02 GMT) Full text and rfc822 format available.

Message #35 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: rudalics <at> gmx.at, 79065 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Tue, 29 Jul 2025 13:44:23 +0300
> Date: Mon, 28 Jul 2025 11:56:26 -0700
> Cc: 79065 <at> debbugs.gnu.org
> From: Jim Porter <jporterbugs <at> gmail.com>
> 
> On 7/28/2025 12:18 AM, martin rudalics via Bug reports for GNU Emacs, 
> the Swiss army knife of text editors wrote:
> > The problem with 'quit-window-kill-buffer' is that it also can be a list
> > of major modes.  What should 'invert' or 'xor' with or without a prefix
> > argument produce in such a case?  Kill the buffer if it is a member of
> > that list, kill it if it not a member of that list ...
> 
> My reasoning was that the prefix argument means, "Do the opposite of 
> what quit-window' would otherwise do." (Hence the name 'invert'.)
> 
> However, another way to do this would be a tri-state:
> 
> * no prefix: obey 'quit-window-kill-buffer'
> * C-u: always kill
> * C--: always bury
> 
> This avoids the 'invert' symbol entirely, and also avoids the additional 
> mental complexity of trying to predict what will happen when using the 
> prefix argument while 'quit-window-kill-buffer' is a list. (That 
> complexity is still there to a degree even without the prefix arg, but 
> it might be clearer for users to have a way of saying, "I want this 
> behavior," rather than just, "I want the opposite of the default.")

That might solve the interactive case (though maybe not in a very
convenient way), but what about calls from Lisp?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Tue, 29 Jul 2025 16:37:01 GMT) Full text and rfc822 format available.

Message #38 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rudalics <at> gmx.at, 79065 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Tue, 29 Jul 2025 09:35:57 -0700
On 7/29/2025 3:44 AM, Eli Zaretskii wrote:
>> From: Jim Porter <jporterbugs <at> gmail.com>
>>
>> However, another way to do this would be a tri-state:
>>
>> * no prefix: obey 'quit-window-kill-buffer'
>> * C-u: always kill
>> * C--: always bury
[snip]
> 
> That might solve the interactive case (though maybe not in a very
> convenient way), but what about calls from Lisp?

I think we could make the Lisp calls work like you suggested, where the 
KILL argument can be:

* 'nil': obey 'quit-window-kill-buffer'
* 'bury': always bury
* 'kill' (or any other non-nil value for compatibility): always kill

As for interactive use, I'm not sure whether the behavior proposed above 
would be more convenient for the average user or whether having the 
prefix arg mean "do the opposite of what it would normally do" would be 
more convenient. The behavior above is simpler to explain though, and 
when using a prefix arg, a user can always predict what will actually 
happen.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79065; Package emacs. (Wed, 30 Jul 2025 08:18:02 GMT) Full text and rfc822 format available.

Message #41 received at 79065 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Jim Porter <jporterbugs <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 79065 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#79065: 31.0.50; [PATCH] Allow inverting the meaning of
 'quit-window-kill-buffer'
Date: Wed, 30 Jul 2025 10:17:43 +0200
> I think we could make the Lisp calls work like you suggested, where the KILL argument can be:
>
> * 'nil': obey 'quit-window-kill-buffer'
> * 'bury': always bury
> * 'kill' (or any other non-nil value for compatibility): always kill

We should rename KILL to BURY-OR-KILL then.  I still don't know whether
and how we would integrate the list of major modes value.  Maybe we
should take a step back and try without that list value.  As Juri meant
the list could be emulated with the help of buffer-local values
installed by the major modes.

martin




This bug report was last modified 50 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.