annotate lisp/term/xterm.el @ 53109:420dc7ac8867

(File Attributes): Describe new parameter ID-FORMAT.
author Lars Hansen <larsh@soem.dk>
date Fri, 21 Nov 2003 18:25:20 +0000
parents 695cf19ef79e
children f0f48b9999fa 040dd41ed7d0 375f2633d815
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42947
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
1 ;;; xterm.el --- define function key sequences and standard colors for xterm
12159
e83a888f32d9 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
42947
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
3 ;; Copyright (C) 1995, 2002 Free Software Foundation, Inc.
14170
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
4
12159
e83a888f32d9 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5 ;; Author: FSF
e83a888f32d9 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Keywords: terminals
e83a888f32d9 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7
14170
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
8 ;; This file is part of GNU Emacs.
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
9
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
13 ;; any later version.
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
14
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
18 ;; GNU General Public License for more details.
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
19
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
20 ;; You should have received a copy of the GNU General Public License
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23cc3f54e536 Update FSF's office address.
Erik Naggum <erik@naggum.no>
parents: 12159
diff changeset
23 ;; Boston, MA 02111-1307, USA.
12159
e83a888f32d9 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24
38431
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14170
diff changeset
25 ;;; Commentary:
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14170
diff changeset
26
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14170
diff changeset
27 ;;; Code:
12159
e83a888f32d9 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28
40694
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
29 (let ((map (make-sparse-keymap)))
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
30 (define-key map "\e[A" [up])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
31 (define-key map "\e[B" [down])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
32 (define-key map "\e[C" [right])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
33 (define-key map "\e[D" [left])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
34 (define-key map "\e[1~" [home])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
35 (define-key map "\e[2~" [insert])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
36 (define-key map "\e[3~" [delete])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
37 (define-key map "\e[4~" [select])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
38 (define-key map "\e[5~" [prior])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
39 (define-key map "\e[6~" [next])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
40 (define-key map "\e[11~" [f1])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
41 (define-key map "\e[12~" [f2])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
42 (define-key map "\e[13~" [f3])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
43 (define-key map "\e[14~" [f4])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
44 (define-key map "\e[15~" [f5])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
45 (define-key map "\e[17~" [f6])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
46 (define-key map "\e[18~" [f7])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
47 (define-key map "\e[19~" [f8])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
48 (define-key map "\e[20~" [f9])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
49 (define-key map "\e[21~" [f10])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
50 (define-key map "\e[23~" [f11])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
51 (define-key map "\e[24~" [f12])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
52 (define-key map "\e[29~" [print])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
53
42947
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
54 (define-key map "\e[2;2~" [S-insert])
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
55 (define-key map "\e[3;2~" [S-delete])
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
56 (define-key map "\e[5;2~" [S-prior])
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
57 (define-key map "\e[6;2~" [S-next])
46065
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
58
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
59 (define-key map "\e[2;5~" [C-insert])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
60 (define-key map "\e[3;5~" [C-delete])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
61 (define-key map "\e[5;5~" [C-prior])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
62 (define-key map "\e[6;5~" [C-next])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
63
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
64 (define-key map "\eOA" [up])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
65 (define-key map "\eOB" [down])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
66 (define-key map "\eOC" [right])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
67 (define-key map "\eOD" [left])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
68 (define-key map "\eOF" [end])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
69 (define-key map "\eOH" [home])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
70
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
71 (define-key map "\eO2A" [S-up])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
72 (define-key map "\eO2B" [S-down])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
73 (define-key map "\eO2C" [S-right])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
74 (define-key map "\eO2D" [S-left])
42947
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
75 (define-key map "\eO2F" [S-end])
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
76 (define-key map "\eO2H" [S-home])
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
77
40694
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
78 (define-key map "\eO5A" [C-up])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
79 (define-key map "\eO5B" [C-down])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
80 (define-key map "\eO5C" [C-right])
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
81 (define-key map "\eO5D" [C-left])
46065
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
82 (define-key map "\eO5F" [C-end])
3f4640971880 (function-key-map): Add some bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42947
diff changeset
83 (define-key map "\eO5H" [C-home])
40694
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
84
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
85 ;; Use inheritance to let the main keymap override those defaults.
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
86 ;; This way we don't override terminfo-derived settings or settings
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
87 ;; made in the .emacs file.
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
88 (set-keymap-parent map (keymap-parent function-key-map))
41fcf9864c4d (function-key-map): Add entry for `ESC [ 3 ~' -> <delete>
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38431
diff changeset
89 (set-keymap-parent function-key-map map))
38431
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14170
diff changeset
90
42947
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
91 ;; Set up colors, for those versions of xterm that support it.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
92 (defvar xterm-standard-colors
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
93 ;; The names in the comments taken from XTerm-col.ad in the xterm
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
94 ;; distribution, see ftp://dickey.his.com/xterm/. RGB values are
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
95 ;; from rgb.txt.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
96 '(("black" 0 ( 0 0 0)) ; black
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
97 ("red" 1 (205 0 0)) ; red3
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
98 ("green" 2 ( 0 205 0)) ; green3
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
99 ("yellow" 3 (205 205 0)) ; yellow3
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
100 ("blue" 4 ( 0 0 205)) ; blue3
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
101 ("magenta" 5 (205 0 205)) ; magenta3
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
102 ("cyan" 6 ( 0 205 205)) ; cyan3
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
103 ("white" 7 (229 229 229)) ; gray90
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
104 ("brightblack" 8 ( 77 77 77)) ; gray30
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
105 ("brightred" 9 (255 0 0)) ; red
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
106 ("brightgreen" 10 ( 0 255 0)) ; green
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
107 ("brightyellow" 11 (255 255 0)) ; yellow
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
108 ("brightblue" 12 ( 0 0 255)) ; blue
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
109 ("brightmagenta" 13 (255 0 255)) ; magenta
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
110 ("brightcyan" 14 ( 0 255 255)) ; cyan
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
111 ("brightwhite" 15 (255 255 255))) ; white
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
112 "Names of 16 standard xterm/aixterm colors, their numbers, and RGB values.")
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
113
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
114 (defun xterm-rgb-convert-to-16bit (prim)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
115 "Convert an 8-bit primary color value PRIM to a corresponding 16-bit value."
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
116 (min 65535 (round (* (/ prim 255.0) 65535.0))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
117
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
118 (defun xterm-register-default-colors ()
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
119 "Register the default set of colors for xterm or compatible emulator.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
120
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
121 This function registers the number of colors returned by `display-color-cells'
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
122 for the currently selected frame. The first 16 colors are taken from
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
123 `xterm-standard-colors', which see, while the rest are computed assuming
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
124 either the 88- or 256-color standard color scheme supported by latest
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
125 versions of xterm."
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
126 (let* ((ncolors (display-color-cells))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
127 (colors xterm-standard-colors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
128 (color (car colors)))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
129 (if (> ncolors 0)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
130 ;; Clear the 8 default tty colors registered by startup.el
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
131 (tty-color-clear))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
132 ;; Only register as many colors as are supported by the display.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
133 (while (and (> ncolors 0) colors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
134 (tty-color-define (car color) (cadr color)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
135 (mapcar 'xterm-rgb-convert-to-16bit
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
136 (car (cddr color))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
137 (setq colors (cdr colors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
138 color (car colors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
139 ncolors (1- ncolors)))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
140 ;; We've exhausted the colors from `xterm-standard-colors'. If there
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
141 ;; are more colors to support, compute them now.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
142 (when (> ncolors 0)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
143 (cond
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
144 ((= ncolors 240) ; 256-color xterm
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
145 ;; 216 non-gray colors first
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
146 (let ((r 0) (g 0) (b 0))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
147 (while (> ncolors 24)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
148 ;; This and other formulae taken from 256colres.pl and
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
149 ;; 88colres.pl in the xterm distribution.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
150 (tty-color-define (format "color-%d" (- 256 ncolors))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
151 (- 256 ncolors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
152 (mapcar 'xterm-rgb-convert-to-16bit
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
153 (list (round (* r 42.5))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
154 (round (* g 42.5))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
155 (round (* b 42.5)))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
156 (setq b (1+ b))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
157 (if (> b 5)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
158 (setq g (1+ g)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
159 b 0))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
160 (if (> g 5)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
161 (setq r (1+ r)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
162 g 0))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
163 (setq ncolors (1- ncolors))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
164 ;; Now the 24 gray colors
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
165 (while (> ncolors 0)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
166 (setq color (xterm-rgb-convert-to-16bit (+ 8 (* (- 24 ncolors) 10))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
167 (tty-color-define (format "color-%d" (- 256 ncolors))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
168 (- 256 ncolors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
169 (list color color color))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
170 (setq ncolors (1- ncolors))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
171 ((= ncolors 72) ; 88-color xterm
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
172 ;; 64 non-gray colors
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
173 (let ((levels '(0 139 205 255))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
174 (r 0) (g 0) (b 0))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
175 (while (> ncolors 8)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
176 (tty-color-define (format "color-%d" (- 88 ncolors))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
177 (- 88 ncolors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
178 (mapcar 'xterm-rgb-convert-to-16bit
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
179 (list (nth r levels)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
180 (nth g levels)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
181 (nth b levels))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
182 (setq b (1+ b))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
183 (if (> b 3)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
184 (setq g (1+ g)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
185 b 0))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
186 (if (> g 3)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
187 (setq r (1+ r)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
188 g 0))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
189 (setq ncolors (1- ncolors))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
190 ;; Now the 8 gray colors
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
191 (while (> ncolors 0)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
192 (setq color (xterm-rgb-convert-to-16bit
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
193 (round
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
194 (if (= ncolors 8)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
195 46.36363636
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
196 (+ (* (- 8 ncolors) 23.18181818) 69.54545454)))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
197 (tty-color-define (format "color-%d" (- 88 ncolors))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
198 (- 88 ncolors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
199 (list color color color))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
200 (setq ncolors (1- ncolors))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
201 (t (error "Unsupported number of xterm colors (%d)" (+ 16 ncolors)))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
202 ;; Modifying color mappings means realized faces don't use the
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
203 ;; right colors, so clear them.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
204 (clear-face-cache)))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
205
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
206 ;; rxvt puts the default colors into an environment variable
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
207 ;; COLORFGBG. We use this to set the background mode in a more
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
208 ;; intelligent way than the default guesswork in startup.el.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
209 (defun xterm-rxvt-set-background-mode ()
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
210 "Set background mode as appropriate for the default rxvt colors."
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
211 (let ((fgbg (getenv "COLORFGBG"))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
212 bg rgb)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
213 (setq frame-background-mode 'light) ; default
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
214 (when (and fgbg
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
215 (string-match ".*;\\([0-9][0-9]?\\)\\'" fgbg))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
216 (setq bg (string-to-number (substring fgbg (match-beginning 1))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
217 ;; The next line assumes that xterm-standard-colors are ordered
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
218 ;; by the color index in the ascending order!
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
219 (setq rgb (car (cddr (nth bg xterm-standard-colors))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
220 ;; See the commentary in frame-set-background-mode about the
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
221 ;; computation below.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
222 (if (< (apply '+ rgb)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
223 ;; The following line assumes that white is the 15th
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
224 ;; color in xterm-standard-colors.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
225 (* (apply '+ (car (cddr (nth 15 xterm-standard-colors)))) 0.6))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
226 (setq frame-background-mode 'dark)))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
227 (frame-set-background-mode (selected-frame))))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
228
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
229 ;; Do it!
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
230 (xterm-register-default-colors)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
231 ;; If this xterm is actually a disguised rxvt, be more intelligent about
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
232 ;; determining the background mode.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
233 (and (getenv "COLORTERM")
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
234 (string-match "\\`rxvt" (getenv "COLORTERM"))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
235 (xterm-rxvt-set-background-mode))
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
236 ;; This recomputes all the default faces given the colors we've just set up.
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
237 (tty-set-up-initial-frame-faces)
76e795715361 (xterm-standard-colors): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 40694
diff changeset
238
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 46065
diff changeset
239 ;;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a
38431
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14170
diff changeset
240 ;;; xterm.el ends here