🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

My Emacs Setup, pt 3: OSX

Published 2013-06-19 @ 12:00

Tagged emacs

This is part of the My Emacs Setup series.

Line 8-9 of my emacs.el load OS and host-specific initialization. I don’t currently have anything specific to my host, but I do have stuff specific to darwin:

1
2
;;; misc/darwin.el
(defvar running-osx (or (featurep 'mac-carbon) (eq 'ns window-system)))

This gives me a clean variable that I can use to guard things if I need to.

1
2
3
4
5
6
7
(when running-osx
  ;; Fixes a tweaky thing on 10.8
  (ns-set-resource nil "ApplePressAndHoldEnabled" "NO")

  ;; resets cmd-~ on emacs 23 and up
  (unless (version< emacs-version "23")
    (global-set-key (kbd "M-`") 'other-frame)))

Sometimes… yeah. I dunno. Sometimes you just need to fix things. I would like the OSX support to be better in emacs. But it isn’t. And it is getting worse. I expect this section to grow over time.

1
2
3
4
5
6
7
8
9
10
11
12
(unless (getenv "TERM_PROGRAM")
  ;; deal with OSX's wonky enivronment by forcing PATH to be correct.
  ;; argh this is stupid
  (let ((fix-env
         (lambda (v) (setenv v (shell-command-to-string
                                (concat "/bin/bash -ilc 'echo -n $" v "'"))))))

    (funcall fix-env "PATH")
    (funcall fix-env "CDPATH")

    (dolist (p (split-string (getenv "PATH") ":" t))
      (add-to-list 'exec-path p t))))

So… in OSX all of your GUI apps, including emacs, are launched by the WindowManager process. This process starts via launchd, which means that it doesn’t load or even inherit your shell environment. All those goodies you have in your .bashrc or whatnot are not available to you in emacs (not counting running a shell inside of emacs). This attempts to patch that up by loading a shell and grabbing values from it. This patches PATH and CDPATH and also patches exec-path to reflect the values in PATH. One last thing to mention… I wish emacs ran scheme. funcall is lame.