2

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!

sbaker
  • 398
  • 1
  • 8
  • May I ask how you "make the current frame invisible and not kill the emacs server process"? – harpo Oct 07 '10 at 00:38
  • Never mind, I found it... for reference, this works perfectly: http://emacs-fu.blogspot.com/2009/03/windows-and-daemons.html – harpo Oct 07 '10 at 00:58

1 Answers1

2

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
  • 1,005
  • 6
  • 7
  • Thanks! Most of the time I'll be using C-x C-c, but found myself X'ing out the window recently & the server restarts were driving me crazy :-) – sbaker Jan 04 '10 at 21:43
  • +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 Oct 04 '10 at 22:05