Subject: Re: bug#77276: 30.1; find-alternate-file no longer disconnects emacsclient

From: Eli Zaretskii <[email-masked]>
Date: Wed, 26 Mar 2025 15:02:38 +0200

> Date: Wed, 26 Mar 2025 07:43:42 -0400
> From:  "Jay Berkenbilt" via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> The issue I'm describing occurs in emacs 30 but not emacs 29 or earlier. I noticed it in during emacs 30.0.93
> but didn't immediately recognize it as a bug. You can see the generated information below, but I have also
> reproduced this on macOS with emacs -Q, and it also happens on my Linux system (with emacs -Q) where I
> build emacs myself, so I don't believe this is environment-specific.
> 
> When you run emacsclient to open a file in an existing emacs, and then run M-x find-alternate-file on the
> same file (e.g., C-x C-v RET), the file loses its connection with emacsclient, but emacsclient does not exit. In
> prior versions, emacsclient would exit after C-x C-v RET.
> 
> emacs 30:
> shell% emacsclient /tmp/a
> emacs: C-x C-v RET    ;; emacsclient is still waiting
> emacs: C-x #   ;; nothing happens; the buffer is no longer connected with emacsclient
> 
> emacs 29 and earlier:
> shell% emacsclient /tmp/a
> emacs: C-x C-v RET    ;; emacsclient exits
> emacs: C-x #   ;; nothing happens; the buffer is no longer connected with emacsclient
> 
> Explicitly killing the buffer with C-x k does cause emacsclient to exit.
> 
> This is probably related to a change in find-alternate-file as the problem occurs with emacs 30 and
> emacsclient from emacs 29 but not with emacs 29 and emacsclient from emacs 30.

This was a deliberate change, see bug#65277.  The previous behavior
was surprising at least, if not a simple bug.

> I consider the older behavior to be more desirable and less surprising as emacsclient shouldn't hang around
> waiting for an event that will never occur. In both emacs 29 and 30, CTRL-c on emacsclient will cause the
> buffer to be removed from emacs before but not after C-x C-v, which I consider to be correct/expected
> behavior. The fact that CTRL-c on emacsclient after C-x C-v leaves the buffer alone also shows that
> emacsclient is no longer connected to the file in emacs 30 after C-x C-v. Note that explicitly killing the buffer
> with C-x k still causes emacsclient to exit.
> 
> I have been using this technique since the dawn of time, perhaps as long as I've been using emacsclient
> (which probably goes back to emacs 18 for me) to intentionally disconnect a file from emacsclient. I'm not
> sure whether there's a better way. I'm trying to retrain my muscle memory to emacsclient -n, but this change
> of behavior has made me realize how deeply this is ingrained into my habits. Anyway, it's not uncommon for
> me to do something like `emacsclient *.tf` and then flip through the files doing C-x # on the ones I don't want
> and C-x C-v RET on the ones I do.

I don't think we should go back to previous behavior, but we might
have a user option to get that old behavior back.