(font-lock-keywords): Docstring improvement.
[bpt/emacs.git] / lisp / disp-table.el
CommitLineData
55535639 1;;; disp-table.el --- functions for dealing with char tables
c0274f38 2
6c89b0e4 3;; Copyright (C) 1987, 94, 95, 1999, 2004 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."
a77a4db4
KH
116 (or standard-display-table
117 (setq standard-display-table (make-display-table)))
a2535589 118 (while (<= l h)
6c89b0e4 119 (aset standard-display-table l (if (or (< l ?\ ) (>= l 127)) (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."
a77a4db4
KH
125 (or standard-display-table
126 (setq standard-display-table (make-display-table)))
798aa8d0 127 (while (<= l h)
1c2c3f16
DL
128 (if (and (>= l ?\ ) (char-valid-p l))
129 (aset standard-display-table l nil))
798aa8d0
JB
130 (setq l (1+ l))))
131
a171458a
KH
132;; This function does NOT take terminal-dependent escape sequences.
133;; For that, you need to go through create-glyph. Use one of the
134;; other functions below, or roll your own.
ef9c36a5 135;;;###autoload
a2535589 136(defun standard-display-ascii (c s)
a171458a 137 "Display character C using printable string S."
a77a4db4
KH
138 (or standard-display-table
139 (setq standard-display-table (make-display-table)))
ef9c36a5 140 (aset standard-display-table c (vconcat s)))
a2535589 141
e31b61e6 142;;;###autoload
a2535589 143(defun standard-display-g1 (c sc)
de7d5cb6
KH
144 "Display character C as character SC in the g1 character set.
145This function assumes that your terminal uses the SO/SI characters;
146it is meaningless for an X frame."
744bcf11 147 (if (memq window-system '(x w32))
de7d5cb6 148 (error "Cannot use string glyphs in a windowing system"))
a77a4db4
KH
149 (or standard-display-table
150 (setq standard-display-table (make-display-table)))
a2535589 151 (aset standard-display-table c
82093c70 152 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
a2535589 153
e31b61e6 154;;;###autoload
a2535589 155(defun standard-display-graphic (c gc)
de7d5cb6
KH
156 "Display character C as character GC in graphics character set.
157This function assumes VT100-compatible escapes; it is meaningless for an
158X frame."
744bcf11 159 (if (memq window-system '(x w32))
de7d5cb6 160 (error "Cannot use string glyphs in a windowing system"))
a77a4db4
KH
161 (or standard-display-table
162 (setq standard-display-table (make-display-table)))
a2535589 163 (aset standard-display-table c
82093c70 164 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
a2535589 165
e31b61e6 166;;;###autoload
a2535589
JA
167(defun standard-display-underline (c uc)
168 "Display character C as character UC plus underlining."
a77a4db4
KH
169 (or standard-display-table
170 (setq standard-display-table (make-display-table)))
a2535589 171 (aset standard-display-table c
71296446 172 (vector
de7d5cb6 173 (if window-system
30c5ceb4 174 (logior uc (lsh (face-id 'underline) 19))
de7d5cb6 175 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
03131799 176
e31b61e6 177;;;###autoload
03131799 178(defun create-glyph (string)
b8fbaf52 179 "Allocate a glyph code to display by sending STRING to the terminal."
03131799
RS
180 (if (= (length glyph-table) 65536)
181 (error "No free glyph codes remain"))
03fd83c5
KH
182 ;; Don't use slots that correspond to ASCII characters.
183 (if (= (length glyph-table) 32)
184 (setq glyph-table (vconcat glyph-table (make-vector 224 nil))))
03131799
RS
185 (setq glyph-table (vconcat glyph-table (list string)))
186 (1- (length glyph-table)))
a2535589 187
2eae7226 188;;;###autoload
951bc45f 189(defun standard-display-european (arg)
3fbd8622 190 "Semi-obsolete way to toggle display of ISO 8859 European characters.
3ea1bd50 191
3fbd8622
KH
192This function is semi-obsolete; if you want to do your editing with
193unibyte characters, it is better to `set-language-environment' coupled
194with either the `--unibyte' option or the EMACS_UNIBYTE environment
195variable, or else customize `enable-multibyte-characters'.
828fac3a 196
3fbd8622
KH
197With prefix argument, this command enables European character display
198if arg is positive, disables it otherwise. Otherwise, it toggles
199European character display.
b2b52747 200
3fbd8622
KH
201When this mode is enabled, characters in the range of 160 to 255
202display not as octal escapes, but as accented characters. Codes 146
203and 160 display as apostrophe and space, even though they are not the
204ASCII codes for apostrophe and space.
40e82ac1 205
3fbd8622
KH
206Enabling European character display with this command noninteractively
207from Lisp code also selects Latin-1 as the language environment, and
208selects unibyte mode for all Emacs buffers \(both existing buffers and
209those created subsequently). This provides increased compatibility
210for users who call this function in `.emacs'."
f5af76c2 211
c3a14a2b 212 (if (or (<= (prefix-numeric-value arg) 0)
2eae7226 213 (and (null arg)
ef9c36a5 214 (char-table-p standard-display-table)
55f5abaf 215 ;; Test 161, because 160 displays as a space.
e470e6f0 216 (equal (aref standard-display-table 161) [161])))
3304a6c4
RS
217 (progn
218 (standard-display-default 160 255)
fbd798e2 219 (unless (or (memq window-system '(x w32)))
3fbd8622
KH
220 (and (terminal-coding-system)
221 (set-terminal-coding-system nil))))
fbd798e2
SM
222 ;; Turn off multibyte chars for more compatibility.
223 (setq-default enable-multibyte-characters nil)
224
225 ;; Switch to Latin-1 language environment
eb72c1bd 226 ;; unless some other has been specified.
fbd798e2
SM
227 (if (equal current-language-environment "English")
228 (set-language-environment "latin-1"))
229 (unless (or noninteractive (memq window-system '(x w32)))
951bc45f
PE
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 239
ab5796a9 240;;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
c0274f38 241;;; disp-table.el ends here