Commit | Line | Data |
---|---|---|
c0274f38 ER |
1 | ;;; disp-table.el --- functions for dealing with char tables. |
2 | ||
ef9c36a5 | 3 | ;; Copyright (C) 1987, 1994, 1995 Free Software Foundation, Inc. |
9750e079 | 4 | |
ef9c36a5 EN |
5 | ;; Author: Erik Naggum <erik@naggum.no> |
6 | ;; Based on a previous version by Howard Gayle | |
e5167999 | 7 | ;; Maintainer: FSF |
a1d15b3e | 8 | ;; Keywords: i18n |
a2535589 JA |
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 | |
e5167999 | 14 | ;; the Free Software Foundation; either version 2, or (at your option) |
a2535589 JA |
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 | |
b578f267 EN |
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. | |
a2535589 | 26 | |
e5167999 | 27 | ;;; Code: |
a2535589 | 28 | |
963fd070 | 29 | (put 'display-table 'char-table-extra-slots 6) |
dc5a82ea | 30 | |
ef9c36a5 EN |
31 | ;;;###autoload |
32 | (defun make-display-table () | |
33 | "Return a new, empty display table." | |
963fd070 | 34 | (make-char-table 'display-table nil)) |
ef9c36a5 EN |
35 | |
36 | (or standard-display-table | |
37 | (setq standard-display-table (make-display-table))) | |
38 | ||
963fd070 RS |
39 | ;;; Display-table slot names. The property value says which slot. |
40 | ||
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) | |
ef9c36a5 EN |
47 | |
48 | ;;;###autoload | |
49 | (defun display-table-slot (display-table slot) | |
50 | "Return the value of the extra slot in DISPLAY-TABLE named SLOT. | |
12c9fbcc EN |
51 | SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol). |
52 | Valid symbols are `truncation', `wrap', `escape', `control', | |
53 | `selective-display', and `vertical-border'." | |
ef9c36a5 EN |
54 | (let ((slot-number |
55 | (if (numberp slot) slot | |
963fd070 | 56 | (or (get slot 'display-table-slot) |
ef9c36a5 EN |
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). | |
12c9fbcc EN |
64 | Valid symbols are `truncation', `wrap', `escape', `control', |
65 | `selective-display', and `vertical-border'." | |
963fd070 RS |
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))) | |
ef9c36a5 EN |
71 | |
72 | ;;;###autoload | |
e31b61e6 | 73 | (defun describe-display-table (dt) |
49116ac0 | 74 | "Describe the display table DT in a help buffer." |
a2535589 | 75 | (with-output-to-temp-buffer "*Help*" |
03131799 | 76 | (princ "\nTruncation glyph: ") |
963fd070 | 77 | (prin1 (display-table-slot dt 'truncation)) |
03131799 | 78 | (princ "\nWrap glyph: ") |
963fd070 | 79 | (prin1 (display-table-slot dt 'wrap)) |
03131799 | 80 | (princ "\nEscape glyph: ") |
963fd070 | 81 | (prin1 (display-table-slot dt 'escape)) |
03131799 | 82 | (princ "\nCtrl glyph: ") |
963fd070 | 83 | (prin1 (display-table-slot dt 'control)) |
afb1e4b4 | 84 | (princ "\nSelective display glyph sequence: ") |
963fd070 | 85 | (prin1 (display-table-slot dt 'selective-display)) |
dc5a82ea | 86 | (princ "\nVertical window border glyph: ") |
963fd070 | 87 | (prin1 (display-table-slot dt 'vertical-border)) |
afb1e4b4 | 88 | (princ "\nCharacter display glyph sequences:\n") |
bb6066c8 RS |
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))) | |
5d74f2a6 KH |
96 | (describe-vector vector)) |
97 | (help-mode)) | |
a2535589 JA |
98 | (print-help-return-message))) |
99 | ||
e31b61e6 | 100 | ;;;###autoload |
a2535589 | 101 | (defun describe-current-display-table () |
bb6066c8 RS |
102 | "Describe the display table in use in the selected window and buffer." |
103 | (interactive) | |
ef9c36a5 EN |
104 | (let ((disptab (or (window-display-table (selected-window)) |
105 | buffer-display-table | |
106 | standard-display-table))) | |
bb6066c8 RS |
107 | (if disptab |
108 | (describe-display-table disptab) | |
109 | (message "No display table")))) | |
a2535589 | 110 | |
e31b61e6 | 111 | ;;;###autoload |
a2535589 | 112 | (defun standard-display-8bit (l h) |
49116ac0 | 113 | "Display characters in the range L to H literally." |
a2535589 JA |
114 | (while (<= l h) |
115 | (if (and (>= l ?\ ) (< l 127)) | |
ef9c36a5 | 116 | (aset standard-display-table l nil) |
afb1e4b4 | 117 | (aset standard-display-table l (vector l))) |
a2535589 JA |
118 | (setq l (1+ l)))) |
119 | ||
798aa8d0 JB |
120 | ;;;###autoload |
121 | (defun standard-display-default (l h) | |
122 | "Display characters in the range L to H using the default notation." | |
123 | (while (<= l h) | |
124 | (if (and (>= l ?\ ) (< l 127)) | |
ef9c36a5 | 125 | (aset standard-display-table l nil) |
798aa8d0 JB |
126 | (aset standard-display-table l nil)) |
127 | (setq l (1+ l)))) | |
128 | ||
a171458a KH |
129 | ;; This function does NOT take terminal-dependent escape sequences. |
130 | ;; For that, you need to go through create-glyph. Use one of the | |
131 | ;; other functions below, or roll your own. | |
ef9c36a5 | 132 | ;;;###autoload |
a2535589 | 133 | (defun standard-display-ascii (c s) |
a171458a | 134 | "Display character C using printable string S." |
ef9c36a5 | 135 | (aset standard-display-table c (vconcat s))) |
a2535589 | 136 | |
e31b61e6 | 137 | ;;;###autoload |
a2535589 | 138 | (defun standard-display-g1 (c sc) |
de7d5cb6 KH |
139 | "Display character C as character SC in the g1 character set. |
140 | This function assumes that your terminal uses the SO/SI characters; | |
141 | it is meaningless for an X frame." | |
142 | (if window-system | |
143 | (error "Cannot use string glyphs in a windowing system")) | |
a2535589 | 144 | (aset standard-display-table c |
82093c70 | 145 | (vector (create-glyph (concat "\016" (char-to-string sc) "\017"))))) |
a2535589 | 146 | |
e31b61e6 | 147 | ;;;###autoload |
a2535589 | 148 | (defun standard-display-graphic (c gc) |
de7d5cb6 KH |
149 | "Display character C as character GC in graphics character set. |
150 | This function assumes VT100-compatible escapes; it is meaningless for an | |
151 | X frame." | |
152 | (if window-system | |
153 | (error "Cannot use string glyphs in a windowing system")) | |
a2535589 | 154 | (aset standard-display-table c |
82093c70 | 155 | (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B"))))) |
a2535589 | 156 | |
e31b61e6 | 157 | ;;;###autoload |
a2535589 JA |
158 | (defun standard-display-underline (c uc) |
159 | "Display character C as character UC plus underlining." | |
de7d5cb6 | 160 | (if window-system (require 'faces)) |
a2535589 | 161 | (aset standard-display-table c |
de7d5cb6 KH |
162 | (vector |
163 | (if window-system | |
c40096a0 | 164 | (logior uc (lsh (face-id (internal-find-face 'underline)) 19)) |
de7d5cb6 | 165 | (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m")))))) |
03131799 RS |
166 | |
167 | ;; Allocate a glyph code to display by sending STRING to the terminal. | |
e31b61e6 | 168 | ;;;###autoload |
03131799 RS |
169 | (defun create-glyph (string) |
170 | (if (= (length glyph-table) 65536) | |
171 | (error "No free glyph codes remain")) | |
03fd83c5 KH |
172 | ;; Don't use slots that correspond to ASCII characters. |
173 | (if (= (length glyph-table) 32) | |
174 | (setq glyph-table (vconcat glyph-table (make-vector 224 nil)))) | |
03131799 RS |
175 | (setq glyph-table (vconcat glyph-table (list string))) |
176 | (1- (length glyph-table))) | |
a2535589 | 177 | |
2eae7226 | 178 | ;;;###autoload |
40e82ac1 | 179 | (defun standard-display-european (arg &optional auto) |
2eae7226 | 180 | "Toggle display of European characters encoded with ISO 8859. |
828fac3a RS |
181 | This function is semi-obsolete; it is better to use |
182 | `set-language-environment' and `set-terminal-coding-system', | |
183 | coupled with the `--unibyte' option if you prefer to use unibyte characters. | |
184 | ||
2eae7226 | 185 | When enabled, characters in the range of 160 to 255 display not |
b2b52747 RS |
186 | as octal escapes, but as accented characters. Codes 146 and 160 |
187 | display as apostrophe and space, even though they are not the ASCII | |
188 | codes for apostrophe and space. | |
189 | ||
40e82ac1 RS |
190 | With prefix argument, enable European character display iff arg is positive. |
191 | ||
f5af76c2 | 192 | Normally, this function turns off `enable-multibyte-characters' |
65c9d785 RS |
193 | for subsequently created Emacs buffers, and for `*scratch*. |
194 | This is because users who call this function | |
6c95fd39 | 195 | probably want to edit European characters in single-byte mode." |
f5af76c2 | 196 | |
6c95fd39 RS |
197 | ;; If the optional argument AUTO is non-nil, this function |
198 | ;; does not alter `enable-multibyte-characters'. | |
199 | ;; AUTO also specifies, in this case, the coding system for terminal output. | |
200 | ;; The AUTO argument is meant for use by startup.el only. | |
201 | ;; which is why it is not in the doc string. | |
798aa8d0 | 202 | (interactive "P") |
c3a14a2b | 203 | (if (or (<= (prefix-numeric-value arg) 0) |
2eae7226 | 204 | (and (null arg) |
ef9c36a5 | 205 | (char-table-p standard-display-table) |
55f5abaf | 206 | ;; Test 161, because 160 displays as a space. |
e470e6f0 | 207 | (equal (aref standard-display-table 161) [161]))) |
3304a6c4 RS |
208 | (progn |
209 | (standard-display-default 160 255) | |
58c81753 | 210 | (unless (memq window-system '(x w32)) |
3304a6c4 | 211 | (set-terminal-coding-system nil))) |
40e82ac1 RS |
212 | ;; If the user does this explicitly, |
213 | ;; turn off multibyte chars for more compatibility. | |
65c9d785 RS |
214 | (unless auto |
215 | (setq-default enable-multibyte-characters nil) | |
216 | (if (get-buffer "*scratch*") | |
217 | (with-current-buffer "*scratch*" | |
eb72c1bd RS |
218 | (set-buffer-multibyte nil)))) |
219 | ;; If the user does this explicitly, | |
220 | ;; switch to Latin-1 language environment | |
221 | ;; unless some other has been specified. | |
222 | (unless auto | |
223 | (if (equal current-language-environment "English") | |
224 | (set-language-environment "latin-1"))) | |
58c81753 | 225 | (unless (or noninteractive (memq window-system '(x w32))) |
3304a6c4 RS |
226 | ;; Send those codes literally to a non-X terminal. |
227 | ;; If AUTO is nil, we are using single-byte characters, | |
228 | ;; so it doesn't matter which one we use. | |
4e633bb8 | 229 | (set-terminal-coding-system |
eb72c1bd RS |
230 | (cond ((not (equal current-language-environment "English")) |
231 | (intern (downcase current-language-environment))) | |
232 | ((eq auto t) 'latin-1) | |
4e633bb8 RS |
233 | ((symbolp auto) (or auto 'latin-1)) |
234 | ((stringp auto) (intern auto))))) | |
eb72c1bd | 235 | (standard-display-european-internal))) |
798aa8d0 | 236 | |
a2535589 | 237 | (provide 'disp-table) |
c0274f38 ER |
238 | |
239 | ;;; disp-table.el ends here |