Comment change.
[bpt/emacs.git] / lisp / disp-table.el
CommitLineData
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
23;; along with GNU Emacs; see the file COPYING. If not, write to
24;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
e5167999 26;;; Code:
a2535589 27
963fd070 28(put 'display-table 'char-table-extra-slots 6)
dc5a82ea 29
ef9c36a5
EN
30;;;###autoload
31(defun make-display-table ()
32 "Return a new, empty display table."
963fd070 33 (make-char-table 'display-table nil))
ef9c36a5
EN
34
35(or standard-display-table
36 (setq standard-display-table (make-display-table)))
37
963fd070
RS
38;;; Display-table slot names. The property value says which slot.
39
40(put 'truncation 'display-table-slot 0)
41(put 'wrap 'display-table-slot 1)
42(put 'escape 'display-table-slot 2)
43(put 'control 'display-table-slot 3)
44(put 'selective-display 'display-table-slot 4)
45(put 'vertical-border 'display-table-slot 5)
ef9c36a5
EN
46
47;;;###autoload
48(defun display-table-slot (display-table slot)
49 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
12c9fbcc
EN
50SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol).
51Valid symbols are `truncation', `wrap', `escape', `control',
52`selective-display', and `vertical-border'."
ef9c36a5
EN
53 (let ((slot-number
54 (if (numberp slot) slot
963fd070 55 (or (get slot 'display-table-slot)
ef9c36a5
EN
56 (error "Invalid display-table slot name: %s" slot)))))
57 (char-table-extra-slot display-table slot-number)))
58
59;;;###autoload
60(defun set-display-table-slot (display-table slot value)
61 "Set the value of the extra slot in DISPLAY-TABLE named SLOT to VALUE.
62SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
12c9fbcc
EN
63Valid symbols are `truncation', `wrap', `escape', `control',
64`selective-display', and `vertical-border'."
963fd070
RS
65 (let ((slot-number
66 (if (numberp slot) slot
67 (or (get slot 'display-table-slot)
68 (error "Invalid display-table slot name: %s" slot)))))
69 (set-char-table-extra-slot display-table slot-number value)))
ef9c36a5
EN
70
71;;;###autoload
e31b61e6 72(defun describe-display-table (dt)
49116ac0 73 "Describe the display table DT in a help buffer."
a2535589 74 (with-output-to-temp-buffer "*Help*"
03131799 75 (princ "\nTruncation glyph: ")
963fd070 76 (prin1 (display-table-slot dt 'truncation))
03131799 77 (princ "\nWrap glyph: ")
963fd070 78 (prin1 (display-table-slot dt 'wrap))
03131799 79 (princ "\nEscape glyph: ")
963fd070 80 (prin1 (display-table-slot dt 'escape))
03131799 81 (princ "\nCtrl glyph: ")
963fd070 82 (prin1 (display-table-slot dt 'control))
afb1e4b4 83 (princ "\nSelective display glyph sequence: ")
963fd070 84 (prin1 (display-table-slot dt 'selective-display))
dc5a82ea 85 (princ "\nVertical window border glyph: ")
963fd070 86 (prin1 (display-table-slot dt 'vertical-border))
afb1e4b4 87 (princ "\nCharacter display glyph sequences:\n")
bb6066c8
RS
88 (save-excursion
89 (set-buffer standard-output)
90 (let ((vector (make-vector 256 nil))
91 (i 0))
92 (while (< i 256)
93 (aset vector i (aref dt i))
94 (setq i (1+ i)))
5d74f2a6
KH
95 (describe-vector vector))
96 (help-mode))
a2535589
JA
97 (print-help-return-message)))
98
e31b61e6 99;;;###autoload
a2535589 100(defun describe-current-display-table ()
bb6066c8
RS
101 "Describe the display table in use in the selected window and buffer."
102 (interactive)
ef9c36a5
EN
103 (let ((disptab (or (window-display-table (selected-window))
104 buffer-display-table
105 standard-display-table)))
bb6066c8
RS
106 (if disptab
107 (describe-display-table disptab)
108 (message "No display table"))))
a2535589 109
e31b61e6 110;;;###autoload
a2535589 111(defun standard-display-8bit (l h)
49116ac0 112 "Display characters in the range L to H literally."
a2535589
JA
113 (while (<= l h)
114 (if (and (>= l ?\ ) (< l 127))
ef9c36a5 115 (aset standard-display-table l nil)
afb1e4b4 116 (aset standard-display-table l (vector l)))
a2535589
JA
117 (setq l (1+ l))))
118
798aa8d0
JB
119;;;###autoload
120(defun standard-display-default (l h)
121 "Display characters in the range L to H using the default notation."
122 (while (<= l h)
123 (if (and (>= l ?\ ) (< l 127))
ef9c36a5 124 (aset standard-display-table l nil)
798aa8d0
JB
125 (aset standard-display-table l nil))
126 (setq l (1+ l))))
127
a171458a
KH
128;; This function does NOT take terminal-dependent escape sequences.
129;; For that, you need to go through create-glyph. Use one of the
130;; other functions below, or roll your own.
ef9c36a5 131;;;###autoload
a2535589 132(defun standard-display-ascii (c s)
a171458a 133 "Display character C using printable string S."
ef9c36a5 134 (aset standard-display-table c (vconcat s)))
a2535589 135
e31b61e6 136;;;###autoload
a2535589 137(defun standard-display-g1 (c sc)
de7d5cb6
KH
138 "Display character C as character SC in the g1 character set.
139This function assumes that your terminal uses the SO/SI characters;
140it is meaningless for an X frame."
141 (if window-system
142 (error "Cannot use string glyphs in a windowing system"))
a2535589 143 (aset standard-display-table c
82093c70 144 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
a2535589 145
e31b61e6 146;;;###autoload
a2535589 147(defun standard-display-graphic (c gc)
de7d5cb6
KH
148 "Display character C as character GC in graphics character set.
149This function assumes VT100-compatible escapes; it is meaningless for an
150X frame."
151 (if window-system
152 (error "Cannot use string glyphs in a windowing system"))
a2535589 153 (aset standard-display-table c
82093c70 154 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
a2535589 155
e31b61e6 156;;;###autoload
a2535589
JA
157(defun standard-display-underline (c uc)
158 "Display character C as character UC plus underlining."
de7d5cb6 159 (if window-system (require 'faces))
a2535589 160 (aset standard-display-table c
de7d5cb6
KH
161 (vector
162 (if window-system
163 (logior uc (lsh (face-id (internal-find-face 'underline)) 8))
164 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
03131799
RS
165
166;; Allocate a glyph code to display by sending STRING to the terminal.
e31b61e6 167;;;###autoload
03131799
RS
168(defun create-glyph (string)
169 (if (= (length glyph-table) 65536)
170 (error "No free glyph codes remain"))
03fd83c5
KH
171 ;; Don't use slots that correspond to ASCII characters.
172 (if (= (length glyph-table) 32)
173 (setq glyph-table (vconcat glyph-table (make-vector 224 nil))))
03131799
RS
174 (setq glyph-table (vconcat glyph-table (list string)))
175 (1- (length glyph-table)))
a2535589 176
2eae7226 177;;;###autoload
798aa8d0 178(defun standard-display-european (arg)
2eae7226
JB
179 "Toggle display of European characters encoded with ISO 8859.
180When enabled, characters in the range of 160 to 255 display not
181as octal escapes, but as accented characters.
182With prefix argument, enable European character display iff arg is positive."
798aa8d0 183 (interactive "P")
c3a14a2b 184 (if (or (<= (prefix-numeric-value arg) 0)
2eae7226 185 (and (null arg)
ef9c36a5 186 (char-table-p standard-display-table)
e470e6f0
KH
187 ;; Test 161, because sometimes people need to make
188 ;; 160 display as a space.
189 (equal (aref standard-display-table 161) [161])))
2eae7226 190 (standard-display-default 160 255)
798aa8d0 191 (standard-display-8bit 160 255)))
798aa8d0 192
a2535589 193(provide 'disp-table)
c0274f38
ER
194
195;;; disp-table.el ends here