diff lisp/env.el @ 83421:bb2edc915032

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
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 26 Dec 2005 02:14:10 +0000
parents 41bb365f41c4
children c82829d08b89
line wrap: on
line diff
--- a/lisp/env.el	Sun Dec 25 20:06:58 2005 +0000
+++ b/lisp/env.el	Mon Dec 26 02:14:10 2005 +0000
@@ -52,7 +52,8 @@
 					locale-coding-system t)
 				     (substring enventry 0
 						(string-match "=" enventry)))))
-			   process-environment)
+			   (append (terminal-parameter nil 'environment)
+				   process-environment))
 		   nil mustmatch nil 'read-envvar-name-history))
 
 ;; History list for VALUE argument to setenv.
@@ -90,7 +91,7 @@
 
 ;; Fixme: Should `process-environment' be recoded if LC_CTYPE &c is set?
 
-(defun setenv (variable &optional value unset substitute-env-vars)
+(defun setenv (variable &optional value unset substitute-env-vars terminal)
   "Set the value of the environment variable named VARIABLE to VALUE.
 VARIABLE should be a string.  VALUE is optional; if not provided or
 nil, the environment variable VARIABLE will be removed.  UNSET
@@ -105,7 +106,14 @@
 appears at the front of the history list when you type in the new value.
 Interactively, always replace environment variables in the new value.
 
-This function works by modifying `process-environment'.
+If optional parameter TERMINAL is non-nil, then it should be a
+terminal id or a frame.  If the specified terminal device has its own
+set of environment variables, this function will modify VAR in it.
+
+Otherwise, this function works by modifying either
+`process-environment' or the environment belonging to the
+terminal device of the selected frame, depending on the value of
+`local-environment-variables'.
 
 As a special case, setting variable `TZ' calls `set-time-zone-rule' as
 a side-effect."
@@ -138,36 +146,58 @@
   (if (and value (multibyte-string-p value))
       (setq value (encode-coding-string value locale-coding-system)))
   (if (string-match "=" variable)
-      (error "Environment variable name `%s' contains `='" variable)
-    (let ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
-	  (case-fold-search nil)
-	  (scan process-environment)
-	  found)
-      (if (string-equal "TZ" variable)
-	  (set-time-zone-rule value))
-      (while scan
-	(cond ((string-match pattern (car scan))
-	       (setq found t)
-	       (if (eq nil value)
+      (error "Environment variable name `%s' contains `='" variable))
+  (let* ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
+	 (case-fold-search nil)
+	 (local-var-p (and (terminal-parameter terminal 'environment)
+			   (or terminal
+			       (eq t local-environment-variables)
+			       (member variable local-environment-variables))))
+	 (scan (if local-var-p
+		   (terminal-parameter terminal 'environment)
+		 process-environment))
+	 found)
+    (if (string-equal "TZ" variable)
+	(set-time-zone-rule value))
+    (while scan
+      (cond ((string-match pattern (car scan))
+	     (setq found t)
+	     (if (eq nil value)
+		 (if local-var-p
+		     (set-terminal-parameter terminal 'environment
+					     (delq (car scan)
+						   (terminal-parameter terminal 'environment)))
 		   (setq process-environment (delq (car scan)
-						   process-environment))
-		 (setcar scan (concat variable "=" value)))
-	       (setq scan nil)))
-	(setq scan (cdr scan)))
-      (or found
-	  (if value
+						   process-environment)))
+	       (setcar scan (concat variable "=" value)))
+	     (setq scan nil)))
+      (setq scan (cdr scan)))
+    (or found
+	(if value
+	    (if local-var-p
+		(set-terminal-parameter nil 'environment
+					(cons (concat variable "=" value)
+					      (terminal-parameter nil 'environment)))
 	      (setq process-environment
 		    (cons (concat variable "=" value)
 			  process-environment))))))
   value)
 
-(defun getenv (variable)
+(defun getenv (variable &optional terminal)
   "Get the value of environment variable VARIABLE.
 VARIABLE should be a string.  Value is nil if VARIABLE is undefined in
 the environment.  Otherwise, value is a string.
 
-This function consults the variable `process-environment'
-for its value."
+If optional parameter TERMINAL is non-nil, then it should be a
+terminal id or a frame.  If the specified terminal device has its own
+set of environment variables, this function will look up VAR in it.
+
+Otherwise, if `local-environment-variables' specifies that VAR is a
+local environment variable, then this function consults the
+environment variables belonging to the terminal device of the selected
+frame.
+
+Otherwise, the value of VAR will come from `process-environment'."
   (interactive (list (read-envvar-name "Get environment variable: " t)))
   (let ((value (getenv-internal (if (multibyte-string-p variable)
 				    (encode-coding-string