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"
                      (with-temp-buffer
                        (call-process "/bin/bash"
                                      nil (list (current-buffer) nil) nil
                                      "-l" "-c" "printf %s \"$PATH\"")
                        (buffer-string)))))

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

2 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 ?

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

Comments are closed.