purcell / exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell
Other
1.41k stars 81 forks source link

exec-path components for macOS, Contents/MacOS/* #81

Closed ghost closed 4 years ago

ghost commented 6 years ago

When starting Emacs:

$PATH = "/usr/bin:/bin:/usr/sbin:/sbin" exec-path = "/usr/bin" "/bin" "/usr/sbin" "/sbin" "/Applications/MacPorts/Emacs.app/Contents/MacOS/libexec" "/Applications/MacPorts/Emacs.app/Contents/MacOS/bin"

After running exec-path-from-shell-initialize:

$PATH = "/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin" exec-path = "/opt/local/bin/" "/opt/local/sbin/" "/Library/Frameworks/Python.framework/Versions/3.7/bin/" "/usr/local/bin/" "/usr/bin/" "/bin/" "/usr/sbin/" "/sbin/" "/Library/TeX/texbin/" "/opt/X11/bin/" "/Applications/MacPorts/Emacs.app/Contents/MacOS/libexec/"

So the "/Applications/MacPorts/Emacs.app/Contents/MacOS/bin" component that is added to exec-path during Emacs start-up is removed by the exec-path-from-shell package.

Is this the expected default behaviour? What is the rational for the package removing it from exec-path?

Emacs is the Emacs.app from MacPorts, the package version is 20180323.1904 from MELPA, macOS 10.13.6

purcell commented 6 years ago

This behaviour makes sense if you read the package description: it reproduces inside Emacs exactly the $PATH that you would see in your shell. The package does not "remove" the internal Emacs path from exec-path so much as simply replace exec-path wholesale.

Does this actually cause a problem for you? If so, I'm sure there would be ways to work around it, e.g. add exec-directory or similar to exec-path after calling exec-path-from-shell-initialize.

ghost commented 6 years ago

But the /Applications/MacPorts/Emacs.app/Contents/MacOS/libexec/ component that is left in the exec-path is not in $PATH

It's the small inconsistency between the /Applications/MacPorts/Emacs.app/Contents/MacOS/libexec and /Applications/MacPorts/Emacs.app/Contents/MacOS/bin components I'm trying to understand.

purcell commented 6 years ago

Here's what I'd expect: when you start up Emacs, it adds both the 'libexec' and 'bin' directories to the PATH. Then when you run exec-path-from-shell, both are removed, because exec-path is replaced with directories in the shell's $PATH, which naturally won't include the Emacs libexec and bin paths. It sounds like that's exactly what's happening for you, and I'm not quite clear whether that answers your last comment.

ghost commented 6 years ago

"Then when you run exec-path-from-shell, both are removed", yes, this is what I was expecting from the package documentation.

However the "/Applications/MacPorts/Emacs.app/Contents/MacOS/libexec/" component is not removed from exec-path by the call to exec-path-from-shell-initialize

purcell commented 6 years ago

That's probably down to your shell config files: when the shell is "exec"-d and asked to print out its path, the shell process inherits Emacs' "PATH" variable. So if your shell config makes some assumptions about the existing value of $PATH, and looks like PATH=/some/extra/path:$PATH rather than PATH=/some/extra/path:/bin:/usr/bin or similar, then this is the behaviour you'll see. I'm wary of explicitly blanking out PATH before calling the shell, because it would cause more breakage and unexpected behaviour to do so.