1 ;;; disp-table.el --- functions for dealing with char tables
3 ;; Copyright (C) 1987, 1994, 1995, 1999 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 (if (and (>= l ?\
) (< l
127))
120 (aset standard-display-table l nil
)
121 (aset standard-display-table l
(vector l
)))
125 (defun standard-display-default (l h
)
126 "Display characters in the range L to H using the default notation."
127 (or standard-display-table
128 (setq standard-display-table
(make-display-table)))
130 (if (and (>= l ?\
) (char-valid-p l
))
131 (aset standard-display-table l nil
))
134 ;; This function does NOT take terminal-dependent escape sequences.
135 ;; For that, you need to go through create-glyph. Use one of the
136 ;; other functions below, or roll your own.
138 (defun standard-display-ascii (c s
)
139 "Display character C using printable string S."
140 (or standard-display-table
141 (setq standard-display-table
(make-display-table)))
142 (aset standard-display-table c
(vconcat s
)))
145 (defun standard-display-g1 (c sc
)
146 "Display character C as character SC in the g1 character set.
147 This function assumes that your terminal uses the SO/SI characters;
148 it is meaningless for an X frame."
149 (if (memq window-system
'(x w32
))
150 (error "Cannot use string glyphs in a windowing system"))
151 (or standard-display-table
152 (setq standard-display-table
(make-display-table)))
153 (aset standard-display-table c
154 (vector (create-glyph (concat "\016" (char-to-string sc
) "\017")))))
157 (defun standard-display-graphic (c gc
)
158 "Display character C as character GC in graphics character set.
159 This function assumes VT100-compatible escapes; it is meaningless for an
161 (if (memq window-system
'(x w32
))
162 (error "Cannot use string glyphs in a windowing system"))
163 (or standard-display-table
164 (setq standard-display-table
(make-display-table)))
165 (aset standard-display-table c
166 (vector (create-glyph (concat "\e(0" (char-to-string gc
) "\e(B")))))
169 (defun standard-display-underline (c uc
)
170 "Display character C as character UC plus underlining."
171 (or standard-display-table
172 (setq standard-display-table
(make-display-table)))
173 (aset standard-display-table c
176 (logior uc
(lsh (face-id 'underline
) 19))
177 (create-glyph (concat "\e[4m" (char-to-string uc
) "\e[m"))))))
180 (defun create-glyph (string)
181 "Allocate a glyph code to display by sending STRING to the terminal."
182 (if (= (length glyph-table
) 65536)
183 (error "No free glyph codes remain"))
184 ;; Don't use slots that correspond to ASCII characters.
185 (if (= (length glyph-table
) 32)
186 (setq glyph-table
(vconcat glyph-table
(make-vector 224 nil
))))
187 (setq glyph-table
(vconcat glyph-table
(list string
)))
188 (1- (length glyph-table
)))
191 (defun standard-display-european (arg)
192 "Semi-obsolete way to toggle display of ISO 8859 European characters.
194 This function is semi-obsolete; if you want to do your editing with
195 unibyte characters, it is better to `set-language-environment' coupled
196 with either the `--unibyte' option or the EMACS_UNIBYTE environment
197 variable, or else customize `enable-multibyte-characters'.
199 With prefix argument, this command enables European character display
200 if arg is positive, disables it otherwise. Otherwise, it toggles
201 European character display.
203 When this mode is enabled, characters in the range of 160 to 255
204 display not as octal escapes, but as accented characters. Codes 146
205 and 160 display as apostrophe and space, even though they are not the
206 ASCII codes for apostrophe and space.
208 Enabling European character display with this command noninteractively
209 from Lisp code also selects Latin-1 as the language environment, and
210 selects unibyte mode for all Emacs buffers \(both existing buffers and
211 those created subsequently). This provides increased compatibility
212 for users who call this function in `.emacs'."
214 (if (or (<= (prefix-numeric-value arg
) 0)
216 (char-table-p standard-display-table
)
217 ;; Test 161, because 160 displays as a space.
218 (equal (aref standard-display-table
161) [161])))
220 (standard-display-default 160 255)
221 (unless (or (memq window-system '(x w32)))
222 (and (terminal-coding-system)
223 (set-terminal-coding-system nil))))
224 ;; Turn off multibyte chars for more compatibility.
225 (setq-default enable-multibyte-characters nil)
227 ;; Switch to Latin-1 language environment
228 ;; unless some other has been specified.
229 (if (equal current-language-environment "English")
230 (set-language-environment "latin-1"))
231 (unless (or noninteractive (memq window-system '(x w32)))
232 ;; Send those codes literally to a character-based terminal.
233 ;; If we are using single-byte characters,
234 ;; it doesn't matter which coding system we use.
235 (set-terminal-coding-system
236 (let ((c (intern (downcase current-language-environment))))
237 (if (coding-system-p c) c 'latin-1))))
238 (standard-display-european-internal)))
240 (provide 'disp-table)
242 ;;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
243 ;;; disp-table.el ends here