1 ;;; case-table.el --- code to extend the character set and support case tables
3 ;; Copyright (C) 1988, 1994, 2005 Free Software Foundation, Inc.
5 ;; Author: Howard Gayle
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 ;; TN/ETX/TX/UMG Howard Gayle UUCP : seismo!enea!erix!howard
30 ;; Telefonaktiebolaget L M Ericsson Phone: +46 8 719 55 65
31 ;; Ericsson Telecom Telex: 14910 ERIC S
32 ;; S-126 25 Stockholm FAX : +46 8 719 64 82
37 (defun describe-buffer-case-table ()
38 "Describe the case table of the current buffer."
40 (let ((description (make-char-table 'case-table)))
42 (function (lambda (key value)
44 (set-char-table-range description key "case-invariant")
47 (cond ((not (natnump value))
49 ((/= key (downcase key))
50 (concat "uppercase, matches "
51 (char-to-string (downcase key))))
52 ((/= key (upcase key))
53 (concat "lowercase, matches "
54 (char-to-string (upcase key))))
55 (t "case-invariant"))))))
58 (with-output-to-temp-buffer "*Help*"
59 (set-buffer standard-output)
60 (describe-vector description)
63 (defun get-upcase-table (case-table)
64 "Return the upcase table of CASE-TABLE."
65 (or (char-table-extra-slot case-table 0)
66 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
67 ;; it as the standard case table.
68 (let ((old (standard-case-table)))
71 (set-standard-case-table case-table)
72 (char-table-extra-slot case-table 0))
73 (or (eq case-table old)
74 (set-standard-case-table old))))))
76 (defun copy-case-table (case-table)
77 (let ((copy (copy-sequence case-table))
78 (up (char-table-extra-slot case-table 0)))
79 ;; Clear out the extra slots (except for upcase table) so that
80 ;; they will be recomputed from the main (downcase) table.
82 (set-char-table-extra-slot copy 0 (copy-sequence up)))
83 (set-char-table-extra-slot copy 1 nil)
84 (set-char-table-extra-slot copy 2 nil)
87 (defun set-case-syntax-delims (l r table)
88 "Make characters L and R a matching pair of non-case-converting delimiters.
89 This sets the entries for L and R in TABLE, which is a string
90 that will be used as the downcase part of a case table.
91 It also modifies `standard-syntax-table' to
92 indicate left and right delimiters."
95 (let ((up (get-upcase-table table)))
98 ;; Clear out the extra slots so that they will be
99 ;; recomputed from the main (downcase) table and upcase table.
100 (set-char-table-extra-slot table 1 nil)
101 (set-char-table-extra-slot table 2 nil)
102 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
103 (standard-syntax-table))
104 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
105 (standard-syntax-table)))
107 (defun set-case-syntax-pair (uc lc table)
108 "Make characters UC and LC a pair of inter-case-converting letters.
109 This sets the entries for characters UC and LC in TABLE, which is a string
110 that will be used as the downcase part of a case table.
111 It also modifies `standard-syntax-table' to give them the syntax of
115 (let ((up (get-upcase-table table)))
118 ;; Clear out the extra slots so that they will be
119 ;; recomputed from the main (downcase) table and upcase table.
120 (set-char-table-extra-slot table 1 nil)
121 (set-char-table-extra-slot table 2 nil)
122 (modify-syntax-entry lc "w " (standard-syntax-table))
123 (modify-syntax-entry uc "w " (standard-syntax-table)))
125 (defun set-upcase-syntax (uc lc table)
126 "Make character UC an upcase of character LC.
127 It also modifies `standard-syntax-table' to give them the syntax of
130 (let ((up (get-upcase-table table)))
133 ;; Clear out the extra slots so that they will be
134 ;; recomputed from the main (downcase) table and upcase table.
135 (set-char-table-extra-slot table 1 nil)
136 (set-char-table-extra-slot table 2 nil)
137 (modify-syntax-entry lc "w " (standard-syntax-table))
138 (modify-syntax-entry uc "w " (standard-syntax-table)))
140 (defun set-downcase-syntax (uc lc table)
141 "Make character LC a downcase of character UC.
142 It also modifies `standard-syntax-table' to give them the syntax of
146 (let ((up (get-upcase-table table)))
148 ;; Clear out the extra slots so that they will be
149 ;; recomputed from the main (downcase) table and upcase table.
150 (set-char-table-extra-slot table 1 nil)
151 (set-char-table-extra-slot table 2 nil)
152 (modify-syntax-entry lc "w " (standard-syntax-table))
153 (modify-syntax-entry uc "w " (standard-syntax-table)))
155 (defun set-case-syntax (c syntax table)
156 "Make character C case-invariant with syntax SYNTAX.
157 This sets the entry for character C in TABLE, which is a string
158 that will be used as the downcase part of a case table.
159 It also modifies `standard-syntax-table'.
160 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
162 (let ((up (get-upcase-table table)))
164 ;; Clear out the extra slots so that they will be
165 ;; recomputed from the main (downcase) table and upcase table.
166 (set-char-table-extra-slot table 1 nil)
167 (set-char-table-extra-slot table 2 nil)
168 (modify-syntax-entry c syntax (standard-syntax-table)))
170 (provide 'case-table)
172 ;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
173 ;;; case-table.el ends here