Emacs For Mac

Emacs Mac Port What is this? This is 'Mac port' addition to GNU Emacs 24. This provides a native GUI support for Mac OS X 10.4 - 10.10. Note that Emacs 23 and later already contain the official GUI support via the NS (Cocoa) port for Mac OS X 10.4 and later.

Binaries for OS X

The official Emacs fully supports Mac OS X (along with GNU/Linux, Windows, DOS, and then some). You can find precompiled versions of emacs and Emacs.app at http://emacsformacosx.com/.

A copy of GNU Emacs 22 without GUI support compiled in is available on all recent versions of Mac OS X via the shell. However, there are other Emacs distributions geared towards Mac OS X that include GUI support as well as other distinctions that may make it a more appropriate choice for some.

Cocoa is the Objective-C API (originally developed by NeXT) that is used for native OS X applications (included in Emacs 23.2). Aquamacs and Emacs.app (which was merged into the official Emacs as of Emacs-23) both run under Cocoa. Note that Emacs.app, GNU Emacs/Cocoa, and GNU Emacs/nextstep refer to the same thing.

  1. Aquamacs is an Emacs for Mac OS X that will feel mostly like an Aqua program - while still being a real GNU Emacs with all the ergonomy and extensibility you've come to expect from this world-class editor.
  2. Apr 04, 2018  Typing 'emacs foo.txt' when foo.txt exists launches a GUI Emacs window with foo.txt loaded. If emacs is already running and has a server, then it will open in the existing window and come to the foreground. Typing 'emacs foo.txt' when foo.txt does not exist launches a GUI Emacs window with an empty text buffer named 'foo.txt'.
  3. Welcome to E-MACS, the e-filing application for the Minnesota appellate courts. Before you get started, please review the information about E-MACS contained in.

Carbon is the C language API (developed by Apple) that lets applications written under OS 9 (or earlier) run under OS X. Carbon Emacs runs under Carbon. As of Emacs 23, Carbon Emacs has been deprecated in favor of Emacs.app.

X11 Emacs is the “original” emacs running under X11 (installed by default in recent versions of Mac OS X)

If you are a Mac user new to Emacs, many people find Aquamacs to be a good choice. Many find it to be more Mac-like than Emacs.app. If you’ve used Emacs before and already have your own Emacs initialization file, then Emacs.app is likely a better choice.

As compared to Aquamacs, Emacs.app is more traditional in its approach, prefers a single frame, and is more likely to work with existing emacs initialization files. When using the vanilla EmacsforOsx binary, a useful site for setting, at least, Emacs server and Emacs client applications is Configuring Emacs on Mac OS X. Emacs shell environments behave differently from Terminal environments and in order to have correct environments like LANG=en_GB.utf-8 LC_ALL=en_GB.utf-8 or PATH= for sub-applications launched from Emacs like R, Octave, Gnuplot etc., set the environments not only in .bash_profile but in .bashrc and try (since Yosemite /etc/launchd.conf is no more consulted for security reasons).

If you are looking for more integration with OSX, Mitsuharu Yamamoto’s Mac port might be the best option. It adds valuable smooth scrolling and subpixel font rendering not found elsewhere. Other than that is it stock standard emacs.

OS X Binary Vanilla builds

These builds are based on the development version of GNU Emacs and do not contain any additional packages or patches. Popular Mac keyboard shortcuts are available though (e.g. Command-O for opening a file); these are mapped to the Super modifier (i.e., the Apple/Command key functions as Super).

  • http://emacsformacosx.com/ – “Pure Emacs! No Extras! No Nonsense!” The site makes available Releases, Pretests & Nightlies.

OS X Distributions with extras

