views:

157

answers:

1

Hi,

I'm using EmacsW32 (patched) on windows. Emacs is running in server mode so that subsequent calls to emacsclientw open files in the same server session.

I have C-x C-c mapped to make the current frame invisible and not kill the emacs server process. I'd like clicking the window's X (close) button to also just hide the frame & not terminate the server process as it currently does.

Any ideas ? Thanks!

+1  A: 

Sure, I have a method of doing this. There may be refinements possible, but this is a good starting place.

First, I setup a variable and advise the kill-emacs function

(defvar bnb/really-kill-emacs nil)
(defadvice kill-emacs (around bnb/really-exit activate)
    "Only kill emacs if the variable is true"
    (if bnb/really-kill-emacs
        ad-do-it)
      (bnb/exit))

The bnb/exit function just makes the frame invisible like what you have bound to C-x C-c.

I then have an additional function to properly exit emacs if that is ever necessary. That will set the variable and call kill-emacs as follows.

(defun bnb/really-kill-emacs ()
    (interactive)
    (setq bnb/really-kill-emacs t)
    (kill-emacs))
bnbeckwith
myCubeIsMyCell
+1 Thanks for the tip... but would you mind providing the **bnb/exit** function, too? I put this code in my init.el, and now I can't exit without calling **bnb/really-kill-emacs** because it says "Symbol's function definition is void: bnb/exit". Sorry, I'm new to emacs and couldn't figure out how to write the function in question.
harpo