aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
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
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')
-rw-r--r--lisp/env.el84
-rw-r--r--lisp/frame.el8
-rw-r--r--lisp/server.el12
3 files changed, 58 insertions, 46 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))
diff --git a/lisp/frame.el b/lisp/frame.el
index ecf0697cae4..339100bbff5 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -674,12 +674,20 @@ setup is for focus to follow the pointer."
674 (cdr (assq 'window-system parameters))) 674 (cdr (assq 'window-system parameters)))
675 (t window-system))) 675 (t window-system)))
676 (frame-creation-function (cdr (assq w frame-creation-function-alist))) 676 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
677 (oldframe (selected-frame))
677 frame) 678 frame)
678 (unless frame-creation-function 679 (unless frame-creation-function
679 (error "Don't know how to create a frame on window system %s" w)) 680 (error "Don't know how to create a frame on window system %s" w))
680 (run-hooks 'before-make-frame-hook) 681 (run-hooks 'before-make-frame-hook)
681 (setq frame (funcall frame-creation-function (append parameters (cdr (assq w window-system-default-frame-alist))))) 682 (setq frame (funcall frame-creation-function (append parameters (cdr (assq w window-system-default-frame-alist)))))
682 (normal-erase-is-backspace-setup-frame frame) 683 (normal-erase-is-backspace-setup-frame frame)
684 ;; Set up the frame-local environment, if needed.
685 (when (eq (frame-display frame) (frame-display oldframe))
686 (let ((env (frame-parameter oldframe 'environment)))
687 (if (not (framep env))
688 (setq env oldframe))
689 (if env
690 (set-frame-parameter frame 'environment env))))
683 (run-hook-with-args 'after-make-frame-functions frame) 691 (run-hook-with-args 'after-make-frame-functions frame)
684 frame)) 692 frame))
685 693
diff --git a/lisp/server.el b/lisp/server.el
index fb587b640a3..f98be109c92 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -620,8 +620,8 @@ The following commands are accepted by the client:
620 ;; emacsclient quits while also preventing 620 ;; emacsclient quits while also preventing
621 ;; `server-save-buffers-kill-display' from unexpectedly 621 ;; `server-save-buffers-kill-display' from unexpectedly
622 ;; killing emacs on that frame. 622 ;; killing emacs on that frame.
623 (list (cons 'client 'nowait)) 623 (list (cons 'client 'nowait) (cons 'environment env))
624 (list (cons 'client proc))))) 624 (list (cons 'client proc) (cons 'environment env)))))
625 (setq frame (make-frame-on-display 625 (setq frame (make-frame-on-display
626 (or display 626 (or display
627 (frame-parameter nil 'display) 627 (frame-parameter nil 'display)
@@ -637,7 +637,6 @@ The following commands are accepted by the client:
637 (select-frame frame) 637 (select-frame frame)
638 (server-client-set client 'frame frame) 638 (server-client-set client 'frame frame)
639 (server-client-set client 'device (frame-display frame)) 639 (server-client-set client 'device (frame-display frame))
640 (set-terminal-parameter frame 'environment env)
641 (setq dontkill t)) 640 (setq dontkill t))
642 ;; This emacs does not support X. 641 ;; This emacs does not support X.
643 (server-log "Window system unsupported" proc) 642 (server-log "Window system unsupported" proc)
@@ -684,12 +683,12 @@ The following commands are accepted by the client:
684 (setq frame (make-frame-on-tty tty type 683 (setq frame (make-frame-on-tty tty type
685 ;; Ignore nowait here; we always need to clean 684 ;; Ignore nowait here; we always need to clean
686 ;; up opened ttys when the client dies. 685 ;; up opened ttys when the client dies.
687 `((client . ,proc))))) 686 `((client . ,proc)
687 (environment . ,env)))))
688 (select-frame frame) 688 (select-frame frame)
689 (server-client-set client 'frame frame) 689 (server-client-set client 'frame frame)
690 (server-client-set client 'tty (display-name frame)) 690 (server-client-set client 'tty (display-name frame))
691 (server-client-set client 'device (frame-display frame)) 691 (server-client-set client 'device (frame-display frame))
692 (set-terminal-parameter frame 'environment env)
693 692
694 ;; Reply with our pid. 693 ;; Reply with our pid.
695 (server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n")) 694 (server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n"))
@@ -740,8 +739,7 @@ The following commands are accepted by the client:
740 ;; -env NAME=VALUE: An environment variable. 739 ;; -env NAME=VALUE: An environment variable.
741 ((and (equal "-env" arg) (string-match "\\([^ ]+\\) " request)) 740 ((and (equal "-env" arg) (string-match "\\([^ ]+\\) " request))
742 (let ((var (server-unquote-arg (match-string 1 request)))) 741 (let ((var (server-unquote-arg (match-string 1 request))))
743 (when coding-system 742 ;; XXX Variables should be encoded as in getenv/setenv.
744 (setq var (decode-coding-string var coding-system)))
745 (setq request (substring request (match-end 0))) 743 (setq request (substring request (match-end 0)))
746 (setq env (cons var env)))) 744 (setq env (cons var env))))
747 745