Custom distributions contain startup routines and tweaks to make Emacs’ UI behavior more “Mac-like”. In addition to that, they typically include recent versions of popular packages.

  • Mitsuharu Yamamoto's Mac port is based on the latest stable release of GNU Emacs (26.2 as of 2019-07-05) and claims to incorporate most of the features of Carbon Emacs and the Carbon+AppKit port from Emacs 22.3. It has improved C-g support, an emulation of ‘select’ that doesn’t require periodic polling, full screen support, subpixel font rendering, and smooth (pixel) scrolling. See the readme for more details. Available via Homebrew and MacPorts (as emacs-mac-app), as discussed below, or prebuilt binaries.
  • AquamacsEmacs is a convenient distribution based on GNU Emacs 25.1. Aquamacs comes preconfigured with a large number of packages and differs from other Emacsen in that it feels more like a Mac OS X application. OS X standard keyboard shortcuts are supported, files open in separate windows or tabs, nice fonts are available, and it has a convenient drag&drop installer. Hundreds of file types are supported (C, Java, HTML, Python, Ruby, AppleScript, XML, R (Splus), LaTeX (AUCTeX) etc.). All these extra modes come included and readily configured – no InitFile hacking. Spell checking is easy to install (e.g., CocoAspell) and asian input methods are also supplied, and options to deal with the missing Meta key on Mac keyboards. Aquamacs is based on Cocoa, the modern user interface framework in OS X. It is a ready-to-use Universal App for PPC and Intel Macs that works well on all recent Mac OS X versions. Recommended for Mac users who want an Emacs that is tailored to the Mac. Experimental versions based on GNU Emacs 25 are also available.
  • Emacs Modified for macOS is a distribution based on the latest stable release of GNU Emacs with a few additions, most notably ESS and AUCTeX. Otherwise, this is a stock distribution of Emacs. Users of Emacs on other platforms will appreciate the similar look and feel of the application.
  • CarbonEmacsPackage provides authentic look and feel of original Emacs, and is a Mac-friendly distribution based on an older version of Emacs, GNU Emacs 22.3. (Newer versions are not planned.) It uses the “.emacs” file under an user’s home directory, making the migration from/to a UNIX/Linux environment easy and straightforward. It comes with tons of extra packages (including AUCTeX, ColorTheme, EmacsMuse, EmacsSession, EmacsSpeaksStatistics, HaskellMode, HowmMode, Mew, nXhtml, PhpMode, PoMode, PsgmlMode, PythonMode, RubyMode etc.) Several Mac-friendly features are added; window-opacity, OSX keyboard shortcuts (MacKeyMode), cocoa-style print dialog (MacPrintMode) and support for filenames with accent signs. A Universal Binary application is available.

Building Emacs From Source

Getting the Source

GIT

To download emacs using git, use this command:

Tarball

Available from the GNU Savannah emacs page. Click on “Download Area” under “Quick Overview”.

Building Emacs for OS X, using the normal GUI

There are many options for building emacs (such as whether to build for the X11 GUI or the Cocoa GUI), which are discussed in the INSTALL file. There is also a script (emacs/mac/make-package) to create a Mac OS X package for use by the installer.

To build Emacs under Mac OS X:

When the build is complete, you should see Emacs.app in ./nextstep/Emacs.app. Simply copy it to your applications folder and open it to run.

For more detailed instructions, see the nextstep/INSTALL file. Additionally, you may benefit from reading the build script here: http://github.com/ieure/emacs-nightly.

As of October 2011, the version of autoconf on OS X Lion is not recent enough to configure/compile Emacs from source. There is a workaround provided by using the autogen/copy_autogen script which will build emacs using pre-generated versions of the required build files. See the comments in `autogen/copy_autogen` for more information.

Aquamacs

AquamacsEmacs can be built via build script or manually. The source is available from a Git repository. Then, do:

When the build is complete, find Aquamacs.app in .nextstep.

Note: changes to any source files in src/ require a simple “make”. The binary will directly be installed into nextstep/Aquamacs.app. Changes to source files in lisp/ require a “make install”. Changes to any lisp files directly in the .app bundle may or may not take effect (upon restarting Aquamacs): for many such files (list lisp/site-load.el), you must call “make”.

Detailed build instructions are available on BuildingAquamacs.

X11 Emacs

Directions to build and install may be found in the INSTALL or INSTALL.REPO files. The basic build and installation of the X11 Emacs application uses the commands:

Carbon Emacs (for Emacs<23)

Directions to build and install may be found in the file newly downloaded to emacs/mac/INSTALL. The basic build and installation of the carbon Emacs application uses the commands:

Note: Carbon emacs has been replaced with Cocoa Emacs in Emacs 23.x. This is why the option --enable-carbon-app is no longer recognised by configure.

Installing Emacs with a Package Manager

Package managers provide a convenient way to install and maintain/upgrade software.

Fink

