With help from #macdev, I was finally able to write a more sophisticated Emacs shell script. If you download https://github.com/mcandre/dotfiles/blob/master/emacs.sh and soft link it as /usr/bin/emacs, it allows you to launch emacs from a terminal as a GUI app, or a pure command line ncurses app, by properly responding to the various emacs command line options.

I'm fairly demanding of my programs, so I hassled a few communities to help the shell script meet a lot of constraints. The dependencies are Emacs for Mac OS X, bash, and Mac OS X, though conceivably the script could be ported to Aquamacs or Homebrew Emacs.

The emacs shell script will work with a file to open, without a file to open, with and without other command line arguments such as -Q, --version, and --help, and files and command line flags can be passed to emacs in arbitrary order (${1+"$@"}).

In GUI mode, Emacs will release control from the shell; you can keep entering commands in the terminal that Emacs was launched from without having to background the process with Control+Z. Emacs does not die with the shell, if you happen to close the terminal (nohup).

Emacs will open in the foreground, not behind the terminal (osascript).

Emacs will not interrupt your terminal experience with stdout messages (> /dev/null).

If you do use the -nw flag, emacs will open inside the terminal in curses mode.



On Fri, Apr 5, 2013 at 11:21 PM, Bob Proulx <bob@proulx.com> wrote:
Steven Degutis wrote:
> Andrew Pennebaker wrote:
> > When I try open -a emacs --args ${1+"$@"}, I have to choose either open a
> > file, or provide a command line argument. I can't do both.
>
> (1) Yes, that's true. That's a limitation of emacs, not the open command.
> Do `emacs --help`

You should be able to do 'emacs -Q filename.rb' however.

I see you using the old idiom ${1+"$@"}.  That is fine.  That will
work everywhere.  But unless you are working on Solaris then that
idiom can be shorted to simply "$@" without checking $1 first.  All
modern shells treat "$@" correctly now and it is required by POSIX.

You have been focusing on trying to get the "open" to work.  But you
could just for the experiment try emacs in a terminal window and get
the test done.

  emacs -nw -Q

Just ignore the who "open" problem for the moment and just test
whether -Q causes your curly brace problem to go away.  Because if
it does then you now the problem is in your emacs customization in
your ~/.emacs or wherever you are locating it.

Bob



--
Cheers,

Andrew Pennebaker
www.yellosoft.us