das rockbüro

it’s more fun to compute.
  • rockbüro.de
  • nils reiter
  • feeds

Carbon Emacs in a Terminal

Veröffentlicht von Nils am 15. November 2008 um 21:56 in Binäres Leben

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.)

  1. Robert am 17. November 2008

    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”).

  2. Ulrike am 3. Dezember 2008

    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 :)

  3. Nils am 3. Dezember 2008

    Hey, that’s great.

    Kudos to Ruth :-)

  4. Sukrit am 23. Januar 2009

    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

Veröffentliche Kommentar

  • Suchen

  • Twitter

    • Wo ist eigentlich meine Wahlbenachrichtigung? #stadthalle #heidelberg 5 days ago
    • ... und morgen stimmen wir alle brav für den #Stadthallenausbau ja? Danke :) #B ¼rgerentscheid #heidelberg 6 days ago
    • Nicht alle Kraken heißen Paul und sagen WM-Ergebnisse vorher: http://npd-blog.info/2010/07/22/krake-200/ #interessant 1 week ago
    • Toll, mal wieder: Chronisch krank http://bit.ly/aaSRee #welt 1 week ago
    • Almost back in #Heidelberg 1 week ago
    • More updates...
  • Google Reader

    • Chronisch krank (Stefan Niggemeier)
    • Storno (Texttheater)
    • Antisemitische Bildsprache bei der Piratenpartei (NPD-BLOG.INFO)
    • Au Spack Video: iPhone 4 (Spreeblick ohne Podcast und Mahoni)
    • Verleger: Leistungsschutzrecht soll Sprache monopolisieren (netzpolitik.org)
    Shared Items
  • Letzte Kommentare

    • Robert bei März
    • Nils bei 26. Februar 2010
    • Robert bei 26. Februar 2010
    • Britta bei 11. Februar 2010
    • Nils bei 30. Januar 2010
    • Michi bei 30. Januar 2010
    • ponk bei 30. Januar 2010
    • Kadir bei Heer4U
    • ke bei Kaffeesätze
    • Britta bei Kaffeesätze
  • Letzte Artikel

    • 20. Januar 2010
    • 21. April 2010
    • 17. April 2010
    • 21. Maerz 2010
    • 19. März 2010
    • März
    • 16. März 2010
    • 15. März 2010
    • 10. März 2010
    • 08. März 2010
  • Kategorien

    • Binäres Leben
      • re:publica
      • Yahoo! Pipes
    • Dies und Jenes
    • Gott und die Welt
      • Heiligendamm
    • Kulturfahrplan
    • Lokalteil
    • Medienkonsum
      • Kaffeesätze
      • Skast
    • Neues aus dem Elfenbeinturm
    • Reflexives
    • Reise, Reise
    • Zwischenruf
  • Archiv

    • Juli 2010
    • April 2010
    • März 2010
    • Februar 2010
    • Januar 2010
    • Dezember 2009
    • November 2009
    • September 2009
    • August 2009
    • April 2009
    • März 2009
    • Februar 2009
    • Januar 2009
    • Dezember 2008
    • November 2008
    • Oktober 2008
    • September 2008
    • August 2008
    • Juli 2008
    • Juni 2008
    • Mai 2008
    • März 2008
    • Februar 2008
    • Januar 2008
    • Dezember 2007
    • November 2007
    • Oktober 2007
    • September 2007
    • August 2007
    • Juli 2007
    • Juni 2007
    • Mai 2007
    • April 2007
    • März 2007
    • Februar 2007
  • Meta

    • Anmelden
    • Artikel-Feed (RSS)
    • Kommentare als RSS
    • WordPress.org

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.
WordPress Theme based on Light Theme