01.08.2020

Emacs.app Mac Os X

Emacs.app Mac Os X 4,9/5 155 votes

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

Install Emacs on OS X

It's nice because it is a completely integrated mac os x application with a dock icon and everything. I find it useful when dragging a file on top of the gnu emacs icon to open it. Last, I should mention that mac os x uses the emacs keystrokes all over the place. Stuff like ^A for beginning of text, ^E for end of text, ^N next line, ^P previous. May 09, 2015  Prelude In this article I’ll share with you a few tips and tricks about running Emacs under the Max OS X operating system. This article will focus on the vanilla GNU Emacs, but if you want a more native OS X experience you might have a look at the enhanced Emacs Mac port. Installation While Emacs is available for installation from various sources I recommend you to use the Emacs for Mac OS X.

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

  • It’s been quite a while since we built Emacs from source on the Mac, but 25.1 has been official release, not to mention macOS (really?) Sierra to muddy the waters, so let’s take it for another spin. As usual, you need Xcode (free in the Mac App Store) to build.
  • Apr 26, 2015  Emacs is one of my favorites editors, but is more simple to install it on other systems like GNU/Linux, here are the step to install Emacs and how to create the Mac OS X client. Install Emacs with homebrew: brew install emacs -srgb -with-cocoa -with-d-bus -with-imagemagick This command is.

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

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

Mac

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.

Emacs Mac Port

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.

Hp solution software download. 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.

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:

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

Here are some tips and tricks on setting up Emacs.app on Mac OS X. Theseare based on my personal experience of using Emacs.app for the past 10 yearsor so; there may be better ways, but these work for me.

Emacs.app Mac Os X

Running Emacs.app from the command line

Call this script 'emacs' and put it somewhere in your PATH (~/bin or /usr/local/bin):

Using emacsclient

  1. Make sure the latest emacsclient binary is in your path:

  2. Call this script 'ec' and put it somewhere in your PATH (~/bin or /usr/local/bin):

  3. Add 'alias emacs=ec' or 'alias emacsclient=ec' to your '.bashrc'. Or just use ec directly.

Using Emacs as the mergetool for git

Add add this snippet to your .gitconfig:

If you want to use emacsclient, add this snippet instead:

Changing the Modifier Keys

Easy

The easiest way is to use the Customize interface: 'M-x customize-group RET ns RET'.

Hard

If you don't like Customize and want to do it manually, the following variables control the modifier keys:

  • ns-alternate-modifier
  • ns-command-modifier
  • ns-control-modifier
  • ns-function-modifier
  • ns-option-modifier (just a different name for ns-alternate-modifier)
  • ns-right-alternate-modifier
  • ns-right-command-modifier
  • ns-right-control-modifier
  • ns-right-option-modifier

Each variable can be set to 'control, 'meta, 'alt, 'super, or 'hyper.

In addition ns-alternative-modifier (and ns-option-modifier) can be setto 'none, which lets it get interpreted by the OS so it can be used toinput special characters.

Emacs Mac Os X

The ns-right-* variables are set to 'left by default which makes them thesame as their left counterpart.

Emacs Os

Verifying the Binary Integrity

This site serves the binaries via SSL and while the binaries are not GPG signed, the application is code signed. You can verify the signature like this:

Or, if you haven't installed emacs yet, but have mounted the disk image:

Look for the following in the output:

'Galvanix' is my consulting partnership and is what I registered my Apple developer account under. If you see that, the binary is intact.