Commit | Line | Data |
---|---|---|
f557c1b1 | 1 | ;;; case-table.el --- code to extend the character set and support case tables -*- lexical-binding: t -*- |
e5167999 | 2 | |
ba318903 | 3 | ;; Copyright (C) 1988, 1994, 2001-2014 Free Software Foundation, Inc. |
3a801d0c | 4 | |
e5167999 | 5 | ;; Author: Howard Gayle |
34dc21db | 6 | ;; Maintainer: emacs-devel@gnu.org |
a1d15b3e | 7 | ;; Keywords: i18n |
bd78fa1d | 8 | ;; Package: emacs |
a2535589 JA |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
eb3fa2cf | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
a2535589 | 13 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
a2535589 JA |
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 | |
eb3fa2cf | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
a2535589 | 24 | |
e5167999 | 25 | ;;; Commentary: |
a2535589 JA |
26 | |
27 | ;; Written by: | |
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 | |
32 | ;; Sweden | |
33 | ||
e5167999 ER |
34 | ;;; Code: |
35 | ||
a2535589 JA |
36 | (defun describe-buffer-case-table () |
37 | "Describe the case table of the current buffer." | |
38 | (interactive) | |
e6905346 RS |
39 | (let ((description (make-char-table 'case-table))) |
40 | (map-char-table | |
41 | (function (lambda (key value) | |
db170c74 KH |
42 | (if (not (natnump value)) |
43 | (if (consp key) | |
44 | (set-char-table-range description key "case-invariant") | |
45 | (aset description key "case-invariant")) | |
46 | (let (from to) | |
47 | (if (consp key) | |
48 | (setq from (car key) to (cdr key)) | |
49 | (setq from (setq to key))) | |
50 | (while (<= from to) | |
51 | (aset | |
52 | description from | |
53 | (cond ((/= from (downcase from)) | |
54 | (concat "uppercase, matches " | |
55 | (char-to-string (downcase from)))) | |
56 | ((/= from (upcase from)) | |
57 | (concat "lowercase, matches " | |
58 | (char-to-string (upcase from)))) | |
59 | (t "case-invariant"))) | |
60 | (setq from (1+ from))))))) | |
e6905346 | 61 | (current-case-table)) |
4536d484 RS |
62 | (save-excursion |
63 | (with-output-to-temp-buffer "*Help*" | |
64 | (set-buffer standard-output) | |
e6905346 | 65 | (describe-vector description) |
383669af | 66 | (help-mode))))) |
a2535589 | 67 | |
f557c1b1 SM |
68 | (defun case-table-get-table (case-table table) |
69 | "Return the TABLE of CASE-TABLE. | |
70 | TABLE can be `down', `up', `eqv' or `canon'." | |
71 | (let ((slot-nb (cdr (assq table '((up . 0) (canon . 1) (eqv . 2)))))) | |
72 | (or (if (eq table 'down) case-table) | |
73 | (char-table-extra-slot case-table slot-nb) | |
74 | ;; Setup all extra slots of CASE-TABLE by temporarily selecting | |
75 | ;; it as the standard case table. | |
76 | (let ((old (standard-case-table))) | |
77 | (unwind-protect | |
78 | (progn | |
79 | (set-standard-case-table case-table) | |
80 | (char-table-extra-slot case-table slot-nb)) | |
81 | (or (eq case-table old) | |
82 | (set-standard-case-table old))))))) | |
83 | ||
e1e89a70 KH |
84 | (defun get-upcase-table (case-table) |
85 | "Return the upcase table of CASE-TABLE." | |
f557c1b1 SM |
86 | (case-table-get-table case-table 'up)) |
87 | (make-obsolete 'get-upcase-table 'case-table-get-table "24.4") | |
e1e89a70 | 88 | |
e6905346 | 89 | (defun copy-case-table (case-table) |
e1e89a70 KH |
90 | (let ((copy (copy-sequence case-table)) |
91 | (up (char-table-extra-slot case-table 0))) | |
92 | ;; Clear out the extra slots (except for upcase table) so that | |
93 | ;; they will be recomputed from the main (downcase) table. | |
94 | (if up | |
95 | (set-char-table-extra-slot copy 0 (copy-sequence up))) | |
e6905346 RS |
96 | (set-char-table-extra-slot copy 1 nil) |
97 | (set-char-table-extra-slot copy 2 nil) | |
98 | copy)) | |
1a7c2dbf | 99 | |
8db3f421 | 100 | (defun set-case-syntax-delims (l r table) |
a2535589 | 101 | "Make characters L and R a matching pair of non-case-converting delimiters. |
8db3f421 RS |
102 | This sets the entries for L and R in TABLE, which is a string |
103 | that will be used as the downcase part of a case table. | |
f46efdf9 | 104 | It also modifies `standard-syntax-table' to |
03131799 | 105 | indicate left and right delimiters." |
8db3f421 RS |
106 | (aset table l l) |
107 | (aset table r r) | |
f557c1b1 | 108 | (let ((up (case-table-get-table table 'up))) |
e1e89a70 KH |
109 | (aset up l l) |
110 | (aset up r r)) | |
e6905346 | 111 | ;; Clear out the extra slots so that they will be |
e1e89a70 | 112 | ;; recomputed from the main (downcase) table and upcase table. |
e6905346 RS |
113 | (set-char-table-extra-slot table 1 nil) |
114 | (set-char-table-extra-slot table 2 nil) | |
a2535589 JA |
115 | (modify-syntax-entry l (concat "(" (char-to-string r) " ") |
116 | (standard-syntax-table)) | |
a2535589 | 117 | (modify-syntax-entry r (concat ")" (char-to-string l) " ") |
f46efdf9 | 118 | (standard-syntax-table))) |
a2535589 | 119 | |
8db3f421 | 120 | (defun set-case-syntax-pair (uc lc table) |
a2535589 | 121 | "Make characters UC and LC a pair of inter-case-converting letters. |
8db3f421 RS |
122 | This sets the entries for characters UC and LC in TABLE, which is a string |
123 | that will be used as the downcase part of a case table. | |
f46efdf9 RS |
124 | It also modifies `standard-syntax-table' to give them the syntax of |
125 | word constituents." | |
8db3f421 RS |
126 | (aset table uc lc) |
127 | (aset table lc lc) | |
f557c1b1 | 128 | (let ((up (case-table-get-table table 'up))) |
2e46e874 KH |
129 | (aset up uc uc) |
130 | (aset up lc uc)) | |
2cf2fc27 | 131 | ;; Clear out the extra slots so that they will be |
2e46e874 KH |
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 | (aset table lc lc) | |
f557c1b1 | 143 | (let ((up (case-table-get-table table 'up))) |
2e46e874 KH |
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 | (aset table uc lc) | |
158 | (aset table lc lc) | |
f557c1b1 | 159 | (let ((up (case-table-get-table table 'up))) |
2e46e874 KH |
160 | (aset up uc uc)) |
161 | ;; Clear out the extra slots so that they will be | |
162 | ;; recomputed from the main (downcase) table and upcase table. | |
e6905346 RS |
163 | (set-char-table-extra-slot table 1 nil) |
164 | (set-char-table-extra-slot table 2 nil) | |
a2535589 | 165 | (modify-syntax-entry lc "w " (standard-syntax-table)) |
f46efdf9 | 166 | (modify-syntax-entry uc "w " (standard-syntax-table))) |
a2535589 | 167 | |
8db3f421 | 168 | (defun set-case-syntax (c syntax table) |
1a7c2dbf KH |
169 | "Make character C case-invariant with syntax SYNTAX. |
170 | This sets the entry for character C in TABLE, which is a string | |
8db3f421 | 171 | that will be used as the downcase part of a case table. |
f46efdf9 | 172 | It also modifies `standard-syntax-table'. |
a2535589 | 173 | SYNTAX should be \" \", \"w\", \".\" or \"_\"." |
8db3f421 | 174 | (aset table c c) |
f557c1b1 | 175 | (let ((up (case-table-get-table table 'up))) |
e1e89a70 | 176 | (aset up c c)) |
2cf2fc27 | 177 | ;; Clear out the extra slots so that they will be |
e1e89a70 | 178 | ;; recomputed from the main (downcase) table and upcase table. |
e6905346 RS |
179 | (set-char-table-extra-slot table 1 nil) |
180 | (set-char-table-extra-slot table 2 nil) | |
f46efdf9 | 181 | (modify-syntax-entry c syntax (standard-syntax-table))) |
a2535589 JA |
182 | |
183 | (provide 'case-table) | |
c0274f38 ER |
184 | |
185 | ;;; case-table.el ends here |