tags:

views:

1227

answers:

4

Hi SO,

I recently installed Emacs 23 (on OS X Leopard) and trying out the emacs server. I have tried both ways: (1) putting (server-start) in my .emacs file, and (2) running emacs --daemon at the terminal (in separate trials; not at the same time). In either case, when I have an emacs frame already open and try to open a separate file in the OS X terminal using emacsclient -t, -tty, or -nw, the file always opens in an existing frame rather than in the terminal as described:

http://www.gnu.org/software/emacs/manual/html_node/emacs/emacsclient-Options.html

http://emacs-fu.blogspot.com/2009/02/emacs-daemon.html

However, emacsclient -c works as expected. Do you have any ideas what may be happening?

Thanks much! -Stephen

+4  A: 

Are you sure you're using the right 'emacsclient' binary? You'll want /Applications/Emacs.app/Contents/MacOS/bin/emacsclient, and by default it will NOT be in your path. If you just invoke a bare emacsclient from the command line, you'll get the emacsclient from the Emacs 22.1 that Apple ships.

If you run emacsclient --version and get this:

$ emacsclient --version
emacsclient 22.1

You're not getting the right one.

genehack
Thanks... I get emacsclient 23.1 so that doesn't appear to be the case
Stephen
+2  A: 

If you installed the binary Emacs.app, you should use the executable inside the package. For example:

$ /Applications/Emacs.app/Contents/MacOS/Emacs -nw

There's also a bin directory inside the package:

$ cd /Applications/Emacs.app/Contents/MacOS/bin
$ ls -la
total 1488
drwxr-xr-x@ 19 ayman   admin     646 Aug 16 02:33 .
drwxr-xr-x@  5 ayman   admin     170 Aug 16 02:33 ..
-rwxr-xr-x@  1 ayman   admin   39704 Aug 16 02:33 b2m
-rwxr-xr-x@  1 ayman   admin  236412 Aug 16 02:33 ctags
lrwxr-xr-x   1 ayman   admin      18 Aug 24 12:54 cvtmail -> ../libexec/cvtmail
lrwxr-xr-x   1 ayman   admin      21 Aug 24 12:54 digest-doc -> ../libexec/digest-doc
-rwxr-xr-x@  1 ayman   admin  122124 Aug 16 02:33 ebrowse
-rwxr-xr-x@  1 ayman   admin   72188 Aug 16 02:33 emacsclient
-rwxr-xr-x@  1 ayman   admin  232344 Aug 16 02:33 etags
lrwxr-xr-x   1 ayman   admin      19 Aug 24 12:54 fakemail -> ../libexec/fakemail
-rwxr-xr-x@  1 ayman   admin    7288 Aug 16 02:26 grep-changelog
lrwxr-xr-x   1 ayman   admin      15 Aug 24 12:54 hexl -> ../libexec/hexl
lrwxr-xr-x   1 ayman   admin      19 Aug 24 12:54 movemail -> ../libexec/movemail
lrwxr-xr-x   1 ayman   admin      18 Aug 24 12:54 profile -> ../libexec/profile
-rwxr-xr-x@  1 ayman   admin    3977 Aug 16 02:26 rcs-checkin
lrwxr-xr-x   1 ayman   admin      18 Aug 24 12:54 rcs2log -> ../libexec/rcs2log
lrwxr-xr-x   1 ayman   admin      21 Aug 24 12:54 sorted-doc -> ../libexec/sorted-doc
lrwxr-xr-x   1 ayman   admin      28 Aug 24 12:54 update-game-score -> ../libexec/update-game-score
lrwxr-xr-x   1 ayman   admin      17 Aug 24 12:54 vcdiff -> ../libexec/vcdiff
$

If you're doing all command line, you can just update your terminal version using MacPort:

$ sudo port install emacs-app

which pushes emacs-app @23.0.0_NS-9.0rc3_1 as of the time of this posting.

ayman
Thanks. I have 'emacs' and 'emacsclient' mapped to the Emacs.app binaries through alias commands in my bash startup file. I didn't want duplicate copies of emacs on my machine but that may be the way to go so that I can open multiple instances of emacs through the terminal...
Stephen
+2  A: 

Thanks all for your suggestions and responses - I think my solution is to add the following to my .bash_profile:

## --- emacs ---
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs'

## --- emacs client ---
## adapted from http://philipweaver.blogspot.com/2009/08/emacs-23.html

# start a windowed frame
alias ec="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n -c -a /Applications/Emacs.app/Contents/MacOS/Emacs"

# start a terminal frame
alias em="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -t -a /Applications/Emacs.app/Contents/MacOS/Emacs -nw"

# do not start a new frame
alias ea="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n -a /Applications/Emacs.app/Contents/MacOS/Emacs"

I tried using emacs --daemon and replacing the Emacs.app with Emacs Client.app icon as suggested by

http://www.cubiclemuses.com/cm/articles/2009/07/30/emacs-23-for-os-x/

but (1) the daemon did not seem to load many of my .emacs customizations and (2) when I would quit Emacs Client it would quit Emacs altogether and generate errors...

So my solution is to use the bash aliases as defined above; add the line, (server-start), to my .emacs file, and add the Emacs.app icon to my OS X dock so that I can use either the icon or one of the aliases to launch emacs, and to open new files in the running instance I can also use the aliases above or C-x C-f (or C-x b) in Emacs.

Stephen
+1  A: 

I don't regularly use emacs on OS X, but I've taken to just starting emacs --daemon on boot/window manager launch, keeping the process running in the background. Is this not an option?

I use the following alias' in my *shrc files:

EDITOR='emacsclient -t'
alias e='emacsclient -n'
alias ew='emacsclient -c -n'
alias et='emacsclient -t'

Though I must admit that I mostly spawn emacs frames from bindings in my window manager (you might consider something like QuickKeys or Quicksliver) that trigger: emacsclient -c -n or emacs -n -e '(make-remember-frame)' which triggers a new org-remember frame...

Hope this helps.

tychoish