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