emacsubuntuemacs23

How to gracefully shutdown emacs daemon?


On login to Ubuntu, I start an Emacs (version 23) daemon using Ubuntu's Startup programs. I then start Emacs clients whenever I need to edit something. When I logoff from Ubuntu, it says Emacs is still running, of course. I need to attach a script somewhere to tell Gnome to shutdown emacs when I logoff/shutdown.

  1. What should the script look like? "kill-emacs" doesn't seem to work.

  2. Where should I put this script? There's nothing in the startup programs (System->Sessions menu) panel that looks useful. I'd prefer something that works in the user's account, rather than hacking the PostSession script or something else with root access.


Solution

  • This linuxquestions.org page has a Python script that can be run during login that listens for the 'save yourself' event that Gnome emits during shutdown. You could modify that to do the:

    emacsclient -e '(save-buffers-kill-emacs)'
    

    Official docs: https://www.emacswiki.org/emacs/EmacsAsDaemon#toc8