aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKaroly Lorentey2005-12-26 02:14:10 +0000
committerKaroly Lorentey2005-12-26 02:14:10 +0000
commitf105f403d206f95bf534226abb99f14aa2f3052e (patch)
treed326884972abd85997fc9e688e0fefa60a3ec977 /lisp
parented8dad6b616204b4dd4e853801f41da6f4c3b0a7 (diff)
downloademacs-f105f403d206f95bf534226abb99f14aa2f3052e.tar.gz
emacs-f105f403d206f95bf534226abb99f14aa2f3052e.zip
Implement automatic terminal-local environment variables via `local-environment-variables'.
* lisp/env.el (setenv, getenv): Add optional terminal parameter. Update docs. (setenv): Handle `local-environment-variables'. (read-envvar-name): Also allow (and complete) local environment variables on the current terminal. * src/callproc.c: Include frame.h and termhooks.h, for terminal parameters. (Qenvironment): New constant. (Vlocal_environment_variables): New variable. (syms_of_callproc): Register and initialize them. (child_setup): Handle Vlocal_environment_variables. (getenv_internal): Add terminal parameter. Handle Vlocal_environment_variables. (Fgetenv_internal): Add terminal parameter. * src/termhooks.h (get_terminal_param): Declare. * src/Makefile.in (callproc.o): Update dependencies. * mac/makefile.MPW (callproc.c.x): Update dependencies. * lisp/termdev.el (terminal-id): Make parameter optional. (terminal-getenv, terminal-setenv, with-terminal-environment): Disable functions. * lisp/mule-cmds.el (set-locale-environment): Convert `terminal-getenv' calls to `getenv'. * lisp/rxvt.el (rxvt-set-background-mode): Ditto. * lisp/x-win.el (x-initialize-window-system): Ditto. * lisp/xterm.el (terminal-init-xterm): Ditto. * lisp/server.el (server-process-filter): Fix reference to the 'display frame parameter. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-461
Diffstat (limited to 'lisp')
-rw-r--r--lisp/env.el76
-rw-r--r--lisp/international/mule-cmds.el6
-rw-r--r--lisp/server.el2
-rw-r--r--lisp/term/rxvt.el2
-rw-r--r--lisp/term/x-win.el3
-rw-r--r--lisp/term/xterm.el4
-rw-r--r--lisp/termdev.el282
7 files changed, 203 insertions, 172 deletions
diff --git a/lisp/env.el b/lisp/env.el
index 409765f5ff4..378b7f078be 100644
--- a/lisp/env.el
+++ b/lisp/env.el
@@ -52,7 +52,8 @@ If it is also not t, RET does not exit if it does non-null completion."
52 locale-coding-system t) 52 locale-coding-system t)
53 (substring enventry 0 53 (substring enventry 0
54 (string-match "=" enventry))))) 54 (string-match "=" enventry)))))
55 process-environment) 55 (append (terminal-parameter nil 'environment)
56 process-environment))
56 nil mustmatch nil 'read-envvar-name-history)) 57 nil mustmatch nil 'read-envvar-name-history))
57 58
58;; History list for VALUE argument to setenv. 59;; History list for VALUE argument to setenv.
@@ -90,7 +91,7 @@ Use `$$' to insert a single dollar sign."
90 91
91;; Fixme: Should `process-environment' be recoded if LC_CTYPE &c is set? 92;; Fixme: Should `process-environment' be recoded if LC_CTYPE &c is set?
92 93
93(defun setenv (variable &optional value unset substitute-env-vars) 94(defun setenv (variable &optional value unset substitute-env-vars terminal)
94 "Set the value of the environment variable named VARIABLE to VALUE. 95 "Set the value of the environment variable named VARIABLE to VALUE.
95VARIABLE should be a string. VALUE is optional; if not provided or 96VARIABLE should be a string. VALUE is optional; if not provided or
96nil, the environment variable VARIABLE will be removed. UNSET 97nil, the environment variable VARIABLE will be removed. UNSET
@@ -105,7 +106,14 @@ Interactively, the current value (if any) of the variable
105appears at the front of the history list when you type in the new value. 106appears at the front of the history list when you type in the new value.
106Interactively, always replace environment variables in the new value. 107Interactively, always replace environment variables in the new value.
107 108
108This function works by modifying `process-environment'. 109If optional parameter TERMINAL is non-nil, then it should be a
110terminal id or a frame. If the specified terminal device has its own
111set of environment variables, this function will modify VAR in it.
112
113Otherwise, this function works by modifying either
114`process-environment' or the environment belonging to the
115terminal device of the selected frame, depending on the value of
116`local-environment-variables'.
109 117
110As a special case, setting variable `TZ' calls `set-time-zone-rule' as 118As a special case, setting variable `TZ' calls `set-time-zone-rule' as
111a side-effect." 119a side-effect."
@@ -138,36 +146,58 @@ a side-effect."
138 (if (and value (multibyte-string-p value)) 146 (if (and value (multibyte-string-p value))
139 (setq value (encode-coding-string value locale-coding-system))) 147 (setq value (encode-coding-string value locale-coding-system)))
140 (if (string-match "=" variable) 148 (if (string-match "=" variable)
141 (error "Environment variable name `%s' contains `='" variable) 149 (error "Environment variable name `%s' contains `='" variable))
142 (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) 150 (let* ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
143 (case-fold-search nil) 151 (case-fold-search nil)
144 (scan process-environment) 152 (local-var-p (and (terminal-parameter terminal 'environment)
145 found) 153 (or terminal
146 (if (string-equal "TZ" variable) 154 (eq t local-environment-variables)
147 (set-time-zone-rule value)) 155 (member variable local-environment-variables))))
148 (while scan 156 (scan (if local-var-p
149 (cond ((string-match pattern (car scan)) 157 (terminal-parameter terminal 'environment)
150 (setq found t) 158 process-environment))
151 (if (eq nil value) 159 found)
160 (if (string-equal "TZ" variable)
161 (set-time-zone-rule value))
162 (while scan
163 (cond ((string-match pattern (car scan))
164 (setq found t)
165 (if (eq nil value)
166 (if local-var-p
167 (set-terminal-parameter terminal 'environment
168 (delq (car scan)
169 (terminal-parameter terminal 'environment)))
152 (setq process-environment (delq (car scan) 170 (setq process-environment (delq (car scan)
153 process-environment)) 171 process-environment)))
154 (setcar scan (concat variable "=" value))) 172 (setcar scan (concat variable "=" value)))
155 (setq scan nil))) 173 (setq scan nil)))
156 (setq scan (cdr scan))) 174 (setq scan (cdr scan)))
157 (or found 175 (or found
158 (if value 176 (if value
177 (if local-var-p
178 (set-terminal-parameter nil 'environment
179 (cons (concat variable "=" value)
180 (terminal-parameter nil 'environment)))
159 (setq process-environment 181 (setq process-environment
160 (cons (concat variable "=" value) 182 (cons (concat variable "=" value)
161 process-environment)))))) 183 process-environment))))))
162 value) 184 value)
163 185
164(defun getenv (variable) 186(defun getenv (variable &optional terminal)
165 "Get the value of environment variable VARIABLE. 187 "Get the value of environment variable VARIABLE.
166VARIABLE should be a string. Value is nil if VARIABLE is undefined in 188VARIABLE should be a string. Value is nil if VARIABLE is undefined in
167the environment. Otherwise, value is a string. 189the environment. Otherwise, value is a string.
168 190
169This function consults the variable `process-environment' 191If optional parameter TERMINAL is non-nil, then it should be a
170for its value." 192terminal id or a frame. If the specified terminal device has its own
193set of environment variables, this function will look up VAR in it.
194
195Otherwise, if `local-environment-variables' specifies that VAR is a
196local environment variable, then this function consults the
197environment variables belonging to the terminal device of the selected
198frame.
199
200Otherwise, the value of VAR will come from `process-environment'."
171 (interactive (list (read-envvar-name "Get environment variable: " t))) 201 (interactive (list (read-envvar-name "Get environment variable: " t)))
172 (let ((value (getenv-internal (if (multibyte-string-p variable) 202 (let ((value (getenv-internal (if (multibyte-string-p variable)
173 (encode-coding-string 203 (encode-coding-string
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index b66243f2270..575653e8f5a 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -2460,7 +2460,7 @@ See also `locale-charset-language-names', `locale-language-names',
2460 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG"))) 2460 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
2461 (while (and vars 2461 (while (and vars
2462 (= 0 (length locale))) ; nil or empty string 2462 (= 0 (length locale))) ; nil or empty string
2463 (setq locale (terminal-getenv (pop vars)))))) 2463 (setq locale (getenv (pop vars) display)))))
2464 2464
2465 (unless locale 2465 (unless locale
2466 ;; The two tests are kept separate so the byte-compiler sees 2466 ;; The two tests are kept separate so the byte-compiler sees
@@ -2573,7 +2573,7 @@ See also `locale-charset-language-names', `locale-language-names',
2573 ;; Mac OS X's Terminal.app by default uses utf-8 regardless of 2573 ;; Mac OS X's Terminal.app by default uses utf-8 regardless of
2574 ;; the locale. 2574 ;; the locale.
2575 (when (and (null window-system) 2575 (when (and (null window-system)
2576 (equal (terminal-getenv "TERM_PROGRAM") "Apple_Terminal")) 2576 (equal (getenv "TERM_PROGRAM" display) "Apple_Terminal"))
2577 (set-terminal-coding-system 'utf-8) 2577 (set-terminal-coding-system 'utf-8)
2578 (set-keyboard-coding-system 'utf-8))) 2578 (set-keyboard-coding-system 'utf-8)))
2579 2579
@@ -2591,7 +2591,7 @@ See also `locale-charset-language-names', `locale-language-names',
2591 (setq ps-paper-type 'a4))) 2591 (setq ps-paper-type 'a4)))
2592 (let ((vars '("LC_ALL" "LC_PAPER" "LANG"))) 2592 (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
2593 (while (and vars (= 0 (length locale))) 2593 (while (and vars (= 0 (length locale)))
2594 (setq locale (terminal-getenv (pop vars))))) 2594 (setq locale (getenv (pop vars) display))))
2595 (when locale 2595 (when locale
2596 ;; As of glibc 2.2.5, these are the only US Letter locales, 2596 ;; As of glibc 2.2.5, these are the only US Letter locales,
2597 ;; and the rest are A4. 2597 ;; and the rest are A4.
diff --git a/lisp/server.el b/lisp/server.el
index 7aed300e99a..fb587b640a3 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -624,7 +624,7 @@ The following commands are accepted by the client:
624 (list (cons 'client proc))))) 624 (list (cons 'client proc)))))
625 (setq frame (make-frame-on-display 625 (setq frame (make-frame-on-display
626 (or display 626 (or display
627 (frame-parameter nil 'device) 627 (frame-parameter nil 'display)
628 (getenv "DISPLAY") 628 (getenv "DISPLAY")
629 (error "Please specify display")) 629 (error "Please specify display"))
630 params)) 630 params))
diff --git a/lisp/term/rxvt.el b/lisp/term/rxvt.el
index e7e92e70042..79994403301 100644
--- a/lisp/term/rxvt.el
+++ b/lisp/term/rxvt.el
@@ -291,7 +291,7 @@ for the currently selected frame."
291;; intelligent way than the default guesswork in startup.el. 291;; intelligent way than the default guesswork in startup.el.
292(defun rxvt-set-background-mode () 292(defun rxvt-set-background-mode ()
293 "Set background mode as appropriate for the default rxvt colors." 293 "Set background mode as appropriate for the default rxvt colors."
294 (let ((fgbg (terminal-getenv "COLORFGBG")) 294 (let ((fgbg (getenv "COLORFGBG" (terminal-id)))
295 bg rgb) 295 bg rgb)
296 (setq default-frame-background-mode 'light) 296 (setq default-frame-background-mode 'light)
297 (when (and fgbg 297 (when (and fgbg
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index 49ef4cb9a58..a61577215e5 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -2407,7 +2407,8 @@ order until succeed.")
2407 (aset x-resource-name i ?-)))) 2407 (aset x-resource-name i ?-))))
2408 2408
2409 (x-open-connection (or x-display-name 2409 (x-open-connection (or x-display-name
2410 (setq x-display-name (terminal-getenv "DISPLAY" nil 'global-ok))) 2410 (setq x-display-name (or (getenv "DISPLAY" (terminal-id))
2411 (getenv "DISPLAY"))))
2411 x-command-line-resources 2412 x-command-line-resources
2412 ;; Exit Emacs with fatal error if this fails and we 2413 ;; Exit Emacs with fatal error if this fails and we
2413 ;; are the initial display. 2414 ;; are the initial display.
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index ecfeaba51fc..399385b4fc4 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -192,8 +192,8 @@
192 ;; rxvt terminals sometimes set the TERM variable to "xterm", but 192 ;; rxvt terminals sometimes set the TERM variable to "xterm", but
193 ;; rxvt's keybindings that are incompatible with xterm's. It is 193 ;; rxvt's keybindings that are incompatible with xterm's. It is
194 ;; better in that case to use rxvt's initializion function. 194 ;; better in that case to use rxvt's initializion function.
195 (if (and (terminal-getenv "COLORTERM") 195 (if (and (getenv "COLORTERM" (terminal-id))
196 (string-match "\\`rxvt" (terminal-getenv "COLORTERM"))) 196 (string-match "\\`rxvt" (getenv "COLORTERM" (terminal-id))))
197 (progn 197 (progn
198 (eval-and-compile (load "term/rxvt")) 198 (eval-and-compile (load "term/rxvt"))
199 (terminal-init-rxvt)) 199 (terminal-init-rxvt))
diff --git a/lisp/termdev.el b/lisp/termdev.el
index f413067d542..5e12740e11c 100644
--- a/lisp/termdev.el
+++ b/lisp/termdev.el
@@ -25,7 +25,7 @@
25 25
26(substitute-key-definition 'suspend-emacs 'suspend-frame global-map) 26(substitute-key-definition 'suspend-emacs 'suspend-frame global-map)
27 27
28(defun terminal-id (terminal) 28(defun terminal-id (&optional terminal)
29 "Return the numerical id of terminal TERMINAL. 29 "Return the numerical id of terminal TERMINAL.
30 30
31TERMINAL can be a terminal id (an integer), a frame, or 31TERMINAL can be a terminal id (an integer), a frame, or
@@ -48,146 +48,146 @@ device (HOST.SERVER.SCREEN) or a tty device file."
48 (t 48 (t
49 (error "Invalid argument %s in `terminal-id'" terminal)))) 49 (error "Invalid argument %s in `terminal-id'" terminal))))
50 50
51(defun terminal-getenv (variable &optional terminal global-ok) 51;; (defun terminal-getenv (variable &optional terminal global-ok)
52 "Get the value of VARIABLE in the client environment of TERMINAL. 52;; "Get the value of VARIABLE in the client environment of TERMINAL.
53VARIABLE should be a string. Value is nil if VARIABLE is undefined in 53;; VARIABLE should be a string. Value is nil if VARIABLE is undefined in
54the environment. Otherwise, value is a string. 54;; the environment. Otherwise, value is a string.
55 55
56If TERMINAL has an associated emacsclient process, then 56;; If TERMINAL has an associated emacsclient process, then
57`terminal-getenv' looks up VARIABLE in the environment of that 57;; `terminal-getenv' looks up VARIABLE in the environment of that
58process; otherwise the function consults the global environment, 58;; process; otherwise the function consults the global environment,
59i.e., the environment of the Emacs process itself. 59;; i.e., the environment of the Emacs process itself.
60 60
61If GLOBAL-OK is non-nil, and VARIABLE is not defined in the 61;; If GLOBAL-OK is non-nil, and VARIABLE is not defined in the
62terminal-local environment, then `terminal-getenv' will return 62;; terminal-local environment, then `terminal-getenv' will return
63its value in the global environment instead. 63;; its value in the global environment instead.
64 64
65TERMINAL can be a terminal id, a frame, or nil (meaning the 65;; TERMINAL can be a terminal id, a frame, or nil (meaning the
66selected frame's terminal)." 66;; selected frame's terminal)."
67 (setq terminal (terminal-id terminal)) 67;; (setq terminal (terminal-id terminal))
68 (if (null (terminal-parameter terminal 'environment)) 68;; (if (null (terminal-parameter terminal 'environment))
69 (getenv variable) 69;; (getenv variable)
70 (if (multibyte-string-p variable) 70;; (if (multibyte-string-p variable)
71 (setq variable (encode-coding-string variable locale-coding-system))) 71;; (setq variable (encode-coding-string variable locale-coding-system)))
72 (let ((env (terminal-parameter terminal 'environment)) 72;; (let ((env (terminal-parameter terminal 'environment))
73 result entry) 73;; result entry)
74 (while (and env (null result)) 74;; (while (and env (null result))
75 (setq entry (car env) 75;; (setq entry (car env)
76 env (cdr env)) 76;; env (cdr env))
77 (if (and (> (length entry) (length variable)) 77;; (if (and (> (length entry) (length variable))
78 (eq ?= (aref entry (length variable))) 78;; (eq ?= (aref entry (length variable)))
79 (equal variable (substring entry 0 (length variable)))) 79;; (equal variable (substring entry 0 (length variable))))
80 (setq result (substring entry (+ (length variable) 1))))) 80;; (setq result (substring entry (+ (length variable) 1)))))
81 (if (and global-ok (null result)) 81;; (if (and global-ok (null result))
82 (getenv variable) 82;; (getenv variable)
83 (and result (decode-coding-string result locale-coding-system)))))) 83;; (and result (decode-coding-string result locale-coding-system))))))
84 84
85(defun terminal-setenv (variable &optional value terminal) 85;; (defun terminal-setenv (variable &optional value terminal)
86 "Set the value of VARIABLE in the environment of TERMINAL. 86;; "Set the value of VARIABLE in the environment of TERMINAL.
87VARIABLE should be string. VALUE is optional; if not provided or 87;; VARIABLE should be string. VALUE is optional; if not provided or
88nil, the environment variable VARIABLE is removed. Returned 88;; nil, the environment variable VARIABLE is removed. Returned
89value is the new value of VARIABLE, or nil if it was removed from 89;; value is the new value of VARIABLE, or nil if it was removed from
90the environment. 90;; the environment.
91 91
92If TERMINAL was created by an emacsclient invocation, then the 92;; If TERMINAL was created by an emacsclient invocation, then the
93variable is set in the environment of the emacsclient process; 93;; variable is set in the environment of the emacsclient process;
94otherwise the function changes the environment of the Emacs 94;; otherwise the function changes the environment of the Emacs
95process itself. 95;; process itself.
96 96
97TERMINAL can be a terminal id, a frame, or nil (meaning the 97;; TERMINAL can be a terminal id, a frame, or nil (meaning the
98selected frame's terminal)." 98;; selected frame's terminal)."
99 (if (null (terminal-parameter terminal 'environment)) 99;; (if (null (terminal-parameter terminal 'environment))
100 (setenv variable value) 100;; (setenv variable value)
101 (with-terminal-environment terminal variable 101;; (with-terminal-environment terminal variable
102 (setenv variable value)))) 102;; (setenv variable value))))
103 103
104(defun terminal-setenv-internal (variable value terminal) 104;; (defun terminal-setenv-internal (variable value terminal)
105 "Set the value of VARIABLE in the environment of TERMINAL. 105;; "Set the value of VARIABLE in the environment of TERMINAL.
106The caller is responsible to ensure that both VARIABLE and VALUE 106;; The caller is responsible to ensure that both VARIABLE and VALUE
107are usable in environment variables and that TERMINAL is a 107;; are usable in environment variables and that TERMINAL is a
108remote terminal." 108;; remote terminal."
109 (if (multibyte-string-p variable) 109;; (if (multibyte-string-p variable)
110 (setq variable (encode-coding-string variable locale-coding-system))) 110;; (setq variable (encode-coding-string variable locale-coding-system)))
111 (if (and value (multibyte-string-p value)) 111;; (if (and value (multibyte-string-p value))
112 (setq value (encode-coding-string value locale-coding-system))) 112;; (setq value (encode-coding-string value locale-coding-system)))
113 (let ((env (terminal-parameter terminal 'environment)) 113;; (let ((env (terminal-parameter terminal 'environment))
114 found) 114;; found)
115 (while (and env (not found)) 115;; (while (and env (not found))
116 (if (and (> (length (car env)) (length variable)) 116;; (if (and (> (length (car env)) (length variable))
117 (eq ?= (aref (car env) (length variable))) 117;; (eq ?= (aref (car env) (length variable)))
118 (equal variable (substring (car env) 0 (length variable)))) 118;; (equal variable (substring (car env) 0 (length variable))))
119 (progn 119;; (progn
120 (if value 120;; (if value
121 (setcar env (concat variable "=" value)) 121;; (setcar env (concat variable "=" value))
122 (set-terminal-parameter terminal 'environment 122;; (set-terminal-parameter terminal 'environment
123 (delq (car env) 123;; (delq (car env)
124 (terminal-parameter terminal 124;; (terminal-parameter terminal
125 'environment)))) 125;; 'environment))))
126 (setq found t)) 126;; (setq found t))
127 (setq env (cdr env)))) 127;; (setq env (cdr env))))
128 (cond 128;; (cond
129 ((and value found) 129;; ((and value found)
130 (setcar env (concat variable "=" value))) 130;; (setcar env (concat variable "=" value)))
131 ((and value (not found)) 131;; ((and value (not found))
132 (set-terminal-parameter terminal 'environment 132;; (set-terminal-parameter terminal 'environment
133 (cons (concat variable "=" value) 133;; (cons (concat variable "=" value)
134 (terminal-parameter terminal 134;; (terminal-parameter terminal
135 'environment)))) 135;; 'environment))))
136 ((and (not value) found) 136;; ((and (not value) found)
137 (set-terminal-parameter terminal 'environment 137;; (set-terminal-parameter terminal 'environment
138 (delq (car env) 138;; (delq (car env)
139 (terminal-parameter terminal 139;; (terminal-parameter terminal
140 'environment))))))) 140;; 'environment)))))))
141 141
142(defmacro with-terminal-environment (terminal vars &rest body) 142;; (defmacro with-terminal-environment (terminal vars &rest body)
143 "Evaluate BODY with environment variables VARS set to those of TERMINAL. 143;; "Evaluate BODY with environment variables VARS set to those of TERMINAL.
144The environment variables are then restored to their previous values. 144;; The environment variables are then restored to their previous values.
145 145
146VARS should be a single string, a list of strings, or t for all 146;; VARS should be a single string, a list of strings, or t for all
147environment variables. 147;; environment variables.
148 148
149TERMINAL can be a terminal id, a frame, or nil (meaning the 149;; TERMINAL can be a terminal id, a frame, or nil (meaning the
150selected frame's terminal). 150;; selected frame's terminal).
151 151
152If BODY uses `setenv' to change environment variables in VARS, 152;; If BODY uses `setenv' to change environment variables in VARS,
153then the new variable values will be remembered for TERMINAL, and 153;; then the new variable values will be remembered for TERMINAL, and
154`terminal-getenv' will return them even outside BODY." 154;; `terminal-getenv' will return them even outside BODY."
155 (declare (indent 2)) 155;; (declare (indent 2))
156 (let ((var (make-symbol "var")) 156;; (let ((var (make-symbol "var"))
157 (term (make-symbol "term")) 157;; (term (make-symbol "term"))
158 (v (make-symbol "v")) 158;; (v (make-symbol "v"))
159 (old-env (make-symbol "old-env"))) 159;; (old-env (make-symbol "old-env")))
160 `(let ((,term ,terminal) ; Evaluate arguments only once. 160;; `(let ((,term ,terminal) ; Evaluate arguments only once.
161 (,v ,vars)) 161;; (,v ,vars))
162 (if (stringp ,v) 162;; (if (stringp ,v)
163 (setq ,v (list ,v))) 163;; (setq ,v (list ,v)))
164 (cond 164;; (cond
165 ((null (terminal-parameter ,term 'environment)) 165;; ((null (terminal-parameter ,term 'environment))
166 ;; Not a remote terminal; nothing to do. 166;; ;; Not a remote terminal; nothing to do.
167 (progn ,@body)) 167;; (progn ,@body))
168 ((eq ,v t) 168;; ((eq ,v t)
169 ;; Switch the entire process-environment. 169;; ;; Switch the entire process-environment.
170 (let (,old-env process-environment) 170;; (let (,old-env process-environment)
171 (setq process-environment (terminal-parameter ,term 'environment)) 171;; (setq process-environment (terminal-parameter ,term 'environment))
172 (unwind-protect 172;; (unwind-protect
173 (progn ,@body) 173;; (progn ,@body)
174 (set-terminal-parameter ,term 'environment process-environment) 174;; (set-terminal-parameter ,term 'environment process-environment)
175 (setq process-environment ,old-env)))) 175;; (setq process-environment ,old-env))))
176 (t 176;; (t
177 ;; Do only a set of variables. 177;; ;; Do only a set of variables.
178 (let (,old-env) 178;; (let (,old-env)
179 (dolist (,var ,v) 179;; (dolist (,var ,v)
180 (setq ,old-env (cons (cons ,var (getenv ,var)) ,old-env)) 180;; (setq ,old-env (cons (cons ,var (getenv ,var)) ,old-env))
181 (setenv ,var (terminal-getenv ,var ,term))) 181;; (setenv ,var (terminal-getenv ,var ,term)))
182 (unwind-protect 182;; (unwind-protect
183 (progn ,@body) 183;; (progn ,@body)
184 ;; Split storing new values and restoring old ones so 184;; ;; Split storing new values and restoring old ones so
185 ;; that we DTRT even if a variable is specified twice in 185;; ;; that we DTRT even if a variable is specified twice in
186 ;; VARS. 186;; ;; VARS.
187 (dolist (,var ,v) 187;; (dolist (,var ,v)
188 (terminal-setenv-internal ,var (getenv ,var) ,term)) 188;; (terminal-setenv-internal ,var (getenv ,var) ,term))
189 (dolist (,var ,old-env) 189;; (dolist (,var ,old-env)
190 (setenv (car ,var) (cdr ,var)))))))))) 190;; (setenv (car ,var) (cdr ,var))))))))))
191 191
192(provide 'termdev) 192(provide 'termdev)
193 193