Carbon Emacs in a Terminal
If you use emacs on a mac, you have two different options: Using Carbon Emacs (or AcquaMacs) or use a command line emacs. The administration of two different emacs configurations, however, is annoying. At least.
Therefore, I always had an alias in my ~/.profile file:
alias emacs="open -a /Applications/Emacs.app"
The alias starts the GUI Emacs when emacs is started in a terminal window.
So far so good. But: console emacs creates a file, if you give a nonexisting file as argument. The open command, however, does not start Emacs.app if the file does not exist.
The solution:
File ~/.profile:
function start_emacs { FILE=$1 if [ ! -e "$FILE" ] then touch $FILE; fi; open -a /Applications/Emacs.app $FILE } alias emacs="start_emacs"
When you call emacs on the command line, it invokes a function defined in the .profile. The function checks, whether the file exists. If it does not, it touches it. Afterwards, Emacs.app is launched.
(If you think of putting all this together in an alias definition: don’t. Variable names are expanded when the alias is defined, not when it is used.)
Last week, I was thinking about the very same solution. :-)
The only problem is, if you accidentally provide a wrong file name, “touch” leaves you with a useless empty file. So I wrote a more sophisticated and completely unreadable shell wrapper, which works as if you had started or switched to Emacs by yourself and opened the file with C-x C-f (using “emacsclient”).
Try
alias emacs=”/Applications/Emacs.app/…/emacs”
(or something to that effect, as long as you specify the correct path to the actual binary that’s buried deep down in the Applications folder).
That’s the way I did it – works fine, no need to touch files, everything as expected. I do get an ugly error message in my xterm every time, but I ignore it and everything seems to work. I think Ruth K. told me to do it this way, so I don’t have any claim to the solution :)
Hey, that’s great.
Kudos to Ruth :-)
Hey thanks a lot for posting this.
I’m still having a slight problem. I keep getting the error message
-bash: start_emacs: command not found
Which directory is it supposed to be in again? Right now I have it in /Users/sukrit — wrong place?
Thanks very much,
SR