4

If I open a second instance of emacs accidentally (which happens more often than I am willing to admit) and then close it, gnuclient starts responding with the following error:

gnuclient: Connection refused
gnuclient: unable to connect to local

Is there a way to fix this without closing the original instance of emacs and then reopening it? Sometimes this is very disruptive, and I've grown quite dependent upon gnuclient.

Perhaps I should be using emacsclient instead? I see that it continues sending files to the original instance (on which the server was started) and is not affected by the start of a second instance.

Perhaps emacsclient should be my default editor rather than emacs.

  • It would be helpful if you write about gnuclient settings (such as gnuserv, gnuserv-start, etc) in your init file and your OS. – Name Aug 20 '15 at 14:44
1

You should use emacsclient. As far as I know it's now preferred way to edit files with already running Emacs instance rather than open new instance of Emacs.

I myself use this:

;; Start Emacs server.

(require 'server)

(unless (server-running-p)
  (server-start))

Here, when server is not already running (i.e. you started first Emacs instance) it's started. When you accidentally start second Emacs instance server-running-p is evaluated to t and server-start is not called. So, it's safe to start more Emacsen without the fear to break something.

Once this is running, you should use emacsclient program to edit files. This will open them in “server” Emacs instance.

I used to have this alias in shell:

#
# ~/.bashrc
#

# …

export EDITOR='emacsclient'
alias e='emacsclient'

But now I usually use EShell from Emacs itself, where I have another alias:

alias e find-file $1

So, I don't need to use emacsclient often. It's still useful in some cases, though. For example I'm typing this in Emacs, in temporary markdown file created by “It's All Text” Firefox plugin that uses emacsclient to tell Emacs that I want to edit the file.

| improve this answer | |

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.