4

What I have so far is

alias em="open -a /Applications/Emacs.app "$@" && osascript -e 'tell application "Emacs.app" to activate'"

But I am stumped.

With that code, em file.txt will activate, but won't open the file. And I get '22:23: syntax error: Expected end of line but found unknown token. (-2741)'


Doing

alias em=open -a /Applications/Emacs.app "$@"

Works fine and then it will open the file, but obviously not bring emacs to the front.


And for some strange reason

osascript -e 'tell application "Emacs.app" to activate'

doesn't activate emacs.... I have no idea what is going on.


I am happy to fix this either with alias code, or with .emacs code


edit: see comments for another thing tried.

tobeannounced
  • 1,999
  • 1
  • 20
  • 30
  • It looks like you really want to use `emacsclient` in combination with an emacs server. – pmr Feb 05 '12 at 16:58

4 Answers4

11

Try this:

(setq ns-pop-up-frames nil)

Works fine for me.

Found it here

LoveAndCoding
  • 7,857
  • 2
  • 31
  • 55
jeff
  • 111
  • 1
  • 3
2

I have the following in my .bashrc sourced by my .profile:

alias emacs='open -a /Applications/Emacs.app "$@"'

And in my .emacs custom area:

(custom-set-variables
 ;; yadda yadda
 ;;...
 '(ns-pop-up-frames nil))

Or if you don't like to M-x customize-variable your way into it, as Jeff said:

(setq ns-pop-up-frames nil)

I didn't need any AppleScript to do this; although I noticed you were missing the end tell? Anyway, works like a charm for me, pops Emacs open, or uses the existing window if there is one, and it's on top, and the Terminal remains ready for more input.

courtlandj
  • 435
  • 9
  • 19
2

Could the problem be that you need to escape you quotes, like this?

alias em="open -a /Applications/Emacs.app \"$@\" && osascript -e 'tell application \"Emacs.app\" to activate'"
Puppe
  • 4,995
  • 26
  • 27
  • Thanks, got rid of the error, but now it tries to load the directory of the file rather than the file, and doesn't activate the Emacs window. Strange. Any ideas? – tobeannounced May 21 '11 at 01:43
0

You can use:

emacsclient -nt somefile

in your terminal, which would open specified file(s) in new buffer using your existing frame rather than a new client frame.

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

zhouji
  • 5,056
  • 1
  • 26
  • 26