]> code.delx.au - gnu-emacs/blob - lisp/term/rxvt.el
Merged from miles@gnu.org--gnu-2005 (patch 469)
[gnu-emacs] / lisp / term / rxvt.el
1 ;;; rxvt.el --- define function key sequences and standard colors for rxvt
2
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
4
5 ;; Author: Eli Zaretskii
6 ;; Keywords: terminals
7
8 ;; This file is part of GNU Emacs.
9
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 2, or (at your option)
13 ;; any later version.
14
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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (require 'server)
30
31 (defvar rxvt-function-map nil
32 "Function key overrides for rxvt.")
33
34 ;; Protect against reloads.
35 (unless rxvt-function-map
36 (setq rxvt-function-map (make-sparse-keymap))
37
38 ;; Set up function-key-map entries that termcap and terminfo don't know.
39 (define-key rxvt-function-map "\e[A" [up])
40 (define-key rxvt-function-map "\e[B" [down])
41 (define-key rxvt-function-map "\e[C" [right])
42 (define-key rxvt-function-map "\e[D" [left])
43 (define-key rxvt-function-map "\e[7~" [home])
44 (define-key rxvt-function-map "\e[2~" [insert])
45 (define-key rxvt-function-map "\e[3~" [delete])
46 (define-key rxvt-function-map "\e[4~" [select])
47 (define-key rxvt-function-map "\e[5~" [prior])
48 (define-key rxvt-function-map "\e[6~" [next])
49 (define-key rxvt-function-map "\e[11~" [f1])
50 (define-key rxvt-function-map "\e[12~" [f2])
51 (define-key rxvt-function-map "\e[13~" [f3])
52 (define-key rxvt-function-map "\e[14~" [f4])
53 (define-key rxvt-function-map "\e[15~" [f5])
54 (define-key rxvt-function-map "\e[17~" [f6])
55 (define-key rxvt-function-map "\e[18~" [f7])
56 (define-key rxvt-function-map "\e[19~" [f8])
57 (define-key rxvt-function-map "\e[20~" [f9])
58 (define-key rxvt-function-map "\e[21~" [f10])
59 (define-key rxvt-function-map "\e[23~" [f11])
60 (define-key rxvt-function-map "\e[24~" [f12])
61 (define-key rxvt-function-map "\e[29~" [print])
62
63 (define-key rxvt-function-map "\e[11^" [C-f1])
64 (define-key rxvt-function-map "\e[12^" [C-f2])
65 (define-key rxvt-function-map "\e[13^" [C-f3])
66 (define-key rxvt-function-map "\e[14^" [C-f4])
67 (define-key rxvt-function-map "\e[15^" [C-f5])
68 (define-key rxvt-function-map "\e[17^" [C-f6])
69 (define-key rxvt-function-map "\e[18^" [C-f7])
70 (define-key rxvt-function-map "\e[19^" [C-f8])
71 (define-key rxvt-function-map "\e[20^" [C-f9])
72 (define-key rxvt-function-map "\e[21^" [C-f10])
73 (define-key rxvt-function-map "\e[23^" [C-f11])
74 (define-key rxvt-function-map "\e[24^" [C-f12])
75
76 (define-key rxvt-function-map "\e[29~" [print])
77
78 (define-key rxvt-function-map "\e[2;2~" [S-insert])
79 (define-key rxvt-function-map "\e[3$" [S-delete])
80
81 (define-key rxvt-function-map "\e[2^" [C-insert])
82 (define-key rxvt-function-map "\e[3^" [C-delete])
83 (define-key rxvt-function-map "\e[5^" [C-prior])
84 (define-key rxvt-function-map "\e[6^" [C-next])
85 (define-key rxvt-function-map "\eOd" [C-left])
86 (define-key rxvt-function-map "\eOc" [C-right])
87 (define-key rxvt-function-map "\eOa" [C-up])
88 (define-key rxvt-function-map "\eOb" [C-down])
89
90 (define-key rxvt-function-map "\e[5$" [S-prior])
91 (define-key rxvt-function-map "\e[6$" [S-next])
92 (define-key rxvt-function-map "\e[8$" [S-end])
93 (define-key rxvt-function-map "\e[7$" [S-home])
94 (define-key rxvt-function-map "\e[d" [S-left])
95 (define-key rxvt-function-map "\e[c" [S-right])
96 (define-key rxvt-function-map "\e[a" [S-up])
97 (define-key rxvt-function-map "\e[b" [S-down]))
98
99 ;; Use inheritance to let the main keymap override those defaults.
100 ;; This way we don't override terminfo-derived settings or settings
101 ;; made in the .emacs file.
102 (let ((m (copy-keymap rxvt-function-map)))
103 (set-keymap-parent m (keymap-parent (terminal-local-value 'function-key-map nil)))
104 (set-keymap-parent (terminal-local-value 'function-key-map nil) m))
105
106
107 ;; Set up colors, for those versions of rxvt that support it.
108 (defvar rxvt-standard-colors
109 ;; The names of the colors in the comments taken from the rxvt.1 man
110 ;; page; the corresponding RGB values--from rgb.txt.
111 '(("black" 0 ( 0 0 0)) ; black
112 ("red" 1 (205 0 0)) ; red3
113 ("green" 2 ( 0 205 0)) ; green3
114 ("yellow" 3 (205 205 0)) ; yellow3
115 ("blue" 4 ( 0 0 205)) ; blue3
116 ("magenta" 5 (205 0 205)) ; magenta3
117 ("cyan" 6 ( 0 205 205)) ; cyan3
118 ("white" 7 (250 235 215)) ; AntiqueWhite
119 ("brightblack" 8 ( 64 64 64)) ; gray25
120 ("brightred" 9 (255 0 0)) ; red
121 ("brightgreen" 10 ( 0 255 0)) ; green
122 ("brightyellow" 11 (255 255 0)) ; yellow
123 ("brightblue" 12 ( 0 0 255)) ; blue
124 ("brightmagenta" 13 (255 0 255)) ; magenta
125 ("brightcyan" 14 ( 0 255 255)) ; cyan
126 ("brightwhite" 15 (255 255 255))) ; white
127 "Names of 16 standard rxvt colors, their numbers, and RGB values.")
128
129 (defun rxvt-rgb-convert-to-16bit (prim)
130 "Convert an 8-bit primary color value PRIM to a corresponding 16-bit value."
131 (min 65535 (round (* (/ prim 255.0) 65535.0))))
132
133 (defun rxvt-register-default-colors ()
134 "Register the default set of colors for rxvt or compatible emulator.
135
136 This function registers the number of colors returned by `display-color-cells'
137 for the currently selected frame."
138 (let* ((ncolors (display-color-cells))
139 (colors rxvt-standard-colors)
140 (color (car colors)))
141 (if (> ncolors 0)
142 ;; Clear the 8 default tty colors registered by startup.el
143 (tty-color-clear))
144 ;; Only register as many colors as are supported by the display.
145 (while (and (> ncolors 0) colors)
146 (tty-color-define (car color) (cadr color)
147 (mapcar 'rxvt-rgb-convert-to-16bit
148 (car (cddr color))))
149 (setq colors (cdr colors)
150 color (car colors)
151 ncolors (1- ncolors)))
152 ;; Modifying color mappings means realized faces don't use the
153 ;; right colors, so clear them.
154 (clear-face-cache)))
155
156 ;; rxvt puts the default colors into an environment variable
157 ;; COLORFGBG. We use this to set the background mode in a more
158 ;; intelligent way than the default guesswork in startup.el.
159 (defun rxvt-set-background-mode ()
160 "Set background mode as appropriate for the default rxvt colors."
161 (let ((fgbg (server-getenv "COLORFGBG"))
162 bg rgb)
163 (setq default-frame-background-mode 'light)
164 (when (and fgbg
165 (string-match ".*;\\([0-9][0-9]?\\)\\'" fgbg))
166 (setq bg (string-to-number (substring fgbg (match-beginning 1))))
167 ;; The next line assumes that rxvt-standard-colors are ordered
168 ;; by the color index in the ascending order!
169 (setq rgb (car (cddr (nth bg rxvt-standard-colors))))
170 ;; See the commentary in frame-set-background-mode about the
171 ;; computation below.
172 (if (< (apply '+ rgb)
173 ;; The following line assumes that white is the 15th
174 ;; color in rxvt-standard-colors.
175 (* (apply '+ (car (cddr (nth 15 rxvt-standard-colors)))) 0.6))
176 (setq default-frame-background-mode 'dark)))
177 (frame-set-background-mode (selected-frame))))
178
179 ;; Do it!
180 (rxvt-register-default-colors)
181 (rxvt-set-background-mode)
182 ;; This recomputes all the default faces given the colors we've just set up.
183 (tty-set-up-initial-frame-faces)
184
185 ;;; arch-tag: 20cf2fb6-6318-4bab-9dbf-1d15048f2257
186 ;;; rxvt.el ends here