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 (or standard-display-table
39 (setq standard-display-table
(make-display-table)))
41 ;;; Display-table slot names. The property value says which slot.
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)
51 (defun display-table-slot (display-table slot
)
52 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
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'."
57 (if (numberp slot
) slot
58 (or (get slot
'display-table-slot
)
59 (error "Invalid display-table slot name: %s" slot
)))))
60 (char-table-extra-slot display-table slot-number
)))
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).
66 Valid symbols are `truncation', `wrap', `escape', `control',
67 `selective-display', and `vertical-border'."
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
)))
75 (defun describe-display-table (dt)
76 "Describe the display table DT in a help buffer."
77 (with-output-to-temp-buffer "*Help*"
78 (princ "\nTruncation glyph: ")
79 (prin1 (display-table-slot dt
'truncation
))
80 (princ "\nWrap glyph: ")
81 (prin1 (display-table-slot dt
'wrap
))
82 (princ "\nEscape glyph: ")
83 (prin1 (display-table-slot dt
'escape
))
84 (princ "\nCtrl glyph: ")
85 (prin1 (display-table-slot dt
'control
))
86 (princ "\nSelective display glyph sequence: ")
87 (prin1 (display-table-slot dt
'selective-display
))
88 (princ "\nVertical window border glyph: ")
89 (prin1 (display-table-slot dt
'vertical-border
))
90 (princ "\nCharacter display glyph sequences:\n")
92 (set-buffer standard-output
)
93 (let ((vector (make-vector 256 nil
))
96 (aset vector i
(aref dt i
))
98 (describe-vector vector
))
100 (print-help-return-message)))
103 (defun describe-current-display-table ()
104 "Describe the display table in use in the selected window and buffer."
106 (let ((disptab (or (window-display-table (selected-window))
108 standard-display-table
)))
110 (describe-display-table disptab
)
111 (message "No display table"))))
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)))
119 (aset standard-display-table l
(if (or (< l ?\
) (>= l
127)) (vector l
)))
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)))
128 (if (and (>= l ?\
) (char-valid-p l
))
129 (aset standard-display-table l nil
))
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.
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
)))
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
))
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")))))
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
159 (if (memq window-system
'(x w32
))
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")))))
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
174 (logior uc
(lsh (face-id 'underline
) 19))
175 (create-glyph (concat "\e[4m" (char-to-string uc
) "\e[m"))))))
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
)))
189 (defun standard-display-european (arg)
190 "Semi-obsolete way to toggle display of ISO 8859 European characters.
192 This function is semi-obsolete; if you want to do your editing with
193 unibyte characters, it is better to `set-language-environment' coupled
194 with either the `--unibyte' option or the EMACS_UNIBYTE environment
195 variable, or else customize `enable-multibyte-characters'.
197 With prefix argument, this command enables European character display
198 if arg is positive, disables it otherwise. Otherwise, it toggles
199 European character display.
201 When this mode is enabled, characters in the range of 160 to 255
202 display not as octal escapes, but as accented characters. Codes 146
203 and 160 display as apostrophe and space, even though they are not the
204 ASCII codes for apostrophe and space.
206 Enabling European character display with this command noninteractively
207 from Lisp code also selects Latin-1 as the language environment, and
208 selects unibyte mode for all Emacs buffers \(both existing buffers and
209 those created subsequently). This provides increased compatibility
210 for users who call this function in `.emacs'."
212 (if (or (<= (prefix-numeric-value arg
) 0)
214 (char-table-p standard-display-table
)
215 ;; Test 161, because 160 displays as a space.
216 (equal (aref standard-display-table
161) [161])))
218 (standard-display-default 160 255)
219 (unless (or (memq window-system '(x w32)))
220 (and (terminal-coding-system)
221 (set-terminal-coding-system nil))))
222 ;; Turn off multibyte chars for more compatibility.
223 (setq-default enable-multibyte-characters nil)
225 ;; Switch to Latin-1 language environment
226 ;; unless some other has been specified.
227 (if (equal current-language-environment "English")
228 (set-language-environment "latin-1"))
229 (unless (or noninteractive (memq window-system '(x w32)))
230 ;; Send those codes literally to a character-based terminal.
231 ;; If we are using single-byte characters,
232 ;; it doesn't matter which coding system we use.
233 (set-terminal-coding-system
234 (let ((c (intern (downcase current-language-environment))))
235 (if (coding-system-p c) c 'latin-1))))
236 (standard-display-european-internal)))
238 (provide 'disp-table)
240 ;;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
241 ;;; disp-table.el ends here