Mercurial > emacs
comparison lisp/env.el @ 83427:2afc49c9f0c0
Store local environment in frame (not terminal) parameters.
* src/callproc.c (child_setup, getenv_internal, Fgetenv_internal):
Store the local environment in a frame (not terminal) parameter.
Update doc strings.
(syms_of_callproc): Update doc strings.
(Qenvironment): Moved to frame.c.
* lisp/env.el (read-envvar-name, setenv, getenv, environment): Use frame
parameters to store the local environment, not terminal parameters.
* server.el (server-process-filter): Store the local environment in a
frame (not terminal) parameter. Do not try to decode environment
strings.
* lisp/frame.el (make-frame): Set up the 'environment frame parameter,
when needed.
* src/frame.c (Qenvironment): Move here from callproc.c.
(Fdelete_frame): Don't allow other frames to refer to a deleted frame
in their 'environment parameter.
(Fframe_with_environment): New function.
(syms_of_frame): Defsubr it. Initialize and staticpro Qenvironment.
* frame.h (Qenvironment): Declare.
* lisp.h (Fframe_with_environment): EXFUN it.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-467
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Thu, 29 Dec 2005 04:31:04 +0000 |
parents | c82829d08b89 |
children | 10f26433fe3f |
comparison
equal
deleted
inserted
replaced
83426:7c7d1f1cb2e7 | 83427:2afc49c9f0c0 |
---|---|
53 (string-match "=" enventry)) | 53 (string-match "=" enventry)) |
54 locale-coding-system t) | 54 locale-coding-system t) |
55 (substring enventry 0 | 55 (substring enventry 0 |
56 (string-match "=" enventry))))) | 56 (string-match "=" enventry))))) |
57 (append process-environment | 57 (append process-environment |
58 (terminal-parameter nil 'environment) | 58 (frame-parameter (frame-with-environment) 'environment) |
59 global-environment)) | 59 global-environment)) |
60 nil mustmatch nil 'read-envvar-name-history)) | 60 nil mustmatch nil 'read-envvar-name-history)) |
61 | 61 |
62 ;; History list for VALUE argument to setenv. | 62 ;; History list for VALUE argument to setenv. |
63 (defvar setenv-history nil) | 63 (defvar setenv-history nil) |
92 start (+ (match-beginning 0) 1))))) | 92 start (+ (match-beginning 0) 1))))) |
93 string)) | 93 string)) |
94 | 94 |
95 ;; Fixme: Should the environment be recoded if LC_CTYPE &c is set? | 95 ;; Fixme: Should the environment be recoded if LC_CTYPE &c is set? |
96 | 96 |
97 (defun setenv (variable &optional value unset substitute-env-vars terminal) | 97 (defun setenv (variable &optional value unset substitute-env-vars frame) |
98 "Set the value of the environment variable named VARIABLE to VALUE. | 98 "Set the value of the environment variable named VARIABLE to VALUE. |
99 VARIABLE should be a string. VALUE is optional; if not provided or | 99 VARIABLE should be a string. VALUE is optional; if not provided or |
100 nil, the environment variable VARIABLE will be removed. UNSET | 100 nil, the environment variable VARIABLE will be removed. UNSET |
101 if non-nil means to remove VARIABLE from the environment. | 101 if non-nil means to remove VARIABLE from the environment. |
102 SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment | 102 SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment |
110 Interactively, always replace environment variables in the new value. | 110 Interactively, always replace environment variables in the new value. |
111 | 111 |
112 If VARIABLE is set in `process-environment', then this function | 112 If VARIABLE is set in `process-environment', then this function |
113 modifies its value there. Otherwise, this function works by | 113 modifies its value there. Otherwise, this function works by |
114 modifying either `global-environment' or the environment | 114 modifying either `global-environment' or the environment |
115 belonging to the terminal device of the selected frame, depending | 115 belonging to the selected frame, depending on the value of |
116 on the value of `local-environment-variables'. | 116 `local-environment-variables'. |
117 | 117 |
118 If optional parameter TERMINAL is non-nil, then it should be a | 118 If optional parameter FRAME is non-nil, then it should be a a |
119 terminal id or a frame. If the specified terminal device has its own | 119 frame. If the specified frame has its own set of environment |
120 set of environment variables, this function will modify VAR in it. | 120 variables, this function will modify VARIABLE in it. Note that |
121 frames on the same terminal device usually share their | |
122 environment, so calling `setenv' on one of them affects the | |
123 others as well. | |
121 | 124 |
122 As a special case, setting variable `TZ' calls `set-time-zone-rule' as | 125 As a special case, setting variable `TZ' calls `set-time-zone-rule' as |
123 a side-effect." | 126 a side-effect." |
124 (interactive | 127 (interactive |
125 (if current-prefix-arg | 128 (if current-prefix-arg |
151 (setq value (encode-coding-string value locale-coding-system))) | 154 (setq value (encode-coding-string value locale-coding-system))) |
152 (if (string-match "=" variable) | 155 (if (string-match "=" variable) |
153 (error "Environment variable name `%s' contains `='" variable)) | 156 (error "Environment variable name `%s' contains `='" variable)) |
154 (let ((pattern (concat "\\`" (regexp-quote variable) "\\(=\\|\\'\\)")) | 157 (let ((pattern (concat "\\`" (regexp-quote variable) "\\(=\\|\\'\\)")) |
155 (case-fold-search nil) | 158 (case-fold-search nil) |
156 (terminal-env (terminal-parameter terminal 'environment)) | 159 (frame-env (frame-parameter (frame-with-environment frame) 'environment)) |
160 (frame-forced (not frame)) | |
157 (scan process-environment) | 161 (scan process-environment) |
158 found) | 162 found) |
163 (setq frame (frame-with-environment frame)) | |
159 (if (string-equal "TZ" variable) | 164 (if (string-equal "TZ" variable) |
160 (set-time-zone-rule value)) | 165 (set-time-zone-rule value)) |
161 (block nil | 166 (block nil |
162 ;; Look for an existing entry for VARIABLE; try `process-environment' first. | 167 ;; Look for an existing entry for VARIABLE; try `process-environment' first. |
163 (while (and scan (stringp (car scan))) | 168 (while (and scan (stringp (car scan))) |
164 (when (string-match pattern (car scan)) | 169 (when (string-match pattern (car scan)) |
165 (if value | 170 (if value |
166 (setcar scan (concat variable "=" value)) | 171 (setcar scan (concat variable "=" value)) |
167 ;; Leave unset variables in `process-environment', | 172 ;; Leave unset variables in `process-environment', |
168 ;; otherwise the overridden value in `global-environment' | 173 ;; otherwise the overridden value in `global-environment' |
169 ;; or terminal-env would become unmasked. | 174 ;; or frame-env would become unmasked. |
170 (setcar scan variable)) | 175 (setcar scan variable)) |
171 (return value)) | 176 (return value)) |
172 (setq scan (cdr scan))) | 177 (setq scan (cdr scan))) |
173 | 178 |
174 ;; Look in the local or global environment, whichever is relevant. | 179 ;; Look in the local or global environment, whichever is relevant. |
175 (let ((local-var-p (and terminal-env | 180 (let ((local-var-p (and frame-env |
176 (or terminal | 181 (or frame-forced |
177 (eq t local-environment-variables) | 182 (eq t local-environment-variables) |
178 (member variable local-environment-variables))))) | 183 (member variable local-environment-variables))))) |
179 (setq scan (if local-var-p | 184 (setq scan (if local-var-p |
180 terminal-env | 185 frame-env |
181 global-environment)) | 186 global-environment)) |
182 (while scan | 187 (while scan |
183 (when (string-match pattern (car scan)) | 188 (when (string-match pattern (car scan)) |
184 (if value | 189 (if value |
185 (setcar scan (concat variable "=" value)) | 190 (setcar scan (concat variable "=" value)) |
186 (if local-var-p | 191 (if local-var-p |
187 (set-terminal-parameter terminal 'environment | 192 (set-frame-parameter frame 'environment |
188 (delq (car scan) terminal-env)) | 193 (delq (car scan) frame-env)) |
189 (setq global-environment (delq (car scan) global-environment))) | 194 (setq global-environment (delq (car scan) global-environment)))) |
190 (return value))) | 195 (return value)) |
191 (setq scan (cdr scan))) | 196 (setq scan (cdr scan))) |
192 | 197 |
193 ;; VARIABLE is not in any environment list. | 198 ;; VARIABLE is not in any environment list. |
194 (if value | 199 (if value |
195 (if local-var-p | 200 (if local-var-p |
196 (set-terminal-parameter nil 'environment | 201 (set-frame-parameter frame 'environment |
197 (cons (concat variable "=" value) | 202 (cons (concat variable "=" value) |
198 terminal-env)) | 203 frame-env)) |
199 (setq global-environment | 204 (setq global-environment |
200 (cons (concat variable "=" value) | 205 (cons (concat variable "=" value) |
201 global-environment)))) | 206 global-environment)))) |
202 (return value))))) | 207 (return value))))) |
203 | 208 |
204 (defun getenv (variable &optional terminal) | 209 (defun getenv (variable &optional frame) |
205 "Get the value of environment variable VARIABLE. | 210 "Get the value of environment variable VARIABLE. |
206 VARIABLE should be a string. Value is nil if VARIABLE is undefined in | 211 VARIABLE should be a string. Value is nil if VARIABLE is undefined in |
207 the environment. Otherwise, value is a string. | 212 the environment. Otherwise, value is a string. |
208 | 213 |
209 If optional parameter TERMINAL is non-nil, then it should be a | 214 If optional parameter FRAME is non-nil, then it should be a |
210 terminal id or a frame. If the specified terminal device has its own | 215 frame. If the specified terminal device has its own set of |
211 set of environment variables, this function will look up VARIABLE in | 216 environment variables, this function will look up VARIABLE in it. |
212 it. | 217 |
213 | 218 Otherwise, this function searches `process-environment' for |
214 Otherwise, this function searches `process-environment' for VARIABLE. | 219 VARIABLE. If it was not found there, then it continues the |
215 If it was not found there, then it continues the search in either | 220 search in either `global-environment' or the environment list of |
216 `global-environment' or the local environment list of the current | 221 the selected frame, depending on the value of |
217 terminal device, depending on the value of | |
218 `local-environment-variables'." | 222 `local-environment-variables'." |
219 (interactive (list (read-envvar-name "Get environment variable: " t))) | 223 (interactive (list (read-envvar-name "Get environment variable: " t))) |
220 (let ((value (getenv-internal (if (multibyte-string-p variable) | 224 (let ((value (getenv-internal (if (multibyte-string-p variable) |
221 (encode-coding-string | 225 (encode-coding-string |
222 variable locale-coding-system) | 226 variable locale-coding-system) |
234 The returned list can not be used to change environment | 238 The returned list can not be used to change environment |
235 variables, only read them. See `setenv' to do that. | 239 variables, only read them. See `setenv' to do that. |
236 | 240 |
237 The list is constructed from elements of `process-environment', | 241 The list is constructed from elements of `process-environment', |
238 `global-environment' and the local environment list of the | 242 `global-environment' and the local environment list of the |
239 current terminal, as specified by `local-environment-variables'. | 243 selected frame, as specified by `local-environment-variables'. |
240 | 244 |
241 Non-ASCII characters are encoded according to the initial value of | 245 Non-ASCII characters are encoded according to the initial value of |
242 `locale-coding-system', i.e. the elements must normally be decoded for use. | 246 `locale-coding-system', i.e. the elements must normally be decoded for use. |
243 See `setenv' and `getenv'." | 247 See `setenv' and `getenv'." |
244 (let ((env (cond ((or (not local-environment-variables) | 248 (let ((env (let ((local-env (frame-parameter (frame-with-environment) |
245 (not (terminal-parameter nil 'environment))) | 249 'environment))) |
246 (append process-environment global-environment nil)) | 250 (cond ((or (not local-environment-variables) |
247 ((consp local-environment-variables) | 251 (not local-env)) |
248 (let ((e (reverse process-environment))) | 252 (append process-environment global-environment nil)) |
249 (dolist (entry local-environment-variables) | 253 ((consp local-environment-variables) |
250 (setq e (cons (getenv entry) e))) | 254 (let ((e (reverse process-environment))) |
251 (append (nreverse e) global-environment nil))) | 255 (dolist (entry local-environment-variables) |
252 (t | 256 (setq e (cons (getenv entry) e))) |
253 (append process-environment (terminal-parameter nil 'environment) nil)))) | 257 (append (nreverse e) global-environment nil))) |
258 (t | |
259 (append process-environment local-env nil))))) | |
254 scan seen) | 260 scan seen) |
255 ;; Find the first valid entry in env. | 261 ;; Find the first valid entry in env. |
256 (while (and env (stringp (car env)) | 262 (while (and env (stringp (car env)) |
257 (or (not (string-match "=" (car env))) | 263 (or (not (string-match "=" (car env))) |
258 (member (substring (car env) 0 (string-match "=" (car env))) seen))) | 264 (member (substring (car env) 0 (string-match "=" (car env))) seen))) |