how do i keep emacs server running when the current window is closed (x) on windows using emacsW32?
Asked Answered
S

1

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!

Sewing answered 4/1, 2010 at 19:7 Comment(2)
May I ask how you "make the current frame invisible and not kill the emacs server process"?Scut
Never mind, I found it... for reference, this works perfectly: emacs-fu.blogspot.com/2009/03/windows-and-daemons.htmlScut
N
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))
Norwegian answered 4/1, 2010 at 21:7 Comment(2)
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 :-)Sewing
+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.Scut

© 2022 - 2024 — McMap. All rights reserved.