(Fread_file_name): Correct handling of dollars in file
[bpt/emacs.git] / lisp / disp-table.el
1 ;;; disp-table.el --- functions for dealing with char tables.
2
3 ;; Copyright (C) 1987, 1994, 1995, 1999 Free Software Foundation, Inc.
4
5 ;; Author: Erik Naggum <erik@naggum.no>
6 ;; Based on a previous version by Howard Gayle
7 ;; Maintainer: FSF
8 ;; Keywords: i18n
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
14 ;; the Free Software Foundation; either version 2, or (at your option)
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
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.
26
27 ;;; Code:
28
29 (put 'display-table 'char-table-extra-slots 6)
30
31 ;;;###autoload
32 (defun make-display-table ()
33 "Return a new, empty display table."
34 (make-char-table 'display-table nil))
35
36 (or standard-display-table
37 (setq standard-display-table (make-display-table)))
38
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)
47
48 ;;;###autoload
49 (defun display-table-slot (display-table slot)
50 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
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'."
54 (let ((slot-number
55 (if (numberp slot) slot
56 (or (get slot 'display-table-slot)
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).
64 Valid symbols are `truncation', `wrap', `escape', `control',
65 `selective-display', and `vertical-border'."
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)))
71
72 ;;;###autoload
73 (defun describe-display-table (dt)
74 "Describe the display table DT in a help buffer."
75 (with-output-to-temp-buffer "*Help*"
76 (princ "\nTruncation glyph: ")
77 (prin1 (display-table-slot dt 'truncation))
78 (princ "\nWrap glyph: ")
79 (prin1 (display-table-slot dt 'wrap))
80 (princ "\nEscape glyph: ")
81 (prin1 (display-table-slot dt 'escape))
82 (princ "\nCtrl glyph: ")
83 (prin1 (display-table-slot dt 'control))
84 (princ "\nSelective display glyph sequence: ")
85 (prin1 (display-table-slot dt 'selective-display))
86 (princ "\nVertical window border glyph: ")
87 (prin1 (display-table-slot dt 'vertical-border))
88 (princ "\nCharacter display glyph sequences:\n")
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)))
96 (describe-vector vector))
97 (help-mode))
98 (print-help-return-message)))
99
100 ;;;###autoload
101 (defun describe-current-display-table ()
102 "Describe the display table in use in the selected window and buffer."
103 (interactive)
104 (let ((disptab (or (window-display-table (selected-window))
105 buffer-display-table
106 standard-display-table)))
107 (if disptab
108 (describe-display-table disptab)
109 (message "No display table"))))
110
111 ;;;###autoload
112 (defun standard-display-8bit (l h)
113 "Display characters in the range L to H literally."
114 (while (<= l h)
115 (if (and (>= l ?\ ) (< l 127))
116 (aset standard-display-table l nil)
117 (aset standard-display-table l (vector l)))
118 (setq l (1+ l))))
119
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))
125 (aset standard-display-table l nil)
126 (aset standard-display-table l nil))
127 (setq l (1+ l))))
128
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.
132 ;;;###autoload
133 (defun standard-display-ascii (c s)
134 "Display character C using printable string S."
135 (aset standard-display-table c (vconcat s)))
136
137 ;;;###autoload
138 (defun standard-display-g1 (c sc)
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"))
144 (aset standard-display-table c
145 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
146
147 ;;;###autoload
148 (defun standard-display-graphic (c gc)
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"))
154 (aset standard-display-table c
155 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
156
157 ;;;###autoload
158 (defun standard-display-underline (c uc)
159 "Display character C as character UC plus underlining."
160 (if window-system (require 'faces))
161 (aset standard-display-table c
162 (vector
163 (if window-system
164 (logior uc (lsh (face-id (internal-find-face 'underline)) 19))
165 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
166
167 ;; Allocate a glyph code to display by sending STRING to the terminal.
168 ;;;###autoload
169 (defun create-glyph (string)
170 (if (= (length glyph-table) 65536)
171 (error "No free glyph codes remain"))
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))))
175 (setq glyph-table (vconcat glyph-table (list string)))
176 (1- (length glyph-table)))
177
178 ;;;###autoload
179 (defun standard-display-european (arg &optional auto)
180 "Toggle display of European characters encoded with ISO 8859.
181
182 This function is semi-obsolete; you can use `set-language-environment'
183 coupled with either the `--unibyte' option, the EMACS_UNIBYTE
184 environment variable or customizing `enable-multibyte-characters' if
185 you prefer to use unibyte characters.
186
187 When enabled, characters in the range of 160 to 255 display not
188 as octal escapes, but as accented characters. Codes 146 and 160
189 display as apostrophe and space, even though they are not the ASCII
190 codes for apostrophe and space.
191
192 With prefix argument, enable European character display iff arg is positive.
193
194 Normally, this function turns off `enable-multibyte-characters' for
195 existing and subsequently created Emacs buffers. This is because
196 users who call this function probably want to edit European characters
197 in single-byte mode."
198
199 ;; If the optional argument AUTO is non-nil, this function
200 ;; does not alter `enable-multibyte-characters'.
201 ;; AUTO also specifies, in this case, the coding system for terminal output.
202 ;; The AUTO argument is meant for use by startup.el only.
203 ;; which is why it is not in the doc string.
204 (interactive "P")
205 (if (or (<= (prefix-numeric-value arg) 0)
206 (and (null arg)
207 (char-table-p standard-display-table)
208 ;; Test 161, because 160 displays as a space.
209 (equal (aref standard-display-table 161) [161])))
210 (progn
211 (standard-display-default 160 255)
212 (unless (memq window-system '(x w32))
213 (set-terminal-coding-system nil)))
214 ;; If the user does this explicitly,
215 ;; turn off multibyte chars for more compatibility.
216 (unless auto
217 (setq-default enable-multibyte-characters nil)
218 (mapcar (lambda (buffer)
219 (with-current-buffer buffer
220 (if enable-multibyte-characters
221 (set-buffer-multibyte nil))))
222 (buffer-list)))
223 ;; If the user does this explicitly,
224 ;; switch to Latin-1 language environment
225 ;; unless some other has been specified.
226 (unless auto
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 non-X terminal.
231 ;; If AUTO is nil, we are using single-byte characters,
232 ;; so it doesn't matter which one we use.
233 (set-terminal-coding-system
234 (cond ((not (equal current-language-environment "English"))
235 (intern (downcase current-language-environment)))
236 ((eq auto t) 'latin-1)
237 ((symbolp auto) (or auto 'latin-1))
238 ((stringp auto) (intern auto)))))
239 (standard-display-european-internal)))
240
241 (provide 'disp-table)
242
243 ;;; disp-table.el ends here