GNU bug report logs - #51993
29.0.50; [PATCH] Killing emacsclient terminal with `server-stop-automatically' doesn't prompt to save files

Previous Next

Package: emacs;

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

Date: Sat, 20 Nov 2021 04:30:01 UTC

Severity: normal

Tags: patch

Found in version 29.0.50

Done: Jim Porter <jporterbugs <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jim Porter <jporterbugs <at> gmail.com>
To: Gregory Heytings <gregory <at> heytings.org>
Cc: larsi <at> gnus.org, 51993 <at> debbugs.gnu.org, eliz <at> gnu.org
Subject: bug#51993: 29.0.50; [PATCH] Killing emacsclient terminal with `server-stop-automatically' doesn't prompt to save files
Date: Tue, 23 Nov 2021 14:08:05 -0800
On 11/23/2021 12:37 PM, Gregory Heytings wrote:
> 
>>> This is not a bug, this is the intented behavior of that feature
>>
>> I started that discussion (and participated throughout it), and I 
>> don't think we actually agreed that this was the intended behavior.
>>
> 
> This is the behavior I intended (and described in the docstring and 
> manual), if you prefer.  And you did not make further comments in 
> bug#51377, which can be interpreted as a kind of agreement.

Unfortunately, I was sidetracked by other things and didn't have a 
chance to comment before Lars merged the patch. Since it had already 
been merged, I thought it best to follow up in a separate bug once I had 
made concise steps to reproduce the issue and a patch to fix it.

>> I should stress that the case I brought up above is just a 
>> counterexample to show a problem with a previous implementation strategy
>>
> 
> Which problem?

Prior to that comment, your proposed implementation would kill Emacs on 
a timer when there were no non-daemon frames left, which could result in 
unsaved changes to files being lost. I replied to point that out and 
showed some steps to reproduce it: 
<https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-10/msg02163.html>.

>> The current behavior on Emacs 29 certainly isn't what I personally 
>> intended when bringing the idea up on emacs-devel.
>>
> 
> Is the current behavior of Emacs 29 with my patch and 
> (server-stop-automatically 'kill-terminal) still not what you want?  If 
> not, what is missing?

If I'm understanding your patch, the behavior I'm looking for is 
essentially a combination of `kill-terminal' and `delete-last-frame'. I 
may be misunderstanding it though, since the call tree in your patch 
confuses me a bit: with `kill-terminal', 
`server-save-buffers-kill-terminal` calls 
`server-stop-automatically--handle-delete-frame', which then calls 
`server-save-buffers-kill-terminal' again.

One of my other goals in my patch was to simplify the logic in 
`server-save-buffers-kill-terminal' and 
`server-stop-automatically--handle-delete-frame' somewhat. Rather than 
to have `server-stop-automatically--handle-delete-frame' check if it was 
called by `save-buffers-kill-terminal', I found that the implementation 
was simpler (to me, anyway) if that logic was lifted up into 
`server-save-buffers-kill-terminal'.

One benefit of this simplification is that it causes fewer changes in 
behavior compared to not using `server-stop-automatically'. For example, 
normally when a user kills an emacsclient terminal, Emacs will prompt 
about saving files *before* deleting any frames. This is nice because it 
allows the user to back out by pressing C-g, leaving Emacs in (almost) 
the same state it was previously. My patch handles that and allows the 
user to press C-g and leave all the current frames open.

With your patch in this bug, using `kill-terminal' and pressing C-x C-c 
will close all frames for the current client but the current one, and 
only then prompt the user to save buffers. Thus, pressing C-g will leave 
the user with only that last client frame still open.

(Note: to test this behavior, you probably need multiple clients open as 
I outlined in the first post to this bug.)

>> I'm concerned that we're now up to 4 different behaviors, when I think 
>> two of them are just the result of a miscommunication between the two 
>> of us.
> 
> They are not, AFAICS.  The four behaviors are four reasonable options, 
> each of which can (and is) described in a short paragraph, and 
> corresponds to a different user preference.  I see no reason to remove 
> any of the current three behaviors because of an unspecified "problem".  
> Especially given that all these behaviors are implemented in only ~50 
> lines of Lisp.

I've specified the problems. I can try to clarify if there's any 
confusion though. This bug is one such problem.

I don't think that a user who opts in to stopping the Emacs daemon 
automatically is *also* opting in to changing the behavior of whether 
Emacs will prompt about saving files when killing a (non-last) client. 
Since there are other clients, the daemon won't be killed, and so the 
behavior should be identical to what happens without 
`server-stop-automatically'. As a user, I would find it very strange 
that enabling `server-stop-automatically' would change Emacs' behavior 
in ways *other than* stopping the server in certain cases.

Of course, a user may indeed want to be able to kill a client (but not 
the daemon) without being prompted to save files, but I think that's 
independent of whether the daemon should be stopped when the last client 
exits. If users *do* want this behavior, we could add a totally separate 
option for it; this would allow users who don't want to be prompted but 
also don't want `server-stop-automatically' to use it.




This bug report was last modified 2 years and 163 days ago.

Previous Next


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