1 ;;; rxvt.el --- define function key sequences and standard colors for rxvt
3 ;; Copyright (C) 2002-2015 Free Software Foundation, Inc.
5 ;; Author: Eli Zaretskii
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (defvar rxvt-function-map
30 (let ((map (make-sparse-keymap)))
31 (set-keymap-parent map xterm-rxvt-function-map
)
33 ;; Set up input-decode-map entries that termcap and terminfo don't know.
34 (define-key map
"\e[7~" [home])
35 (define-key map "\e[8~" [end])
36 ;; The strings emitted by f11 and f12 are the same as the strings
37 ;; emitted by S-f1 and S-f2, so don't define f11 and f12.
38 ;; (define-key rxvt-function-map "\e[23~" [f11])
39 ;; (define-key rxvt-function-map "\e[24~" [f12])
40 (define-key map "\e[23~" [S-f1])
41 (define-key map "\e[24~" [S-f2])
43 (define-key map "\e[11^" [C-f1])
44 (define-key map "\e[12^" [C-f2])
45 (define-key map "\e[13^" [C-f3])
46 (define-key map "\e[14^" [C-f4])
47 (define-key map "\e[15^" [C-f5])
48 (define-key map "\e[17^" [C-f6])
49 (define-key map "\e[18^" [C-f7])
50 (define-key map "\e[19^" [C-f8])
51 (define-key map "\e[20^" [C-f9])
52 (define-key map "\e[21^" [C-f10])
54 (define-key map "\e[25~" [S-f3])
55 (define-key map "\e[26~" [S-f4])
56 (define-key map "\e[28~" [S-f5])
57 (define-key map "\e[29~" [S-f6])
58 (define-key map "\e[31~" [S-f7])
59 (define-key map "\e[32~" [S-f8])
60 (define-key map "\e[33~" [S-f9])
61 (define-key map "\e[34~" [S-f10])
63 (define-key map "\e[23^" [C-S-f1])
64 (define-key map "\e[24^" [C-S-f2])
65 (define-key map "\e[25^" [C-S-f3])
66 (define-key map "\e[26^" [C-S-f4])
67 (define-key map "\e[28^" [C-S-f5])
68 (define-key map "\e[29^" [C-S-f6])
69 (define-key map "\e[31^" [C-S-f7])
70 (define-key map "\e[32^" [C-S-f8])
71 (define-key map "\e[33^" [C-S-f9])
72 (define-key map "\e[34^" [C-S-f10])
74 (define-key map "\e[2^" [C-insert])
75 (define-key map "\e[3^" [C-delete])
76 (define-key map "\e[5^" [C-prior])
77 (define-key map "\e[6^" [C-next])
78 (define-key map "\e[7^" [C-home])
79 (define-key map "\e[8^" [C-end])
80 (define-key map "\eOd" [C-left])
81 (define-key map "\eOc" [C-right])
82 (define-key map "\eOa" [C-up])
83 (define-key map "\eOb" [C-down])
85 (define-key map "\e[3$" [S-delete])
86 (define-key map "\e[5$" [S-prior])
87 (define-key map "\e[6$" [S-next])
88 (define-key map "\e[7$" [S-home])
89 (define-key map "\e[8$" [S-end])
90 (define-key map "\e[d" [S-left])
91 (define-key map "\e[c" [S-right])
92 (define-key map "\e[a" [S-up])
93 (define-key map "\e[b" [S-down])
95 "Function key overrides for rxvt.")
97 (defvar rxvt-alternatives-map
98 (let ((map (make-sparse-keymap)))
99 ;; The terminal initialization C code file might have initialized
100 ;; function keys F11->F42 from the termcap/terminfo information. On
101 ;; a PC-style keyboard these keys correspond to
102 ;; MODIFIER-FUNCTION_KEY, where modifier is S-, C-, C-S-. The
103 ;; code here substitutes the corresponding definitions in
104 ;; function-key-map. This substitution is needed because if a key
105 ;; definition if found in function-key-map, there are no further
106 ;; lookups in other keymaps.
107 (define-key map [f11] [S-f1])
108 (define-key map [f12] [S-f2])
109 (define-key map [f13] [S-f3])
110 (define-key map [f14] [S-f4])
111 (define-key map [f15] [S-f5])
112 (define-key map [f16] [S-f6])
113 (define-key map [f17] [S-f7])
114 (define-key map [f18] [S-f8])
115 (define-key map [f19] [S-f9])
116 (define-key map [f20] [S-f10])
118 (define-key map [f23] [C-f1])
119 (define-key map [f24] [C-f2])
120 (define-key map [f25] [C-f3])
121 (define-key map [f26] [C-f4])
122 (define-key map [f27] [C-f5])
123 (define-key map [f28] [C-f6])
124 (define-key map [f29] [C-f7])
125 (define-key map [f30] [C-f8])
126 (define-key map [f31] [C-f9])
127 (define-key map [f32] [C-f10])
129 (define-key map [f33] [C-S-f1])
130 (define-key map [f34] [C-S-f2])
131 (define-key map [f35] [C-S-f3])
132 (define-key map [f36] [C-S-f4])
133 (define-key map [f37] [C-S-f5])
134 (define-key map [f38] [C-S-f6])
135 (define-key map [f39] [C-S-f7])
136 (define-key map [f40] [C-S-f8])
137 (define-key map [f41] [C-S-f9])
138 (define-key map [f42] [C-S-f10])
140 "Keymap of possible alternative meanings for some keys.")
142 ;; Set up colors, for those versions of rxvt that support it.
143 (defvar rxvt-standard-colors
144 ;; The names of the colors in the comments taken from the rxvt.1 man
145 ;; page; the corresponding RGB values--from rgb.txt.
146 '(("black" 0 ( 0 0 0)) ; black
147 ("red" 1 (205 0 0)) ; red3
148 ("green" 2 ( 0 205 0)) ; green3
149 ("yellow" 3 (205 205 0)) ; yellow3
150 ("blue" 4 ( 0 0 205)) ; blue3
151 ("magenta" 5 (205 0 205)) ; magenta3
152 ("cyan" 6 ( 0 205 205)) ; cyan3
153 ("white" 7 (229 229 229)) ; gray90
154 ("brightblack" 8 ( 77 77 77)) ; gray30
155 ("brightred" 9 (255 0 0)) ; red
156 ("brightgreen" 10 ( 0 255 0)) ; green
157 ("brightyellow" 11 (255 255 0)) ; yellow
158 ("brightblue" 12 ( 0 0 255)) ; blue
159 ("brightmagenta" 13 (255 0 255)) ; magenta
160 ("brightcyan" 14 ( 0 255 255)) ; cyan
161 ("brightwhite" 15 (255 255 255))) ; white
162 "Names of 16 standard rxvt colors, their numbers, and RGB values.")
164 (defun terminal-init-rxvt ()
165 "Terminal initialization function for rxvt."
167 (xterm--push-map rxvt-alternatives-map local-function-key-map)
168 (xterm--push-map rxvt-function-map input-decode-map)
170 ;; Initialize colors and background mode.
171 (xterm-register-default-colors rxvt-standard-colors)
172 (rxvt-set-background-mode)
173 ;; This recomputes all the default faces given the colors we've just set up.
174 (tty-set-up-initial-frame-faces))
176 ;; rxvt puts the default colors into an environment variable
177 ;; COLORFGBG. We use this to set the background mode in a more
178 ;; intelligent way than the default guesswork in startup.el.
179 (defun rxvt-set-background-mode ()
180 "Set background mode as appropriate for the default rxvt colors."
181 (let ((fgbg (getenv "COLORFGBG"))
183 (set-terminal-parameter nil 'background-mode 'light)
185 (string-match ".*;\\([0-9][0-9]?\\)\\'" fgbg))
186 (setq bg (string-to-number (substring fgbg (match-beginning 1))))
187 ;; The next line assumes that rxvt-standard-colors are ordered
188 ;; by the color index in the ascending order!
189 (setq rgb (car (cddr (nth bg rxvt-standard-colors))))
190 ;; See the commentary in frame-set-background-mode about the
191 ;; computation below.
192 (if (< (apply '+ rgb)
193 ;; The following line assumes that white is the 15th
194 ;; color in rxvt-standard-colors.
195 (* (apply '+ (car (cddr (nth 15 rxvt-standard-colors)))) 0.6))
196 (set-terminal-parameter nil 'background-mode 'dark)))))
198 ;;; rxvt.el ends here