Emacs C-x C-c overriding save-buffers-kill-terminal if within last open frame

女生的网名这么多〃 提交于 2019-12-11 03:17:51

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/3691028/emacs-c-x-c-c-overriding-save-buffers-kill-terminal-if-within-last-open-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!