Making OSX Emacs less broken

If you find that Emacs on OSX fails to pick up the same $PATH setting that you get in command line shells, instead defaulting to an impoverished default that doesn’t include (for instance) anything installed via MacPorts:

(add-hook 'after-init-hook
         #'(lambda ()
             (setenv "PATH"
                 (call-process "/bin/bash"
                               (list (current-buffer) nil)
                               "-l" "-c" "printf %s \"$PATH\"")

I am only embarrassed that I put up with the brokenness for as long as I did.

Responses to “Making OSX Emacs less broken”

  1. Howard M. Lewis Ship

    Thanks! This makes a huge difference to me.

    Why is it necessary to execute it as an after-init-hook, can’t it just execute as part of ~/.emacs.d/init.el ?

    1. Zack Weinberg

      Probably it would work fine as part of init.el. I just habitually try not to do anything there but set variables and hooks and define functions.