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)."
52 (if (numberp slot) slot
53 (or (get slot 'display-table-slot)
54 (error "Invalid display-table slot name: %s" slot)))))
55 (char-table-extra-slot display-table slot-number)))
58 (defun set-display-table-slot (display-table slot value)
59 "Set the value of the extra slot in DISPLAY-TABLE named SLOT to VALUE.
60 SLOT may be a number from 0 to 5 inclusive, or a name (symbol).
61 See `display-table-slot-name-alist' for the names and numbers."
63 (if (numberp slot) slot
64 (or (get slot 'display-table-slot)
65 (error "Invalid display-table slot name: %s" slot)))))
66 (set-char-table-extra-slot display-table slot-number value)))
69 (defun describe-display-table (dt)
70 "Describe the display table DT in a help buffer."
71 (with-output-to-temp-buffer "*Help*"
72 (princ "\nTruncation glyph: ")
73 (prin1 (display-table-slot dt 'truncation))
74 (princ "\nWrap glyph: ")
75 (prin1 (display-table-slot dt 'wrap))
76 (princ "\nEscape glyph: ")
77 (prin1 (display-table-slot dt 'escape))
78 (princ "\nCtrl glyph: ")
79 (prin1 (display-table-slot dt 'control))
80 (princ "\nSelective display glyph sequence: ")
81 (prin1 (display-table-slot dt 'selective-display))
82 (princ "\nVertical window border glyph: ")
83 (prin1 (display-table-slot dt 'vertical-border))
84 (princ "\nCharacter display glyph sequences:\n")
86 (set-buffer standard-output)
87 (let ((vector (make-vector 256 nil))
90 (aset vector i (aref dt i))
92 (describe-vector vector))
94 (print-help-return-message)))
97 (defun describe-current-display-table ()
98 "Describe the display table in use in the selected window and buffer."
100 (let ((disptab (or (window-display-table (selected-window))
102 standard-display-table)))
104 (describe-display-table disptab)
105 (message "No display table"))))
108 (defun standard-display-8bit (l h)
109 "Display characters in the range L to H literally."
111 (if (and (>= l ?\ ) (< l 127))
112 (aset standard-display-table l nil)
113 (aset standard-display-table l (vector l)))
117 (defun standard-display-default (l h)
118 "Display characters in the range L to H using the default notation."
120 (if (and (>= l ?\ ) (< l 127))
121 (aset standard-display-table l nil)
122 (aset standard-display-table l nil))
125 ;; This function does NOT take terminal-dependent escape sequences.
126 ;; For that, you need to go through create-glyph. Use one of the
127 ;; other functions below, or roll your own.
129 (defun standard-display-ascii (c s)
130 "Display character C using printable string S."
131 (aset standard-display-table c (vconcat s)))
134 (defun standard-display-g1 (c sc)
135 "Display character C as character SC in the g1 character set.
136 This function assumes that your terminal uses the SO/SI characters;
137 it is meaningless for an X frame."
139 (error "Cannot use string glyphs in a windowing system"))
140 (aset standard-display-table c
141 (vector (create-glyph (concat "\016" (char-to-string sc) "\017")))))
144 (defun standard-display-graphic (c gc)
145 "Display character C as character GC in graphics character set.
146 This function assumes VT100-compatible escapes; it is meaningless for an
149 (error "Cannot use string glyphs in a windowing system"))
150 (aset standard-display-table c
151 (vector (create-glyph (concat "\e(0" (char-to-string gc) "\e(B")))))
154 (defun standard-display-underline (c uc)
155 "Display character C as character UC plus underlining."
156 (if window-system (require 'faces))
157 (aset standard-display-table c
160 (logior uc (lsh (face-id (internal-find-face 'underline)) 8))
161 (create-glyph (concat "\e[4m" (char-to-string uc) "\e[m"))))))
163 ;; Allocate a glyph code to display by sending STRING to the terminal.
165 (defun create-glyph (string)
166 (if (= (length glyph-table) 65536)
167 (error "No free glyph codes remain"))
168 ;; Don't use slots that correspond to ASCII characters.
169 (if (= (length glyph-table) 32)
170 (setq glyph-table (vconcat glyph-table (make-vector 224 nil))))
171 (setq glyph-table (vconcat glyph-table (list string)))
172 (1- (length glyph-table)))
175 (defun standard-display-european (arg)
176 "Toggle display of European characters encoded with ISO 8859.
177 When enabled, characters in the range of 160 to 255 display not
178 as octal escapes, but as accented characters.
179 With prefix argument, enable European character display iff arg is positive."
181 (if (or (<= (prefix-numeric-value arg) 0)
183 (char-table-p standard-display-table)
184 (equal (aref standard-display-table 160) [160])))
185 (standard-display-default 160 255)
186 (standard-display-8bit 160 255)))
188 (provide 'disp-table)
190 ;;; disp-table.el ends here