My Emacs Setup, pt 3: OSX
Published 2013-06-19 @ 12:00
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:
This gives me a clean variable that I can use to guard things if I need to.
(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.
(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
CDPATH and also patches
reflect the values in
PATH. One last thing to mention… I wish
emacs ran scheme.
funcall is lame.