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