[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: graceful shutdown of non-interactive Elisp program
From: |
Eli Zaretskii |
Subject: |
Re: graceful shutdown of non-interactive Elisp program |
Date: |
Sun, 14 Jun 2020 18:01:10 +0300 |
> From: Paul Pogonyshev <pogonyshev@gmail.com>
> Date: Sat, 13 Jun 2020 23:42:51 +0200
>
> I'm trying to make a Elisp program that is run in a non-interactive mode,
> i.e. essentially as `emacs --batch
> --load myfile.el'. A normal way to shutdown terminal programs is with C-c,
> which is expected to be "graceful"
> shutdown, e.g. the program still has a chance to save files etc.
>
> However, with Elisp I'm not sure how to achieve that except for constantly
> modifying `kill-emacs-hook', which
> would be a nightmare from coding perspective.
>
> Naively I would expect this print "GOING DOWN" when aborted with C-c:
>
> $ emacs --batch --eval "(unwind-protect (while t) (message \"GOING
> DOWN\"))"
>
> For example, Python's handler of SIGINT raises an exception within the
> program, which unwinds the stack
> as usual and, unless caught, cause program termination after cleaning up as
> expected (e.g. running all
> `finally' clauses and closing all `with' context managers). However, in
> Elisp, as I understand, there is no way
> to have a say in handling SIGINT other than adding a function to
> `kill-emacs-hook'.
I don't think I follow. If you want to raise an exception from a
kill-emacs-hook (assuming that you want the unwind-protect forms to do
something), you can do that from kill-emacs-hook, no?
And if you had a say in handling SIGINT, what would you do in the
handler that you cannot do in kill-emacs-hook?
Also, you mention batch mode, but is it relevant? That is, are you
saying that Emacs behaves differently in an interactive session when
it gets a fatal signal?
I'm confused.