1 ;;; case-table.el --- code to extend the character set and support case tables
3 ;; Copyright (C) 1988, 1994, 2002, 2003, 2004,
4 ;; 2005, 2006 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 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 the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
30 ;; TN/ETX/TX/UMG Howard Gayle UUCP : seismo!enea!erix!howard
31 ;; Telefonaktiebolaget L M Ericsson Phone: +46 8 719 55 65
32 ;; Ericsson Telecom Telex: 14910 ERIC S
33 ;; S-126 25 Stockholm FAX : +46 8 719 64 82
38 (defvar set-case-syntax-offset
0)
40 (defvar set-case-syntax-set-multibyte nil
)
42 (defun describe-buffer-case-table ()
43 "Describe the case table of the current buffer."
45 (let ((description (make-char-table 'case-table
)))
47 (function (lambda (key value
)
50 (cond ((not (natnump value
))
52 ((/= key
(downcase key
))
53 (concat "uppercase, matches "
54 (char-to-string (downcase key
))))
55 ((/= key
(upcase key
))
56 (concat "lowercase, matches "
57 (char-to-string (upcase key
))))
58 (t "case-invariant")))))
61 (with-output-to-temp-buffer "*Help*"
62 (set-buffer standard-output
)
63 (describe-vector description
)
66 (defun get-upcase-table (case-table)
67 "Return the upcase table of CASE-TABLE."
68 (or (char-table-extra-slot case-table
0)
69 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
70 ;; it as the standard case table.
71 (let ((old (standard-case-table)))
74 (set-standard-case-table case-table
)
75 (char-table-extra-slot case-table
0))
76 (or (eq case-table old
)
77 (set-standard-case-table old
))))))
79 (defun copy-case-table (case-table)
80 (let ((copy (copy-sequence case-table
))
81 (up (char-table-extra-slot case-table
0)))
82 ;; Clear out the extra slots (except for upcase table) so that
83 ;; they will be recomputed from the main (downcase) table.
85 (set-char-table-extra-slot copy
0 (copy-sequence up
)))
86 (set-char-table-extra-slot copy
1 nil
)
87 (set-char-table-extra-slot copy
2 nil
)
90 (defsubst set-case-syntax-1
(char)
91 "Offset CHAR by `set-case-syntax-offset' if CHAR is a non-ASCII 8-bit char."
92 (if (and (>= char
128) (< char
256))
93 (+ char set-case-syntax-offset
)
96 (defun set-case-syntax-delims (l r table
)
97 "Make characters L and R a matching pair of non-case-converting delimiters.
98 This sets the entries for L and R in TABLE, which is a string
99 that will be used as the downcase part of a case table.
100 It also modifies `standard-syntax-table' to
101 indicate left and right delimiters."
102 (setq l
(set-case-syntax-1 l
))
103 (setq r
(set-case-syntax-1 r
))
106 (let ((up (get-upcase-table table
)))
109 ;; Clear out the extra slots so that they will be
110 ;; recomputed from the main (downcase) table and upcase table.
111 (set-char-table-extra-slot table
1 nil
)
112 (set-char-table-extra-slot table
2 nil
)
113 (modify-syntax-entry l
(concat "(" (char-to-string r
) " ")
114 (standard-syntax-table))
115 (modify-syntax-entry r
(concat ")" (char-to-string l
) " ")
116 (standard-syntax-table)))
118 (defun set-case-syntax-pair (uc lc table
)
119 "Make characters UC and LC a pair of inter-case-converting letters.
120 This sets the entries for characters UC and LC in TABLE, which is a string
121 that will be used as the downcase part of a case table.
122 It also modifies `standard-syntax-table' to give them the syntax of
124 (setq uc
(set-case-syntax-1 uc
))
125 (setq lc
(set-case-syntax-1 lc
))
128 (let ((up (get-upcase-table table
)))
131 ;; Clear out the extra slots so that they will be
132 ;; recomputed from the main (downcase) table and upcase table.
133 (set-char-table-extra-slot table
1 nil
)
134 (set-char-table-extra-slot table
2 nil
)
135 (modify-syntax-entry lc
"w " (standard-syntax-table))
136 (modify-syntax-entry uc
"w " (standard-syntax-table)))
138 (defun set-upcase-syntax (uc lc table
)
139 "Make character UC an upcase of character LC.
140 It also modifies `standard-syntax-table' to give them the syntax of
142 (setq uc
(set-case-syntax-1 uc
))
143 (setq lc
(set-case-syntax-1 lc
))
145 (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-downcase-syntax (uc lc table
)
156 "Make character LC a downcase of character UC.
157 It also modifies `standard-syntax-table' to give them the syntax of
159 (setq uc
(set-case-syntax-1 uc
))
160 (setq lc
(set-case-syntax-1 lc
))
163 (let ((up (get-upcase-table table
)))
165 ;; Clear out the extra slots so that they will be
166 ;; recomputed from the main (downcase) table and upcase table.
167 (set-char-table-extra-slot table
1 nil
)
168 (set-char-table-extra-slot table
2 nil
)
169 (modify-syntax-entry lc
"w " (standard-syntax-table))
170 (modify-syntax-entry uc
"w " (standard-syntax-table)))
172 (defun set-case-syntax (c syntax table
)
173 "Make character C case-invariant with syntax SYNTAX.
174 This sets the entry for character C in TABLE, which is a string
175 that will be used as the downcase part of a case table.
176 It also modifies `standard-syntax-table'.
177 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
178 (setq c
(set-case-syntax-1 c
))
180 (let ((up (get-upcase-table table
)))
182 ;; Clear out the extra slots so that they will be
183 ;; recomputed from the main (downcase) table and upcase table.
184 (set-char-table-extra-slot table
1 nil
)
185 (set-char-table-extra-slot table
2 nil
)
186 (modify-syntax-entry c syntax
(standard-syntax-table)))
188 (provide 'case-table
)
190 ;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
191 ;;; case-table.el ends here