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