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
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)
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.
28 (put 'display-table
'char-table-extra-slots
6)
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)
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'."
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
)))
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'."
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
)))
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")
89 (set-buffer standard-output
)
90 (let ((vector (make-vector 256 nil
))
93 (aset vector i
(aref dt i
))
95 (describe-vector vector
))
97 (print-help-return-message)))
100 (defun describe-current-display-table ()
101 "Describe the display table in use in the selected window and buffer."
103 (let ((disptab (or (window-display-table (selected-window))
105 standard-display-table
)))
107 (describe-display-table disptab
)
108 (message "No display table"))))
111 (defun standard-display-8bit (l h
)
112 "Display characters in the range L to H literally."
114 (if (and (>= l ?\
) (< l
127))
115 (aset standard-display-table l nil
)
116 (aset standard-display-table l
(vector l
)))
120 (defun standard-display-default (l h
)
121 "Display characters in the range L to H using the default notation."
123 (if (and (>= l ?\
) (< l
127))
124 (aset standard-display-table l nil
)
125 (aset standard-display-table l nil
))
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.
132 (defun standard-display-ascii (c s
)
133 "Display character C using printable string S."
134 (aset standard-display-table c
(vconcat s
)))
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."
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")))))
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
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")))))
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
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.
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
)))
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."
184 (if (or (<= (prefix-numeric-value arg
) 0)
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