1 ;;; disp-table.el --- functions for dealing with char tables
3 ;; Copyright (C) 1987, 94, 95, 1999, 2004 Free Software Foundation, Inc.
5 ;; Author: Erik Naggum <erik@naggum.no>
6 ;; Based on a previous version by Howard Gayle
10 ;; This file is part of GNU Emacs.
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)
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.
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.
31 (put 'display-table 'char-table-extra-slots 6)
34 (defun make-display-table ()
35 "Return a new, empty display table."
36 (make-char-table 'display-table nil))
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 ?\\))
43 ;; (table (make-display-table))
45 ;; (set-char-table-extra-slot table 2 backslash)
46 ;; (aset table 2208 (vector backslash ?\ ))
47 ;; (aset table 2221 (vector backslash ?-))
49 ;; (set-char-table-extra-slot table 3 (+ face ?^))
51 ;; (set-char-table-extra-slot table 4 (vector dot dot dot))
54 ;;; Display-table slot names. The property value says which slot.
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)
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'."
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)))
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'."
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)))
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")
105 (set-buffer standard-output)
106 (let ((vector (make-vector 256 nil))
109 (aset vector i (aref dt i))
111 (describe-vector vector))
113 (print-help-return-message)))
116 (defun describe-current-display-table ()
117 "Describe the display table in use in the selected window and buffer."
119 (let ((disptab (or (window-display-table (selected-window))
121 standard-display-table)))
123 (describe-display-table disptab)
124 (message "No display table"))))
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)))
132 (aset standard-display-table l (if (or (< l ?\ ) (>= l 127)) (vector l)))
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)))
141 (if (and (>= l ?\ ) (char-valid-p l))
142 (aset standard-display-table l nil))
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.
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)))
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")))))
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
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")))))
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
187 (logior uc (lsh (face-id 'underline) 19))
188 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
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)))
202 (defun standard-display-european (arg)
203 "Semi-obsolete way to toggle display of ISO 8859 European characters.
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'.
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.
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.
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'."
225 (if (or (<= (prefix-numeric-value arg) 0)
227 (char-table-p standard-display-table)
228 ;; Test 161, because 160 displays as a space.
229 (equal (aref standard-display-table 161) [161])))
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)
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)))
251 (provide 'disp-table)
253 ;;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
254 ;;; disp-table.el ends here