I'd like to propose a change to emacs-vcs ebuild. Primary aim of this patch is allow emacs to shutdown gracefully. Current shutdown method does not trigger kill-emacs-query-functions, kill-emacs-hook, server-done-hook hooks. Reproducible: Always
Created attachment 247762 [details, diff] init.d script patch
Have you tested this with both baselayout-1 and openrc?
(In reply to comment #2) > Have you tested this with both baselayout-1 and openrc? > Tested only under baselayout-1. But I doubt openrc differs somehow. The problem actually in emacs itself. See http://stackoverflow.com/questions/3737207/emacsclient-hook-on-kill for details.
(In reply to comment #3) > The problem actually in emacs itself. See > http://stackoverflow.com/questions/3737207/emacsclient-hook-on-kill for > details. Right, and the discussion that is linked there was a previous request from Tassilo Horn (see URL), with bug 246462 being the corresponding Gentoo bug. And now I remember that we have already implemented something to provide for such additional functionality when stopping. Basically, you should set EMACS_STOP to point to a script that will call emacsclient. However, I'm reluctant to add any sort of interactive behaviour to the default shutdown sequence. Reception of SIGTERM in Emacs will call shut_down_emacs which at least autosaves all buffers, so there should be no data loss. Beyond that, users' preferences for shutdown behaviour may be very different, and I think that the EMACS_STOP solution is general enough to account for the different needs. *** This bug has been marked as a duplicate of bug 246462 ***
(In reply to comment #4) Ok, I see now. But why not add this or similar script to /usr/share/emacs... and provide it as a standard solution to stop reinventing the wheel each time?
The problem with external stop script now is that it cannot get environment variables from /etc/init.d runscript. To shutdown emacs properly at least USER, EMACS, PIDFILE should be exported. SVCNAME preferably too.
(In reply to comment #5) > But why not add this or similar script to /usr/share/emacs... and provide it > as a standard solution to stop reinventing the wheel each time? Yes, I'll consider this. It should go to /usr/libexec/emacs/ or /usr/share/doc/emacs-daemon-*/ though. And I won't assign EMACS_STOP by default. (In reply to comment #6) > The problem with external stop script now is that it cannot get environment > variables from /etc/init.d runscript. To shutdown emacs properly at least > USER, EMACS, PIDFILE should be exported. EMACS_DEBUG and EMACS_TIMEOUT, too. I wonder why nobody has complained yet that those variables are not exported. Seems that at least USER would be needed, unless one has a separate stop script for each user. > SVCNAME preferably too. This is an internal runscript variable, so it normally shouldn't be exported (also it was renamed to RC_SVCNAME in openrc, where SVCNAME is only kept for backwards compatibility).
Could you test if this change would suit your needs: http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1564 The emacs-stop.sh script is only meant as an example, therefore I've kept it as simple as possible. Especially, emacsclient calls (kill-emacs) only.
(In reply to comment #8) > Could you test if this change would suit your needs: > http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1564 > > The emacs-stop.sh script is only meant as an example, therefore I've kept it as > simple as possible. Especially, emacsclient calls (kill-emacs) only. > This simple example works ok except the case when some client is connected to emacsserver. In this case, a message asking to disconnect pops in emacs, but kill-emacs is never completed. Thus emacs will be killed after timeout. But that's not a real problem. The real problem with such simple script is that unsaved buffers are not saved. Thus we have a data loss. That's why I suggest you to add more logic (e.g. from my patch) to EMACS_LISP_EXPR, cause now it's plain error-prone.
As I said before, users' preferences may be very different. And there's no need to pass everything in emacsclient's argument, since any additional commands can be added to kill-emacs-hook. This has the additional advantage that it can be set individually by each user. But I've added a comment with a short explanation: http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1565
(In reply to comment #10) > As I said before, users' preferences may be very different. And there's no need > to pass everything in emacsclient's argument, since any additional commands can > be added to kill-emacs-hook. This has the additional advantage that it can be > set individually by each user. > > But I've added a comment with a short explanation: > http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1565 > Ok. You are a maintainer after all :) Release it!
Included with version 0.18. Thanks.