Setting the PATH variable from within Emacs

A Small function to set the PATH variable from within Emacs. You can define the function and the path definitions in your .emacs file:

Very useful for OS X, where the default path is set by plists.

;; Define a function to setup additional path
 (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")))))

and use it as:

;;; Set localized PATH for OS X
 (if (fboundp 'my-add-path)
     (let ((my-paths (list
                    "/opt/local/bin"
                    "/usr/local/bin"
                    "/usr/local/sbin"
                    "/usr/local/mysql/bin"
          "~/bin")))
         (dolist (path-to-add my-paths (getenv "PATH"))
         (my-add-path path-to-add))))
Advertisement

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.