6

I find running the following is different from just running emacs on mac

/Applications/Emacs.app/Contents/MacOS/Emacs -nw

Should I create an alias in zsh/bash for it?

eugene
  • 481
  • 1
  • 5
  • 11
  • 2
    I open the Emacs.app just like any ordinary mac apps via Dock, Launchpad, Spotlight etc. I don't use Emacs inside a terminal. The builtin `/usr/bin/emacs` is too old. Feel free to create an alias for it. – xuchunyang Nov 09 '19 at 16:25

4 Answers4

7

Just to expand on @ghoetker's answer:

  1. Install Emacs into your application folder from https://emacsformacosx.com/
  2. Using the terminal, open the file ~/.zshrc in your favorite text editor.
  3. Somewhere near the bottom of the file, add the line: alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'
  4. Restart the terminal, or type source ~/.zshrc

From now on, typing emacs will open up Emacs in the Finder.

Edit: to cover some questions that have come up, the link in this answer is only one source for Emacs, and there are dozens of others. Anywhere you download it from you will need to take the proper precautions to make sure it's being downloaded from a safe source. How exactly to do that is beyond the scope of this question but if anyone has a particular problem please post it and I'll do what I can to help.

Raydot
  • 186
  • 1
  • 4
  • Thank you. Is there a way to make it not block the terminal itself? So I would like it to open Emacs on its own separate window, and the terminal prompt to return without me having to close Emacs first , if possible. – a06e Oct 07 '22 at 15:01
  • I think you're getting a bit outside the bounds of what the Terminal is able to do there, as you're literally running the program on top of shell instance you're looking at in the Terminal. You can always cmd-shift-t to open a new tab, look for a library like xdotool that will let you run keyboard commands from the shell, program macros into the Terminal itself, etc. But Unix doesn't really have the equivalent of a "multi-finder," if that's what you mean. You can also open a new shell within emacs itself: esc-x "shell." – Raydot Oct 07 '22 at 17:09
  • Have you seen MacVim (https://macvim-dev.github.io/macvim/)? When you start it from the terminal (`mvim`), it opens in a new window and the shell returns immediately. – a06e Oct 07 '22 at 20:55
  • Right, that's a "standalone" version of MacVim which runs as a desktop application. I haven't tried but I'm guessing you can download a similar version of emacs, and then add an alias to your shell as ghoetker suggests below. What I'm saying is this doesn't really have as much to do with emacs itself as it does with your emacs and Terminal environments and how you have them set up. Also, check out iTerm2, which is Terminal on steroids! – Raydot Oct 07 '22 at 23:16
  • ...and most people use emacs so they don't have to leave the Terminal. – Raydot Oct 07 '22 at 23:27
  • Thanks, I'm just asking how I can setup Emacs so it behaves in the same fashion as MacVim does. – a06e Oct 08 '22 at 08:27
  • So just to be more direct in my answer to your question: 1) Find and download an application version of Emacs, 2) Set up an alias in your terminal to launch from a keyword (like 'memacs'). – Raydot Oct 10 '22 at 18:38
  • Do you know of any particular "application version of Emacs"? Sorry if the question is naive. – a06e Oct 10 '22 at 19:03
  • emacswiki.org/emacs/EmacsForMacOS , as posted below. I'm sure a Google search could turn up still more. – Raydot Oct 16 '22 at 18:35
  • Not working for me; I get `Emacs-arm64-11[57131:4219915] +[NSXPCSharedListener endpointForReply:withListenerName:]: an error occurred while attempting to obtain endpoint for listener 'ClientCallsAuxiliary': Connection interrupted` – AdamC Feb 03 '23 at 18:31
  • Just use open. `open Emacs.app` This does the same as clicking on EMacs.app in the Finder – mmmmmm Mar 03 '23 at 00:43
  • @AdamC can you be (a lot) more specific? – Raydot Mar 03 '23 at 20:09
4

Yes. An alias to the binary within Emacs.app is useful and will allow to call an up-to-date version of emacs from the terminal via “emacs”. I have the following set up

alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'
ghoetker
  • 81
  • 3
4

Applying Dave Kanter's recipe, I still run into trouble: "Emacs" can't be opened because Apple cannot check it for malicious software.

To get it to run, I had to open Settings, Settings, Security & Privacy, General tab and there give Emacs permission to open anyway, at my own risk.

Now I can run Emacs from the command line, albeit without options or arguments (no file name, no -nw option...).

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    To solve the issue `"Emacs" can't be opened because Apple cannot check it for malicious software`, see also this answer: https://emacs.stackexchange.com/a/69444/25843 – Timur Shtatland Nov 23 '21 at 19:23
  • The problem there is where you get your Emacs from. You will have to get a version that can be verified, or do the verification yourself before you try to install -- the same grain of salt with which you should take pretty much anything you download from the internet. I found a more comprehensive list of links at https://www.emacswiki.org/emacs/EmacsForMacOS , same caveat though. – Raydot Dec 01 '21 at 20:10
3

I initially used:

alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'

allowing me to open Emacs from terminal but not in it even if I used emacs -nw

After finding I couldn't open Emacs to run in terminal, I replaced the original alias in my .zshrc with:

alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs -nw)'

Now, if I want the gui version I open Emacs using spotlight. If I want the terminal version, I type "emacs" in terminal providing the best of both worlds. With the original line using "$@" I couldn't get Emacs to run in terminal even using "emacs -nw"