(using-unix-filesystems):
[emacs.git] / lisp / disp-table.el
blobd75dd41e701be87ad4b51331ce2fb906f7c7a17f
1 ;;; disp-table.el --- functions for dealing with char tables.
3 ;; Copyright (C) 1987, 1994, 1995 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
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;;; Code:
28 (put 'display-table 'char-table-extra-slots 6)
30 ;;;###autoload
31 (defun make-display-table ()
32 "Return a new, empty display table."
33 (make-char-table 'display-table nil))
35 (or standard-display-table
36 (setq standard-display-table (make-display-table)))
38 ;;; Display-table slot names. The property value says which slot.
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)
47 ;;;###autoload
48 (defun display-table-slot (display-table slot)
49 "Return the value of the extra slot in DISPLAY-TABLE named SLOT.
50 SLOT may be a number from 0 to 5 inclusive, or a slot name (symbol).
51 Valid symbols are `truncation', `wrap', `escape', `control',
52 `selective-display', and `vertical-border'."
53 (let ((slot-number
54 (if (numberp slot) slot
55 (or (get slot 'display-table-slot)
56 (error "Invalid display-table slot name: %s" slot)))))
57 (char-table-extra-slot display-table slot-number)))
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.
62 SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
63 Valid symbols are `truncation', `wrap', `escape', `control',
64 `selective-display', and `vertical-border'."
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)))
71 ;;;###autoload
72 (defun describe-display-table (dt)
73 "Describe the display table DT in a help buffer."
74 (with-output-to-temp-buffer "*Help*"
75 (princ "\nTruncation glyph: ")
76 (prin1 (display-table-slot dt 'truncation))
77 (princ "\nWrap glyph: ")
78 (prin1 (display-table-slot dt 'wrap))
79 (princ "\nEscape glyph: ")
80 (prin1 (display-table-slot dt 'escape))
81 (princ "\nCtrl glyph: ")
82 (prin1 (display-table-slot dt 'control))
83 (princ "\nSelective display glyph sequence: ")
84 (prin1 (display-table-slot dt 'selective-display))
85 (princ "\nVertical window border glyph: ")
86 (prin1 (display-table-slot dt 'vertical-border))
87 (princ "\nCharacter display glyph sequences:\n")
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)))
95 (describe-vector vector))
96 (help-mode))
97 (print-help-return-message)))
99 ;;;###autoload
100 (defun describe-current-display-table ()
101 "Describe the display table in use in the selected window and buffer."
102 (interactive)
103 (let ((disptab (or (window-display-table (selected-window))
104 buffer-display-table
105 standard-display-table)))
106 (if disptab
107 (describe-display-table disptab)
108 (message "No display table"))))
110 ;;;###autoload
111 (defun standard-display-8bit (l h)
112 "Display characters in the range L to H literally."
113 (while (<= l h)
114 (if (and (>= l ?\ ) (< l 127))
115 (aset standard-display-table l nil)
116 (aset standard-display-table l (vector l)))
117 (setq l (1+ l))))
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))
124 (aset standard-display-table l nil)
125 (aset standard-display-table l nil))
126 (setq l (1+ l))))
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.
131 ;;;###autoload
132 (defun standard-display-ascii (c s)
133 "Display character C using printable string S."
134 (aset standard-display-table c (vconcat s)))
136 ;;;###autoload
137 (defun standard-display-g1 (c sc)
138 "Display character C as character SC in the g1 character set.
139 This function assumes that your terminal uses the SO/SI characters;
140 it is meaningless for an X frame."
141 (if window-system
142 (error "Cannot use string glyphs in a windowing system"))
143 (aset standard-display-table c
144 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
146 ;;;###autoload
147 (defun standard-display-graphic (c gc)
148 "Display character C as character GC in graphics character set.
149 This function assumes VT100-compatible escapes; it is meaningless for an
150 X frame."
151 (if window-system
152 (error "Cannot use string glyphs in a windowing system"))
153 (aset standard-display-table c
154 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
156 ;;;###autoload
157 (defun standard-display-underline (c uc)
158 "Display character C as character UC plus underlining."
159 (if window-system (require 'faces))
160 (aset standard-display-table c
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"))))))
166 ;; Allocate a glyph code to display by sending STRING to the terminal.
167 ;;;###autoload
168 (defun create-glyph (string)
169 (if (= (length glyph-table) 65536)
170 (error "No free glyph codes remain"))
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))))
174 (setq glyph-table (vconcat glyph-table (list string)))
175 (1- (length glyph-table)))
177 ;;;###autoload
178 (defun standard-display-european (arg)
179 "Toggle display of European characters encoded with ISO 8859.
180 When enabled, characters in the range of 160 to 255 display not
181 as octal escapes, but as accented characters.
182 With prefix argument, enable European character display iff arg is positive."
183 (interactive "P")
184 (if (or (<= (prefix-numeric-value arg) 0)
185 (and (null arg)
186 (char-table-p standard-display-table)
187 ;; Test 161, because 160 displays as a space.
188 (equal (aref standard-display-table 161) [161])))
189 (standard-display-default 160 255)
190 (standard-display-8bit 160 255)
191 ;; Make non-line-break space display as a plain space.
192 ;; Most X fonts do the wrong thing for code 160.
193 (aset standard-display-table 160 [32])))
195 (provide 'disp-table)
197 ;;; disp-table.el ends here