Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use GUI Emacs on OS X when opening files with emacsclient

Tags:

emacs

macos

I'm trying to setup Emacs (which I installed via brew install emacs --cocoa) in a way that I can use it the in following way:

  1. emacsclient file.txt creates a new GUI Frame if there is none already
  2. emacsclient file2.txt replaces the contents of the existing frame if there is one
  3. emacsclient should always return immediately and not block the shell it has been called from
  4. At any given point in time there should basically be one Emacs window and one emacs --daemon process

As I said I installed Emacs via homebrew. To have a daemon starting when I log in I added ~/Library/LaunchAgents/org.gnu.emacs.plist with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>org.gnu.emacs</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/Cellar/emacs/HEAD/bin/emacs</string>
      <string>--daemon</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

I confirmed that this starts the process. So far I tried various variants to call emacsclient:

  1. /usr/local/Cellar/emacs/HEAD/bin/emacsclient file.txt this opens emacs in my terminal
  2. /usr/local/Cellar/emacs/HEAD/bin/emacsclient -c file.txt this opens up a new Emacs GUI frame (good!) but it somehow does not have the same font-size/typeface settings. Also when I close that frame and open another file with emacsclient -c the Emacs process seems to crash.
  3. /usr/local/Cellar/emacs/HEAD/bin/emacsclient -n file.txt just exits right away

I'm not sure what I'm supposed to do. I've found a lot of tutorials on this but many weren't clear if the objective is to get a daemon working just for terminal usage of emacs etc.

I'd be very interested to hear how you use Emacs on OS X, especially how you setup an Emacs daemon and how/if you are using the GUI variant.

like image 894
Martin Klepsch Avatar asked Jul 30 '14 18:07

Martin Klepsch


People also ask

How do I start Emacs in GUI mode?

If you are working with a graphical user interface, start Emacs by clicking its icon or by running emacs & at the command line. The & tells the command line to open Emacs in the background and immediately return control of the terminal to you.

Is Emacs installed by default on Mac?

OS X comes with a preinstalled version of Emacs, but alas it is the outdated Emacs 22. Fortunately, obtaining a newer release is really simple. There are several popular ways to do it.

How do I install Emacs on my Macbook Pro?

Mostly simply, download and run the emacs- version -installer.exe which will install Emacs and create shortcuts for you. Alternately, download emacs- version . zip then unzip, preserving the directory structure.


1 Answers

As it happens so often I found a solution while writing this. Putting the following into my init.el allowed me to open files in the existing GUI frame.

(require 'server)
(unless (server-running-p)
  (server-start))

I assume that this works because the server process is bound to the GUI instance of Emacs but I'm still very open to someone else enlightening me on this.

like image 128
Martin Klepsch Avatar answered Sep 20 '22 10:09

Martin Klepsch