1 ;;; case-table.el --- code to extend the character set and support case tables
3 ;; Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 ;; Author: 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 3 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
28 ;; TN/ETX/TX/UMG Howard Gayle UUCP : seismo!enea!erix!howard
29 ;; Telefonaktiebolaget L M Ericsson Phone: +46 8 719 55 65
30 ;; Ericsson Telecom Telex: 14910 ERIC S
31 ;; S-126 25 Stockholm FAX : +46 8 719 64 82
36 (defun describe-buffer-case-table ()
37 "Describe the case table of the current buffer."
39 (let ((description (make-char-table 'case-table
)))
41 (function (lambda (key value
)
43 (set-char-table-range description key
"case-invariant")
46 (cond ((not (natnump value
))
48 ((/= key
(downcase key
))
49 (concat "uppercase, matches "
50 (char-to-string (downcase key
))))
51 ((/= key
(upcase key
))
52 (concat "lowercase, matches "
53 (char-to-string (upcase key
))))
54 (t "case-invariant"))))))
57 (with-output-to-temp-buffer "*Help*"
58 (set-buffer standard-output
)
59 (describe-vector description
)
62 (defun get-upcase-table (case-table)
63 "Return the upcase table of CASE-TABLE."
64 (or (char-table-extra-slot case-table
0)
65 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
66 ;; it as the standard case table.
67 (let ((old (standard-case-table)))
70 (set-standard-case-table case-table
)
71 (char-table-extra-slot case-table
0))
72 (or (eq case-table old
)
73 (set-standard-case-table old
))))))
75 (defun copy-case-table (case-table)
76 (let ((copy (copy-sequence case-table
))
77 (up (char-table-extra-slot case-table
0)))
78 ;; Clear out the extra slots (except for upcase table) so that
79 ;; they will be recomputed from the main (downcase) table.
81 (set-char-table-extra-slot copy
0 (copy-sequence up
)))
82 (set-char-table-extra-slot copy
1 nil
)
83 (set-char-table-extra-slot copy
2 nil
)
86 (defun set-case-syntax-delims (l r table
)
87 "Make characters L and R a matching pair of non-case-converting delimiters.
88 This sets the entries for L and R in TABLE, which is a string
89 that will be used as the downcase part of a case table.
90 It also modifies `standard-syntax-table' to
91 indicate left and right delimiters."
94 (let ((up (get-upcase-table table
)))
97 ;; Clear out the extra slots so that they will be
98 ;; recomputed from the main (downcase) table and upcase table.
99 (set-char-table-extra-slot table
1 nil
)
100 (set-char-table-extra-slot table
2 nil
)
101 (modify-syntax-entry l
(concat "(" (char-to-string r
) " ")
102 (standard-syntax-table))
103 (modify-syntax-entry r
(concat ")" (char-to-string l
) " ")
104 (standard-syntax-table)))
106 (defun set-case-syntax-pair (uc lc table
)
107 "Make characters UC and LC a pair of inter-case-converting letters.
108 This sets the entries for characters UC and LC in TABLE, which is a string
109 that will be used as the downcase part of a case table.
110 It also modifies `standard-syntax-table' to give them the syntax of
114 (let ((up (get-upcase-table table
)))
117 ;; Clear out the extra slots so that they will be
118 ;; recomputed from the main (downcase) table and upcase table.
119 (set-char-table-extra-slot table
1 nil
)
120 (set-char-table-extra-slot table
2 nil
)
121 (modify-syntax-entry lc
"w " (standard-syntax-table))
122 (modify-syntax-entry uc
"w " (standard-syntax-table)))
124 (defun set-upcase-syntax (uc lc table
)
125 "Make character UC an upcase of character LC.
126 It also modifies `standard-syntax-table' to give them the syntax of
129 (let ((up (get-upcase-table table
)))
132 ;; Clear out the extra slots so that they will be
133 ;; recomputed from the main (downcase) table and upcase table.
134 (set-char-table-extra-slot table
1 nil
)
135 (set-char-table-extra-slot table
2 nil
)
136 (modify-syntax-entry lc
"w " (standard-syntax-table))
137 (modify-syntax-entry uc
"w " (standard-syntax-table)))
139 (defun set-downcase-syntax (uc lc table
)
140 "Make character LC a downcase of character UC.
141 It also modifies `standard-syntax-table' to give them the syntax of
145 (let ((up (get-upcase-table table
)))
147 ;; Clear out the extra slots so that they will be
148 ;; recomputed from the main (downcase) table and upcase table.
149 (set-char-table-extra-slot table
1 nil
)
150 (set-char-table-extra-slot table
2 nil
)
151 (modify-syntax-entry lc
"w " (standard-syntax-table))
152 (modify-syntax-entry uc
"w " (standard-syntax-table)))
154 (defun set-case-syntax (c syntax table
)
155 "Make character C case-invariant with syntax SYNTAX.
156 This sets the entry for character C in TABLE, which is a string
157 that will be used as the downcase part of a case table.
158 It also modifies `standard-syntax-table'.
159 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
161 (let ((up (get-upcase-table table
)))
163 ;; Clear out the extra slots so that they will be
164 ;; recomputed from the main (downcase) table and upcase table.
165 (set-char-table-extra-slot table
1 nil
)
166 (set-char-table-extra-slot table
2 nil
)
167 (modify-syntax-entry c syntax
(standard-syntax-table)))
169 (provide 'case-table
)
171 ;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
172 ;;; case-table.el ends here