(cvs-file-to-string): Move condition-case outside.
[bpt/emacs.git] / lisp / disp-table.el
CommitLineData
55535639 1;;; disp-table.el --- functions for dealing with char tables
c0274f38 2
3ea1bd50 3;; Copyright (C) 1987, 1994, 1995, 1999 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
55535639
PJ
27;;; Commentary:
28
e5167999 29;;; Code:
a2535589 30
963fd070 31(put 'display-table 'char-table-extra-slots 6)
dc5a82ea 32
ef9c36a5
EN
33;;;###autoload
34(defun make-display-table ()
35 "Return a new, empty display table."
963fd070 36 (make-char-table 'display-table nil))
ef9c36a5
EN
37
38(or standard-display-table
39 (setq standard-display-table (make-display-table)))
40
963fd070
RS
41;;; Display-table slot names. The property value says which slot.
42
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)
ef9c36a5
EN
49
50;;;###autoload
51(defun display-table-slot (display-table slot)
52 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
12c9fbcc
EN
53SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol).
54Valid symbols are `truncation', `wrap', `escape', `control',
55`selective-display', and `vertical-border'."
ef9c36a5
EN
56 (let ((slot-number
57 (if (numberp slot) slot
963fd070 58 (or (get slot 'display-table-slot)
ef9c36a5
EN
59 (error "Invalid display-table slot name: %s" slot)))))
60 (char-table-extra-slot display-table slot-number)))
61
62;;;###autoload
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.
65SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
12c9fbcc
EN
66Valid symbols are `truncation', `wrap', `escape', `control',
67`selective-display', and `vertical-border'."
963fd070
RS
68 (let ((slot-number
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)))
ef9c36a5
EN
73
74;;;###autoload
e31b61e6 75(defun describe-display-table (dt)
49116ac0 76 "Describe the display table DT in a help buffer."
a2535589 77 (with-output-to-temp-buffer "*Help*"
03131799 78 (princ "\nTruncation glyph: ")
963fd070 79 (prin1 (display-table-slot dt 'truncation))
03131799 80 (princ "\nWrap glyph: ")
963fd070 81 (prin1 (display-table-slot dt 'wrap))
03131799 82 (princ "\nEscape glyph: ")
963fd070 83 (prin1 (display-table-slot dt 'escape))
03131799 84 (princ "\nCtrl glyph: ")
963fd070 85 (prin1 (display-table-slot dt 'control))
afb1e4b4 86 (princ "\nSelective display glyph sequence: ")
963fd070 87 (prin1 (display-table-slot dt 'selective-display))
dc5a82ea 88 (princ "\nVertical window border glyph: ")
963fd070 89 (prin1 (display-table-slot dt 'vertical-border))
afb1e4b4 90 (princ "\nCharacter display glyph sequences:\n")
bb6066c8
RS
91 (save-excursion
92 (set-buffer standard-output)
93 (let ((vector (make-vector 256 nil))
94 (i 0))
95 (while (< i 256)
96 (aset vector i (aref dt i))
97 (setq i (1+ i)))
5d74f2a6
KH
98 (describe-vector vector))
99 (help-mode))
a2535589
JA
100 (print-help-return-message)))
101
e31b61e6 102;;;###autoload
a2535589 103(defun describe-current-display-table ()
bb6066c8
RS
104 "Describe the display table in use in the selected window and buffer."
105 (interactive)
ef9c36a5
EN
106 (let ((disptab (or (window-display-table (selected-window))
107 buffer-display-table
108 standard-display-table)))
bb6066c8
RS
109 (if disptab
110 (describe-display-table disptab)
111 (message "No display table"))))
a2535589 112
e31b61e6 113;;;###autoload
a2535589 114(defun standard-display-8bit (l h)
49116ac0 115 "Display characters in the range L to H literally."
a2535589
JA
116 (while (<= l h)
117 (if (and (>= l ?\ ) (< l 127))
ef9c36a5 118 (aset standard-display-table l nil)
afb1e4b4 119 (aset standard-display-table l (vector l)))
a2535589
JA
120 (setq l (1+ l))))
121
798aa8d0
JB
122;;;###autoload
123(defun standard-display-default (l h)
124 "Display characters in the range L to H using the default notation."
125 (while (<= l h)
1c2c3f16
DL
126 (if (and (>= l ?\ ) (char-valid-p l))
127 (aset standard-display-table l nil))
798aa8d0
JB
128 (setq l (1+ l))))
129
a171458a
KH
130;; This function does NOT take terminal-dependent escape sequences.
131;; For that, you need to go through create-glyph. Use one of the
132;; other functions below, or roll your own.
ef9c36a5 133;;;###autoload
a2535589 134(defun standard-display-ascii (c s)
a171458a 135 "Display character C using printable string S."
ef9c36a5 136 (aset standard-display-table c (vconcat s)))
a2535589 137
e31b61e6 138;;;###autoload
a2535589 139(defun standard-display-g1 (c sc)
de7d5cb6
KH
140 "Display character C as character SC in the g1 character set.
141This function assumes that your terminal uses the SO/SI characters;
142it is meaningless for an X frame."
744bcf11 143 (if (memq window-system '(x w32))
de7d5cb6 144 (error "Cannot use string glyphs in a windowing system"))
a2535589 145 (aset standard-display-table c
82093c70 146 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
a2535589 147
e31b61e6 148;;;###autoload
a2535589 149(defun standard-display-graphic (c gc)
de7d5cb6
KH
150 "Display character C as character GC in graphics character set.
151This function assumes VT100-compatible escapes; it is meaningless for an
152X frame."
744bcf11 153 (if (memq window-system '(x w32))
de7d5cb6 154 (error "Cannot use string glyphs in a windowing system"))
a2535589 155 (aset standard-display-table c
82093c70 156 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
a2535589 157
e31b61e6 158;;;###autoload
a2535589
JA
159(defun standard-display-underline (c uc)
160 "Display character C as character UC plus underlining."
a2535589 161 (aset standard-display-table c
de7d5cb6
KH
162 (vector
163 (if window-system
30c5ceb4 164 (logior uc (lsh (face-id 'underline) 19))
de7d5cb6 165 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
03131799 166
e31b61e6 167;;;###autoload
03131799 168(defun create-glyph (string)
b8fbaf52 169 "Allocate a glyph code to display by sending STRING to the terminal."
03131799
RS
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
951bc45f 179(defun standard-display-european (arg)
3fbd8622 180 "Semi-obsolete way to toggle display of ISO 8859 European characters.
3ea1bd50 181
3fbd8622
KH
182This function is semi-obsolete; if you want to do your editing with
183unibyte characters, it is better to `set-language-environment' coupled
184with either the `--unibyte' option or the EMACS_UNIBYTE environment
185variable, or else customize `enable-multibyte-characters'.
828fac3a 186
3fbd8622
KH
187With prefix argument, this command enables European character display
188if arg is positive, disables it otherwise. Otherwise, it toggles
189European character display.
b2b52747 190
3fbd8622
KH
191When this mode is enabled, characters in the range of 160 to 255
192display not as octal escapes, but as accented characters. Codes 146
193and 160 display as apostrophe and space, even though they are not the
194ASCII codes for apostrophe and space.
40e82ac1 195
3fbd8622
KH
196Enabling European character display with this command noninteractively
197from Lisp code also selects Latin-1 as the language environment, and
198selects unibyte mode for all Emacs buffers \(both existing buffers and
199those created subsequently). This provides increased compatibility
200for users who call this function in `.emacs'."
f5af76c2 201
c3a14a2b 202 (if (or (<= (prefix-numeric-value arg) 0)
2eae7226 203 (and (null arg)
ef9c36a5 204 (char-table-p standard-display-table)
55f5abaf 205 ;; Test 161, because 160 displays as a space.
e470e6f0 206 (equal (aref standard-display-table 161) [161])))
3304a6c4
RS
207 (progn
208 (standard-display-default 160 255)
3fbd8622 209 (unless (or (memq window-system '(x w32))
951bc45f 210 (interactive-p))
3fbd8622
KH
211 (and (terminal-coding-system)
212 (set-terminal-coding-system nil))))
213 ;; If the user does this explicitly from Lisp (as in .emacs),
40e82ac1 214 ;; turn off multibyte chars for more compatibility.
951bc45f 215 (unless (interactive-p)
65c9d785 216 (setq-default enable-multibyte-characters nil)
3ea1bd50
RS
217 (mapcar (lambda (buffer)
218 (with-current-buffer buffer
219 (if enable-multibyte-characters
220 (set-buffer-multibyte nil))))
221 (buffer-list)))
eb72c1bd
RS
222 ;; If the user does this explicitly,
223 ;; switch to Latin-1 language environment
224 ;; unless some other has been specified.
951bc45f 225 (unless (interactive-p)
eb72c1bd
RS
226 (if (equal current-language-environment "English")
227 (set-language-environment "latin-1")))
3fbd8622 228 (unless (or noninteractive (memq window-system '(x w32))
951bc45f
PE
229 (interactive-p))
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.
4e633bb8 233 (set-terminal-coding-system
951bc45f
PE
234 (let ((c (intern (downcase current-language-environment))))
235 (if (coding-system-p c) c 'latin-1))))
eb72c1bd 236 (standard-display-european-internal)))
798aa8d0 237
a2535589 238(provide 'disp-table)
c0274f38
ER
239
240;;; disp-table.el ends here