662
|
1 ;;; disp-table.el --- functions for dealing with char tables.
|
|
2
|
24116
|
3 ;; Copyright (C) 1987, 1994, 1995, 1999 Free Software Foundation, Inc.
|
845
|
4
|
13164
|
5 ;; Author: Erik Naggum <erik@naggum.no>
|
|
6 ;; Based on a previous version by Howard Gayle
|
807
|
7 ;; Maintainer: FSF
|
3012
|
8 ;; Keywords: i18n
|
36
|
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
|
807
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
36
|
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
|
14169
|
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.
|
36
|
26
|
807
|
27 ;;; Code:
|
36
|
28
|
13199
|
29 (put 'display-table 'char-table-extra-slots 6)
|
13164
|
30
|
|
31 ;;;###autoload
|
|
32 (defun make-display-table ()
|
|
33 "Return a new, empty display table."
|
13199
|
34 (make-char-table 'display-table nil))
|
13164
|
35
|
|
36 (or standard-display-table
|
|
37 (setq standard-display-table (make-display-table)))
|
|
38
|
13199
|
39 ;;; Display-table slot names. The property value says which slot.
|
13164
|
40
|
13199
|
41 (put 'truncation 'display-table-slot 0)
|
|
42 (put 'wrap 'display-table-slot 1)
|
|
43 (put 'escape 'display-table-slot 2)
|
|
44 (put 'control 'display-table-slot 3)
|
|
45 (put 'selective-display 'display-table-slot 4)
|
|
46 (put 'vertical-border 'display-table-slot 5)
|
13164
|
47
|
|
48 ;;;###autoload
|
|
49 (defun display-table-slot (display-table slot)
|
|
50 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
|
13683
d628bf92f672
(display-table-slot,set-display-table-slot): Document the slot names.
Erik Naggum <erik@naggum.no>
diff
changeset
|
51 SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol).
|
d628bf92f672
(display-table-slot,set-display-table-slot): Document the slot names.
Erik Naggum <erik@naggum.no>
diff
changeset
|
52 Valid symbols are `truncation', `wrap', `escape', `control',
|
d628bf92f672
(display-table-slot,set-display-table-slot): Document the slot names.
Erik Naggum <erik@naggum.no>
diff
changeset
|
53 `selective-display', and `vertical-border'."
|
13164
|
54 (let ((slot-number
|
|
55 (if (numberp slot) slot
|
13199
|
56 (or (get slot 'display-table-slot)
|
13164
|
57 (error "Invalid display-table slot name: %s" slot)))))
|
|
58 (char-table-extra-slot display-table slot-number)))
|
|
59
|
|
60 ;;;###autoload
|
|
61 (defun set-display-table-slot (display-table slot value)
|
|
62 "Set the value of the extra slot in DISPLAY-TABLE named SLOT to VALUE.
|
|
63 SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
|
13683
d628bf92f672
(display-table-slot,set-display-table-slot): Document the slot names.
Erik Naggum <erik@naggum.no>
diff
changeset
|
64 Valid symbols are `truncation', `wrap', `escape', `control',
|
d628bf92f672
(display-table-slot,set-display-table-slot): Document the slot names.
Erik Naggum <erik@naggum.no>
diff
changeset
|
65 `selective-display', and `vertical-border'."
|
13199
|
66 (let ((slot-number
|
|
67 (if (numberp slot) slot
|
|
68 (or (get slot 'display-table-slot)
|
|
69 (error "Invalid display-table slot name: %s" slot)))))
|
|
70 (set-char-table-extra-slot display-table slot-number value)))
|
13164
|
71
|
|
72 ;;;###autoload
|
2072
|
73 (defun describe-display-table (dt)
|
584
|
74 "Describe the display table DT in a help buffer."
|
36
|
75 (with-output-to-temp-buffer "*Help*"
|
696
|
76 (princ "\nTruncation glyph: ")
|
13199
|
77 (prin1 (display-table-slot dt 'truncation))
|
696
|
78 (princ "\nWrap glyph: ")
|
13199
|
79 (prin1 (display-table-slot dt 'wrap))
|
696
|
80 (princ "\nEscape glyph: ")
|
13199
|
81 (prin1 (display-table-slot dt 'escape))
|
696
|
82 (princ "\nCtrl glyph: ")
|
13199
|
83 (prin1 (display-table-slot dt 'control))
|
2628
|
84 (princ "\nSelective display glyph sequence: ")
|
13199
|
85 (prin1 (display-table-slot dt 'selective-display))
|
8920
|
86 (princ "\nVertical window border glyph: ")
|
13199
|
87 (prin1 (display-table-slot dt 'vertical-border))
|
2628
|
88 (princ "\nCharacter display glyph sequences:\n")
|
4936
|
89 (save-excursion
|
|
90 (set-buffer standard-output)
|
|
91 (let ((vector (make-vector 256 nil))
|
|
92 (i 0))
|
|
93 (while (< i 256)
|
|
94 (aset vector i (aref dt i))
|
|
95 (setq i (1+ i)))
|
9856
|
96 (describe-vector vector))
|
|
97 (help-mode))
|
36
|
98 (print-help-return-message)))
|
|
99
|
2072
|
100 ;;;###autoload
|
36
|
101 (defun describe-current-display-table ()
|
4936
|
102 "Describe the display table in use in the selected window and buffer."
|
|
103 (interactive)
|
13164
|
104 (let ((disptab (or (window-display-table (selected-window))
|
|
105 buffer-display-table
|
|
106 standard-display-table)))
|
4936
|
107 (if disptab
|
|
108 (describe-display-table disptab)
|
|
109 (message "No display table"))))
|
36
|
110
|
2072
|
111 ;;;###autoload
|
36
|
112 (defun standard-display-8bit (l h)
|
584
|
113 "Display characters in the range L to H literally."
|
36
|
114 (while (<= l h)
|
|
115 (if (and (>= l ?\ ) (< l 127))
|
13164
|
116 (aset standard-display-table l nil)
|
2628
|
117 (aset standard-display-table l (vector l)))
|
36
|
118 (setq l (1+ l))))
|
|
119
|
2072
|
120 ;;;###autoload
|
3033
|
121 (defun standard-display-default (l h)
|
|
122 "Display characters in the range L to H using the default notation."
|
|
123 (while (<= l h)
|
31157
|
124 (if (and (>= l ?\ ) (char-valid-p l))
|
|
125 (aset standard-display-table l nil))
|
3033
|
126 (setq l (1+ l))))
|
|
127
|
10435
|
128 ;; This function does NOT take terminal-dependent escape sequences.
|
|
129 ;; For that, you need to go through create-glyph. Use one of the
|
|
130 ;; other functions below, or roll your own.
|
13164
|
131 ;;;###autoload
|
36
|
132 (defun standard-display-ascii (c s)
|
10435
|
133 "Display character C using printable string S."
|
13164
|
134 (aset standard-display-table c (vconcat s)))
|
36
|
135
|
2072
|
136 ;;;###autoload
|
36
|
137 (defun standard-display-g1 (c sc)
|
6418
|
138 "Display character C as character SC in the g1 character set.
|
|
139 This function assumes that your terminal uses the SO/SI characters;
|
|
140 it is meaningless for an X frame."
|
29201
|
141 (if (memq window-system '(x w32))
|
6418
|
142 (error "Cannot use string glyphs in a windowing system"))
|
36
|
143 (aset standard-display-table c
|
2523
|
144 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
|
36
|
145
|
2072
|
146 ;;;###autoload
|
36
|
147 (defun standard-display-graphic (c gc)
|
6418
|
148 "Display character C as character GC in graphics character set.
|
|
149 This function assumes VT100-compatible escapes; it is meaningless for an
|
|
150 X frame."
|
29201
|
151 (if (memq window-system '(x w32))
|
6418
|
152 (error "Cannot use string glyphs in a windowing system"))
|
36
|
153 (aset standard-display-table c
|
2523
|
154 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
|
36
|
155
|
2072
|
156 ;;;###autoload
|
36
|
157 (defun standard-display-underline (c uc)
|
|
158 "Display character C as character UC plus underlining."
|
|
159 (aset standard-display-table c
|
6418
|
160 (vector
|
|
161 (if window-system
|
29249
|
162 (logior uc (lsh (face-id 'underline) 19))
|
6418
|
163 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
|
36
|
164
|
2072
|
165 ;;;###autoload
|
696
|
166 (defun create-glyph (string)
|
29510
|
167 "Allocate a glyph code to display by sending STRING to the terminal."
|
696
|
168 (if (= (length glyph-table) 65536)
|
|
169 (error "No free glyph codes remain"))
|
6417
|
170 ;; Don't use slots that correspond to ASCII characters.
|
|
171 (if (= (length glyph-table) 32)
|
|
172 (setq glyph-table (vconcat glyph-table (make-vector 224 nil))))
|
696
|
173 (setq glyph-table (vconcat glyph-table (list string)))
|
|
174 (1- (length glyph-table)))
|
36
|
175
|
3061
|
176 ;;;###autoload
|
26124
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
177 (defun standard-display-european (arg)
|
24813
|
178 "Semi-obsolete way to toggle display of ISO 8859 European characters.
|
24116
|
179
|
24813
|
180 This function is semi-obsolete; if you want to do your editing with
|
|
181 unibyte characters, it is better to `set-language-environment' coupled
|
|
182 with either the `--unibyte' option or the EMACS_UNIBYTE environment
|
|
183 variable, or else customize `enable-multibyte-characters'.
|
|
184
|
|
185 With prefix argument, this command enables European character display
|
|
186 if arg is positive, disables it otherwise. Otherwise, it toggles
|
|
187 European character display.
|
22008
|
188
|
24813
|
189 When this mode is enabled, characters in the range of 160 to 255
|
|
190 display not as octal escapes, but as accented characters. Codes 146
|
|
191 and 160 display as apostrophe and space, even though they are not the
|
|
192 ASCII codes for apostrophe and space.
|
19850
|
193
|
24813
|
194 Enabling European character display with this command noninteractively
|
|
195 from Lisp code also selects Latin-1 as the language environment, and
|
|
196 selects unibyte mode for all Emacs buffers \(both existing buffers and
|
|
197 those created subsequently). This provides increased compatibility
|
|
198 for users who call this function in `.emacs'."
|
19618
|
199
|
7830
|
200 (if (or (<= (prefix-numeric-value arg) 0)
|
3061
|
201 (and (null arg)
|
13164
|
202 (char-table-p standard-display-table)
|
13822
|
203 ;; Test 161, because 160 displays as a space.
|
13794
|
204 (equal (aref standard-display-table 161) [161])))
|
19814
|
205 (progn
|
|
206 (standard-display-default 160 255)
|
24813
|
207 (unless (or (memq window-system '(x w32))
|
26124
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
208 (interactive-p))
|
24813
|
209 (and (terminal-coding-system)
|
|
210 (set-terminal-coding-system nil))))
|
|
211 ;; If the user does this explicitly from Lisp (as in .emacs),
|
19066
|
212 ;; turn off multibyte chars for more compatibility.
|
26124
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
213 (unless (interactive-p)
|
20906
|
214 (setq-default enable-multibyte-characters nil)
|
24116
|
215 (mapcar (lambda (buffer)
|
|
216 (with-current-buffer buffer
|
|
217 (if enable-multibyte-characters
|
|
218 (set-buffer-multibyte nil))))
|
|
219 (buffer-list)))
|
21855
|
220 ;; If the user does this explicitly,
|
|
221 ;; switch to Latin-1 language environment
|
|
222 ;; unless some other has been specified.
|
26124
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
223 (unless (interactive-p)
|
21855
|
224 (if (equal current-language-environment "English")
|
|
225 (set-language-environment "latin-1")))
|
24813
|
226 (unless (or noninteractive (memq window-system '(x w32))
|
26124
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
227 (interactive-p))
|
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
228 ;; Send those codes literally to a character-based terminal.
|
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
229 ;; If we are using single-byte characters,
|
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
230 ;; it doesn't matter which coding system we use.
|
19920
1d832fd69760
(standard-display-european): Do something useful where AUTO is t or a symbol.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
231 (set-terminal-coding-system
|
26124
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
232 (let ((c (intern (downcase current-language-environment))))
|
ee67b2340a0f
* disp-table.el (standard-display-european): Remove undocumented
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
233 (if (coding-system-p c) c 'latin-1))))
|
21855
|
234 (standard-display-european-internal)))
|
3033
|
235
|
36
|
236 (provide 'disp-table)
|
662
|
237
|
|
238 ;;; disp-table.el ends here
|