0

I'm using emacs26 on macOS and using server-client for the fast initialization.

However, it's a bit annoying that a new emacs instance is always spawning when I run "Emacs.app" with SpotLight instead of running 'emacsclient' in terminal. What I want is running emacs server as a background service when first emacs instance is created (when there is no running server), and other new instances are connected to the server without massive library loading.

To achieve that, I think these four functionalities are needed for the init.el.

  1. Check running emacs server.
  2. Run server as a background service.(For the first instance)
  3. Attach to running server.
  4. Skip rest of initialization.

Is there any example of init.el showing those functionalities?

2

1 Answer 1

2

If your init file is being evaluated, then you are starting a server, not a client. Or you are starting a non-server instance of Emacs. Your init file is not looked at by emacsclient (and there is nothing you can put into your init file which could transform the emacs instance which is evaluating it into a client of some other instance -- and even if there was, it would be the wrong solution).

If you use the client invocation emacsclient -a '' then the client will connect to an existing server if there is one, and if not it will start a new daemon and connect to it.

Maybe this is what you're after?

i.e. Never run emacs at all, or alias the command to do the thing you want.

5
  • So... does it mean that I should link Emacs.app to 'emacsclient' instead of full 'emacs'?
    – Henry Jeon
    Feb 19, 2019 at 11:11
  • 2
    Other than "it's an OSX thing" I have no idea what "Emacs.app" is (nor "SpotLight" for that matter), so I'll leave it to someone else to make specific recommendations. emacs and emacsclient do have independent option sets, so you can't treat them completely interchangeably, but presumably you can cover off your usual use-case with some kind of alias or wrapper script.
    – phils
    Feb 19, 2019 at 11:44
  • @HenryJeon No. From a terminal run emacsclient -c -a '' The -c flag will create a new frame, ie: give you a gui window.
    – nega
    Feb 19, 2019 at 15:21
  • Thanks. So opening emacsclient gui from terminal seems to be done with aliasing. The rest of the part is launch emacsclient from Spotlight or Launhpad... and maybe I can find the references.
    – Henry Jeon
    Feb 19, 2019 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.