![[Home]](https://www.emacswiki.org/images/logo218x38.png)
This variable is the equivalent of the PATH environment variable for Emacs. It contains a list of directories Emacs will search for executables.
Here’s an example of appending the /sw/bin directory to the exec-path and PATH variables (useful for Mac OS X users running LaTeX):
(setenv "PATH" (concat (getenv "PATH") ":/sw/bin")) (setq exec-path (append exec-path '("/sw/bin")))
I found there are difference between ‘exec-path’ and PATH.
(defun set-exec-path-from-shell-PATH () "Set up Emacs' `exec-path' and PATH environment variable to match that used by the user's shell. This is particularly useful under Mac OS X and macOS, where GUI apps are not started from a shell." (interactive) (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -c 'echo $PATH'" )))) (setenv "PATH" path-from-shell) (setq exec-path (split-string path-from-shell path-separator)))) (set-exec-path-from-shell-PATH)
Found at https://agel.readthedocs.io/en/latest/configuration.html#path-to-the-ag-executable.
Note: when using fish shell "$SHELL --login -c 'string join : $PATH'" should be used as argument to shell-command-to-string, as fish prints $PATH (and other variables ending in path) separated with spaces instead of colons.
2021-03-23: Deleted the -i flag from the shell invocation in the function. Starting the shell with the -i command causes plumbing errors in the shell’s output and the resulting error message confuses the parsing, setting both the env PATH and the exec-path incorrectly.