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 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, 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 (defun describe-buffer-case-table ()
39 "Describe the case table of the current buffer."
41 (let ((description (make-char-table 'case-table
)))
43 (function (lambda (key value
)
45 (set-char-table-range description key
"case-invariant")
48 (cond ((not (natnump value
))
50 ((/= key
(downcase key
))
51 (concat "uppercase, matches "
52 (char-to-string (downcase key
))))
53 ((/= key
(upcase key
))
54 (concat "lowercase, matches "
55 (char-to-string (upcase key
))))
56 (t "case-invariant"))))))
59 (with-output-to-temp-buffer "*Help*"
60 (set-buffer standard-output
)
61 (describe-vector description
)
64 (defun get-upcase-table (case-table)
65 "Return the upcase table of CASE-TABLE."
66 (or (char-table-extra-slot case-table
0)
67 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
68 ;; it as the standard case table.
69 (let ((old (standard-case-table)))
72 (set-standard-case-table case-table
)
73 (char-table-extra-slot case-table
0))
74 (or (eq case-table old
)
75 (set-standard-case-table old
))))))
77 (defun copy-case-table (case-table)
78 (let ((copy (copy-sequence case-table
))
79 (up (char-table-extra-slot case-table
0)))
80 ;; Clear out the extra slots (except for upcase table) so that
81 ;; they will be recomputed from the main (downcase) table.
83 (set-char-table-extra-slot copy
0 (copy-sequence up
)))
84 (set-char-table-extra-slot copy
1 nil
)
85 (set-char-table-extra-slot copy
2 nil
)
88 (defun set-case-syntax-delims (l r table
)
89 "Make characters L and R a matching pair of non-case-converting delimiters.
90 This sets the entries for L and R in TABLE, which is a string
91 that will be used as the downcase part of a case table.
92 It also modifies `standard-syntax-table' to
93 indicate left and right delimiters."
96 (let ((up (get-upcase-table table
)))
99 ;; Clear out the extra slots so that they will be
100 ;; recomputed from the main (downcase) table and upcase table.
101 (set-char-table-extra-slot table
1 nil
)
102 (set-char-table-extra-slot table
2 nil
)
103 (modify-syntax-entry l
(concat "(" (char-to-string r
) " ")
104 (standard-syntax-table))
105 (modify-syntax-entry r
(concat ")" (char-to-string l
) " ")
106 (standard-syntax-table)))
108 (defun set-case-syntax-pair (uc lc table
)
109 "Make characters UC and LC a pair of inter-case-converting letters.
110 This sets the entries for characters UC and LC in TABLE, which is a string
111 that will be used as the downcase part of a case table.
112 It also modifies `standard-syntax-table' to give them the syntax of
116 (let ((up (get-upcase-table table
)))
119 ;; Clear out the extra slots so that they will be
120 ;; recomputed from the main (downcase) table and upcase table.
121 (set-char-table-extra-slot table
1 nil
)
122 (set-char-table-extra-slot table
2 nil
)
123 (modify-syntax-entry lc
"w " (standard-syntax-table))
124 (modify-syntax-entry uc
"w " (standard-syntax-table)))
126 (defun set-upcase-syntax (uc lc table
)
127 "Make character UC an upcase of character LC.
128 It also modifies `standard-syntax-table' to give them the syntax of
131 (let ((up (get-upcase-table table
)))
134 ;; Clear out the extra slots so that they will be
135 ;; recomputed from the main (downcase) table and upcase table.
136 (set-char-table-extra-slot table
1 nil
)
137 (set-char-table-extra-slot table
2 nil
)
138 (modify-syntax-entry lc
"w " (standard-syntax-table))
139 (modify-syntax-entry uc
"w " (standard-syntax-table)))
141 (defun set-downcase-syntax (uc lc table
)
142 "Make character LC a downcase of character UC.
143 It also modifies `standard-syntax-table' to give them the syntax of
147 (let ((up (get-upcase-table table
)))
149 ;; Clear out the extra slots so that they will be
150 ;; recomputed from the main (downcase) table and upcase table.
151 (set-char-table-extra-slot table
1 nil
)
152 (set-char-table-extra-slot table
2 nil
)
153 (modify-syntax-entry lc
"w " (standard-syntax-table))
154 (modify-syntax-entry uc
"w " (standard-syntax-table)))
156 (defun set-case-syntax (c syntax table
)
157 "Make character C case-invariant with syntax SYNTAX.
158 This sets the entry for character C in TABLE, which is a string
159 that will be used as the downcase part of a case table.
160 It also modifies `standard-syntax-table'.
161 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
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 c syntax
(standard-syntax-table)))
171 (provide 'case-table
)
173 ;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
174 ;;; case-table.el ends here