Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gracefully shutdown emacs daemon? [closed]

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.

like image 995
projectshave Avatar asked Jul 22 '09 19:07

projectshave


People also ask

How do I shut down Emacs daemon?

Stopping the Emacs Daemon The simplest way to stop the emacs daemon from within emacs is to use the kill-emacs or save-buffers-kill-emacs commands. Here is a more advanced function will ask if you want to save any modified buffers, quit your session, and shutdown the associated emacs server instance.

How do I restart my Emacs server?

With server-start To start a server in an existing Emacs session, run M-x server-start. A server started in this manner will close when the last visible Emacs frame closes. If you want Emacs to automatically run a server on startup, add the following to your configuration file.

How do I know if my Emacs server is running?

In emacs check the value of server-socket-dir . Check if there are some files in this directory. If does, then the server is running.

What is EmacsClient?

EmacsClient allows one to open a file for editing in an already running Emacs. Because it doesn't start a new Emacs instance at each invocation, you can set up EmacsClient as the default editor, e.g. in the environment variable EDITOR or VISUAL.


1 Answers

ShreevatsaR is right, the answer is kill-emacs or save-buffers-kill-emacs, both of which are interactive, and so can be run from within Emacs with M-x save-buffers-kill-emacs. This is probably the best way to do it, since you will get to save modified files.

Another alternative is to make a shell file like this:

#!/bin/bash emacsclient -e "(kill-emacs)" 

Which you can run from wherever you like (menu icon, panel, etc).

like image 183
haxney Avatar answered Sep 29 '22 08:09

haxney