Emacs.app Mac Os X

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. #!/bin/bash (open -a /Applications/Emacs.app '$@') & Caveat: in order to get emacs to open the current directory in Dired by name mode, you need to use. Environment: OS X Yosemite Version 10.10.2; GNU Emacs 24.4.2 (x8664-apple-darwin14.0.0, NS apple-appkit-1343.14) of 2014-11-13. OS X Control and Command keys. Mac keyboards conveniently have separate Control, Meta (a.k.a. Option or Alt) and Command (⌘) keys. You have the traditional Emacs bindings on Control and Meta, and the OS X bindings on Command. As recommended previously, you should strongly consider re-binding Caps Lock to Control, system-wide. Configuring Emacs on Mac OS X Tuesday, May 07, 2013 I wanted a nice experience using Emacs for Mac OS X. By 'nice' I mean: Emacs runs in server mode. It's started like other OS X software by Launch Services. I can connect to it with graphical or terminal-based.

  1. Emacs For Mac Os X
  2. Emacs For Mac

This is a quick note on the setup of Emacs on Mac OS X.

Install Emacs on OS X

The simplest way to install Emacs on Mac is using Homebrew. Here is the commands:

If you want to try a patched Emacs with transparent titlebar, install as follows

(You may add --without-spacemacs-icon, if you keep only one version of Emacs.)

Emacs

Run Emacs as daemon

If you have run the Emacs, you can start an Emacs server by the emacs-lisp function (server-start). Then you could anywhere open files in or create a frame of this Emacs by emacsclient -nc. However, this is rarely used. An alternative way is to run Emacs as daemon

and open emacsclient in the same way.

In my Mac, I run multiple Emacs servers (each Emacs process as daemon is called one server) to allow using multiple color themes (e.g. I use a light theme for text editing like Markdown, LaTeX, and use dark themes for coding). The way to do it is giving each daemon process a name so as to connect to it later via emacsclient:

and later you could connect to them, e.g. the main server, by

To stop an Emacs server (the daemon process), you could call (kill-emacs) in anyEmacs frame connecting to this daemon. Alternatively, use system command kill withprocess ID listed and grepped by ps aux | grep -i 'emacs --daemon'.

To quickly start Emacs as daemon, connect to and kill them, I wrote a bash scriptfunction emacs-server-func.sh on my githubrepository, which provides commands es, ec, ecc:

  • es: list all Emacs daemon processes
  • es start: start main and coding servers by default
    • es start m or es start main: start main server
    • es start c or es start coding: start coding server
    • es start YOURNAME: start a sever with your given name
  • es stop: stop all Emacs daemon processes
    • es stop m or es stop main: stop main server, similar for coding
    • es stop YOURNAME: start the sever with the given name
  • ec FILENAME: connecting to the main server and open the file FILENAME in a new frame
  • ecc FILENAME: connecting to the coding server and open the file FILENAME in a new frame.

Alternatively, we could use Alfred.app to perform the same tasks. We need its PowerPack in order to build Workflows. Create an Input using Keyword, with the keyword es start (with Argument Optional, enabling with space), shown as

Then, connect to an Action of Run Script, in which choose bash and fill the following codes

Similarly create workflows for es stop, ec, etc. The scripts are the same as thecodes provided in emacs-server-func.sh. We just copy and paste them into Alfredand create shortcuts to run them. The whole workflow looks as

and you could find the workflow, named Emacs.alfredworkflow, on my github repository.

Since Mac OS X by default only allows one Emacs instance (not via daemon), we may use the follow code to open multiple ones, which is created as a workflow in Alfred triggered by em new:

Create an app via Automator to open files in Emacs clients by double-clicks

Automator is a built-in OS X app for creating custom automated user workflows forjust about any installed app you might have or even OS functionality. Suppose wecould like to open files by default in the Emacs client named as main. You may openfiles in the Emacs.app, however, with too much user-defined configurations, it is tooslow to be acceptable. Using the daemon mode and opening in clients are a better choice.

The following shows how to create an app that allows opening files in Emacs clients.

  1. Launch Automator and create a new document. Select Application as its type.

  2. Search the Actions palette on the left for the Run AppleScript action and add itto your Automator document.

  3. In the Run AppleScript building block, copy and paste the following codes:

    and Save it with name, e.g. Open in Emacs.app in the file format Application.

  4. Now you go to the files with specific extensions, right-click it, choose Get Info and choose our app Open in Emacs.app as the application to open it. If you prefer to using Emacs to open all files of this extension, click Change All....

Load different themes for Emacs servers/daemons

In practice, I prefer light themes for text editing (like Markdown, LaTeX, org mode) and dark themes for programming. To achieve, we run multiple Emacs daemon processes, e.g. main and coding. Now we will describe how to load different themes in your .emacs or init.el configurations.

First of all, we need to prepare a few variables and loading functions:

These functions are essential since the theme has to be loaded when the frame is firstly created, instead of when the elisp files are loaded during emacs --daemon.

Emacs For Mac Os X

Then we define different themes for each severs (the daemon processes), for examples:

where these constant variables are defined as follows in advance for convenience:

Emacs For Mac

The last step is to load or reload themes depending on specific Emacs running modes: