1

Note: I had asked this question before under https://apple.stackexchange.com/questions/181007/emacsclient-waits-when-alternate-editor-is-used.

I created the following script emc to invoke emacs (if already an emacs instance is running, the arguments should be opened in this instance, otherwise, a new instance should be started; the -n causes emacsclient not to wait):

#!/bin/bash
/Applications/MacPorts/Emacs.app/Contents/MacOS/bin/emacsclient --alternate-editor "/Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs" --no-wait  ${1+"$@"}

When already an emacs is running, the script works as expected; if, however, no emacs is running so far, a new one is started and the files are opened, but emacsclient waits until this instance is closed and gives the following output:

computerName:bin user$ emc .
/Applications/MacPorts/Emacs.app/Contents/MacOS/bin/emacsclient: 
can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

How can I avoid this waiting?

2
  • I just ignore the warning. It seems to always say that but it is usually working for me. My setup is in my .emacs: ;; Start server and set directory (setq server-socket-dir (format "/tmp/emacs1000")) and then I have a bash alias of # emacs aliases alias emacs='emacsclient -t -s server --alternate-editor='
    – dustin
    Commented Apr 18, 2015 at 4:37
  • Hello Dustin, thanks for your reply. I am not using emacs inside the terminal, I am using emacs.app. My problem is that I don't want the emacsclient to wait in the terminal (I want to continue working in the terminal). Commented Apr 18, 2015 at 9:54

1 Answer 1

2

I think the wait may be because of the command you specified for the alternate editor. The no wait flag, wont help you here, as that flag is for emacsclient not emacs. As you're probably aware the alternate editor will be run, if there is no emacs instance running, so try using Emacs -Q or Emacs -q if those work without the wait, then try: Emacs --debug-init as it may be something in your configuration causing the wait.

To get rid of the message you can add a 2> /dev/null at the end of your command.

I use OS X but I compile my own emacs, I use it as follows and have no wait time, I don't specify an alternate editor command, this ensures that the emacs daemon starts if not already running.

/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -a "" -n -c "$@" 2> /dev/null

To run on the terminal I use:

/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -a "" -t "$@" 2> /dev/null

I experience no wait time using the above method. This should work with your macports version as well as with any other version, I use this same script in Linux without issues.

I hope this helps.

4
  • Thanks for the reply. Now I understand why it is waiting, not because of the emacsclient, but because of the emacs process it started. Is there perhaps any way to start the alternate editor in such a way that the process keeps running even when the terminal is closed (nohup)? Commented Apr 19, 2015 at 3:55
  • You could use nohup but I think it would be better to just use emacs daemon, maybe run it as a login item in OS X or from /etc/rc.local if you're on unix. You can find some tips for using the daemon in OS X here: emacsformacosx.com/tips The homebrew guys have a launch agent configuration for running emacs daemon on login you can find it here: github.com/Homebrew/homebrew/blob/master/Library/Formula/… You just need to save that portion to a file in: ~/Library/LaunchAgents and then do launchctl load ~/Library/LaunchAgents/emacs.plist I hope this helps.
    – xmonk
    Commented Apr 21, 2015 at 11:00
  • I tried the following: 1) open a terminal 2) run /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs 3) start /Applications/MacPorts/Emacs.app/Contents/MacOS/bin/emacsclient . The problem is that now an emacs is started, but in the terminal and not the graphical app. Commented Apr 25, 2015 at 4:12
  • Try /Applications/MacPorts/Emacs.app/Contents/MacOS/bin/emacsclient -n -c .
    – xmonk
    Commented Apr 25, 2015 at 12:46

Your Answer

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

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