I recently bought my first Mac in a decade and am in the process of configuring it. I'm an Emacs user and have determined I want just regular Emacs not Aquamacs so that I can use my existing configuration from other operating systems. I've tried following a lot of how-tos I've found online (like this one, this one and this one from the site from which I downloaded Emacs), and have tried combining the pieces any number of ways, but have never gotten things into a state even approaching what I'm used to/hoping for:
- An Emacs daemon starts running either at startup or as soon as I need it; either is fine. Any new Emacs frames are backed by the same server.
- When I open a text file from the Finder the file opens in Emacs, in an existing graphical frame if possible.
- If I run Emacs.app, the system reuses the emacs daemon that is running in the background instead of starting a new instance and opening a new window on it. (hat tip)
- When I run Emacs from a terminal the terminal goes about its business without waiting for me to finish with Emacs (unless I use '-nw')
- AFAIK at no point during the operations described above should Emacs end up in a state ("server-edit mode?") where it's waiting for me to type
C-x #
, although I don't have a deep understanding of this one. - (I would regard this as a bonus) There is some way for me to invoke Emacs from a terminal so that Emacs reuses an existing frame if possible.
How could I configure Emacs to behave like this?
I'm particularly perplexed by getting the Finder to open things in Emacs that way I want (#2), since the guides I've found generally create a number of aliases, Applescripts, bash scripts, etc. and I'm not sure which I want to tell the Finder to use to open text files.
Thanks!
A. @lawlist asks, "Is a new frame being opened by default when you open a new file from the terminal even though there is an existing frame?" The answer is that if I start a server at startup as described here, open a frame, and then open a file by typing /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n <whatever>
, I can get the file to open in an existing frame. If there is no frame currently open I have to use "-nc" or when I try to open a file nothing happens.
B. @lawlist asks, "Do you want the daemon running on login, or would it be sufficient to load Emacs manually after the login?" Running manually would be fine.
M-x server-start
will manually start the server so thatemacsclient
can communicate with it. I have placed(server-start)
in myinit.el
file instead of using a daemon at login -- however, many people prefer the daemon login option. And of course, the.emacs
file would be a suitable place for(server-start)
.ns-find-file
-- which is activated automatically when a file is associated with Emacs.app. My intercept file function in the links above also modifiesns-find-file
if that is something that interests you. Of course, you need Emacs built--with-ns
.