summaryrefslogtreecommitdiff
path: root/lisp/frame.el
diff options
context:
space:
mode:
authorKaroly Lorentey <lorentey@elte.hu>2005-11-19 19:17:56 +0000
committerKaroly Lorentey <lorentey@elte.hu>2005-11-19 19:17:56 +0000
commit59e085e04d44b0331620b55a64eb94bf99cf81b1 (patch)
treed6c04a67e99ec5ef0229e23b6303596cb1c555b6 /lisp/frame.el
parente3362cebc3485806379cac1986b901f3da20d59d (diff)
downloademacs-59e085e04d44b0331620b55a64eb94bf99cf81b1.tar.gz
Store client's environment in terminal parameters, not server parameters.
* lisp/loadup.el: Don't load server. * lisp/ldefs-boot.el: Update. * lib-src/emacsclient.c (main): Send environment only when a new display is created. * lisp/server.el (server-save-buffers-kill-display): Add autoload cookie. Move stuff not specific to server into `save-buffers-kill-display'. * lisp/files.el (save-buffers-kill-display): New function. (ctl-x-map): Bind it to C-x C-c. * lisp/frame.el (terminal-getenv): New function. * lisp/international/mule-cmds.el (set-locale-environment): Use it. * lisp/frame.el (with-terminal-environment): New macro. * lisp/server.el (server-getenv, server-with-client-environment): Remove. (server-getenv-from, server-with-environment): New functions. (server-process-filter): Change syntax of environment variables. Put environment into terminal parameters, not client parameters. * lisp/term/rxvt.el: Don't require server. (rxvt-set-background-mode): Use terminal-getenv, not server-getenv. * lisp/term/x-win.el (x-initialize-window-system): Ditto. * lisp/term/xterm.el (terminal-init-xterm): Ditto. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-443
Diffstat (limited to 'lisp/frame.el')
-rw-r--r--lisp/frame.el54
1 files changed, 54 insertions, 0 deletions
diff --git a/lisp/frame.el b/lisp/frame.el
index fb494429fea..98df0359ddc 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -1511,6 +1511,60 @@ selected frame's terminal)."
(add-hook 'delete-frame-functions 'terminal-handle-delete-frame)
+(defun terminal-getenv (variable &optional terminal)
+ "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 was created by an emacsclient invocation, then the
+variable is looked up in the environment of the emacsclient
+process; otherwise the function consults the environment of the
+Emacs process.
+
+TERMINAL can be a terminal id, a frame, or nil (meaning the
+selected frame's terminal)."
+ (setq terminal (terminal-id terminal))
+ (if (not (terminal-parameter-p terminal 'environment))
+ (getenv variable)
+ (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 (null result)
+ (getenv variable)
+ result))))
+
+(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 list of strings.
+
+TERMINAL can be a terminal id, a frame, or nil (meaning the
+selected frame's terminal).
+
+See also `terminal-getenv'."
+ (declare (indent 2))
+ (let ((oldvalues (make-symbol "oldvalues"))
+ (var (make-symbol "var"))
+ (value (make-symbol "value"))
+ (pair (make-symbol "pair")))
+ `(let (,oldvalues)
+ (dolist (,var ,vars)
+ (let ((,value (terminal-getenv ,var ,terminal)))
+ (setq ,oldvalues (cons (cons ,var (getenv ,var)) ,oldvalues))
+ (setenv ,var ,value)))
+ (unwind-protect
+ (progn ,@body)
+ (dolist (,pair ,oldvalues)
+ (setenv (car ,pair) (cdr ,pair)))))))
+
+
(provide 'frame)
;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56