*** empty log message ***
[bpt/emacs.git] / lisp / term / xterm.el
CommitLineData
63e9afde 1;;; xterm.el --- define function key sequences and standard colors for xterm
92abb02b 2
f2e3589a 3;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005,
d7a0267c 4;; 2006, 2007 Free Software Foundation, Inc.
2fe590dc 5
92abb02b
KH
6;; Author: FSF
7;; Keywords: terminals
8
2fe590dc
EN
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 2, 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
4fc5845f
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
92abb02b 25
6a05d05f
PJ
26;;; Commentary:
27
28;;; Code:
92abb02b 29
8cbd7bed 30(defvar xterm-function-map (make-sparse-keymap)
941d4811
KL
31 "Function key map overrides for xterm.")
32
8cbd7bed
KL
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])
974b73e8
KL
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])
8cbd7bed
KL
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
9d079907
KL
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
3f87f67e 182;; These keys are available in xterm starting from version 216
251bc578 183;; if the modifyOtherKeys resource is set to 1.
3f87f67e 184
12b6af5c
KL
185(define-key xterm-function-map "\e[27;5;9~" [C-tab])
186(define-key xterm-function-map "\e[27;5;13~" [C-return])
3f87f67e 187(define-key xterm-function-map "\e[27;5;39~" [?\C-\'])
12b6af5c 188(define-key xterm-function-map "\e[27;5;44~" [?\C-,])
3f87f67e 189(define-key xterm-function-map "\e[27;5;45~" [?\C--])
12b6af5c
KL
190(define-key xterm-function-map "\e[27;5;46~" [?\C-.])
191(define-key xterm-function-map "\e[27;5;47~" [?\C-/])
3f87f67e
KL
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])
9d079907 196(define-key xterm-function-map "\e[27;5;59~" [?\C-\;])
3f87f67e 197(define-key xterm-function-map "\e[27;5;61~" [?\C-=])
12b6af5c 198(define-key xterm-function-map "\e[27;5;92~" [?\C-\\])
3f87f67e
KL
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-%])
9d079907 205(define-key xterm-function-map "\e[27;6;38~" [?\C-&])
3f87f67e
KL
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-+])
3f87f67e
KL
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->])
9d079907 213(define-key xterm-function-map "\e[27;6;63~" [(control ??)])
3f87f67e 214
12b6af5c
KL
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").
9d079907
KL
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])
251bc578 220
12b6af5c
KL
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--])
251bc578 224(define-key xterm-function-map "\e[27;13;46~" [?\C-\M-.])
12b6af5c
KL
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-%])
9d079907 245(define-key xterm-function-map "\e[27;14;38~" [?\C-\M-&])
12b6af5c
KL
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->])
9d079907 253(define-key xterm-function-map "\e[27;14;63~" [(control meta ??)])
12b6af5c 254
9d079907
KL
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])
12b6af5c 257
9d079907 258(define-key xterm-function-map "\e[27;7;32~" [?\C-\M-\s])
12b6af5c
KL
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-%])
9d079907 283(define-key xterm-function-map "\e[27;8;38~" [?\C-\M-&])
12b6af5c
KL
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->])
9d079907 291(define-key xterm-function-map "\e[27;8;63~" [(control meta ??)])
12b6af5c
KL
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
9d079907
KL
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])
8cbd7bed
KL
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])
fbf34973 324
4f0c9ba7
DN
325(defun terminal-init-xterm ()
326 "Terminal initialization function for xterm."
327 ;; rxvt terminals sometimes set the TERM variable to "xterm", but
8cbd7bed 328 ;; rxvt's keybindings are incompatible with xterm's. It is
4f0c9ba7 329 ;; better in that case to use rxvt's initializion function.
36ab8612
MB
330 (if (and (getenv "COLORTERM" (selected-frame))
331 (string-match "\\`rxvt" (getenv "COLORTERM" (selected-frame))))
8cbd7bed
KL
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
5efe831f 340 ;; definition is found in function-key-map, there are no further
8cbd7bed
KL
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 ;; Use inheritance to let the main keymap override those defaults.
395 ;; This way we don't override terminfo-derived settings or settings
396 ;; made in the .emacs file.
397 (let ((m (copy-keymap xterm-function-map)))
398 (set-keymap-parent m (keymap-parent local-function-key-map))
399 (set-keymap-parent local-function-key-map m)))
400
4f0c9ba7
DN
401 (xterm-register-default-colors)
402 ;; This recomputes all the default faces given the colors we've just set up.
c40bb1ba 403 (tty-set-up-initial-frame-faces))
2bb819d5 404
63e9afde
EZ
405;; Set up colors, for those versions of xterm that support it.
406(defvar xterm-standard-colors
407 ;; The names in the comments taken from XTerm-col.ad in the xterm
408 ;; distribution, see ftp://dickey.his.com/xterm/. RGB values are
409 ;; from rgb.txt.
410 '(("black" 0 ( 0 0 0)) ; black
411 ("red" 1 (205 0 0)) ; red3
412 ("green" 2 ( 0 205 0)) ; green3
413 ("yellow" 3 (205 205 0)) ; yellow3
9fb518aa 414 ("blue" 4 ( 0 0 238)) ; blue2
63e9afde
EZ
415 ("magenta" 5 (205 0 205)) ; magenta3
416 ("cyan" 6 ( 0 205 205)) ; cyan3
417 ("white" 7 (229 229 229)) ; gray90
9fb518aa 418 ("brightblack" 8 (127 127 127)) ; gray50
63e9afde
EZ
419 ("brightred" 9 (255 0 0)) ; red
420 ("brightgreen" 10 ( 0 255 0)) ; green
421 ("brightyellow" 11 (255 255 0)) ; yellow
9fb518aa 422 ("brightblue" 12 (92 92 255)) ; rgb:5c/5c/ff
63e9afde
EZ
423 ("brightmagenta" 13 (255 0 255)) ; magenta
424 ("brightcyan" 14 ( 0 255 255)) ; cyan
425 ("brightwhite" 15 (255 255 255))) ; white
426 "Names of 16 standard xterm/aixterm colors, their numbers, and RGB values.")
427
428(defun xterm-rgb-convert-to-16bit (prim)
429 "Convert an 8-bit primary color value PRIM to a corresponding 16-bit value."
ce102cb1 430 (logior prim (lsh prim 8)))
63e9afde
EZ
431
432(defun xterm-register-default-colors ()
433 "Register the default set of colors for xterm or compatible emulator.
434
435This function registers the number of colors returned by `display-color-cells'
436for the currently selected frame. The first 16 colors are taken from
437`xterm-standard-colors', which see, while the rest are computed assuming
438either the 88- or 256-color standard color scheme supported by latest
439versions of xterm."
3224dac1 440 (let* ((ncolors (display-color-cells (selected-frame)))
63e9afde
EZ
441 (colors xterm-standard-colors)
442 (color (car colors)))
443 (if (> ncolors 0)
444 ;; Clear the 8 default tty colors registered by startup.el
445 (tty-color-clear))
446 ;; Only register as many colors as are supported by the display.
447 (while (and (> ncolors 0) colors)
448 (tty-color-define (car color) (cadr color)
449 (mapcar 'xterm-rgb-convert-to-16bit
450 (car (cddr color))))
451 (setq colors (cdr colors)
452 color (car colors)
453 ncolors (1- ncolors)))
454 ;; We've exhausted the colors from `xterm-standard-colors'. If there
455 ;; are more colors to support, compute them now.
456 (when (> ncolors 0)
457 (cond
458 ((= ncolors 240) ; 256-color xterm
459 ;; 216 non-gray colors first
460 (let ((r 0) (g 0) (b 0))
461 (while (> ncolors 24)
462 ;; This and other formulae taken from 256colres.pl and
463 ;; 88colres.pl in the xterm distribution.
464 (tty-color-define (format "color-%d" (- 256 ncolors))
465 (- 256 ncolors)
466 (mapcar 'xterm-rgb-convert-to-16bit
ce102cb1
DN
467 (list (if (zerop r) 0 (+ (* r 40) 55))
468 (if (zerop g) 0 (+ (* g 40) 55))
469 (if (zerop b) 0 (+ (* b 40) 55)))))
470
63e9afde
EZ
471 (setq b (1+ b))
472 (if (> b 5)
473 (setq g (1+ g)
474 b 0))
475 (if (> g 5)
476 (setq r (1+ r)
477 g 0))
478 (setq ncolors (1- ncolors))))
479 ;; Now the 24 gray colors
480 (while (> ncolors 0)
481 (setq color (xterm-rgb-convert-to-16bit (+ 8 (* (- 24 ncolors) 10))))
482 (tty-color-define (format "color-%d" (- 256 ncolors))
483 (- 256 ncolors)
484 (list color color color))
485 (setq ncolors (1- ncolors))))
486 ((= ncolors 72) ; 88-color xterm
487 ;; 64 non-gray colors
488 (let ((levels '(0 139 205 255))
489 (r 0) (g 0) (b 0))
490 (while (> ncolors 8)
491 (tty-color-define (format "color-%d" (- 88 ncolors))
492 (- 88 ncolors)
493 (mapcar 'xterm-rgb-convert-to-16bit
494 (list (nth r levels)
495 (nth g levels)
496 (nth b levels))))
497 (setq b (1+ b))
498 (if (> b 3)
499 (setq g (1+ g)
500 b 0))
501 (if (> g 3)
502 (setq r (1+ r)
503 g 0))
504 (setq ncolors (1- ncolors))))
505 ;; Now the 8 gray colors
506 (while (> ncolors 0)
507 (setq color (xterm-rgb-convert-to-16bit
ce102cb1 508 (floor
63e9afde
EZ
509 (if (= ncolors 8)
510 46.36363636
511 (+ (* (- 8 ncolors) 23.18181818) 69.54545454)))))
512 (tty-color-define (format "color-%d" (- 88 ncolors))
513 (- 88 ncolors)
514 (list color color color))
515 (setq ncolors (1- ncolors))))
516 (t (error "Unsupported number of xterm colors (%d)" (+ 16 ncolors)))))
517 ;; Modifying color mappings means realized faces don't use the
518 ;; right colors, so clear them.
519 (clear-face-cache)))
520
4dab1ffd 521;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a
6a05d05f 522;;; xterm.el ends here