Mercurial > emacs
comparison lisp/env.el @ 21201:425bf2edf1d4
(setenv): Simplify reading of args by passing old value as the default.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 17 Mar 1998 08:14:28 +0000 |
parents | 83f275dcd93a |
children | 845292e36d62 |
comparison
equal
deleted
inserted
replaced
21200:ea520c42a342 | 21201:425bf2edf1d4 |
---|---|
61 | 61 |
62 This function works by modifying `process-environment'." | 62 This function works by modifying `process-environment'." |
63 (interactive | 63 (interactive |
64 (if current-prefix-arg | 64 (if current-prefix-arg |
65 (list (read-envvar-name "Clear environment variable: " 'exact) nil t) | 65 (list (read-envvar-name "Clear environment variable: " 'exact) nil t) |
66 (let* ((var (read-envvar-name "Set environment variable: " nil)) | 66 (let ((var (read-envvar-name "Set environment variable: " nil))) |
67 (oldval (getenv var)) | |
68 newval | |
69 oldhist) | |
70 ;; Don't put the current value on the history | |
71 ;; if it is already there. | |
72 (if (equal oldval (car setenv-history)) | |
73 (setq oldval nil)) | |
74 ;; Now if OLDVAL is non-nil, we should add it to the history. | |
75 (if oldval | |
76 (setq setenv-history (cons oldval setenv-history))) | |
77 (setq oldhist setenv-history) | |
78 (setq newval (read-from-minibuffer (format "Set %s to value: " var) | |
79 nil nil nil 'setenv-history)) | |
80 ;; If we added the current value to the history, remove it. | |
81 ;; Note that read-from-minibuffer may have added the new value. | |
82 ;; Don't remove that! | |
83 (if oldval | |
84 (if (eq oldhist setenv-history) | |
85 (setq setenv-history (cdr setenv-history)) | |
86 (setcdr setenv-history (cdr (cdr setenv-history))))) | |
87 ;; Here finally we specify the args to give call setenv with. | 67 ;; Here finally we specify the args to give call setenv with. |
88 (list var newval)))) | 68 (list var (read-from-minibuffer (format "Set %s to value: " var) |
69 nil nil nil 'setenv-history | |
70 (getenv var)))))) | |
89 (if unset (setq value nil)) | 71 (if unset (setq value nil)) |
90 (if (string-match "=" variable) | 72 (if (string-match "=" variable) |
91 (error "Environment variable name `%s' contains `='" variable) | 73 (error "Environment variable name `%s' contains `='" variable) |
92 (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) | 74 (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) |
93 (case-fold-search nil) | 75 (case-fold-search nil) |