diff options
| -rw-r--r-- | lisp/env.el | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lisp/env.el b/lisp/env.el index 3445d1c060e..145c164ddde 100644 --- a/lisp/env.el +++ b/lisp/env.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; setenv.el --- functions to manipulate environment variables. | 1 | ;;; env.el --- functions to manipulate environment variables. |
| 2 | 2 | ||
| 3 | ;;; Copyright Free Software Foundation 1991 | 3 | ;;; Copyright Free Software Foundation 1991 |
| 4 | 4 | ||
| @@ -31,24 +31,30 @@ | |||
| 31 | ;;; Code: | 31 | ;;; Code: |
| 32 | 32 | ||
| 33 | ;;;###autoload | 33 | ;;;###autoload |
| 34 | (defun setenv (variable value) | 34 | (defun putenv (variable &optional value) |
| 35 | "Set the value of the environment variable named VARIABLE to VALUE. | 35 | "Set the value of the environment variable named VARIABLE to VALUE. |
| 36 | VARIABLE and VALUE should both be strings. | 36 | VARIABLE should be a string. VALUE is optional; if not provided or is |
| 37 | `nil', the environment variable VARIABLE will be removed. | ||
| 37 | This function works by modifying `process-environment'." | 38 | This function works by modifying `process-environment'." |
| 38 | (interactive "sSet environment variable: \nsSet %s to value: ") | 39 | (interactive "sSet environment variable: \nsSet %s to value: ") |
| 39 | (if (string-match "=" variable) | 40 | (if (string-match "=" variable) |
| 40 | (error "Environment variable name contains `='") | 41 | (error "Environment variable name `%s' contains `='" variable) |
| 41 | (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) | 42 | (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) |
| 42 | (scan process-environment)) | 43 | (scan process-environment)) |
| 43 | (while scan | 44 | (while scan |
| 44 | (cond | 45 | (cond |
| 45 | ((string-match pattern (car scan)) | 46 | ((string-match pattern (car scan)) |
| 46 | (setcar scan (concat variable "=" value)) | 47 | (if (eq nil value) |
| 48 | (setq process-environment (delq (car scan) process-environment)) | ||
| 49 | (setcar scan (concat variable "=" value))) | ||
| 47 | (setq scan nil)) | 50 | (setq scan nil)) |
| 48 | ((null (setq scan (cdr scan))) | 51 | ((null (setq scan (cdr scan))) |
| 49 | (setq process-environment | 52 | (setq process-environment |
| 50 | (cons (concat variable "=" value) process-environment)))))))) | 53 | (cons (concat variable "=" value) process-environment)))))))) |
| 51 | 54 | ||
| 52 | (provide 'setenv) | 55 | ;; Provide backward-contemptibility. |
| 56 | (fset 'setenv 'putenv) | ||
| 53 | 57 | ||
| 54 | ;;; setenv.el ends here | 58 | (provide 'env) |
| 59 | |||
| 60 | ;;; env.el ends here | ||