Permalink
Browse files

Make the list of copied variables customizable. (See #2)

  • Loading branch information...
1 parent f349bc2 commit f88aa7edecf1ed93a9ec5a1e7ba623e485b833e4 @purcell committed Oct 7, 2012
Showing with 26 additions and 10 deletions.
  1. +5 −3 README.md
  2. +21 −7 exec-path-from-shell.el
View
@@ -11,8 +11,8 @@ different environment than a shell in a terminal window, because OS X does not
run a shell during the login. Obviously this will lead to unexpected results
when calling external utilities like `make` from Emacs.
-This library intends to work around this problem by copying important
-environment variables from the user's shell.
+This library works around this problem by copying important environment
+variables from the user's shell.
Installation
------------
@@ -33,7 +33,9 @@ Add the following to your `init.el`:
This sets `$MANPATH`, `$PATH` and `exec-path` from your shell, but only on OS X.
-You can copy values of other environment variables with
+You can copy values of other environment variables by customizing
+`exec-path-from-shell-variables` before invoking
+`exec-path-from-shell-initialize`, or by calling
`exec-path-from-shell-copy-env`, e.g.:
```scheme
View
@@ -56,6 +56,16 @@
;;; Code:
+(defgroup exec-path-from-shell nil
+ "Make Emacs use shell-defined values for $PATH etc."
+ :prefix "exec-path-from-shell-"
+ :group 'environment)
+
+(defcustom exec-path-from-shell-variables
+ '("PATH" "MANPATH")
+ "List of environment variables which are copied from the shell."
+ :group 'exec-path-from-shell)
+
(defun exec-path-from-shell-getenv (name)
"Get the environment variable NAME from the user's shell.
@@ -71,20 +81,24 @@ variable of NAME and return this output as string."
(defun exec-path-from-shell-copy-env (name)
"Set the environment variable $NAME from the user's shell.
-Return the value of the environment variable."
+As a special case, if the variable is $PATH, then `exec-path' is
+also set appropriately. Return the value of the environment
+variable."
(interactive "sCopy value of which environment variable from shell? ")
- (setenv name (exec-path-from-shell-getenv name)))
+ (prog1
+ (setenv name (exec-path-from-shell-getenv name))
+ (when (string-equal "PATH" name)
+ (setq exec-path (split-string (getenv "PATH") path-separator)))))
;;;###autoload
(defun exec-path-from-shell-initialize ()
"Initialize environment from the user's shell.
-Set $MANPATH, $PATH and `exec-path' from the corresponding
-variables in the user's shell."
+The values of all the environment variables named in
+`exec-path-from-shell-variables' are set from the corresponding
+values used in the user's shell."
(interactive)
- (exec-path-from-shell-copy-env "MANPATH")
- (setq exec-path (split-string (exec-path-from-shell-copy-env "PATH")
- path-separator)))
+ (mapc 'exec-path-from-shell-copy-env exec-path-from-shell-variables))
(provide 'exec-path-from-shell)

0 comments on commit f88aa7e

Please sign in to comment.