Fink http://fink.sourceforge.net/ includes various versions of Emacs in packages such as `emacs23`, `emacs24`, emacs24-nox`. It also includes packages for various Emacs extensions such as AUCTeX.

Homebrew

Homebrew has Emacs 26.1 as of January 2019.

Cask homebrew installation

Homebrew now recommends to use the cask version with the following message: “Please try the Cask for a better-supported Cocoa version”

To install the cask version:

This installs a pre-built package from https://emacsformacosx.com/

Standard homebrew installation

If you prefer not to run the cask version, you can still use the old homebrew recipe.

  • A Cocoa-specific Emacs.app can be built using the --with-cocoa switch.
  • A version supporting X11 can be built using the --with-x switch. Note that this version will not have all of the features of the Cocoa version; use only if necessary.

Other options include:

  • --keep-ctags Don’t remove the ctags executable that emacs provides. Use of this flag is not recommended Instead, use brew install ctags after installation.
  • --srgb This option will enable sRGB colors when using Cocoa.

To install using the --with-cocoa switch, one simply uses:

to get some “pretty” colours add the --srgb switch:

and finally link it to your Applications folder:

Emacs Editor For Mac

This creates a symlink and not an alias. So Spotlight may not find it (tested on macOS Sierra 10.12.2). Spotlight indexes symlinks to files that are treated as system files, but it doesn’t show them in the GUI. It does show aliases though, so you could just command-option-drag /usr/local/Cellar/emacs/*/Emacs.app to /Applications/ from Finder. Or:

After installation, using the emacs command in the terminal or shell will run the -nw version of Emacs. If you want to run the Cocoa version using this command, you simply add a line to your .bash_profile.

Emacs-Plus version in tap

To instead use the emacs-plus version, which is like regular homebrew emacs but with some configuration options enabled,

Mitsuharu version in tap

To instead use the Yamamoto Mitsuharu version of Emacs 26.2 (with more mac-specific features):

and finally link it to your Applications folder (default Homebrew App location):

MacPorts

MacPorts http://www.macports.org/ is another means of installing Emacs on OS X (and other unix-alikes for that matter).

As of December 15, 2016 it provides the following packages:

  • emacs 25.1
  • emacs-app 25.1
  • emacs23 23.4
  • emacs-mac-app 6.1
  • xemacs 21.4.22
  • and quite a few more…

See Available Ports for the current list.

The emacs executable installs to: /opt/local/bin/emacs

The emacs-app executable installs to: /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs

The various emacs packages MacPorts offers (e.g., org-mode) will install to: /opt/local/share/emacs/site-lisp/

Mac

Note that Mac OS X Lion comes with GNU Emacs 22.1.1, located at: /usr/bin/emacs

Linux users, add these lines to your .profile (or .bashrc, etc.) to feel at home:

Mac

alias emacs='/Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs'

alias emacsclient='/Applications/MacPorts/Emacs.app/Contents/MacOS/bin/emacsclient'

Emacs for mac osx

For the OS X native (Cocoa) versions, once you’ve got MacPorts installed, run

or (if you prefer a – usually more recent– development version)

It’s also possible to build the development version of GNU Emacs with ATSUI – Apple Type Services for Unicode Imaging.

Mitsuharu version in MacPorts

To instead use the Yamamoto Mitsuharu version of Emacs 26.2 (with more mac-specific features):

The application will appear in your Applications/MacPorts folder.

Terminal Emulation

Read up on iTerm2 if you want to spend most of your time in ssh using emacs rather than the GUI.

Tips

Visit Mac files with native Mac app in dired

Use the shell mode. Make sure cursor is at the file, then type: ! open <RET>

Using the GUI Emacs.app from the command line.

To debug-init:

To --debug-init if you installed the Emacs.app from Macports:

To open a file from a terminal. This can be used in combination with the sudo command.

As above but for when Emacs.app has been installed via MacPorts.

Call Emacs from other programs

Insert this into the .bash_profile file in your home directory:

Unlike “open -a”, this command will open a new window, and won’t terminate until you close the window (C-x C-c). So, the calling program will wait until you’ve finished editing, before it reads the file. For example, change control programs like git and svn will call emacs to edit your description of a change.

Using Emacs.app from the Dock

Create an app that runs a shell script that runs Emacs.app, like this: use Finder to navigate to /Applications and double-click Automator.app. Select the document type “Application” and click “Choose”. In the list on the left, select “Library”. In the next list, find “Run Shell Script” and drag it into the workflow area on the right. In the new shell script, delete the text and replace it with:

Select “Shell: /bin/bash” and “Pass input: as arguments”. Click “File > Save…” and choose a name and location for your new app. For example, you might choose the /Applications directory and name the app “Emacs for Dock.” Don’t replace Emacs.app.

If you like, you can change your new app’s icon to match Emacs.app, like this: select Emacs.app and right-click “Get Info” or press cmd+i. In the info window, select the small icon in the top left corner and copy it (cmd+c). Next, select your new application, get its info, select the small icon and paste (cmd+v).

Drag your new app into the Dock as usual, and you’re good to go.

Your new app does two things that the Dock doesn’t (on Mac OS 10.9). The “cd” command causes emacs to start in your home directory, instead of the root directory “/”. The --login option gives emacs the same environment as an interactive Terminal. In particular, it gives emacs your usual PATH environment variable, so you can run commands in emacs the same as commands in Terminal. An alternative to --login is -i, which sets the environment differently, as described in the Bash reference manual.

If you followed above guide, and registered the app to the dock, and clicked it, it will actually create another icon in the dock for the running Emacs application. After that, if you click the original app icon, it will not create another running app in the Dock, but the Automator might spin infinitely, as you already have it (as in the second app icon).

If you’re using “M-x server-start”, then you could use following script instead above one:

Above script is tested in Aquamacs, but it may work with Emacs. What it does, if you click the original App Icon twice, it will just give the focus to the Emacs(Aquamacs), and if you drag a file to it, it will call emacsclient to transfer it to the Emacs process. If there is no Emacs process, it will create it. – CinSK

Use Alt/Option as Meta Key under terminal emulators

For Terminal.app, starting from Snow Leopard: Go to Preferences > Settings > Keyboard > Use option as meta key. Starting from El Capitan (or maybe earlier): Go to Preferences > Profiles > Keyboard > Use Option as Meta Key.

For iTerm: Go to Manage Profiles > Keyboard profiles > (your profile) > Option Key as… For iTerm2: Go to Preferences > Profiles > Keys > Left/Right option key acts as: Meta

If you want to use Option key for both international characters and Meta key in Emacs, see this page for iTerm 0.10.x patch and/or binary.

Alt-b and Alt-f for navigating by word also works for your shell now.

Use Left Command as Meta Key under iTerm2 terminal emulator

  1. In iTerm2 go to Preferences > Keys
  2. Under Remap Modifier Keys, change Left Command Key to behave like Right Option
  3. Then go to Preferences > Profiles > $YourProfile > Keys
  4. On the bottom right of the screen click “Right option key acts as: +Esc”

Call AppleScript from Emacs

I use Andrew Choi’s build of GNU Emacs at work every day on OS X. I keep some notes and some Lisp functions for calling AppleScript from Emacs in my advogato.org diary:

Encoding for Terminal.app on OS X

  • UTF-8

The OS X Terminal.app uses UTF-8 by default. To get the correct behaviour from the Emacs that comes with OS X, I use the following settings in my InitFile file:

you also can write accents like this C-x 8 ‘ character see C-x 8 C-h

See UnicodeEncoding.

This also works with XEmacs 21.5.9 and above, at least.

  • Ctrl-Up and Ctrl-Down in shell-mode

In shell-mode, the [C-up] and [C-down] key-bindings do not work as expected to browse the history ring. The problem is that Terminal.app does not properly send these control sequences. To fix this behavior, open Terminal.app Preferences>>Settings>>Keyboard. Select the “+” button and you will see that you can add bindings to the “cursor down” key with the “control” modifier. Select “send string to shell”, and enter “ESCp”, i.e., emacs M-p. Similarly, define control cursor up to send “ESCn” to the shell.

Binding modifier keys

The variables available for binding the modifier keys:

values can be 'control, 'alt, 'meta, 'super, 'hyper, nil (setting to nil allows the OS to assign values)

Also see http://lists.gnu.org/archive/html/help-gnu-emacs/2011-02/msg00019.html

example usage:

Example to bind the mac-right-option-modifier to 'none so you can still use it to write accents:

Emacs keybindings in Cocoa Apps

This information does not regard the actual use of emacs, but I think many people will be happy to find out that some cursor movement / text editing keybindings can be used in Cocoa Apps. If you ever happen to use any other application on your Mac … You can also set up additional keybindings as described in this document.

http://www.lorax.com/FreeStuff/TextExtras.html provides additional Emacs like features to every Cocoa application like alt-/ completion

Emacs keybindings in Terminal

So control-s is just beeping at me in emacs in the Mac OS X Terminal (10.4) on my home machine but works fine on 10.2 on my work machine – what gives? I’ve looked into the flow control tty issue and tried to disable it – still emacs just sits there beeping. M-x save-buffers and M-x isearch gets to be a pain. Any hints for the Mac OS X Terminal?

I don’t know the answer to this, but the fact that it is beeping means that Emacs is probably getting it and just not understanding it. If it had anything to do with flow control, you wouldn’t get even beeping. – JonathanArnold
this can be caused by checking the “speak selected text when the key is pressed” in the “Speech” control panel/sysprefs. The default key is ctrl-s. – JeremyLeipzig

Say I want to run the function “forward-sexp” bound to C-M-f. I should be able to get at it with “hold ctrl, hold alt, hit f”. However, if I actually do that I get the result of the command forward-word (M-f). To actually get forward-sexp I must “hit esc, hold ctrl, hit f”. However the alt key works fine as meta for things like M-x and basically anything that doesn’t also require ctrl. Anyone know how to fix this? (This is using Terminal.app on 10.4.9 btw).

iTerm sends C-M-keys and mouse events. Remote emacsen run for months via iTerm + ssh + screen. Any volunteers to hack C-M- and mouse input into Terminal.app with GDB and Objective-C?

See the following blog post for swapping the cmd and meta key. Also, if you want to retain one of the Option key functions as modifier for national characters, see this page for iTerm patch and/or binary.

Terminals on most operating systems (including Terminal.app) have a very limited set of keys that they send to applications. Rarely will they send C-M-keys to the app. For this and several other reasons I recommend running Emacs as a full app, not inside a terminal, except for quick changes. You can use Esc C-f in a pinch but it’s not as efficient as M-C-f.
C-M-f binding is processed properly in Leopard’s Terminal.app. I filed a bug-report with Apple when running Tiger and actually received an email reply telling me this would be fixed in Leopard (which it was).

Emacs Keybindings under X11

See the following blog post for using alt as your meta key:

Maximize Emacs 23.3 and 24+ in Mac OS X Lion

Fullscreen mode is not offered in either 23.3 or 24+. In trying to adapt the “maximize-frame” function below I inadvertently discovered that if one uses the maximize control button once the frame is maximized vertically, twice the frame is maximized both vertically and horizontally and three times results in the frame restored to its original size. Good enough for me!

-pmr

You can also use Right Zoom ( http://www.macupdate.com/app/mac/30591/right-zoom ) with

Emacs For Mac Osx

-dwd

Enable / Disable Anti-Aliasing

To turn on/off anti-aliasing, use the following commands. By default, anti-aliasing is on.

For Emacs >= 24.4 and OS X >= 10.5, the default font backend has changed, and no longer supports these commands. The old backend can be used instead by running the following command in Terminal.app.

The commands will then work normally.

Another option is to use the following defaults command, which has some effect, but not as much as using the previous method.

To reverse the changes, use

Open emacsclient in a new iTerm tab from Mac's Finder

Make fullscreen works with posframe.el

Hacking on the Sources

The section is meant to collect useful hacks to the C sources (or to Lisp sources that are executed before any init files are read, such as startup.el).

True fullscreen for the Cocoa build in Emacs 23

This fork has patches for true fullscreen and it works wonderfully.

Changing the Scrollbar Appearance

The size of the “knob” in a given window’s scrollbar is proportional to how much of the buffer is displayed in the window. When the whole buffer is displayed in the window, the knob takes up the entire scrollbar. I find this distracting (not to mention aesthetically objectionable), and much prefer the behavior of applications like iTerm that show an empty scrollbar slot in such cases.

You can get that effect in Emacs by making a small change to src/nsterm.m. Look for this bit of code:

and replace it with:

A further change is to have the knob be of constant, minimal size, so that it only indicates position in the buffer, instead of changing size according to the portion of the buffer displayed in the window (I find the variable sizes distracting). To do this, use the replacement code: