A very simple eLisp function to add new path elements to the PATH environment variable. Very useful for adding new comint executables from within .emacs/init.el files.
(defun my-add-path (path-element) "Add the specified path element to the Emacs PATH" (interactive "DEnter directory to be added to path: ") (if (file-directory-p path-element) (setenv "PATH" (concat (expand-file-name path-element) path-separator (getenv "PATH")))))
2 thoughts on “Emacs function to add new path elements to the $PATH environment variable”
I suggest this change:
(or (getenv “PATH”) “”)
because, in theory, PATH variable can be nonexistent. In practice it rarely is but CONCAT function expects sequence-type arguments and it should always get those even if GETENV returns nil.