]> code.delx.au - gnu-emacs/blob - lisp/term/xterm.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / term / xterm.el
1 ;;; xterm.el --- define function key sequences and standard colors for xterm
2
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: FSF
7 ;; Keywords: terminals
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (defvar xterm-function-map (make-sparse-keymap)
31 "Function key map overrides for xterm.")
32
33 ;; xterm from X.org 6.8.2 uses these key definitions.
34 (define-key xterm-function-map "\eOP" [f1])
35 (define-key xterm-function-map "\eOQ" [f2])
36 (define-key xterm-function-map "\eOR" [f3])
37 (define-key xterm-function-map "\eOS" [f4])
38 (define-key xterm-function-map "\e[15~" [f5])
39 (define-key xterm-function-map "\e[17~" [f6])
40 (define-key xterm-function-map "\e[18~" [f7])
41 (define-key xterm-function-map "\e[19~" [f8])
42 (define-key xterm-function-map "\e[20~" [f9])
43 (define-key xterm-function-map "\e[21~" [f10])
44 (define-key xterm-function-map "\e[23~" [f11])
45 (define-key xterm-function-map "\e[24~" [f12])
46
47 (define-key xterm-function-map "\eO2P" [S-f1])
48 (define-key xterm-function-map "\eO2Q" [S-f2])
49 (define-key xterm-function-map "\eO2R" [S-f3])
50 (define-key xterm-function-map "\eO2S" [S-f4])
51 (define-key xterm-function-map "\e[1;2P" [S-f1])
52 (define-key xterm-function-map "\e[1;2Q" [S-f2])
53 (define-key xterm-function-map "\e[1;2R" [S-f3])
54 (define-key xterm-function-map "\e[1;2S" [S-f4])
55 (define-key xterm-function-map "\e[15;2~" [S-f5])
56 (define-key xterm-function-map "\e[17;2~" [S-f6])
57 (define-key xterm-function-map "\e[18;2~" [S-f7])
58 (define-key xterm-function-map "\e[19;2~" [S-f8])
59 (define-key xterm-function-map "\e[20;2~" [S-f9])
60 (define-key xterm-function-map "\e[21;2~" [S-f10])
61 (define-key xterm-function-map "\e[23;2~" [S-f11])
62 (define-key xterm-function-map "\e[24;2~" [S-f12])
63
64 (define-key xterm-function-map "\eO5P" [C-f1])
65 (define-key xterm-function-map "\eO5Q" [C-f2])
66 (define-key xterm-function-map "\eO5R" [C-f3])
67 (define-key xterm-function-map "\eO5S" [C-f4])
68 (define-key xterm-function-map "\e[15;5~" [C-f5])
69 (define-key xterm-function-map "\e[17;5~" [C-f6])
70 (define-key xterm-function-map "\e[18;5~" [C-f7])
71 (define-key xterm-function-map "\e[19;5~" [C-f8])
72 (define-key xterm-function-map "\e[20;5~" [C-f9])
73 (define-key xterm-function-map "\e[21;5~" [C-f10])
74 (define-key xterm-function-map "\e[23;5~" [C-f11])
75 (define-key xterm-function-map "\e[24;5~" [C-f12])
76
77 (define-key xterm-function-map "\eO6P" [C-S-f1])
78 (define-key xterm-function-map "\eO6Q" [C-S-f2])
79 (define-key xterm-function-map "\eO6R" [C-S-f3])
80 (define-key xterm-function-map "\eO6S" [C-S-f4])
81 (define-key xterm-function-map "\e[15;6~" [C-S-f5])
82 (define-key xterm-function-map "\e[17;6~" [C-S-f6])
83 (define-key xterm-function-map "\e[18;6~" [C-S-f7])
84 (define-key xterm-function-map "\e[19;6~" [C-S-f8])
85 (define-key xterm-function-map "\e[20;6~" [C-S-f9])
86 (define-key xterm-function-map "\e[21;6~" [C-S-f10])
87 (define-key xterm-function-map "\e[23;6~" [C-S-f11])
88 (define-key xterm-function-map "\e[24;6~" [C-S-f12])
89
90 (define-key xterm-function-map "\eO3P" [A-f1])
91 (define-key xterm-function-map "\eO3Q" [A-f2])
92 (define-key xterm-function-map "\eO3R" [A-f3])
93 (define-key xterm-function-map "\eO3S" [A-f4])
94 (define-key xterm-function-map "\e[15;3~" [A-f5])
95 (define-key xterm-function-map "\e[17;3~" [A-f6])
96 (define-key xterm-function-map "\e[18;3~" [A-f7])
97 (define-key xterm-function-map "\e[19;3~" [A-f8])
98 (define-key xterm-function-map "\e[20;3~" [A-f9])
99 (define-key xterm-function-map "\e[21;3~" [A-f10])
100 (define-key xterm-function-map "\e[23;3~" [A-f11])
101 (define-key xterm-function-map "\e[24;3~" [A-f12])
102
103 (define-key xterm-function-map "\eOA" [up])
104 (define-key xterm-function-map "\eOB" [down])
105 (define-key xterm-function-map "\eOC" [right])
106 (define-key xterm-function-map "\eOD" [left])
107 (define-key xterm-function-map "\eOF" [end])
108 (define-key xterm-function-map "\eOH" [home])
109
110 (define-key xterm-function-map "\e[1;2A" [S-up])
111 (define-key xterm-function-map "\e[1;2B" [S-down])
112 (define-key xterm-function-map "\e[1;2C" [S-right])
113 (define-key xterm-function-map "\e[1;2D" [S-left])
114 (define-key xterm-function-map "\e[1;2F" [S-end])
115 (define-key xterm-function-map "\e[1;2H" [S-home])
116
117 (define-key xterm-function-map "\e[1;5A" [C-up])
118 (define-key xterm-function-map "\e[1;5B" [C-down])
119 (define-key xterm-function-map "\e[1;5C" [C-right])
120 (define-key xterm-function-map "\e[1;5D" [C-left])
121 (define-key xterm-function-map "\e[1;5F" [C-end])
122 (define-key xterm-function-map "\e[1;5H" [C-home])
123
124 (define-key xterm-function-map "\e[1;6A" [C-S-up])
125 (define-key xterm-function-map "\e[1;6B" [C-S-down])
126 (define-key xterm-function-map "\e[1;6C" [C-S-right])
127 (define-key xterm-function-map "\e[1;6D" [C-S-left])
128 (define-key xterm-function-map "\e[1;6F" [C-S-end])
129 (define-key xterm-function-map "\e[1;6H" [C-S-home])
130
131 (define-key xterm-function-map "\e[1;3A" [A-up])
132 (define-key xterm-function-map "\e[1;3B" [A-down])
133 (define-key xterm-function-map "\e[1;3C" [A-right])
134 (define-key xterm-function-map "\e[1;3D" [A-left])
135 (define-key xterm-function-map "\e[1;3F" [A-end])
136 (define-key xterm-function-map "\e[1;3H" [A-home])
137
138 (define-key xterm-function-map "\e[2~" [insert])
139 (define-key xterm-function-map "\e[3~" [delete])
140 (define-key xterm-function-map "\e[5~" [prior])
141 (define-key xterm-function-map "\e[6~" [next])
142
143 (define-key xterm-function-map "\e[2;2~" [S-insert])
144 (define-key xterm-function-map "\e[3;2~" [S-delete])
145 (define-key xterm-function-map "\e[5;2~" [S-prior])
146 (define-key xterm-function-map "\e[6;2~" [S-next])
147
148 (define-key xterm-function-map "\e[2;5~" [C-insert])
149 (define-key xterm-function-map "\e[3;5~" [C-delete])
150 (define-key xterm-function-map "\e[5;5~" [C-prior])
151 (define-key xterm-function-map "\e[6;5~" [C-next])
152
153 (define-key xterm-function-map "\e[2;6~" [C-S-insert])
154 (define-key xterm-function-map "\e[3;6~" [C-S-delete])
155 (define-key xterm-function-map "\e[5;6~" [C-S-prior])
156 (define-key xterm-function-map "\e[6;6~" [C-S-next])
157
158 (define-key xterm-function-map "\e[2;3~" [A-insert])
159 (define-key xterm-function-map "\e[3;3~" [A-delete])
160 (define-key xterm-function-map "\e[5;3~" [A-prior])
161 (define-key xterm-function-map "\e[6;3~" [A-next])
162
163 (define-key xterm-function-map "\e[4~" [select])
164 (define-key xterm-function-map "\e[29~" [print])
165
166 (define-key xterm-function-map "\eOj" [kp-multiply])
167 (define-key xterm-function-map "\eOk" [kp-add])
168 (define-key xterm-function-map "\eOl" [kp-separator])
169 (define-key xterm-function-map "\eOm" [kp-subtract])
170 (define-key xterm-function-map "\eOo" [kp-divide])
171 (define-key xterm-function-map "\eOp" [kp-0])
172 (define-key xterm-function-map "\eOq" [kp-1])
173 (define-key xterm-function-map "\eOr" [kp-2])
174 (define-key xterm-function-map "\eOs" [kp-3])
175 (define-key xterm-function-map "\eOt" [kp-4])
176 (define-key xterm-function-map "\eOu" [kp-5])
177 (define-key xterm-function-map "\eOv" [kp-6])
178 (define-key xterm-function-map "\eOw" [kp-7])
179 (define-key xterm-function-map "\eOx" [kp-8])
180 (define-key xterm-function-map "\eOy" [kp-9])
181
182 ;; These keys are available in xterm starting from version 216
183 ;; if the modifyOtherKeys resource is set to 1.
184
185 (define-key xterm-function-map "\e[27;5;9~" [C-tab])
186 (define-key xterm-function-map "\e[27;5;13~" [C-return])
187 (define-key xterm-function-map "\e[27;5;39~" [?\C-\'])
188 (define-key xterm-function-map "\e[27;5;44~" [?\C-,])
189 (define-key xterm-function-map "\e[27;5;45~" [?\C--])
190 (define-key xterm-function-map "\e[27;5;46~" [?\C-.])
191 (define-key xterm-function-map "\e[27;5;47~" [?\C-/])
192 (define-key xterm-function-map "\e[27;5;48~" [?\C-0])
193 (define-key xterm-function-map "\e[27;5;49~" [?\C-1])
194 ;; Not all C-DIGIT keys have a distinct binding.
195 (define-key xterm-function-map "\e[27;5;57~" [?\C-9])
196 (define-key xterm-function-map "\e[27;5;59~" [?\C-\;])
197 (define-key xterm-function-map "\e[27;5;61~" [?\C-=])
198 (define-key xterm-function-map "\e[27;5;92~" [?\C-\\])
199
200 (define-key xterm-function-map "\e[27;6;33~" [?\C-!])
201 (define-key xterm-function-map "\e[27;6;34~" [?\C-\"])
202 (define-key xterm-function-map "\e[27;6;35~" [?\C-#])
203 (define-key xterm-function-map "\e[27;6;36~" [?\C-$])
204 (define-key xterm-function-map "\e[27;6;37~" [?\C-%])
205 (define-key xterm-function-map "\e[27;6;38~" [?\C-&])
206 (define-key xterm-function-map "\e[27;6;40~" [?\C-(])
207 (define-key xterm-function-map "\e[27;6;41~" [?\C-)])
208 (define-key xterm-function-map "\e[27;6;42~" [?\C-*])
209 (define-key xterm-function-map "\e[27;6;43~" [?\C-+])
210 (define-key xterm-function-map "\e[27;6;58~" [?\C-:])
211 (define-key xterm-function-map "\e[27;6;60~" [?\C-<])
212 (define-key xterm-function-map "\e[27;6;62~" [?\C->])
213 (define-key xterm-function-map "\e[27;6;63~" [(control ??)])
214
215 ;; These are the strings emitted for various C-M- combinations
216 ;; for keyboards that the Meta and Alt modifiers are on the same
217 ;; key (usually labeled "Alt").
218 (define-key xterm-function-map "\e[27;13;9~" [C-M-tab])
219 (define-key xterm-function-map "\e[27;13;13~" [C-M-return])
220
221 (define-key xterm-function-map "\e[27;13;39~" [?\C-\M-\'])
222 (define-key xterm-function-map "\e[27;13;44~" [?\C-\M-,])
223 (define-key xterm-function-map "\e[27;13;45~" [?\C-\M--])
224 (define-key xterm-function-map "\e[27;13;46~" [?\C-\M-.])
225 (define-key xterm-function-map "\e[27;13;47~" [?\C-\M-/])
226 (define-key xterm-function-map "\e[27;13;48~" [?\C-\M-0])
227 (define-key xterm-function-map "\e[27;13;49~" [?\C-\M-1])
228 (define-key xterm-function-map "\e[27;13;50~" [?\C-\M-2])
229 (define-key xterm-function-map "\e[27;13;51~" [?\C-\M-3])
230 (define-key xterm-function-map "\e[27;13;52~" [?\C-\M-4])
231 (define-key xterm-function-map "\e[27;13;53~" [?\C-\M-5])
232 (define-key xterm-function-map "\e[27;13;54~" [?\C-\M-6])
233 (define-key xterm-function-map "\e[27;13;55~" [?\C-\M-7])
234 (define-key xterm-function-map "\e[27;13;56~" [?\C-\M-8])
235 (define-key xterm-function-map "\e[27;13;57~" [?\C-\M-9])
236 (define-key xterm-function-map "\e[27;13;59~" [?\C-\M-\;])
237 (define-key xterm-function-map "\e[27;13;61~" [?\C-\M-=])
238 (define-key xterm-function-map "\e[27;13;92~" [?\C-\M-\\])
239
240 (define-key xterm-function-map "\e[27;14;33~" [?\C-\M-!])
241 (define-key xterm-function-map "\e[27;14;34~" [?\C-\M-\"])
242 (define-key xterm-function-map "\e[27;14;35~" [?\C-\M-#])
243 (define-key xterm-function-map "\e[27;14;36~" [?\C-\M-$])
244 (define-key xterm-function-map "\e[27;14;37~" [?\C-\M-%])
245 (define-key xterm-function-map "\e[27;14;38~" [?\C-\M-&])
246 (define-key xterm-function-map "\e[27;14;40~" [?\C-\M-\(])
247 (define-key xterm-function-map "\e[27;14;41~" [?\C-\M-\)])
248 (define-key xterm-function-map "\e[27;14;42~" [?\C-\M-*])
249 (define-key xterm-function-map "\e[27;14;43~" [?\C-\M-+])
250 (define-key xterm-function-map "\e[27;14;58~" [?\C-\M-:])
251 (define-key xterm-function-map "\e[27;14;60~" [?\C-\M-<])
252 (define-key xterm-function-map "\e[27;14;62~" [?\C-\M->])
253 (define-key xterm-function-map "\e[27;14;63~" [(control meta ??)])
254
255 (define-key xterm-function-map "\e[27;7;9~" [C-M-tab])
256 (define-key xterm-function-map "\e[27;7;13~" [C-M-return])
257
258 (define-key xterm-function-map "\e[27;7;32~" [?\C-\M-\s])
259 (define-key xterm-function-map "\e[27;7;39~" [?\C-\M-\'])
260 (define-key xterm-function-map "\e[27;7;44~" [?\C-\M-,])
261 (define-key xterm-function-map "\e[27;7;45~" [?\C-\M--])
262 (define-key xterm-function-map "\e[27;7;46~" [?\C-\M-.])
263 (define-key xterm-function-map "\e[27;7;47~" [?\C-\M-/])
264 (define-key xterm-function-map "\e[27;7;48~" [?\C-\M-0])
265 (define-key xterm-function-map "\e[27;7;49~" [?\C-\M-1])
266 (define-key xterm-function-map "\e[27;7;50~" [?\C-\M-2])
267 (define-key xterm-function-map "\e[27;7;51~" [?\C-\M-3])
268 (define-key xterm-function-map "\e[27;7;52~" [?\C-\M-4])
269 (define-key xterm-function-map "\e[27;7;53~" [?\C-\M-5])
270 (define-key xterm-function-map "\e[27;7;54~" [?\C-\M-6])
271 (define-key xterm-function-map "\e[27;7;55~" [?\C-\M-7])
272 (define-key xterm-function-map "\e[27;7;56~" [?\C-\M-8])
273 (define-key xterm-function-map "\e[27;7;57~" [?\C-\M-9])
274 (define-key xterm-function-map "\e[27;7;59~" [?\C-\M-\;])
275 (define-key xterm-function-map "\e[27;7;61~" [?\C-\M-=])
276 (define-key xterm-function-map "\e[27;7;92~" [?\C-\M-\\])
277
278 (define-key xterm-function-map "\e[27;8;33~" [?\C-\M-!])
279 (define-key xterm-function-map "\e[27;8;34~" [?\C-\M-\"])
280 (define-key xterm-function-map "\e[27;8;35~" [?\C-\M-#])
281 (define-key xterm-function-map "\e[27;8;36~" [?\C-\M-$])
282 (define-key xterm-function-map "\e[27;8;37~" [?\C-\M-%])
283 (define-key xterm-function-map "\e[27;8;38~" [?\C-\M-&])
284 (define-key xterm-function-map "\e[27;8;40~" [?\C-\M-\(])
285 (define-key xterm-function-map "\e[27;8;41~" [?\C-\M-\)])
286 (define-key xterm-function-map "\e[27;8;42~" [?\C-\M-*])
287 (define-key xterm-function-map "\e[27;8;43~" [?\C-\M-+])
288 (define-key xterm-function-map "\e[27;8;58~" [?\C-\M-:])
289 (define-key xterm-function-map "\e[27;8;60~" [?\C-\M-<])
290 (define-key xterm-function-map "\e[27;8;62~" [?\C-\M->])
291 (define-key xterm-function-map "\e[27;8;63~" [(control meta ??)])
292
293 (define-key xterm-function-map "\e[27;2;9~" [S-tab])
294 (define-key xterm-function-map "\e[27;2;13~" [S-return])
295
296 (define-key xterm-function-map "\e[27;6;9~" [C-S-tab])
297 (define-key xterm-function-map "\e[27;6;13~" [C-S-return])
298
299 ;; Other versions of xterm might emit these.
300 (define-key xterm-function-map "\e[A" [up])
301 (define-key xterm-function-map "\e[B" [down])
302 (define-key xterm-function-map "\e[C" [right])
303 (define-key xterm-function-map "\e[D" [left])
304 (define-key xterm-function-map "\e[1~" [home])
305
306 (define-key xterm-function-map "\e[1;2A" [S-up])
307 (define-key xterm-function-map "\e[1;2B" [S-down])
308 (define-key xterm-function-map "\e[1;2C" [S-right])
309 (define-key xterm-function-map "\e[1;2D" [S-left])
310 (define-key xterm-function-map "\e[1;2F" [S-end])
311 (define-key xterm-function-map "\e[1;2H" [S-home])
312
313 (define-key xterm-function-map "\e[1;5A" [C-up])
314 (define-key xterm-function-map "\e[1;5B" [C-down])
315 (define-key xterm-function-map "\e[1;5C" [C-right])
316 (define-key xterm-function-map "\e[1;5D" [C-left])
317 (define-key xterm-function-map "\e[1;5F" [C-end])
318 (define-key xterm-function-map "\e[1;5H" [C-home])
319
320 (define-key xterm-function-map "\e[11~" [f1])
321 (define-key xterm-function-map "\e[12~" [f2])
322 (define-key xterm-function-map "\e[13~" [f3])
323 (define-key xterm-function-map "\e[14~" [f4])
324
325 (defun terminal-init-xterm ()
326 "Terminal initialization function for xterm."
327 ;; rxvt terminals sometimes set the TERM variable to "xterm", but
328 ;; rxvt's keybindings are incompatible with xterm's. It is
329 ;; better in that case to use rxvt's initializion function.
330 (if (and (getenv "COLORTERM" (selected-frame))
331 (string-match "\\`rxvt" (getenv "COLORTERM" (selected-frame))))
332 (tty-run-terminal-initialization (selected-frame) "rxvt")
333
334 ;; The terminal intialization C code file might have initialized
335 ;; function keys F13->F60 from the termcap/terminfo information. On
336 ;; a PC-style keyboard these keys correspond to
337 ;; MODIFIER-FUNCTION_KEY, where modifier is S-, C, A-, C-S-. The
338 ;; code here subsitutes the corresponding defintions in
339 ;; function-key-map. This substitution is needed because if a key
340 ;; definition is found in function-key-map, there are no further
341 ;; lookups in other keymaps.
342 (substitute-key-definition [f13] [S-f1] local-function-key-map)
343 (substitute-key-definition [f14] [S-f2] local-function-key-map)
344 (substitute-key-definition [f15] [S-f3] local-function-key-map)
345 (substitute-key-definition [f16] [S-f4] local-function-key-map)
346 (substitute-key-definition [f17] [S-f5] local-function-key-map)
347 (substitute-key-definition [f18] [S-f6] local-function-key-map)
348 (substitute-key-definition [f19] [S-f7] local-function-key-map)
349 (substitute-key-definition [f20] [S-f8] local-function-key-map)
350 (substitute-key-definition [f21] [S-f9] local-function-key-map)
351 (substitute-key-definition [f22] [S-f10] local-function-key-map)
352 (substitute-key-definition [f23] [S-f11] local-function-key-map)
353 (substitute-key-definition [f24] [S-f12] local-function-key-map)
354
355 (substitute-key-definition [f25] [C-f1] local-function-key-map)
356 (substitute-key-definition [f26] [C-f2] local-function-key-map)
357 (substitute-key-definition [f27] [C-f3] local-function-key-map)
358 (substitute-key-definition [f28] [C-f4] local-function-key-map)
359 (substitute-key-definition [f29] [C-f5] local-function-key-map)
360 (substitute-key-definition [f30] [C-f6] local-function-key-map)
361 (substitute-key-definition [f31] [C-f7] local-function-key-map)
362 (substitute-key-definition [f32] [C-f8] local-function-key-map)
363 (substitute-key-definition [f33] [C-f9] local-function-key-map)
364 (substitute-key-definition [f34] [C-f10] local-function-key-map)
365 (substitute-key-definition [f35] [C-f11] local-function-key-map)
366 (substitute-key-definition [f36] [C-f12] local-function-key-map)
367
368 (substitute-key-definition [f37] [C-S-f1] local-function-key-map)
369 (substitute-key-definition [f38] [C-S-f2] local-function-key-map)
370 (substitute-key-definition [f39] [C-S-f3] local-function-key-map)
371 (substitute-key-definition [f40] [C-S-f4] local-function-key-map)
372 (substitute-key-definition [f41] [C-S-f5] local-function-key-map)
373 (substitute-key-definition [f42] [C-S-f6] local-function-key-map)
374 (substitute-key-definition [f43] [C-S-f7] local-function-key-map)
375 (substitute-key-definition [f44] [C-S-f8] local-function-key-map)
376 (substitute-key-definition [f45] [C-S-f9] local-function-key-map)
377 (substitute-key-definition [f46] [C-S-f10] local-function-key-map)
378 (substitute-key-definition [f47] [C-S-f11] local-function-key-map)
379 (substitute-key-definition [f48] [C-S-f12] local-function-key-map)
380
381 (substitute-key-definition [f49] [A-f1] local-function-key-map)
382 (substitute-key-definition [f50] [A-f2] local-function-key-map)
383 (substitute-key-definition [f51] [A-f3] local-function-key-map)
384 (substitute-key-definition [f52] [A-f4] local-function-key-map)
385 (substitute-key-definition [f53] [A-f5] local-function-key-map)
386 (substitute-key-definition [f54] [A-f6] local-function-key-map)
387 (substitute-key-definition [f55] [A-f7] local-function-key-map)
388 (substitute-key-definition [f56] [A-f8] local-function-key-map)
389 (substitute-key-definition [f57] [A-f9] local-function-key-map)
390 (substitute-key-definition [f58] [A-f10] local-function-key-map)
391 (substitute-key-definition [f59] [A-f11] local-function-key-map)
392 (substitute-key-definition [f60] [A-f12] local-function-key-map)
393
394 (let ((map (copy-keymap xterm-function-map)))
395
396 ;; Use inheritance to let the main keymap override those defaults.
397 ;; This way we don't override terminfo-derived settings or settings
398 ;; made in the .emacs file.
399 (set-keymap-parent map (keymap-parent local-function-key-map))
400 (set-keymap-parent local-function-key-map map)))
401
402 (xterm-register-default-colors)
403 ;; This recomputes all the default faces given the colors we've just set up.
404 (tty-set-up-initial-frame-faces)
405
406 ;; Try to turn on the modifyOtherKeys feature on modern xterms.
407 ;; When it is turned on much more key bindings work: things like
408 ;; C-. C-, etc.
409 ;; To do that we need to find out if the current terminal supports
410 ;; modifyOtherKeys. At this time only xterm does.
411 (let ((coding-system-for-read 'binary)
412 (chr nil)
413 (str nil))
414 ;; Try to find out the type of terminal by sending a "Secondary
415 ;; Device Attributes (DA)" query.
416 (send-string-to-terminal "\e[>0c")
417
418 ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c
419 (when (equal (read-event nil nil 0.1) ?\e)
420 (when (equal (read-event nil nil 0.1) ?\[)
421 (while (not (equal (setq chr (read-event nil nil 0.1)) ?c))
422 (setq str (concat str (string chr))))
423 (when (string-match ">0;\\([0-9]+\\);0" str)
424 ;; NUMBER2 is the xterm version number, look for something
425 ;; greater than 216, the version when modifyOtherKeys was
426 ;; introduced.
427 (when (>= (string-to-number
428 (substring str (match-beginning 1) (match-end 1))) 216)
429 ;; Make sure that the modifyOtherKeys state is restored when
430 ;; suspending, resuming and exiting.
431 (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys)
432 (add-hook 'suspend-resume-hook 'xterm-turn-on-modify-other-keys)
433 (add-hook 'kill-emacs-hook 'xterm-turn-off-modify-other-keys)
434 (xterm-turn-on-modify-other-keys)))))))
435
436 ;; Set up colors, for those versions of xterm that support it.
437 (defvar xterm-standard-colors
438 ;; The names in the comments taken from XTerm-col.ad in the xterm
439 ;; distribution, see ftp://dickey.his.com/xterm/. RGB values are
440 ;; from rgb.txt.
441 '(("black" 0 ( 0 0 0)) ; black
442 ("red" 1 (205 0 0)) ; red3
443 ("green" 2 ( 0 205 0)) ; green3
444 ("yellow" 3 (205 205 0)) ; yellow3
445 ("blue" 4 ( 0 0 238)) ; blue2
446 ("magenta" 5 (205 0 205)) ; magenta3
447 ("cyan" 6 ( 0 205 205)) ; cyan3
448 ("white" 7 (229 229 229)) ; gray90
449 ("brightblack" 8 (127 127 127)) ; gray50
450 ("brightred" 9 (255 0 0)) ; red
451 ("brightgreen" 10 ( 0 255 0)) ; green
452 ("brightyellow" 11 (255 255 0)) ; yellow
453 ("brightblue" 12 (92 92 255)) ; rgb:5c/5c/ff
454 ("brightmagenta" 13 (255 0 255)) ; magenta
455 ("brightcyan" 14 ( 0 255 255)) ; cyan
456 ("brightwhite" 15 (255 255 255))) ; white
457 "Names of 16 standard xterm/aixterm colors, their numbers, and RGB values.")
458
459 (defun xterm-rgb-convert-to-16bit (prim)
460 "Convert an 8-bit primary color value PRIM to a corresponding 16-bit value."
461 (logior prim (lsh prim 8)))
462
463 (defun xterm-register-default-colors ()
464 "Register the default set of colors for xterm or compatible emulator.
465
466 This function registers the number of colors returned by `display-color-cells'
467 for the currently selected frame. The first 16 colors are taken from
468 `xterm-standard-colors', which see, while the rest are computed assuming
469 either the 88- or 256-color standard color scheme supported by latest
470 versions of xterm."
471 (let* ((ncolors (display-color-cells (selected-frame)))
472 (colors xterm-standard-colors)
473 (color (car colors)))
474 (if (> ncolors 0)
475 ;; Clear the 8 default tty colors registered by startup.el
476 (tty-color-clear))
477 ;; Only register as many colors as are supported by the display.
478 (while (and (> ncolors 0) colors)
479 (tty-color-define (car color) (cadr color)
480 (mapcar 'xterm-rgb-convert-to-16bit
481 (car (cddr color))))
482 (setq colors (cdr colors)
483 color (car colors)
484 ncolors (1- ncolors)))
485 ;; We've exhausted the colors from `xterm-standard-colors'. If there
486 ;; are more colors to support, compute them now.
487 (when (> ncolors 0)
488 (cond
489 ((= ncolors 240) ; 256-color xterm
490 ;; 216 non-gray colors first
491 (let ((r 0) (g 0) (b 0))
492 (while (> ncolors 24)
493 ;; This and other formulae taken from 256colres.pl and
494 ;; 88colres.pl in the xterm distribution.
495 (tty-color-define (format "color-%d" (- 256 ncolors))
496 (- 256 ncolors)
497 (mapcar 'xterm-rgb-convert-to-16bit
498 (list (if (zerop r) 0 (+ (* r 40) 55))
499 (if (zerop g) 0 (+ (* g 40) 55))
500 (if (zerop b) 0 (+ (* b 40) 55)))))
501
502 (setq b (1+ b))
503 (if (> b 5)
504 (setq g (1+ g)
505 b 0))
506 (if (> g 5)
507 (setq r (1+ r)
508 g 0))
509 (setq ncolors (1- ncolors))))
510 ;; Now the 24 gray colors
511 (while (> ncolors 0)
512 (setq color (xterm-rgb-convert-to-16bit (+ 8 (* (- 24 ncolors) 10))))
513 (tty-color-define (format "color-%d" (- 256 ncolors))
514 (- 256 ncolors)
515 (list color color color))
516 (setq ncolors (1- ncolors))))
517 ((= ncolors 72) ; 88-color xterm
518 ;; 64 non-gray colors
519 (let ((levels '(0 139 205 255))
520 (r 0) (g 0) (b 0))
521 (while (> ncolors 8)
522 (tty-color-define (format "color-%d" (- 88 ncolors))
523 (- 88 ncolors)
524 (mapcar 'xterm-rgb-convert-to-16bit
525 (list (nth r levels)
526 (nth g levels)
527 (nth b levels))))
528 (setq b (1+ b))
529 (if (> b 3)
530 (setq g (1+ g)
531 b 0))
532 (if (> g 3)
533 (setq r (1+ r)
534 g 0))
535 (setq ncolors (1- ncolors))))
536 ;; Now the 8 gray colors
537 (while (> ncolors 0)
538 (setq color (xterm-rgb-convert-to-16bit
539 (floor
540 (if (= ncolors 8)
541 46.36363636
542 (+ (* (- 8 ncolors) 23.18181818) 69.54545454)))))
543 (tty-color-define (format "color-%d" (- 88 ncolors))
544 (- 88 ncolors)
545 (list color color color))
546 (setq ncolors (1- ncolors))))
547 (t (error "Unsupported number of xterm colors (%d)" (+ 16 ncolors)))))
548 ;; Modifying color mappings means realized faces don't use the
549 ;; right colors, so clear them.
550 (clear-face-cache)))
551
552 (defun xterm-turn-on-modify-other-keys ()
553 "Turn on the modifyOtherKeys feature of xterm."
554 (send-string-to-terminal "\e[>4;1m"))
555
556 (defun xterm-turn-off-modify-other-keys ()
557 "Turn off the modifyOtherKeys feature of xterm."
558 (send-string-to-terminal "\e[>4m"))
559
560 ;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a
561 ;;; xterm.el ends here