]> code.delx.au - gnu-emacs/blob - lisp/case-table.el
(get-upcase-table): New function.
[gnu-emacs] / lisp / case-table.el
1 ;;; case-table.el --- code to extend the character set and support case tables
2
3 ;; Copyright (C) 1988, 1994, 2005 Free Software Foundation, Inc.
4
5 ;; Author: Howard Gayle
6 ;; Maintainer: FSF
7 ;; Keywords: i18n
8
9 ;; This file is part of GNU Emacs.
10
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)
14 ;; any later version.
15
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.
20
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.
25
26 ;;; Commentary:
27
28 ;; Written by:
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
33 ;; Sweden
34
35 ;;; Code:
36
37 (defvar set-case-syntax-offset 0)
38
39 (defvar set-case-syntax-set-multibyte nil)
40
41 (defun describe-buffer-case-table ()
42 "Describe the case table of the current buffer."
43 (interactive)
44 (let ((description (make-char-table 'case-table)))
45 (map-char-table
46 (function (lambda (key value)
47 (aset
48 description key
49 (cond ((not (natnump value))
50 "case-invariant")
51 ((/= key (downcase key))
52 (concat "uppercase, matches "
53 (char-to-string (downcase key))))
54 ((/= key (upcase key))
55 (concat "lowercase, matches "
56 (char-to-string (upcase key))))
57 (t "case-invariant")))))
58 (current-case-table))
59 (save-excursion
60 (with-output-to-temp-buffer "*Help*"
61 (set-buffer standard-output)
62 (describe-vector description)
63 (help-mode)))))
64
65 (defun get-upcase-table (case-table)
66 "Return the upcase table of CASE-TABLE."
67 (or (char-table-extra-slot case-table 0)
68 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
69 ;; it as the standard case table.
70 (let ((old (standard-case-table)))
71 (unwind-protect
72 (progn
73 (set-standard-case-table case-table)
74 (char-table-extra-slot case-table 0))
75 (or (eq case-table old)
76 (set-standard-case-table old))))))
77
78 (defun copy-case-table (case-table)
79 (let ((copy (copy-sequence case-table))
80 (up (char-table-extra-slot case-table 0)))
81 ;; Clear out the extra slots (except for upcase table) so that
82 ;; they will be recomputed from the main (downcase) table.
83 (if up
84 (set-char-table-extra-slot copy 0 (copy-sequence up)))
85 (set-char-table-extra-slot copy 1 nil)
86 (set-char-table-extra-slot copy 2 nil)
87 copy))
88
89 (defsubst set-case-syntax-1 (char)
90 "Offset CHAR by `set-case-syntax-offset' if CHAR is a non-ASCII 8-bit char."
91 (if (and (>= char 128) (< char 256))
92 (+ char set-case-syntax-offset)
93 char))
94
95 (defun set-case-syntax-delims (l r table)
96 "Make characters L and R a matching pair of non-case-converting delimiters.
97 This sets the entries for L and R in TABLE, which is a string
98 that will be used as the downcase part of a case table.
99 It also modifies `standard-syntax-table' to
100 indicate left and right delimiters."
101 (setq l (set-case-syntax-1 l))
102 (setq r (set-case-syntax-1 r))
103 (aset table l l)
104 (aset table r r)
105 (let ((up (get-upcase-table table)))
106 (aset up l l)
107 (aset up r r))
108 ;; Clear out the extra slots so that they will be
109 ;; recomputed from the main (downcase) table and upcase table.
110 (set-char-table-extra-slot table 1 nil)
111 (set-char-table-extra-slot table 2 nil)
112 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
113 (standard-syntax-table))
114 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
115 (standard-syntax-table)))
116
117 (defun set-case-syntax-pair (uc lc table)
118 "Make characters UC and LC a pair of inter-case-converting letters.
119 This sets the entries for characters UC and LC in TABLE, which is a string
120 that will be used as the downcase part of a case table.
121 It also modifies `standard-syntax-table' to give them the syntax of
122 word constituents."
123 (setq uc (set-case-syntax-1 uc))
124 (setq lc (set-case-syntax-1 lc))
125 (aset table uc lc)
126 (aset table lc lc)
127 (let ((up (get-upcase-table table)))
128 (aset up uc uc)
129 (aset up lc uc))
130 ;; Clear out the extra slots so that they will be
131 ;; recomputed from the main (downcase) table and upcase table.
132 (set-char-table-extra-slot table 1 nil)
133 (set-char-table-extra-slot table 2 nil)
134 (modify-syntax-entry lc "w " (standard-syntax-table))
135 (modify-syntax-entry uc "w " (standard-syntax-table)))
136
137 (defun set-upcase-syntax (uc lc table)
138 "Make character UC an upcase of character LC.
139 It also modifies `standard-syntax-table' to give them the syntax of
140 word constituents."
141 (setq uc (set-case-syntax-1 uc))
142 (setq lc (set-case-syntax-1 lc))
143 (let ((up (get-upcase-table table)))
144 (aset up uc uc)
145 (aset up lc uc))
146 ;; Clear out the extra slots so that they will be
147 ;; recomputed from the main (downcase) table and upcase table.
148 (set-char-table-extra-slot table 1 nil)
149 (set-char-table-extra-slot table 2 nil)
150 (modify-syntax-entry lc "w " (standard-syntax-table))
151 (modify-syntax-entry uc "w " (standard-syntax-table)))
152
153 (defun set-downcase-syntax (uc lc table)
154 "Make character LC a downcase of character UC.
155 It also modifies `standard-syntax-table' to give them the syntax of
156 word constituents."
157 (setq uc (set-case-syntax-1 uc))
158 (setq lc (set-case-syntax-1 lc))
159 (aset table uc lc)
160 (aset table lc lc)
161 ;; Clear out the extra slots so that they will be
162 ;; recomputed from the main (downcase) table and upcase table.
163 (set-char-table-extra-slot table 1 nil)
164 (set-char-table-extra-slot table 2 nil)
165 (modify-syntax-entry lc "w " (standard-syntax-table))
166 (modify-syntax-entry uc "w " (standard-syntax-table)))
167
168 (defun set-case-syntax (c syntax table)
169 "Make character C case-invariant with syntax SYNTAX.
170 This sets the entry for character C in TABLE, which is a string
171 that will be used as the downcase part of a case table.
172 It also modifies `standard-syntax-table'.
173 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
174 (setq c (set-case-syntax-1 c))
175 (aset table c c)
176 (let ((up (get-upcase-table table)))
177 (aset up c c))
178 ;; Clear out the extra slots so that they will be
179 ;; recomputed from the main (downcase) table and upcase table.
180 (set-char-table-extra-slot table 1 nil)
181 (set-char-table-extra-slot table 2 nil)
182 (modify-syntax-entry c syntax (standard-syntax-table)))
183
184 (provide 'case-table)
185
186 ;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
187 ;;; case-table.el ends here