I am trying to setup emacs as server so that emacs (same instance) can be invoked from a file browser like nautilus
Results not satisfactory
I have the foll. in
[Desktop Entry] Name=EmacsClient GenericName=Text Editor Comment=Edit text MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; Exec=emacsclient -n -a emacs %F Icon=emacs Type=Application Terminal=false Categories=Development;TextEditor; StartupWMClass=Emacs
(server-start) in my init
When I try that I get two icons for emacs in ubuntu launcher -- one is 'fake' ie it does not respond to click
- emacs started with --daemon
- emacs.desktop as earlier described
However now closing a window with the 'X' does not prompt to save files Nor at system shutdown time
tried adding this to my init
(defun shutdown-emacs-server () (interactive) (when (not (eq window-system 'x)) (message "Initializing x windows system.") (x-initialize-window-system) (when (not x-display-name) (setq x-display-name (getenv "DISPLAY"))) (select-frame (make-frame-on-display x-display-name '((window-system . x))))) (let ((last-nonmenu-event nil)(window-system "x"))(save-buffers-kill-emacs)))
And then an explicit shutdown command needs to be issued:
$ emacsclient -e '(shutdown-emacs-server)'
But this is unreliable -- sometimes it pops up the save dialog, sometimes not
So any suggestions on how to use emacs as a server?
[Ubuntu xenial running unity]