views:

52

answers:

2

I have setup emacs -daemon to run on login to Gnome and associated emacsclient with .cpp and .py files that I work with in Eclipse in order that emacs is used as my default editor for these files when selected within Eclipse. This way I can get a good work flow combining the editing capabilities of emacs and the project/build management and debugging facilities of Eclipse.

Anyhoo... I want to prevent C-x C-c from closing the Emacs frame I am currently editing in if it is the only Emacs frame remaining visible at any given moment.

Is there a way of querying the daemon Emacs process in order to find out how many frames are open and override the default C-x C-c behaviour to do nothing (if only 1 frame remaining) thereby ensuring there is always at least one visible frame open at all times?

Some elisp that implements this behaviour and that can be added to my .emacs would be great.

Bonus Points :¬) I have aliases that map vi, emacs etc... to "emacsclient -c", so I get emacs frames coming and going all the time in general. A further enhancement would be for Eclipse to send files that I want to edit directly to a specific frame e.g. the 1st frame opened with emacsclient -c.

A: 

Within emacs-clients, save-buffers-kill-terminal only calls server-save-buffers-kill-terminal, so you might want to install an advice onto that to not affect non-client frames. The frame-list function cal be used to introspect the currently existing frames. It apparently always includes one entry for the daemon process itself, and then one for each open frame.

(defadvice server-save-buffers-kill-terminal (around dont-kill-last-client-frame activate)
  (when (< 2 (length (frame-list)))
    ad-do-it))
rafl
A: 

Make emacs immortal (what ever the way you've started it) :

(defadvice kill-emacs (around emacs-immortal) nil)
(ad-activate 'kill-emacs)

Use ad-deactivate to deactivate this trick.

Jérôme Radix