4

When I run emacsclient -nc filename.txt in my terminal, emacs opens in my terminal. I would prefer it to open in the main Emacs.app frame. Similar to how the terminal shortcuts work for Atom.

2
  • 1
    Possible duplicate of run emacs gui from emacclient – Basil Feb 10 '18 at 12:16
  • That is a similar, but different problem. That question also has no accepted answer. I've solved my problem now, and I will explain below. – groodt Feb 10 '18 at 23:37
3

I found my problem, so I'll answer my own question.

Homebrew emacs automatically starts the emacs daemon server through launchctl. When I then run emacsclient -nc filename.txt in the terminal it attaches to this daemon, rather than the server that I am running in my GUI Emacs.app frame.

My solution is as follows:

  1. Remove the homebrew installed emacs service brew services stop emacs
  2. Ensure (server-start) is in your init.el
  3. Set your Emacs.app to start at startup by putting it in "Login Items" (System Preferences -> Users & Groups)
  4. Now when I run emacsclient -nc filename.txt, it opens as a frame of the GUI Emacs.app and not inside my terminal.
  5. It can then be convenient to setup an alias for emacsclient. alias ec="emacsclient -nc"
1
  • 1
    I do not think step 1. is necessary to the solution. Brew services does the same thing as your step 3. The important thing is that the emacs demon is running. If it is not, the OS will start a new emacs process when you call emacsclient and run it on terminal. Without your own answer it was difficult the guess that you were not running the demon. I'll create an answer to that effect. – Heikki Feb 11 '18 at 16:10
0

You need to pass the -c flag.

$ emacsclient -c filename.txt

If that doesn't work, make sure that you have installed Emacs with Cocoa support:

$ brew install --with-cocoa emacs
0

You own answer contains the answer among other things: You need to have the emacs server running to have emacsclient to open a window or frame in the existing GUI emacs instance.

2
  • It is true that you need to have the emacs server running to use emacsclient. However, on my system, if the emacs server / daemon is run via launchctl, running emacsclient in the terminal will start emacs in the terminal, not in the GUI emacs instance, which is what I specifically wanted to achieve. – groodt Feb 11 '18 at 23:31
  • I can see emacs process running with brew services list and emacsclient works as expected as long as I have the emacs server running. Maybe there is something else in interfering in your system. – Heikki Feb 12 '18 at 14:15
0

For me, the problem was in ALTERNATE_EDITOR env variable set to emacs. So, when emacsclient tried to start, then wouldn't connect via socket (server-start was not started), and failed with nonzero status, it silently started emacs instead.

Setting ALTERNATE_EDITOR="" and starting server-start fixed this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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