Commit | Line | Data |
---|---|---|
55535639 | 1 | ;;; case-table.el --- code to extend the character set and support case tables |
e5167999 | 2 | |
0d30b337 | 3 | ;; Copyright (C) 1988, 1994, 2002, 2003, 2004, |
aaef169d | 4 | ;; 2005, 2006 Free Software Foundation, Inc. |
3a801d0c | 5 | |
e5167999 ER |
6 | ;; Author: Howard Gayle |
7 | ;; Maintainer: FSF | |
a1d15b3e | 8 | ;; Keywords: i18n |
a2535589 JA |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
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 | |
e5167999 | 14 | ;; the Free Software Foundation; either version 2, or (at your option) |
a2535589 JA |
15 | ;; any later version. |
16 | ||
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. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
b578f267 | 23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
086add15 LK |
24 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | ;; Boston, MA 02110-1301, USA. | |
a2535589 | 26 | |
e5167999 | 27 | ;;; Commentary: |
a2535589 JA |
28 | |
29 | ;; Written by: | |
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 | |
34 | ;; Sweden | |
35 | ||
e5167999 ER |
36 | ;;; Code: |
37 | ||
cc1cdd74 RS |
38 | (defvar set-case-syntax-offset 0) |
39 | ||
40f30b63 RS |
40 | (defvar set-case-syntax-set-multibyte nil) |
41 | ||
a2535589 JA |
42 | (defun describe-buffer-case-table () |
43 | "Describe the case table of the current buffer." | |
44 | (interactive) | |
e6905346 RS |
45 | (let ((description (make-char-table 'case-table))) |
46 | (map-char-table | |
47 | (function (lambda (key value) | |
adfb70a1 | 48 | (aset |
e6905346 | 49 | description key |
adfb70a1 | 50 | (cond ((not (natnump value)) |
e6905346 RS |
51 | "case-invariant") |
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"))))) | |
59 | (current-case-table)) | |
4536d484 RS |
60 | (save-excursion |
61 | (with-output-to-temp-buffer "*Help*" | |
62 | (set-buffer standard-output) | |
e6905346 | 63 | (describe-vector description) |
383669af | 64 | (help-mode))))) |
a2535589 | 65 | |
e1e89a70 KH |
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))) | |
72 | (unwind-protect | |
73 | (progn | |
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)))))) | |
78 | ||
e6905346 | 79 | (defun copy-case-table (case-table) |
e1e89a70 KH |
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. | |
84 | (if up | |
85 | (set-char-table-extra-slot copy 0 (copy-sequence up))) | |
e6905346 RS |
86 | (set-char-table-extra-slot copy 1 nil) |
87 | (set-char-table-extra-slot copy 2 nil) | |
88 | copy)) | |
1a7c2dbf | 89 | |
c9e83877 RS |
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) | |
94 | char)) | |
95 | ||
8db3f421 | 96 | (defun set-case-syntax-delims (l r table) |
a2535589 | 97 | "Make characters L and R a matching pair of non-case-converting delimiters. |
8db3f421 RS |
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. | |
f46efdf9 | 100 | It also modifies `standard-syntax-table' to |
03131799 | 101 | indicate left and right delimiters." |
c9e83877 RS |
102 | (setq l (set-case-syntax-1 l)) |
103 | (setq r (set-case-syntax-1 r)) | |
8db3f421 RS |
104 | (aset table l l) |
105 | (aset table r r) | |
e1e89a70 KH |
106 | (let ((up (get-upcase-table table))) |
107 | (aset up l l) | |
108 | (aset up r r)) | |
e6905346 | 109 | ;; Clear out the extra slots so that they will be |
e1e89a70 | 110 | ;; recomputed from the main (downcase) table and upcase table. |
e6905346 RS |
111 | (set-char-table-extra-slot table 1 nil) |
112 | (set-char-table-extra-slot table 2 nil) | |
a2535589 JA |
113 | (modify-syntax-entry l (concat "(" (char-to-string r) " ") |
114 | (standard-syntax-table)) | |
a2535589 | 115 | (modify-syntax-entry r (concat ")" (char-to-string l) " ") |
f46efdf9 | 116 | (standard-syntax-table))) |
a2535589 | 117 | |
8db3f421 | 118 | (defun set-case-syntax-pair (uc lc table) |
a2535589 | 119 | "Make characters UC and LC a pair of inter-case-converting letters. |
8db3f421 RS |
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. | |
f46efdf9 RS |
122 | It also modifies `standard-syntax-table' to give them the syntax of |
123 | word constituents." | |
e1e89a70 KH |
124 | (setq uc (set-case-syntax-1 uc)) |
125 | (setq lc (set-case-syntax-1 lc)) | |
126 | (aset table uc lc) | |
127 | (aset table lc lc) | |
128 | (let ((up (get-upcase-table table))) | |
129 | (aset up uc uc) | |
130 | (aset up lc uc)) | |
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))) | |
137 | ||
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 | |
141 | word constituents." | |
142 | (setq uc (set-case-syntax-1 uc)) | |
143 | (setq lc (set-case-syntax-1 lc)) | |
9afd1c3c | 144 | (aset table lc lc) |
e1e89a70 KH |
145 | (let ((up (get-upcase-table table))) |
146 | (aset up uc uc) | |
147 | (aset up lc uc)) | |
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))) | |
154 | ||
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 | |
158 | word constituents." | |
c9e83877 RS |
159 | (setq uc (set-case-syntax-1 uc)) |
160 | (setq lc (set-case-syntax-1 lc)) | |
8db3f421 RS |
161 | (aset table uc lc) |
162 | (aset table lc lc) | |
9afd1c3c KH |
163 | (let ((up (get-upcase-table table))) |
164 | (aset up uc uc)) | |
2cf2fc27 | 165 | ;; Clear out the extra slots so that they will be |
e1e89a70 | 166 | ;; recomputed from the main (downcase) table and upcase table. |
e6905346 RS |
167 | (set-char-table-extra-slot table 1 nil) |
168 | (set-char-table-extra-slot table 2 nil) | |
a2535589 | 169 | (modify-syntax-entry lc "w " (standard-syntax-table)) |
f46efdf9 | 170 | (modify-syntax-entry uc "w " (standard-syntax-table))) |
a2535589 | 171 | |
8db3f421 | 172 | (defun set-case-syntax (c syntax table) |
1a7c2dbf KH |
173 | "Make character C case-invariant with syntax SYNTAX. |
174 | This sets the entry for character C in TABLE, which is a string | |
8db3f421 | 175 | that will be used as the downcase part of a case table. |
f46efdf9 | 176 | It also modifies `standard-syntax-table'. |
a2535589 | 177 | SYNTAX should be \" \", \"w\", \".\" or \"_\"." |
c9e83877 | 178 | (setq c (set-case-syntax-1 c)) |
8db3f421 | 179 | (aset table c c) |
e1e89a70 KH |
180 | (let ((up (get-upcase-table table))) |
181 | (aset up c c)) | |
2cf2fc27 | 182 | ;; Clear out the extra slots so that they will be |
e1e89a70 | 183 | ;; recomputed from the main (downcase) table and upcase table. |
e6905346 RS |
184 | (set-char-table-extra-slot table 1 nil) |
185 | (set-char-table-extra-slot table 2 nil) | |
f46efdf9 | 186 | (modify-syntax-entry c syntax (standard-syntax-table))) |
a2535589 JA |
187 | |
188 | (provide 'case-table) | |
c0274f38 | 189 | |
ab5796a9 | 190 | ;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d |
c0274f38 | 191 | ;;; case-table.el ends here |