]> code.delx.au - gnu-emacs/blob - lisp/disp-table.el
Add an autoloaded table, that doesn't require this library, with glyph face.
[gnu-emacs] / lisp / disp-table.el
1 ;;; disp-table.el --- functions for dealing with char tables
2
3 ;; Copyright (C) 1987, 94, 95, 1999, 2004 Free Software Foundation, Inc.
4
5 ;; Author: Erik Naggum <erik@naggum.no>
6 ;; Based on a previous version by Howard Gayle
7 ;; Maintainer: FSF
8 ;; Keywords: i18n
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (put 'display-table 'char-table-extra-slots 6)
32
33 ;;;###autoload
34 (defun make-display-table ()
35 "Return a new, empty display table."
36 (make-char-table 'display-table nil))
37
38 ;;;###autoload (setq standard-display-table #^[t nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil #^^[nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil [11534428 32] nil nil nil nil nil nil nil nil nil nil nil nil [11534428 45] nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil] nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil display-table nil nil 11534428 11534430 [11534382 11534382 11534382] nil])
39 ;; This code generates the preceding table:
40 ;; (let* ((face (lsh (face-id 'glyph) 19))
41 ;; (backslash (+ face ?\\))
42 ;; (dot (+ face ?.))
43 ;; (table (make-display-table))
44 ;; print-length)
45 ;; (set-char-table-extra-slot table 2 backslash)
46 ;; (aset table 2208 (vector backslash ?\ ))
47 ;; (aset table 2221 (vector backslash ?-))
48 ;;
49 ;; (set-char-table-extra-slot table 3 (+ face ?^))
50 ;;
51 ;; (set-char-table-extra-slot table 4 (vector dot dot dot))
52 ;; (print table))
53
54 ;;; Display-table slot names. The property value says which slot.
55
56 (put 'truncation 'display-table-slot 0)
57 (put 'wrap 'display-table-slot 1)
58 (put 'escape 'display-table-slot 2)
59 (put 'control 'display-table-slot 3)
60 (put 'selective-display 'display-table-slot 4)
61 (put 'vertical-border 'display-table-slot 5)
62
63 ;;;###autoload
64 (defun display-table-slot (display-table slot)
65 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
66 SLOT may be a number from 0 to 5 inclusive, or a slot 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 (char-table-extra-slot display-table slot-number)))
74
75 ;;;###autoload
76 (defun set-display-table-slot (display-table slot value)
77 "Set the value of the extra slot in DISPLAY-TABLE named SLOT to VALUE.
78 SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
79 Valid symbols are `truncation', `wrap', `escape', `control',
80 `selective-display', and `vertical-border'."
81 (let ((slot-number
82 (if (numberp slot) slot
83 (or (get slot 'display-table-slot)
84 (error "Invalid display-table slot name: %s" slot)))))
85 (set-char-table-extra-slot display-table slot-number value)))
86
87 ;;;###autoload
88 (defun describe-display-table (dt)
89 "Describe the display table DT in a help buffer."
90 (with-output-to-temp-buffer "*Help*"
91 (princ "\nTruncation glyph: ")
92 (prin1 (display-table-slot dt 'truncation))
93 (princ "\nWrap glyph: ")
94 (prin1 (display-table-slot dt 'wrap))
95 (princ "\nEscape glyph: ")
96 (prin1 (display-table-slot dt 'escape))
97 (princ "\nCtrl glyph: ")
98 (prin1 (display-table-slot dt 'control))
99 (princ "\nSelective display glyph sequence: ")
100 (prin1 (display-table-slot dt 'selective-display))
101 (princ "\nVertical window border glyph: ")
102 (prin1 (display-table-slot dt 'vertical-border))
103 (princ "\nCharacter display glyph sequences:\n")
104 (save-excursion
105 (set-buffer standard-output)
106 (let ((vector (make-vector 256 nil))
107 (i 0))
108 (while (< i 256)
109 (aset vector i (aref dt i))
110 (setq i (1+ i)))
111 (describe-vector vector))
112 (help-mode))
113 (print-help-return-message)))
114
115 ;;;###autoload
116 (defun describe-current-display-table ()
117 "Describe the display table in use in the selected window and buffer."
118 (interactive)
119 (let ((disptab (or (window-display-table (selected-window))
120 buffer-display-table
121 standard-display-table)))
122 (if disptab
123 (describe-display-table disptab)
124 (message "No display table"))))
125
126 ;;;###autoload
127 (defun standard-display-8bit (l h)
128 "Display characters in the range L to H literally."
129 (or standard-display-table
130 (setq standard-display-table (make-display-table)))
131 (while (<= l h)
132 (aset standard-display-table l (if (or (< l ?\ ) (>= l 127)) (vector l)))
133 (setq l (1+ l))))
134
135 ;;;###autoload
136 (defun standard-display-default (l h)
137 "Display characters in the range L to H using the default notation."
138 (or standard-display-table
139 (setq standard-display-table (make-display-table)))
140 (while (<= l h)
141 (if (and (>= l ?\ ) (char-valid-p l))
142 (aset standard-display-table l nil))
143 (setq l (1+ l))))
144
145 ;; This function does NOT take terminal-dependent escape sequences.
146 ;; For that, you need to go through create-glyph. Use one of the
147 ;; other functions below, or roll your own.
148 ;;;###autoload
149 (defun standard-display-ascii (c s)
150 "Display character C using printable string S."
151 (or standard-display-table
152 (setq standard-display-table (make-display-table)))
153 (aset standard-display-table c (vconcat s)))
154
155 ;;;###autoload
156 (defun standard-display-g1 (c sc)
157 "Display character C as character SC in the g1 character set.
158 This function assumes that your terminal uses the SO/SI characters;
159 it is meaningless for an X frame."
160 (if (memq window-system '(x w32))
161 (error "Cannot use string glyphs in a windowing system"))
162 (or standard-display-table
163 (setq standard-display-table (make-display-table)))
164 (aset standard-display-table c
165 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
166
167 ;;;###autoload
168 (defun standard-display-graphic (c gc)
169 "Display character C as character GC in graphics character set.
170 This function assumes VT100-compatible escapes; it is meaningless for an
171 X frame."
172 (if (memq window-system '(x w32))
173 (error "Cannot use string glyphs in a windowing system"))
174 (or standard-display-table
175 (setq standard-display-table (make-display-table)))
176 (aset standard-display-table c
177 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
178
179 ;;;###autoload
180 (defun standard-display-underline (c uc)
181 "Display character C as character UC plus underlining."
182 (or standard-display-table
183 (setq standard-display-table (make-display-table)))
184 (aset standard-display-table c
185 (vector
186 (if window-system
187 (logior uc (lsh (face-id 'underline) 19))
188 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
189
190 ;;;###autoload
191 (defun create-glyph (string)
192 "Allocate a glyph code to display by sending STRING to the terminal."
193 (if (= (length glyph-table) 65536)
194 (error "No free glyph codes remain"))
195 ;; Don't use slots that correspond to ASCII characters.
196 (if (= (length glyph-table) 32)
197 (setq glyph-table (vconcat glyph-table (make-vector 224 nil))))
198 (setq glyph-table (vconcat glyph-table (list string)))
199 (1- (length glyph-table)))
200
201 ;;;###autoload
202 (defun standard-display-european (arg)
203 "Semi-obsolete way to toggle display of ISO 8859 European characters.
204
205 This function is semi-obsolete; if you want to do your editing with
206 unibyte characters, it is better to `set-language-environment' coupled
207 with either the `--unibyte' option or the EMACS_UNIBYTE environment
208 variable, or else customize `enable-multibyte-characters'.
209
210 With prefix argument, this command enables European character display
211 if arg is positive, disables it otherwise. Otherwise, it toggles
212 European character display.
213
214 When this mode is enabled, characters in the range of 160 to 255
215 display not as octal escapes, but as accented characters. Codes 146
216 and 160 display as apostrophe and space, even though they are not the
217 ASCII codes for apostrophe and space.
218
219 Enabling European character display with this command noninteractively
220 from Lisp code also selects Latin-1 as the language environment, and
221 selects unibyte mode for all Emacs buffers \(both existing buffers and
222 those created subsequently). This provides increased compatibility
223 for users who call this function in `.emacs'."
224
225 (if (or (<= (prefix-numeric-value arg) 0)
226 (and (null arg)
227 (char-table-p standard-display-table)
228 ;; Test 161, because 160 displays as a space.
229 (equal (aref standard-display-table 161) [161])))
230 (progn
231 (standard-display-default 160 255)
232 (unless (or (memq window-system '(x w32)))
233 (and (terminal-coding-system)
234 (set-terminal-coding-system nil))))
235 ;; Turn off multibyte chars for more compatibility.
236 (setq-default enable-multibyte-characters nil)
237
238 ;; Switch to Latin-1 language environment
239 ;; unless some other has been specified.
240 (if (equal current-language-environment "English")
241 (set-language-environment "latin-1"))
242 (unless (or noninteractive (memq window-system '(x w32)))
243 ;; Send those codes literally to a character-based terminal.
244 ;; If we are using single-byte characters,
245 ;; it doesn't matter which coding system we use.
246 (set-terminal-coding-system
247 (let ((c (intern (downcase current-language-environment))))
248 (if (coding-system-p c) c 'latin-1))))
249 (standard-display-european-internal)))
250
251 (provide 'disp-table)
252
253 ;;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
254 ;;; disp-table.el ends here