Subject: bug#13522: 24.2; save-buffer removes edited file under some conditions

From: Vincent Lefevre <[email-masked]>
Date: Mon, 14 Mar 2022 18:32:37 +0100

On 2022-03-14 19:02:14 +0200, Eli Zaretskii wrote:
> > Note that in any case, C-x C-c in Emacs does not replace Ctrl-C in the
> > terminal, as with C-x C-c, Emacs quits with a zero exit status, which
> > may not be what one wants. Example: in a "svn ci", one may want to
> > abort the commit without losing the text written in Emacs. Ctrl-C in
> > the terminal (where "svn ci" has been run) allows one to do that.
> 
> Emacs is not SVN, and doesn't work in transactions.

You missed my point. "svn ci" runs an editor, e.g. Emacs. If I want
to interrupt (i.e. abort) the "svn ci", I need to do Ctrl-C in the
terminal. The same is true with shell scripts that run Emacs.

> > SIGINT could be equivalent to something like C-g in Emacs + quit
> > without saving (a backup of the current buffer can be kept),
> > exiting with a non-zero exit status. Note that you do not need to
> > do everything in the signal handler. In general, what is done is
> > just to set some variable saying that SIGINT has been received.
> > The abort of the operations is done in the main code.
> 
> When the program is delivered a fatal signal, the only way to get back
> to "main code" is longjmp from the signal handler, which is already
> "not recommended", to say the least.

No, SIGINT is *not* a fatal signal. What is done with it is what the
application decides. You don't need a longjmp. Setting a variable in
the signal handler and handle it in the general code should be
sufficient.

BTW, there's the same issue when requesting to close the X11 window.
I get a "Question" dialogue, asking me whether I want to save the
file. I answer "No". I get another question saying

  Modified buffers exist; exit anyway?

I answer "Yes". Emacs quits, but the file is no longer there; there's
just the backup.

Handling SIGINT could be similar to this case (which should be fixed),
where the answers "No" and "Yes" are assumed.

-- 
Vincent Lefèvre <[email-masked]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)