diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/env.el | 76 | ||||
| -rw-r--r-- | lisp/international/mule-cmds.el | 6 | ||||
| -rw-r--r-- | lisp/server.el | 2 | ||||
| -rw-r--r-- | lisp/term/rxvt.el | 2 | ||||
| -rw-r--r-- | lisp/term/x-win.el | 3 | ||||
| -rw-r--r-- | lisp/term/xterm.el | 4 | ||||
| -rw-r--r-- | lisp/termdev.el | 282 |
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." 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 @@ Use `$$' to insert a single dollar sign." ;; 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 @@ Interactively, the current value (if any) of the variable 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 @@ a side-effect." (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 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', (let ((vars '("LC_ALL" "LC_CTYPE" "LANG"))) (while (and vars (= 0 (length locale))) ; nil or empty string - (setq locale (terminal-getenv (pop vars)))))) + (setq locale (getenv (pop vars) display))))) (unless locale ;; The two tests are kept separate so the byte-compiler sees @@ -2573,7 +2573,7 @@ See also `locale-charset-language-names', `locale-language-names', ;; Mac OS X's Terminal.app by default uses utf-8 regardless of ;; the locale. (when (and (null window-system) - (equal (terminal-getenv "TERM_PROGRAM") "Apple_Terminal")) + (equal (getenv "TERM_PROGRAM" display) "Apple_Terminal")) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8))) @@ -2591,7 +2591,7 @@ See also `locale-charset-language-names', `locale-language-names', (setq ps-paper-type 'a4))) (let ((vars '("LC_ALL" "LC_PAPER" "LANG"))) (while (and vars (= 0 (length locale))) - (setq locale (terminal-getenv (pop vars))))) + (setq locale (getenv (pop vars) display)))) (when locale ;; As of glibc 2.2.5, these are the only US Letter locales, ;; 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: (list (cons 'client proc))))) (setq frame (make-frame-on-display (or display - (frame-parameter nil 'device) + (frame-parameter nil 'display) (getenv "DISPLAY") (error "Please specify display")) 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." ;; intelligent way than the default guesswork in startup.el. (defun rxvt-set-background-mode () "Set background mode as appropriate for the default rxvt colors." - (let ((fgbg (terminal-getenv "COLORFGBG")) + (let ((fgbg (getenv "COLORFGBG" (terminal-id))) bg rgb) (setq default-frame-background-mode 'light) (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.") (aset x-resource-name i ?-)))) (x-open-connection (or x-display-name - (setq x-display-name (terminal-getenv "DISPLAY" nil 'global-ok))) + (setq x-display-name (or (getenv "DISPLAY" (terminal-id)) + (getenv "DISPLAY")))) x-command-line-resources ;; Exit Emacs with fatal error if this fails and we ;; 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 @@ ;; rxvt terminals sometimes set the TERM variable to "xterm", but ;; rxvt's keybindings that are incompatible with xterm's. It is ;; better in that case to use rxvt's initializion function. - (if (and (terminal-getenv "COLORTERM") - (string-match "\\`rxvt" (terminal-getenv "COLORTERM"))) + (if (and (getenv "COLORTERM" (terminal-id)) + (string-match "\\`rxvt" (getenv "COLORTERM" (terminal-id)))) (progn (eval-and-compile (load "term/rxvt")) (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 @@ (substitute-key-definition 'suspend-emacs 'suspend-frame global-map) -(defun terminal-id (terminal) +(defun terminal-id (&optional terminal) "Return the numerical id of terminal TERMINAL. TERMINAL can be a terminal id (an integer), a frame, or @@ -48,146 +48,146 @@ device (HOST.SERVER.SCREEN) or a tty device file." (t (error "Invalid argument %s in `terminal-id'" terminal)))) -(defun terminal-getenv (variable &optional terminal global-ok) - "Get the value of VARIABLE in the client environment of TERMINAL. -VARIABLE should be a string. Value is nil if VARIABLE is undefined in -the environment. Otherwise, value is a string. - -If TERMINAL has an associated emacsclient process, then -`terminal-getenv' looks up VARIABLE in the environment of that -process; otherwise the function consults the global environment, -i.e., the environment of the Emacs process itself. - -If GLOBAL-OK is non-nil, and VARIABLE is not defined in the -terminal-local environment, then `terminal-getenv' will return -its value in the global environment instead. - -TERMINAL can be a terminal id, a frame, or nil (meaning the -selected frame's terminal)." - (setq terminal (terminal-id terminal)) - (if (null (terminal-parameter terminal 'environment)) - (getenv variable) - (if (multibyte-string-p variable) - (setq variable (encode-coding-string variable locale-coding-system))) - (let ((env (terminal-parameter terminal 'environment)) - result entry) - (while (and env (null result)) - (setq entry (car env) - env (cdr env)) - (if (and (> (length entry) (length variable)) - (eq ?= (aref entry (length variable))) - (equal variable (substring entry 0 (length variable)))) - (setq result (substring entry (+ (length variable) 1))))) - (if (and global-ok (null result)) - (getenv variable) - (and result (decode-coding-string result locale-coding-system)))))) - -(defun terminal-setenv (variable &optional value terminal) - "Set the value of VARIABLE in the environment of TERMINAL. -VARIABLE should be string. VALUE is optional; if not provided or -nil, the environment variable VARIABLE is removed. Returned -value is the new value of VARIABLE, or nil if it was removed from -the environment. - -If TERMINAL was created by an emacsclient invocation, then the -variable is set in the environment of the emacsclient process; -otherwise the function changes the environment of the Emacs -process itself. - -TERMINAL can be a terminal id, a frame, or nil (meaning the -selected frame's terminal)." - (if (null (terminal-parameter terminal 'environment)) - (setenv variable value) - (with-terminal-environment terminal variable - (setenv variable value)))) - -(defun terminal-setenv-internal (variable value terminal) - "Set the value of VARIABLE in the environment of TERMINAL. -The caller is responsible to ensure that both VARIABLE and VALUE -are usable in environment variables and that TERMINAL is a -remote terminal." - (if (multibyte-string-p variable) - (setq variable (encode-coding-string variable locale-coding-system))) - (if (and value (multibyte-string-p value)) - (setq value (encode-coding-string value locale-coding-system))) - (let ((env (terminal-parameter terminal 'environment)) - found) - (while (and env (not found)) - (if (and (> (length (car env)) (length variable)) - (eq ?= (aref (car env) (length variable))) - (equal variable (substring (car env) 0 (length variable)))) - (progn - (if value - (setcar env (concat variable "=" value)) - (set-terminal-parameter terminal 'environment - (delq (car env) - (terminal-parameter terminal - 'environment)))) - (setq found t)) - (setq env (cdr env)))) - (cond - ((and value found) - (setcar env (concat variable "=" value))) - ((and value (not found)) - (set-terminal-parameter terminal 'environment - (cons (concat variable "=" value) - (terminal-parameter terminal - 'environment)))) - ((and (not value) found) - (set-terminal-parameter terminal 'environment - (delq (car env) - (terminal-parameter terminal - 'environment))))))) - -(defmacro with-terminal-environment (terminal vars &rest body) - "Evaluate BODY with environment variables VARS set to those of TERMINAL. -The environment variables are then restored to their previous values. - -VARS should be a single string, a list of strings, or t for all -environment variables. - -TERMINAL can be a terminal id, a frame, or nil (meaning the -selected frame's terminal). - -If BODY uses `setenv' to change environment variables in VARS, -then the new variable values will be remembered for TERMINAL, and -`terminal-getenv' will return them even outside BODY." - (declare (indent 2)) - (let ((var (make-symbol "var")) - (term (make-symbol "term")) - (v (make-symbol "v")) - (old-env (make-symbol "old-env"))) - `(let ((,term ,terminal) ; Evaluate arguments only once. - (,v ,vars)) - (if (stringp ,v) - (setq ,v (list ,v))) - (cond - ((null (terminal-parameter ,term 'environment)) - ;; Not a remote terminal; nothing to do. - (progn ,@body)) - ((eq ,v t) - ;; Switch the entire process-environment. - (let (,old-env process-environment) - (setq process-environment (terminal-parameter ,term 'environment)) - (unwind-protect - (progn ,@body) - (set-terminal-parameter ,term 'environment process-environment) - (setq process-environment ,old-env)))) - (t - ;; Do only a set of variables. - (let (,old-env) - (dolist (,var ,v) - (setq ,old-env (cons (cons ,var (getenv ,var)) ,old-env)) - (setenv ,var (terminal-getenv ,var ,term))) - (unwind-protect - (progn ,@body) - ;; Split storing new values and restoring old ones so - ;; that we DTRT even if a variable is specified twice in - ;; VARS. - (dolist (,var ,v) - (terminal-setenv-internal ,var (getenv ,var) ,term)) - (dolist (,var ,old-env) - (setenv (car ,var) (cdr ,var)))))))))) +;; (defun terminal-getenv (variable &optional terminal global-ok) +;; "Get the value of VARIABLE in the client environment of TERMINAL. +;; VARIABLE should be a string. Value is nil if VARIABLE is undefined in +;; the environment. Otherwise, value is a string. + +;; If TERMINAL has an associated emacsclient process, then +;; `terminal-getenv' looks up VARIABLE in the environment of that +;; process; otherwise the function consults the global environment, +;; i.e., the environment of the Emacs process itself. + +;; If GLOBAL-OK is non-nil, and VARIABLE is not defined in the +;; terminal-local environment, then `terminal-getenv' will return +;; its value in the global environment instead. + +;; TERMINAL can be a terminal id, a frame, or nil (meaning the +;; selected frame's terminal)." +;; (setq terminal (terminal-id terminal)) +;; (if (null (terminal-parameter terminal 'environment)) +;; (getenv variable) +;; (if (multibyte-string-p variable) +;; (setq variable (encode-coding-string variable locale-coding-system))) +;; (let ((env (terminal-parameter terminal 'environment)) +;; result entry) +;; (while (and env (null result)) +;; (setq entry (car env) +;; env (cdr env)) +;; (if (and (> (length entry) (length variable)) +;; (eq ?= (aref entry (length variable))) +;; (equal variable (substring entry 0 (length variable)))) +;; (setq result (substring entry (+ (length variable) 1))))) +;; (if (and global-ok (null result)) +;; (getenv variable) +;; (and result (decode-coding-string result locale-coding-system)))))) + +;; (defun terminal-setenv (variable &optional value terminal) +;; "Set the value of VARIABLE in the environment of TERMINAL. +;; VARIABLE should be string. VALUE is optional; if not provided or +;; nil, the environment variable VARIABLE is removed. Returned +;; value is the new value of VARIABLE, or nil if it was removed from +;; the environment. + +;; If TERMINAL was created by an emacsclient invocation, then the +;; variable is set in the environment of the emacsclient process; +;; otherwise the function changes the environment of the Emacs +;; process itself. + +;; TERMINAL can be a terminal id, a frame, or nil (meaning the +;; selected frame's terminal)." +;; (if (null (terminal-parameter terminal 'environment)) +;; (setenv variable value) +;; (with-terminal-environment terminal variable +;; (setenv variable value)))) + +;; (defun terminal-setenv-internal (variable value terminal) +;; "Set the value of VARIABLE in the environment of TERMINAL. +;; The caller is responsible to ensure that both VARIABLE and VALUE +;; are usable in environment variables and that TERMINAL is a +;; remote terminal." +;; (if (multibyte-string-p variable) +;; (setq variable (encode-coding-string variable locale-coding-system))) +;; (if (and value (multibyte-string-p value)) +;; (setq value (encode-coding-string value locale-coding-system))) +;; (let ((env (terminal-parameter terminal 'environment)) +;; found) +;; (while (and env (not found)) +;; (if (and (> (length (car env)) (length variable)) +;; (eq ?= (aref (car env) (length variable))) +;; (equal variable (substring (car env) 0 (length variable)))) +;; (progn +;; (if value +;; (setcar env (concat variable "=" value)) +;; (set-terminal-parameter terminal 'environment +;; (delq (car env) +;; (terminal-parameter terminal +;; 'environment)))) +;; (setq found t)) +;; (setq env (cdr env)))) +;; (cond +;; ((and value found) +;; (setcar env (concat variable "=" value))) +;; ((and value (not found)) +;; (set-terminal-parameter terminal 'environment +;; (cons (concat variable "=" value) +;; (terminal-parameter terminal +;; 'environment)))) +;; ((and (not value) found) +;; (set-terminal-parameter terminal 'environment +;; (delq (car env) +;; (terminal-parameter terminal +;; 'environment))))))) + +;; (defmacro with-terminal-environment (terminal vars &rest body) +;; "Evaluate BODY with environment variables VARS set to those of TERMINAL. +;; The environment variables are then restored to their previous values. + +;; VARS should be a single string, a list of strings, or t for all +;; environment variables. + +;; TERMINAL can be a terminal id, a frame, or nil (meaning the +;; selected frame's terminal). + +;; If BODY uses `setenv' to change environment variables in VARS, +;; then the new variable values will be remembered for TERMINAL, and +;; `terminal-getenv' will return them even outside BODY." +;; (declare (indent 2)) +;; (let ((var (make-symbol "var")) +;; (term (make-symbol "term")) +;; (v (make-symbol "v")) +;; (old-env (make-symbol "old-env"))) +;; `(let ((,term ,terminal) ; Evaluate arguments only once. +;; (,v ,vars)) +;; (if (stringp ,v) +;; (setq ,v (list ,v))) +;; (cond +;; ((null (terminal-parameter ,term 'environment)) +;; ;; Not a remote terminal; nothing to do. +;; (progn ,@body)) +;; ((eq ,v t) +;; ;; Switch the entire process-environment. +;; (let (,old-env process-environment) +;; (setq process-environment (terminal-parameter ,term 'environment)) +;; (unwind-protect +;; (progn ,@body) +;; (set-terminal-parameter ,term 'environment process-environment) +;; (setq process-environment ,old-env)))) +;; (t +;; ;; Do only a set of variables. +;; (let (,old-env) +;; (dolist (,var ,v) +;; (setq ,old-env (cons (cons ,var (getenv ,var)) ,old-env)) +;; (setenv ,var (terminal-getenv ,var ,term))) +;; (unwind-protect +;; (progn ,@body) +;; ;; Split storing new values and restoring old ones so +;; ;; that we DTRT even if a variable is specified twice in +;; ;; VARS. +;; (dolist (,var ,v) +;; (terminal-setenv-internal ,var (getenv ,var) ,term)) +;; (dolist (,var ,old-env) +;; (setenv (car ,var) (cdr ,var)))))))))) (provide 'termdev) |
