Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have installed “Emacs for Mac OS X” on my Mac running Mac OS X 10.6.

How can I run it from a command line to open a file? For example, when I do this:

$ emacs aFile.txt

It just uses the in-window “Terminal” emacs, not the emacs from Mac OS X 10.6 that I installed.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

This should open it in the UI Emacs:

open -a Emacs aFile.txt

That works for any Mac application, to get it fired up appropriately.

share|improve this answer
    
Thanks. It works, but when the file does not exit, it said "The file /Users/scheung/a.txt does not exist." how can I make emacs creates a new file name 'aFile.txt' for me? –  michael Feb 9 '12 at 5:29

You have a LOT of options here:

probably the one that will be the least work to get 80% of the possible functionality would be to just prepend /Applications/Emacs.app/Contents/MacOS/ to your PATH variable (in your .bash_profile if you don't want to do this manually all the time; I'm assuming you use bash) and invoke the program as Emacs, that way you get the cli behavior you expect when launching emacs, and the gui for the actual editing (to skip the gui use the -nx flag when starting emacs); and then you can also alias emacs=Emacs so you don't have to get the case right or change your habits.

another option is to start an emacs daemon (/Applications/Emacs.app/Contents/MacOS/Emacs --daemon) and pass it files with emacsclient which you can just alias to emacs like alias emacs="emacsclient -t -s $TMPDIR/emacs$(id -u)/server"; in addition to this there's the option of starting the daemon from launchd when you login, in case your emacs is slow to start.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.