Coffeecupp_ over at the Emacs reddit asks if there’s a way on macOS to prevent Emacs from quitting when the last window is closed. That’s not a problem I have but I learned a couple of useful things from the discussion.
First, and this applies to all OSes, mbork suggests just setting the confirm-kill-emacs
variable:
(setq confirm-kill-emacs #'y-or-n-p) ; or yes-or-no-p is you're really paranoid
For some technical reasons that doesn’t do quite what coffeecupp_ needed but it did solve a problem for me. I have a periodic task in which I need to take data from a Notes app window into Emacs. I do that be positioning my Emacs window over the Notes window so just the data I’m interested in shows. Afterwards, I usually use Cmd+Tab to bring the Notes app to the foreground so I can kill it with Cmd+q. Of course, I usually type Cmd+q first and kill Emacs instead.
I was sure that Emacs had a way to ask for confirmation before killing but I never got around to finding out what it is. Thanks to mbork, I now know so I won’t have that particular problem again. Normally, I hate confirmation messages like that but I kill Emacs on purpose much less frequently than I do by accident so it make sense for my particular workflow.
The other thing I learned is the difference between emacs –daemon and starting server mode in init.el. I always assumed they did pretty much the same thing but it turns out there’s a useful difference. If your goal is to ensure that Emacs keeps running—as opposed to just enabling emacsclient
—then you should use emacs --daemon
. The answers in the above Stack Overflow question explain this in a little more detail.
So, not bad for a question I didn’t care about in the first place.
UPDATE
: y-or-no-p → y-or-n-p.