diff options
| author | Richard M. Stallman | 1994-06-22 04:39:27 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-06-22 04:39:27 +0000 |
| commit | cbfe666bc7a5b6bbf4373be925a4baa84fec3d44 (patch) | |
| tree | 8e072065d66b14554e5b047f55b641bc35ff2fe4 | |
| parent | dad146f93689dab0a3d73e100f9d2ca0ab78974f (diff) | |
| download | emacs-cbfe666bc7a5b6bbf4373be925a4baa84fec3d44.tar.gz emacs-cbfe666bc7a5b6bbf4373be925a4baa84fec3d44.zip | |
(setenv): Rewrite. Provide a way to unset interactively.
| -rw-r--r-- | lisp/env.el | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/lisp/env.el b/lisp/env.el index cbf6dcf2156..dc591ab26f2 100644 --- a/lisp/env.el +++ b/lisp/env.el | |||
| @@ -31,30 +31,38 @@ | |||
| 31 | ;;; Code: | 31 | ;;; Code: |
| 32 | 32 | ||
| 33 | ;;;###autoload | 33 | ;;;###autoload |
| 34 | (defun setenv (variable &optional value) | 34 | (defun setenv (variable &optional value unset) |
| 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 should be a string. VALUE is optional; if not provided or is | 36 | VARIABLE should be a string. VALUE is optional; if not provided or is |
| 37 | `nil', the environment variable VARIABLE will be removed. | 37 | `nil', the environment variable VARIABLE will be removed. |
| 38 | |||
| 39 | Interactively, a prefix argument means to unset the variable. | ||
| 38 | This function works by modifying `process-environment'." | 40 | This function works by modifying `process-environment'." |
| 39 | (interactive "sSet environment variable: \nsSet %s to value: ") | 41 | (interactive |
| 42 | (if current-prefix-arg | ||
| 43 | (list (read-string "Clear environment variable: ") nil t) | ||
| 44 | (let ((var (read-string "Set environment variable: "))) | ||
| 45 | (list var (read-string (format "Set %s to value: " var)))))) | ||
| 46 | (if unset (setq value nil)) | ||
| 40 | (if (string-match "=" variable) | 47 | (if (string-match "=" variable) |
| 41 | (error "Environment variable name `%s' contains `='" variable) | 48 | (error "Environment variable name `%s' contains `='" variable) |
| 42 | (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) | 49 | (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) |
| 43 | (case-fold-search nil) | 50 | (case-fold-search nil) |
| 44 | (scan process-environment)) | 51 | (scan process-environment) |
| 45 | (if scan | 52 | found) |
| 46 | (while scan | 53 | (while scan |
| 47 | (cond | 54 | (cond ((string-match pattern (car scan)) |
| 48 | ((string-match pattern (car scan)) | 55 | (setq found t) |
| 49 | (if (eq nil value) | 56 | (if (eq nil value) |
| 50 | (setq process-environment (delq (car scan) process-environment)) | 57 | (setq process-environment (delq (car scan) process-environment)) |
| 51 | (setcar scan (concat variable "=" value))) | 58 | (setcar scan (concat variable "=" value))) |
| 52 | (setq scan nil)) | 59 | (setq scan nil))) |
| 53 | ((null (setq scan (cdr scan))) | 60 | (setq scan (cdr scan))) |
| 61 | (or found | ||
| 62 | (if value | ||
| 54 | (setq process-environment | 63 | (setq process-environment |
| 55 | (cons (concat variable "=" value) process-environment))))) | 64 | (cons (concat variable "=" value) |
| 56 | (setq process-environment | 65 | process-environment))))))) |
| 57 | (cons (concat variable "=" value) process-environment)))))) | ||
| 58 | 66 | ||
| 59 | (provide 'env) | 67 | (provide 'env) |
| 60 | 68 | ||