*** empty log message ***
[emacs.git] / lisp / disp-table.el
blob6a8fe08ca2020464684e5f5a4a0e18d00a9b9d46
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
7 ;; Maintainer: FSF
8 ;; Keywords: i18n
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)
15 ;; any later version.
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.
27 ;;; Commentary:
29 ;;; Code:
31 (put 'display-table 'char-table-extra-slots 6)
33 ;;;###autoload
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)
50 ;;;###autoload
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'."
56 (let ((slot-number
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)))
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.
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'."
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)))
74 ;;;###autoload
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")
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)))
98 (describe-vector vector))
99 (help-mode))
100 (print-help-return-message)))
102 ;;;###autoload
103 (defun describe-current-display-table ()
104 "Describe the display table in use in the selected window and buffer."
105 (interactive)
106 (let ((disptab (or (window-display-table (selected-window))
107 buffer-display-table
108 standard-display-table)))
109 (if disptab
110 (describe-display-table disptab)
111 (message "No display table"))))
113 ;;;###autoload
114 (defun standard-display-8bit (l h)
115 "Display characters in the range L to H literally."
116 (while (<= l h)
117 (if (and (>= l ?\ ) (< l 127))
118 (aset standard-display-table l nil)
119 (aset standard-display-table l (vector l)))
120 (setq l (1+ l))))
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)
126 (if (and (>= l ?\ ) (char-valid-p l))
127 (aset standard-display-table l nil))
128 (setq l (1+ l))))
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.
133 ;;;###autoload
134 (defun standard-display-ascii (c s)
135 "Display character C using printable string S."
136 (aset standard-display-table c (vconcat s)))
138 ;;;###autoload
139 (defun standard-display-g1 (c sc)
140 "Display character C as character SC in the g1 character set.
141 This function assumes that your terminal uses the SO/SI characters;
142 it is meaningless for an X frame."
143 (if (memq window-system '(x w32))
144 (error "Cannot use string glyphs in a windowing system"))
145 (aset standard-display-table c
146 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
148 ;;;###autoload
149 (defun standard-display-graphic (c gc)
150 "Display character C as character GC in graphics character set.
151 This function assumes VT100-compatible escapes; it is meaningless for an
152 X frame."
153 (if (memq window-system '(x w32))
154 (error "Cannot use string glyphs in a windowing system"))
155 (aset standard-display-table c
156 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
158 ;;;###autoload
159 (defun standard-display-underline (c uc)
160 "Display character C as character UC plus underlining."
161 (aset standard-display-table c
162 (vector
163 (if window-system
164 (logior uc (lsh (face-id 'underline) 19))
165 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
167 ;;;###autoload
168 (defun create-glyph (string)
169 "Allocate a glyph code to display by sending STRING to the terminal."
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)))
178 ;;;###autoload
179 (defun standard-display-european (arg)
180 "Semi-obsolete way to toggle display of ISO 8859 European characters.
182 This function is semi-obsolete; if you want to do your editing with
183 unibyte characters, it is better to `set-language-environment' coupled
184 with either the `--unibyte' option or the EMACS_UNIBYTE environment
185 variable, or else customize `enable-multibyte-characters'.
187 With prefix argument, this command enables European character display
188 if arg is positive, disables it otherwise. Otherwise, it toggles
189 European character display.
191 When this mode is enabled, characters in the range of 160 to 255
192 display not as octal escapes, but as accented characters. Codes 146
193 and 160 display as apostrophe and space, even though they are not the
194 ASCII codes for apostrophe and space.
196 Enabling European character display with this command noninteractively
197 from Lisp code also selects Latin-1 as the language environment, and
198 selects unibyte mode for all Emacs buffers \(both existing buffers and
199 those created subsequently). This provides increased compatibility
200 for users who call this function in `.emacs'."
202 (if (or (<= (prefix-numeric-value arg) 0)
203 (and (null arg)
204 (char-table-p standard-display-table)
205 ;; Test 161, because 160 displays as a space.
206 (equal (aref standard-display-table 161) [161])))
207 (progn
208 (standard-display-default 160 255)
209 (unless (or (memq window-system '(x w32)))
210 (and (terminal-coding-system)
211 (set-terminal-coding-system nil))))
212 ;; Turn off multibyte chars for more compatibility.
213 (setq-default enable-multibyte-characters nil)
215 ;; Switch to Latin-1 language environment
216 ;; unless some other has been specified.
217 (if (equal current-language-environment "English")
218 (set-language-environment "latin-1"))
219 (unless (or noninteractive (memq window-system '(x w32)))
220 ;; Send those codes literally to a character-based terminal.
221 ;; If we are using single-byte characters,
222 ;; it doesn't matter which coding system we use.
223 (set-terminal-coding-system
224 (let ((c (intern (downcase current-language-environment))))
225 (if (coding-system-p c) c 'latin-1))))
226 (standard-display-european-internal)))
228 (provide 'disp-table)
230 ;;; disp-table.el ends here