]> code.delx.au - gnu-emacs/blob - lisp/disp-table.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / disp-table.el
1 ;;; disp-table.el --- functions for dealing with char tables
2
3 ;; Copyright (C) 1987, 1994, 1995, 1999, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Erik Naggum <erik@naggum.no>
7 ;; Based on a previous version by Howard Gayle
8 ;; Maintainer: FSF
9 ;; Keywords: i18n
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
15 ;; the Free Software Foundation; either version 3, or (at your option)
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
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 (put 'display-table 'char-table-extra-slots 6)
33
34 ;;;###autoload
35 (defun make-display-table ()
36 "Return a new, empty display table."
37 (make-char-table 'display-table nil))
38
39 (or standard-display-table
40 (setq standard-display-table (make-display-table)))
41
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)
50
51 ;;;###autoload
52 (defun display-table-slot (display-table slot)
53 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
54 SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol).
55 Valid symbols are `truncation', `wrap', `escape', `control',
56 `selective-display', and `vertical-border'."
57 (let ((slot-number
58 (if (numberp slot) slot
59 (or (get slot 'display-table-slot)
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.
66 SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
67 Valid symbols are `truncation', `wrap', `escape', `control',
68 `selective-display', and `vertical-border'."
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)))
74
75 ;;;###autoload
76 (defun describe-display-table (dt)
77 "Describe the display table DT in a help buffer."
78 (with-help-window "*Help*"
79 (princ "\nTruncation glyph: ")
80 (prin1 (display-table-slot dt 'truncation))
81 (princ "\nWrap glyph: ")
82 (prin1 (display-table-slot dt 'wrap))
83 (princ "\nEscape glyph: ")
84 (prin1 (display-table-slot dt 'escape))
85 (princ "\nCtrl glyph: ")
86 (prin1 (display-table-slot dt 'control))
87 (princ "\nSelective display glyph sequence: ")
88 (prin1 (display-table-slot dt 'selective-display))
89 (princ "\nVertical window border glyph: ")
90 (prin1 (display-table-slot dt 'vertical-border))
91 (princ "\nCharacter display glyph sequences:\n")
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)))
99 (describe-vector vector))
100 (help-mode))))
101
102 ;;;###autoload
103 (defun describe-current-display-table ()
104 "Describe the display table in use in the selected window and buffer."
105 (interactive)
106 (let ((disptab (or (window-display-table (selected-window))
107 buffer-display-table
108 standard-display-table)))
109 (if disptab
110 (describe-display-table disptab)
111 (message "No display table"))))
112
113 ;;;###autoload
114 (defun standard-display-8bit (l h)
115 "Display characters in the range L to H literally."
116 (or standard-display-table
117 (setq standard-display-table (make-display-table)))
118 (while (<= l h)
119 (aset standard-display-table l (if (or (< l ?\s) (>= l 127)) (vector l)))
120 (setq l (1+ l))))
121
122 ;;;###autoload
123 (defun standard-display-default (l h)
124 "Display characters in the range L to H using the default notation."
125 (or standard-display-table
126 (setq standard-display-table (make-display-table)))
127 (while (<= l h)
128 (if (and (>= l ?\s) (characterp l))
129 (aset standard-display-table l nil))
130 (setq l (1+ l))))
131
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.
135 ;;;###autoload
136 (defun standard-display-ascii (c s)
137 "Display character C using printable string S."
138 (or standard-display-table
139 (setq standard-display-table (make-display-table)))
140 (aset standard-display-table c (vconcat s)))
141
142 ;;;###autoload
143 (defun standard-display-g1 (c sc)
144 "Display character C as character SC in the g1 character set.
145 This function assumes that your terminal uses the SO/SI characters;
146 it is meaningless for an X frame."
147 (if (memq window-system '(x w32 mac))
148 (error "Cannot use string glyphs in a windowing system"))
149 (or standard-display-table
150 (setq standard-display-table (make-display-table)))
151 (aset standard-display-table c
152 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
153
154 ;;;###autoload
155 (defun standard-display-graphic (c gc)
156 "Display character C as character GC in graphics character set.
157 This function assumes VT100-compatible escapes; it is meaningless for an
158 X frame."
159 (if (memq window-system '(x w32 mac))
160 (error "Cannot use string glyphs in a windowing system"))
161 (or standard-display-table
162 (setq standard-display-table (make-display-table)))
163 (aset standard-display-table c
164 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
165
166 ;;;###autoload
167 (defun standard-display-underline (c uc)
168 "Display character C as character UC plus underlining."
169 (or standard-display-table
170 (setq standard-display-table (make-display-table)))
171 (aset standard-display-table c
172 (vector
173 (if window-system
174 (make-glyph-code uc 'underline)
175 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
176
177 ;;;###autoload
178 (defun create-glyph (string)
179 "Allocate a glyph code to display by sending STRING to the terminal."
180 (if (= (length glyph-table) 65536)
181 (error "No free glyph codes remain"))
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))))
185 (setq glyph-table (vconcat glyph-table (list string)))
186 (1- (length glyph-table)))
187
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
192 ;; face id greater that 512 are silently ignored.
193 (if (and face (<= (face-id face) #x1ff))
194 (logior char (lsh (face-id face) 22))
195 char))
196
197 ;;;###autoload
198 (defun glyph-char (glyph)
199 "Return the character of glyph code GLYPH."
200 (logand glyph #x3fffff))
201
202 ;;;###autoload
203 (defun glyph-face (glyph)
204 "Return the face of glyph code GLYPH, or nil if glyph has default face."
205 (let ((face-id (lsh glyph -22)))
206 (and (> face-id 0)
207 (car (delq nil (mapcar (lambda (face)
208 (and (eq (get face 'face) face-id)
209 face))
210 (face-list)))))))
211
212 ;;;###autoload
213 (defun standard-display-european (arg)
214 "Semi-obsolete way to toggle display of ISO 8859 European characters.
215
216 This function is semi-obsolete; if you want to do your editing with
217 unibyte characters, it is better to `set-language-environment' coupled
218 with either the `--unibyte' option or the EMACS_UNIBYTE environment
219 variable, or else customize `enable-multibyte-characters'.
220
221 With prefix argument, this command enables European character display
222 if ARG is positive, disables it otherwise. Otherwise, it toggles
223 European character display.
224
225 When this mode is enabled, characters in the range of 160 to 255
226 display not as octal escapes, but as accented characters. Codes 146
227 and 160 display as apostrophe and space, even though they are not the
228 ASCII codes for apostrophe and space.
229
230 Enabling European character display with this command noninteractively
231 from Lisp code also selects Latin-1 as the language environment, and
232 selects unibyte mode for all Emacs buffers \(both existing buffers and
233 those created subsequently). This provides increased compatibility
234 for users who call this function in `.emacs'."
235
236 (if (or (<= (prefix-numeric-value arg) 0)
237 (and (null arg)
238 (char-table-p standard-display-table)
239 ;; Test 161, because 160 displays as a space.
240 (equal (aref standard-display-table 161) [161])))
241 (progn
242 (standard-display-default 160 255)
243 (unless (or (memq window-system '(x w32 mac)))
244 (and (terminal-coding-system)
245 (set-terminal-coding-system nil))))
246
247 (display-warning 'i18n
248 "`standard-display-european' is semi-obsolete; see its doc string for details"
249 :warning)
250
251 ;; Switch to Latin-1 language environment
252 ;; unless some other has been specified.
253 (if (equal current-language-environment "English")
254 (set-language-environment "latin-1"))
255 (unless (or noninteractive (memq window-system '(x w32 mac)))
256 ;; Send those codes literally to a character-based terminal.
257 ;; If we are using single-byte characters,
258 ;; it doesn't matter which coding system we use.
259 (set-terminal-coding-system
260 (let ((c (intern (downcase current-language-environment))))
261 (if (coding-system-p c) c 'latin-1))))
262 (standard-display-european-internal)))
263
264 (provide 'disp-table)
265
266 ;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
267 ;;; disp-table.el ends here