]> code.delx.au - gnu-emacs/blobdiff - lisp/env.el
(Version, mh-version): Update for release 7.95.
[gnu-emacs] / lisp / env.el
index 912634482bf37719750b47db8c1619f62379c9cd..1b6c038cbea8eed6ac6a4e533d3978198b8b0b74 100644 (file)
@@ -1,6 +1,7 @@
 ;;; env.el --- functions to manipulate environment variables
 
-;; Copyright (C) 1991, 1994, 2000, 2001, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1991, 1994, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: processes, unix
@@ -19,8 +20,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -63,12 +64,14 @@ If it is also not t, RET does not exit if it does non-null completion."
 `$FOO' where FOO is an environment variable name means to substitute
 the value of that variable.  The variable name should be terminated
 with a character not a letter, digit or underscore; otherwise, enclose
-the entire variable name in braces.  Use `$$' to insert a single
-dollar sign."
+the entire variable name in braces.  For instance, in `ab$cd-x',
+`$cd' is treated as an environment variable.
+
+Use `$$' to insert a single dollar sign."
   (let ((start 0))
     (while (string-match
            (eval-when-compile
-             (rx (or (and "$" (submatch (1+ (regexp "[:alnum:]_"))))
+             (rx (or (and "$" (submatch (1+ (regexp "[[:alnum:]_]"))))
                      (and "${" (submatch (minimal-match (0+ anything))) "}")
                      "$$")))
            string start)
@@ -87,28 +90,30 @@ dollar sign."
 
 ;; Fixme: Should `process-environment' be recoded if LC_CTYPE &c is set?
 
-(defun setenv (variable &optional value unset substitute-env-vars)
+(defun setenv (variable &optional value substitute-env-vars)
   "Set the value of the environment variable named VARIABLE to VALUE.
-VARIABLE should be a string.  VALUE is optional; if not provided or is
-`nil', the environment variable VARIABLE will be removed.  UNSET
-if non-nil means to remove VARIABLE from the environment.
-SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment
-variables in VALUE with `substitute-env-vars', where see.
-Value is the new value if VARIABLE, or nil if removed from the
-environment.
+VARIABLE should be a string.  VALUE is optional; if not provided or
+nil, the environment variable VARIABLE will be removed.
 
 Interactively, a prefix argument means to unset the variable.
 Interactively, the current value (if any) of the variable
 appears at the front of the history list when you type in the new value.
 Interactively, always replace environment variables in the new value.
 
+SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment
+variables in VALUE with `substitute-env-vars', which see.
+This is normally used only for interactive calls.
+
+The return value is the new value of VARIABLE, or nil if
+it was removed from the environment.
+
 This function works by modifying `process-environment'.
 
 As a special case, setting variable `TZ' calls `set-time-zone-rule' as
 a side-effect."
   (interactive
    (if current-prefix-arg
-       (list (read-envvar-name "Clear environment variable: " 'exact) nil t)
+       (list (read-envvar-name "Clear environment variable: " 'exact) nil)
      (let* ((var (read-envvar-name "Set environment variable: " nil))
            (value (getenv var)))
        (when value
@@ -118,20 +123,16 @@ a side-effect."
             (read-from-minibuffer (format "Set %s to value: " var)
                                   nil nil nil 'setenv-history
                                   value)
-            nil
             t))))
   (if (and (multibyte-string-p variable) locale-coding-system)
-      (unless (memq (coding-system-base locale-coding-system)
-                   (find-coding-systems-string (concat variable value)))
-       (error "Can't encode `%s=%s' with `locale-coding-system'"
-              variable (or value "")))
-    (unless (memq 'undecided (find-coding-systems-string variable))
-      (error "Can't encode `%s=%s' with unspecified `locale-coding-system'"
-            variable (or value ""))))
-  (if unset 
-      (setq value nil)
-    (if substitute-env-vars
-       (setq value (substitute-env-vars value))))
+      (let ((codings (find-coding-systems-string (concat variable value))))
+       (unless (or (eq 'undecided (car codings))
+                   (memq (coding-system-base locale-coding-system) codings))
+         (error "Can't encode `%s=%s' with `locale-coding-system'"
+                variable (or value "")))))
+  (and value
+       substitute-env-vars
+       (setq value (substitute-env-vars value)))
   (if (multibyte-string-p variable)
       (setq variable (encode-coding-string variable locale-coding-system)))
   (if (and value (multibyte-string-p value))
@@ -180,4 +181,5 @@ for its value."
 
 (provide 'env)
 
+;;; arch-tag: b7d6a8f7-bc81-46db-8e39-8d721d4ed0b8
 ;;; env.el ends here