views:

1910

answers:

6

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.

+3  A: 

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).

haxney
I think what the questioner wants is something that can be put in a place that is automatically executed when GNOME is asked to log out. (So it's more of a Gnome/Ubuntu/X question than an Emacs question, actually.)
ShreevatsaR
+1  A: 

Hi,

you can put emacsclient -e "(kill-emacs)" in GDM's PostSession directory or directly in the Default script:

/etc/gdm/PostSession/Default

see also GDM documentation.

danielpoe
Thanks, but my post says I didn't want to use PostSession because it requires (AFAIK) root access to modify it. If a user can add something in autostart, there should be a way to add something to "autoshutdown".
projectshave
+3  A: 

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)"' thing.

(N.b. I haven't actually tested the script myself...)

genehack
A: 

Perhaps the most general solution would be to put a script in the system PostSession directory that runs every executable script in ~/.logout-d, or something similar. Then you can put whatever scripts you like in ~/.logout-d, and they will be run on logout.

The script might be as simple as run-parts ~/.logout.d.

Note: Untested, though I do use a startup script that does run-parts ~/.autostart.d, and that's been working fine forever.

Edit: Of course, it would be just as easy to modify the above python script to execute that same command, but I personally don't like the idea of loading a script for my entire session just to run commands on logout.

Ryan Thompson
+1  A: 

I think that using a script in /etc/init.d is a cleaner solution. Check here for more details http://www.emacswiki.org/emacs/EmacsAsDaemon

sub
+2  A: 
willert