Emacs function to add new path elements to the $PATH environment variable

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")))))
About these ads

2 Comments on “Emacs function to add new path elements to the $PATH environment variable”

  1. Oz says:

    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.

  2. [...] Emacs function to add new path elements to the $PATH environment variable January 20101 comment 5 [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 67 other followers