aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/env.el
diff options
context:
space:
mode:
authorKaroly Lorentey2005-12-29 04:31:04 +0000
committerKaroly Lorentey2005-12-29 04:31:04 +0000
commitda8e8fc14f3166ec596e34f43fbfea866d1176df (patch)
tree9c31affcb4b837cac4793f10acbafc562bfd08e4 /lisp/env.el
parent86f5ca04d94ad551d3aa726e15281e75ef0189ed (diff)
downloademacs-da8e8fc14f3166ec596e34f43fbfea866d1176df.tar.gz
emacs-da8e8fc14f3166ec596e34f43fbfea866d1176df.zip
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
Diffstat (limited to 'lisp/env.el')
-rw-r--r--lisp/env.el84
1 files changed, 45 insertions, 39 deletions
diff --git a/lisp/env.el b/lisp/env.el
index 7099a72ca2c..38a9e865283 100644
--- a/lisp/env.el
+++ b/lisp/env.el
@@ -55,7 +55,7 @@ If it is also not t, RET does not exit if it does non-null completion."
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
@@ -94,7 +94,7 @@ Use `$$' to insert a single dollar sign."
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.
99VARIABLE should be a string. VALUE is optional; if not provided or 99VARIABLE should be a string. VALUE is optional; if not provided or
100nil, the environment variable VARIABLE will be removed. UNSET 100nil, the environment variable VARIABLE will be removed. UNSET
@@ -112,12 +112,15 @@ Interactively, always replace environment variables in the new value.
112If VARIABLE is set in `process-environment', then this function 112If VARIABLE is set in `process-environment', then this function
113modifies its value there. Otherwise, this function works by 113modifies its value there. Otherwise, this function works by
114modifying either `global-environment' or the environment 114modifying either `global-environment' or the environment
115belonging to the terminal device of the selected frame, depending 115belonging to the selected frame, depending on the value of
116on the value of `local-environment-variables'. 116`local-environment-variables'.
117 117
118If optional parameter TERMINAL is non-nil, then it should be a 118If optional parameter FRAME is non-nil, then it should be a a
119terminal id or a frame. If the specified terminal device has its own 119frame. If the specified frame has its own set of environment
120set of environment variables, this function will modify VAR in it. 120variables, this function will modify VARIABLE in it. Note that
121frames on the same terminal device usually share their
122environment, so calling `setenv' on one of them affects the
123others as well.
121 124
122As a special case, setting variable `TZ' calls `set-time-zone-rule' as 125As a special case, setting variable `TZ' calls `set-time-zone-rule' as
123a side-effect." 126a side-effect."
@@ -153,9 +156,11 @@ a side-effect."
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
@@ -166,55 +171,54 @@ a side-effect."
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.
206VARIABLE should be a string. Value is nil if VARIABLE is undefined in 211VARIABLE should be a string. Value is nil if VARIABLE is undefined in
207the environment. Otherwise, value is a string. 212the environment. Otherwise, value is a string.
208 213
209If optional parameter TERMINAL is non-nil, then it should be a 214If optional parameter FRAME is non-nil, then it should be a
210terminal id or a frame. If the specified terminal device has its own 215frame. If the specified terminal device has its own set of
211set of environment variables, this function will look up VARIABLE in 216environment variables, this function will look up VARIABLE in it.
212it.
213 217
214Otherwise, this function searches `process-environment' for VARIABLE. 218Otherwise, this function searches `process-environment' for
215If it was not found there, then it continues the search in either 219VARIABLE. If it was not found there, then it continues the
216`global-environment' or the local environment list of the current 220search in either `global-environment' or the environment list of
217terminal device, depending on the value of 221the selected frame, 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)
@@ -236,21 +240,23 @@ variables, only read them. See `setenv' to do that.
236 240
237The list is constructed from elements of `process-environment', 241The 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
239current terminal, as specified by `local-environment-variables'. 243selected frame, as specified by `local-environment-variables'.
240 244
241Non-ASCII characters are encoded according to the initial value of 245Non-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.
243See `setenv' and `getenv'." 247See `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))