Mercurial > emacs
annotate lisp/termdev.el @ 84402:6e599fa0f77d
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 08 Sep 2007 10:35:27 +0000 |
parents | 5f9de879d4da |
children | 875f30e5371e |
rev | line source |
---|---|
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
1 ;;; termdev.el --- functions for dealing with terminals |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
2 |
83729
5f9de879d4da
Update copyright years, update license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
83431
diff
changeset
|
3 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
4 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
5 ;; Author: Karoly Lorentey <karoly@lorentey.hu> |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
6 ;; Created: 2005-12-22 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
7 ;; Keywords: internal |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
8 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
10 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
83729
5f9de879d4da
Update copyright years, update license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
83431
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
14 ;; any later version. |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
15 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
20 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
25 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
26 (substitute-key-definition 'suspend-emacs 'suspend-frame global-map) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
27 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
28 (defun terminal-id (&optional terminal) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
29 "Return the numerical id of terminal TERMINAL. |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
30 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
31 TERMINAL can be a terminal id (an integer), a frame, or |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
32 nil (meaning the selected frame's terminal). Alternatively, |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
33 TERMINAL may be the name of an X display |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
34 device (HOST.SERVER.SCREEN) or a tty device file." |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
35 (cond |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
36 ((integerp terminal) |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
37 (if (terminal-live-p terminal) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
38 terminal |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
39 (signal 'wrong-type-argument (list 'terminal-live-p terminal)))) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
40 ((or (null terminal) (framep terminal)) |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
41 (frame-terminal terminal)) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
42 ((stringp terminal) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
43 (let ((f (car (filtered-frame-list (lambda (frame) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
44 (or (equal (frame-parameter frame 'display) terminal) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
45 (equal (frame-parameter frame 'tty) terminal))))))) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
46 (or f (error "Display %s does not exist" terminal)) |
83431
76396de7f50a
Rename `struct device' to `struct terminal'. Rename some terminal-related functions similarly.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
47 (frame-terminal f))) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
48 (t |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
49 (error "Invalid argument %s in `terminal-id'" terminal)))) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
50 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
51 ;; (defun terminal-getenv (variable &optional terminal global-ok) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
52 ;; "Get the value of VARIABLE in the client environment of TERMINAL. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
53 ;; VARIABLE should be a string. Value is nil if VARIABLE is undefined in |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
54 ;; the environment. Otherwise, value is a string. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
55 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
56 ;; If TERMINAL has an associated emacsclient process, then |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
57 ;; `terminal-getenv' looks up VARIABLE in the environment of that |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
58 ;; process; otherwise the function consults the global environment, |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
59 ;; i.e., the environment of the Emacs process itself. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
60 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
61 ;; If GLOBAL-OK is non-nil, and VARIABLE is not defined in the |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
62 ;; terminal-local environment, then `terminal-getenv' will return |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
63 ;; its value in the global environment instead. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
64 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
65 ;; TERMINAL can be a terminal id, a frame, or nil (meaning the |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
66 ;; selected frame's terminal)." |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
67 ;; (setq terminal (terminal-id terminal)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
68 ;; (if (null (terminal-parameter terminal 'environment)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
69 ;; (getenv variable) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
70 ;; (if (multibyte-string-p variable) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
71 ;; (setq variable (encode-coding-string variable locale-coding-system))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
72 ;; (let ((env (terminal-parameter terminal 'environment)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
73 ;; result entry) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
74 ;; (while (and env (null result)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
75 ;; (setq entry (car env) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
76 ;; env (cdr env)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
77 ;; (if (and (> (length entry) (length variable)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
78 ;; (eq ?= (aref entry (length variable))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
79 ;; (equal variable (substring entry 0 (length variable)))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
80 ;; (setq result (substring entry (+ (length variable) 1))))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
81 ;; (if (and global-ok (null result)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
82 ;; (getenv variable) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
83 ;; (and result (decode-coding-string result locale-coding-system)))))) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
84 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
85 ;; (defun terminal-setenv (variable &optional value terminal) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
86 ;; "Set the value of VARIABLE in the environment of TERMINAL. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
87 ;; VARIABLE should be string. VALUE is optional; if not provided or |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
88 ;; nil, the environment variable VARIABLE is removed. Returned |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
89 ;; value is the new value of VARIABLE, or nil if it was removed from |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
90 ;; the environment. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
91 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
92 ;; If TERMINAL was created by an emacsclient invocation, then the |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
93 ;; variable is set in the environment of the emacsclient process; |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
94 ;; otherwise the function changes the environment of the Emacs |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
95 ;; process itself. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
96 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
97 ;; TERMINAL can be a terminal id, a frame, or nil (meaning the |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
98 ;; selected frame's terminal)." |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
99 ;; (if (null (terminal-parameter terminal 'environment)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
100 ;; (setenv variable value) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
101 ;; (with-terminal-environment terminal variable |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
102 ;; (setenv variable value)))) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
103 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
104 ;; (defun terminal-setenv-internal (variable value terminal) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
105 ;; "Set the value of VARIABLE in the environment of TERMINAL. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
106 ;; The caller is responsible to ensure that both VARIABLE and VALUE |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
107 ;; are usable in environment variables and that TERMINAL is a |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
108 ;; remote terminal." |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
109 ;; (if (multibyte-string-p variable) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
110 ;; (setq variable (encode-coding-string variable locale-coding-system))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
111 ;; (if (and value (multibyte-string-p value)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
112 ;; (setq value (encode-coding-string value locale-coding-system))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
113 ;; (let ((env (terminal-parameter terminal 'environment)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
114 ;; found) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
115 ;; (while (and env (not found)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
116 ;; (if (and (> (length (car env)) (length variable)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
117 ;; (eq ?= (aref (car env) (length variable))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
118 ;; (equal variable (substring (car env) 0 (length variable)))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
119 ;; (progn |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
120 ;; (if value |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
121 ;; (setcar env (concat variable "=" value)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
122 ;; (set-terminal-parameter terminal 'environment |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
123 ;; (delq (car env) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
124 ;; (terminal-parameter terminal |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
125 ;; 'environment)))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
126 ;; (setq found t)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
127 ;; (setq env (cdr env)))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
128 ;; (cond |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
129 ;; ((and value found) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
130 ;; (setcar env (concat variable "=" value))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
131 ;; ((and value (not found)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
132 ;; (set-terminal-parameter terminal 'environment |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
133 ;; (cons (concat variable "=" value) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
134 ;; (terminal-parameter terminal |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
135 ;; 'environment)))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
136 ;; ((and (not value) found) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
137 ;; (set-terminal-parameter terminal 'environment |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
138 ;; (delq (car env) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
139 ;; (terminal-parameter terminal |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
140 ;; 'environment))))))) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
141 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
142 ;; (defmacro with-terminal-environment (terminal vars &rest body) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
143 ;; "Evaluate BODY with environment variables VARS set to those of TERMINAL. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
144 ;; The environment variables are then restored to their previous values. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
145 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
146 ;; VARS should be a single string, a list of strings, or t for all |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
147 ;; environment variables. |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
148 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
149 ;; TERMINAL can be a terminal id, a frame, or nil (meaning the |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
150 ;; selected frame's terminal). |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
151 |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
152 ;; If BODY uses `setenv' to change environment variables in VARS, |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
153 ;; then the new variable values will be remembered for TERMINAL, and |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
154 ;; `terminal-getenv' will return them even outside BODY." |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
155 ;; (declare (indent 2)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
156 ;; (let ((var (make-symbol "var")) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
157 ;; (term (make-symbol "term")) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
158 ;; (v (make-symbol "v")) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
159 ;; (old-env (make-symbol "old-env"))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
160 ;; `(let ((,term ,terminal) ; Evaluate arguments only once. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
161 ;; (,v ,vars)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
162 ;; (if (stringp ,v) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
163 ;; (setq ,v (list ,v))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
164 ;; (cond |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
165 ;; ((null (terminal-parameter ,term 'environment)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
166 ;; ;; Not a remote terminal; nothing to do. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
167 ;; (progn ,@body)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
168 ;; ((eq ,v t) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
169 ;; ;; Switch the entire process-environment. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
170 ;; (let (,old-env process-environment) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
171 ;; (setq process-environment (terminal-parameter ,term 'environment)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
172 ;; (unwind-protect |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
173 ;; (progn ,@body) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
174 ;; (set-terminal-parameter ,term 'environment process-environment) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
175 ;; (setq process-environment ,old-env)))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
176 ;; (t |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
177 ;; ;; Do only a set of variables. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
178 ;; (let (,old-env) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
179 ;; (dolist (,var ,v) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
180 ;; (setq ,old-env (cons (cons ,var (getenv ,var)) ,old-env)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
181 ;; (setenv ,var (terminal-getenv ,var ,term))) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
182 ;; (unwind-protect |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
183 ;; (progn ,@body) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
184 ;; ;; Split storing new values and restoring old ones so |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
185 ;; ;; that we DTRT even if a variable is specified twice in |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
186 ;; ;; VARS. |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
187 ;; (dolist (,var ,v) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
188 ;; (terminal-setenv-internal ,var (getenv ,var) ,term)) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
189 ;; (dolist (,var ,old-env) |
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83420
diff
changeset
|
190 ;; (setenv (car ,var) (cdr ,var)))))))))) |
83416
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
191 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
192 (provide 'termdev) |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
193 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
194 ;;; arch-tag: 4c4df277-1ec1-4f56-bfde-7f156fe62fb2 |
4513d8dcdfd5
Reimplement and extend support for terminal-local environment variables.
Karoly Lorentey <lorentey@elte.hu>
parents:
diff
changeset
|
195 ;;; termdev.el ends here |