(handle_one_xevent): For Gtk+ and ConfigureNotify, call
[bpt/emacs.git] / lisp / disp-table.el
CommitLineData
55535639 1;;; disp-table.el --- functions for dealing with char tables
c0274f38 2
e91081eb 3;; Copyright (C) 1987, 1994, 1995, 1999, 2001, 2002, 2003, 2004,
409cc4a3 4;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
9750e079 5
ef9c36a5
EN
6;; Author: Erik Naggum <erik@naggum.no>
7;; Based on a previous version by Howard Gayle
e5167999 8;; Maintainer: FSF
a1d15b3e 9;; Keywords: i18n
a2535589
JA
10
11;; This file is part of GNU Emacs.
12
13;; GNU Emacs is free software; you can redistribute it and/or modify
14;; it under the terms of the GNU General Public License as published by
b4aa6026 15;; the Free Software Foundation; either version 3, or (at your option)
a2535589
JA
16;; any later version.
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
b578f267 24;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
25;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26;; Boston, MA 02110-1301, USA.
a2535589 27
55535639
PJ
28;;; Commentary:
29
e5167999 30;;; Code:
a2535589 31
963fd070 32(put 'display-table 'char-table-extra-slots 6)
dc5a82ea 33
ef9c36a5
EN
34;;;###autoload
35(defun make-display-table ()
36 "Return a new, empty display table."
963fd070 37 (make-char-table 'display-table nil))
ef9c36a5
EN
38
39(or standard-display-table
40 (setq standard-display-table (make-display-table)))
41
963fd070
RS
42;;; Display-table slot names. The property value says which slot.
43
44(put 'truncation 'display-table-slot 0)
45(put 'wrap 'display-table-slot 1)
46(put 'escape 'display-table-slot 2)
47(put 'control 'display-table-slot 3)
48(put 'selective-display 'display-table-slot 4)
49(put 'vertical-border 'display-table-slot 5)
ef9c36a5
EN
50
51;;;###autoload
52(defun display-table-slot (display-table slot)
53 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
12c9fbcc
EN
54SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol).
55Valid symbols are `truncation', `wrap', `escape', `control',
56`selective-display', and `vertical-border'."
ef9c36a5
EN
57 (let ((slot-number
58 (if (numberp slot) slot
963fd070 59 (or (get slot 'display-table-slot)
ef9c36a5
EN
60 (error "Invalid display-table slot name: %s" slot)))))
61 (char-table-extra-slot display-table slot-number)))
62
63;;;###autoload
64(defun set-display-table-slot (display-table slot value)
65 "Set the value of the extra slot in DISPLAY-TABLE named SLOT to VALUE.
66SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
12c9fbcc
EN
67Valid symbols are `truncation', `wrap', `escape', `control',
68`selective-display', and `vertical-border'."
963fd070
RS
69 (let ((slot-number
70 (if (numberp slot) slot
71 (or (get slot 'display-table-slot)
72 (error "Invalid display-table slot name: %s" slot)))))
73 (set-char-table-extra-slot display-table slot-number value)))
ef9c36a5
EN
74
75;;;###autoload
e31b61e6 76(defun describe-display-table (dt)
49116ac0 77 "Describe the display table DT in a help buffer."
e3d68257 78 (with-help-window "*Help*"
03131799 79 (princ "\nTruncation glyph: ")
963fd070 80 (prin1 (display-table-slot dt 'truncation))
03131799 81 (princ "\nWrap glyph: ")
963fd070 82 (prin1 (display-table-slot dt 'wrap))
03131799 83 (princ "\nEscape glyph: ")
963fd070 84 (prin1 (display-table-slot dt 'escape))
03131799 85 (princ "\nCtrl glyph: ")
963fd070 86 (prin1 (display-table-slot dt 'control))
afb1e4b4 87 (princ "\nSelective display glyph sequence: ")
963fd070 88 (prin1 (display-table-slot dt 'selective-display))
dc5a82ea 89 (princ "\nVertical window border glyph: ")
963fd070 90 (prin1 (display-table-slot dt 'vertical-border))
afb1e4b4 91 (princ "\nCharacter display glyph sequences:\n")
bb6066c8
RS
92 (save-excursion
93 (set-buffer standard-output)
94 (let ((vector (make-vector 256 nil))
95 (i 0))
96 (while (< i 256)
97 (aset vector i (aref dt i))
98 (setq i (1+ i)))
5d74f2a6 99 (describe-vector vector))
e3d68257 100 (help-mode))))
a2535589 101
e31b61e6 102;;;###autoload
a2535589 103(defun describe-current-display-table ()
bb6066c8
RS
104 "Describe the display table in use in the selected window and buffer."
105 (interactive)
ef9c36a5
EN
106 (let ((disptab (or (window-display-table (selected-window))
107 buffer-display-table
108 standard-display-table)))
bb6066c8
RS
109 (if disptab
110 (describe-display-table disptab)
111 (message "No display table"))))
a2535589 112
e31b61e6 113;;;###autoload
a2535589 114(defun standard-display-8bit (l h)
49116ac0 115 "Display characters in the range L to H literally."
6b61353c
KH
116 (or standard-display-table
117 (setq standard-display-table (make-display-table)))
a2535589 118 (while (<= l h)
dae50e4f 119 (aset standard-display-table l (if (or (< l ?\s) (>= l 127)) (vector l)))
a2535589
JA
120 (setq l (1+ l))))
121
798aa8d0
JB
122;;;###autoload
123(defun standard-display-default (l h)
124 "Display characters in the range L to H using the default notation."
6b61353c
KH
125 (or standard-display-table
126 (setq standard-display-table (make-display-table)))
798aa8d0 127 (while (<= l h)
a0451a71 128 (if (and (>= l ?\s) (characterp l))
1c2c3f16 129 (aset standard-display-table l nil))
798aa8d0
JB
130 (setq l (1+ l))))
131
a171458a
KH
132;; This function does NOT take terminal-dependent escape sequences.
133;; For that, you need to go through create-glyph. Use one of the
134;; other functions below, or roll your own.
ef9c36a5 135;;;###autoload
a2535589 136(defun standard-display-ascii (c s)
a171458a 137 "Display character C using printable string S."
6b61353c
KH
138 (or standard-display-table
139 (setq standard-display-table (make-display-table)))
ef9c36a5 140 (aset standard-display-table c (vconcat s)))
a2535589 141
e31b61e6 142;;;###autoload
a2535589 143(defun standard-display-g1 (c sc)
de7d5cb6
KH
144 "Display character C as character SC in the g1 character set.
145This function assumes that your terminal uses the SO/SI characters;
146it is meaningless for an X frame."
06b4a81b 147 (if (memq window-system '(x w32 mac))
de7d5cb6 148 (error "Cannot use string glyphs in a windowing system"))
6b61353c
KH
149 (or standard-display-table
150 (setq standard-display-table (make-display-table)))
a2535589 151 (aset standard-display-table c
82093c70 152 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
a2535589 153
e31b61e6 154;;;###autoload
a2535589 155(defun standard-display-graphic (c gc)
de7d5cb6
KH
156 "Display character C as character GC in graphics character set.
157This function assumes VT100-compatible escapes; it is meaningless for an
158X frame."
06b4a81b 159 (if (memq window-system '(x w32 mac))
de7d5cb6 160 (error "Cannot use string glyphs in a windowing system"))
6b61353c
KH
161 (or standard-display-table
162 (setq standard-display-table (make-display-table)))
a2535589 163 (aset standard-display-table c
82093c70 164 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
a2535589 165
e31b61e6 166;;;###autoload
a2535589
JA
167(defun standard-display-underline (c uc)
168 "Display character C as character UC plus underlining."
6b61353c
KH
169 (or standard-display-table
170 (setq standard-display-table (make-display-table)))
a2535589 171 (aset standard-display-table c
71296446 172 (vector
de7d5cb6 173 (if window-system
7dbfbd91 174 (make-glyph-code uc 'underline)
de7d5cb6 175 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
03131799 176
e31b61e6 177;;;###autoload
03131799 178(defun create-glyph (string)
b8fbaf52 179 "Allocate a glyph code to display by sending STRING to the terminal."
03131799
RS
180 (if (= (length glyph-table) 65536)
181 (error "No free glyph codes remain"))
03fd83c5
KH
182 ;; Don't use slots that correspond to ASCII characters.
183 (if (= (length glyph-table) 32)
184 (setq glyph-table (vconcat glyph-table (make-vector 224 nil))))
03131799
RS
185 (setq glyph-table (vconcat glyph-table (list string)))
186 (1- (length glyph-table)))
a2535589 187
7dbfbd91
KS
188;;;###autoload
189(defun make-glyph-code (char &optional face)
190 "Return a glyph code representing char CHAR with face FACE."
191 ;; Due to limitations on Emacs integer values, faces with
7cc8cfc0 192 ;; face id greater that 512 are silently ignored.
20e70daf
KS
193 (if (not face)
194 char
195 (let ((fid (face-id face)))
196 (cond
197 ((not fid) (error "unknown face"))
198 ((< fid 64) ; we have 32 - 3(LSB) - 1(SIGN) - 22(CHAR) = 6 bits for face id
199 (logior char (lsh fid 22)))
200 (t (cons char fid))))))
7dbfbd91
KS
201
202;;;###autoload
203(defun glyph-char (glyph)
204 "Return the character of glyph code GLYPH."
20e70daf
KS
205 (if (consp glyph)
206 (car glyph)
207 (logand glyph #x3fffff)))
7dbfbd91
KS
208
209;;;###autoload
210(defun glyph-face (glyph)
211 "Return the face of glyph code GLYPH, or nil if glyph has default face."
20e70daf
KS
212
213 (let ((face-id (if (consp glyph) (cdr glyph) (lsh glyph -22))))
7dbfbd91
KS
214 (and (> face-id 0)
215 (car (delq nil (mapcar (lambda (face)
216 (and (eq (get face 'face) face-id)
217 face))
218 (face-list)))))))
219
2eae7226 220;;;###autoload
951bc45f 221(defun standard-display-european (arg)
3fbd8622 222 "Semi-obsolete way to toggle display of ISO 8859 European characters.
3ea1bd50 223
3fbd8622
KH
224This function is semi-obsolete; if you want to do your editing with
225unibyte characters, it is better to `set-language-environment' coupled
226with either the `--unibyte' option or the EMACS_UNIBYTE environment
227variable, or else customize `enable-multibyte-characters'.
828fac3a 228
3fbd8622 229With prefix argument, this command enables European character display
178f6d1f 230if ARG is positive, disables it otherwise. Otherwise, it toggles
3fbd8622 231European character display.
b2b52747 232
3fbd8622
KH
233When this mode is enabled, characters in the range of 160 to 255
234display not as octal escapes, but as accented characters. Codes 146
235and 160 display as apostrophe and space, even though they are not the
236ASCII codes for apostrophe and space.
40e82ac1 237
3fbd8622
KH
238Enabling European character display with this command noninteractively
239from Lisp code also selects Latin-1 as the language environment, and
240selects unibyte mode for all Emacs buffers \(both existing buffers and
241those created subsequently). This provides increased compatibility
242for users who call this function in `.emacs'."
f5af76c2 243
c3a14a2b 244 (if (or (<= (prefix-numeric-value arg) 0)
2eae7226 245 (and (null arg)
ef9c36a5 246 (char-table-p standard-display-table)
55f5abaf 247 ;; Test 161, because 160 displays as a space.
e470e6f0 248 (equal (aref standard-display-table 161) [161])))
3304a6c4
RS
249 (progn
250 (standard-display-default 160 255)
06b4a81b 251 (unless (or (memq window-system '(x w32 mac)))
3fbd8622
KH
252 (and (terminal-coding-system)
253 (set-terminal-coding-system nil))))
6fbb1eb0
RS
254
255 (display-warning 'i18n
61af05c3 256 "`standard-display-european' is semi-obsolete; see its doc string for details"
6fbb1eb0 257 :warning)
fbd798e2
SM
258
259 ;; Switch to Latin-1 language environment
eb72c1bd 260 ;; unless some other has been specified.
fbd798e2
SM
261 (if (equal current-language-environment "English")
262 (set-language-environment "latin-1"))
d64f470d 263 (unless (or noninteractive (memq window-system '(x w32 mac)))
951bc45f
PE
264 ;; Send those codes literally to a character-based terminal.
265 ;; If we are using single-byte characters,
266 ;; it doesn't matter which coding system we use.
4e633bb8 267 (set-terminal-coding-system
951bc45f
PE
268 (let ((c (intern (downcase current-language-environment))))
269 (if (coding-system-p c) c 'latin-1))))
eb72c1bd 270 (standard-display-european-internal)))
798aa8d0 271
a2535589 272(provide 'disp-table)
c0274f38 273
178f6d1f 274;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
c0274f38 275;;; disp-table.el ends here