14

What I would like to achieve

  • one instance of emacs
  • if i open any text file from nautilus, it should open in the current emacs instance
  • if i close emacs, it shouldn't really close it, just hide it

What I have currently

  • I set emacs23 to start at startup
  • I have (start-server) in my init
  • I leave emacs open
  • I have emacsclient as the default texteditor

Issues I encountered while trying to achieve what I wanted

  • emacs gives the following error if i quit emacs and try to start it again

File error: Cannot bind server socket, address already in use

Things I tried

Update: I tried again with the stackoverflow link, and now most of it is working. However, something I would like to be able to do is to reload the init file, so that I can make changes to my init file without restarting the computer. Any ideas?

Also, if the server is running and I have emacs false-closed (see emacs fu link), how can i start it again without loading a file? eg what would the equivalent of running emacs23 be, as this doesn't work (see error written above)

Community
  • 1
  • 1
tobeannounced
  • 1,999
  • 1
  • 20
  • 30

4 Answers4

24
  • remove (start-server) from .emacs
  • use emacsclient "$@" -a "" to start emacs whether it is running or not

If you save emacsclient "$@" -a "" as a script e.g. in editor file then editor -c creates a new frame, editor -t opens new frame in the terminal, and editor FILE visits FILE in an existing frame. It starts emacs server if it is not running.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • i wish I could upvote you 1000 times. this was the info I needed to get this working on OSX. thanks much – Tom Willis Dec 17 '10 at 10:26
  • I get an error message with your script: "-a or ALTERNATIVE_EDITOR can not be an empty string." on windows. – progician Jan 10 '14 at 14:27
  • @progician: [empty string is explicitly supported](http://www.gnu.org/software/emacs/manual/html_node/emacs/emacsclient-Options.html#emacsclient-Options). If it doesn't work on Windows; try to set `ALTERNATE_EDITOR=emacs --daemon` environment variable (drop `-a ""` from the command). If it doesn't work; [ask a separate question](http://stackoverflow.com/questions/ask) (this question is about Linux, though the solution works as is on OSX too) – jfs Jan 10 '14 at 14:35
3

I start emacs with emacs --daemon so that emacs starts in a daemonized mode. Then I would set EDITOR to emacsclient -t -a emacs -nw which opens a new terminal emacs frame attached to your emacs daemon, with a "no window" version of emacs used as an alternate if there isn't an emacs-server running. For opening emacs windows in the GUI I the editor command is emacsclient -n -c -a emacs.

It's also possible to run more than one emacs instance on a single machine, if you don't want to have buffers from one project be intermingled with buffers from another project. See my my post on the subject.

tychoish
  • 661
  • 4
  • 7
2

However, something I would like to be able to do is to reload the init file, so that I can make changes to my init file without restarting the computer.

Reading through the methods behind the daemon-effect you're looking for, none of them seem to preclude simply loading your init file and issuing an eval-buffer call after edits are made.

Also, if the server is running and I have emacs false-closed (see emacs fu link), how can i start it again without loading a file?

Running emacsclient (rather than emacs23) should do the trick, I would think.

R. P. Dillon
  • 2,780
  • 1
  • 18
  • 20
2

Hmm, not sure about running emacs as a client, but I frequently revise and apply changes to my .emacs file, without closing emacs.

Simple edit the file (within or outside of emacs, it doesn't matter which). The M-x load-file, emacs will ask you for the file's path and name, which is easy if it's ~/.emacs.

Type the path and filename then RET and emacs will reload with your changes. Any buffers you had open will still be there.

J.L.
  • 21
  • 1