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

20 01 2010

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

Actions

Information

2 responses

20 01 2010
Oz

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 01 2011
2010 in review « /usr

[...] 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 )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: