*** empty log message ***
[bpt/emacs.git] / lisp / case-table.el
CommitLineData
55535639 1;;; case-table.el --- code to extend the character set and support case tables
e5167999 2
e91081eb 3;; Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004,
ae940284 4;; 2005, 2006, 2007, 2008, 2009 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
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)
064808ae
KH
42 (if (consp key)
43 (set-char-table-range description key "case-invariant")
44 (aset
45 description key
46 (cond ((not (natnump value))
47 "case-invariant")
48 ((/= key (downcase key))
49 (concat "uppercase, matches "
50 (char-to-string (downcase key))))
51 ((/= key (upcase key))
52 (concat "lowercase, matches "
53 (char-to-string (upcase key))))
54 (t "case-invariant"))))))
e6905346 55 (current-case-table))
4536d484
RS
56 (save-excursion
57 (with-output-to-temp-buffer "*Help*"
58 (set-buffer standard-output)
e6905346 59 (describe-vector description)
383669af 60 (help-mode)))))
a2535589 61
e1e89a70
KH
62(defun get-upcase-table (case-table)
63 "Return the upcase table of CASE-TABLE."
64 (or (char-table-extra-slot case-table 0)
65 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
66 ;; it as the standard case table.
67 (let ((old (standard-case-table)))
68 (unwind-protect
69 (progn
70 (set-standard-case-table case-table)
71 (char-table-extra-slot case-table 0))
72 (or (eq case-table old)
73 (set-standard-case-table old))))))
74
e6905346 75(defun copy-case-table (case-table)
e1e89a70
KH
76 (let ((copy (copy-sequence case-table))
77 (up (char-table-extra-slot case-table 0)))
78 ;; Clear out the extra slots (except for upcase table) so that
79 ;; they will be recomputed from the main (downcase) table.
80 (if up
81 (set-char-table-extra-slot copy 0 (copy-sequence up)))
e6905346
RS
82 (set-char-table-extra-slot copy 1 nil)
83 (set-char-table-extra-slot copy 2 nil)
84 copy))
1a7c2dbf 85
8db3f421 86(defun set-case-syntax-delims (l r table)
a2535589 87 "Make characters L and R a matching pair of non-case-converting delimiters.
8db3f421
RS
88This sets the entries for L and R in TABLE, which is a string
89that will be used as the downcase part of a case table.
f46efdf9 90It also modifies `standard-syntax-table' to
03131799 91indicate left and right delimiters."
8db3f421
RS
92 (aset table l l)
93 (aset table r r)
e1e89a70
KH
94 (let ((up (get-upcase-table table)))
95 (aset up l l)
96 (aset up r r))
e6905346 97 ;; Clear out the extra slots so that they will be
e1e89a70 98 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
99 (set-char-table-extra-slot table 1 nil)
100 (set-char-table-extra-slot table 2 nil)
a2535589
JA
101 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
102 (standard-syntax-table))
a2535589 103 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
f46efdf9 104 (standard-syntax-table)))
a2535589 105
8db3f421 106(defun set-case-syntax-pair (uc lc table)
a2535589 107 "Make characters UC and LC a pair of inter-case-converting letters.
8db3f421
RS
108This sets the entries for characters UC and LC in TABLE, which is a string
109that will be used as the downcase part of a case table.
f46efdf9
RS
110It also modifies `standard-syntax-table' to give them the syntax of
111word constituents."
8db3f421
RS
112 (aset table uc lc)
113 (aset table lc lc)
2e46e874
KH
114 (let ((up (get-upcase-table table)))
115 (aset up uc uc)
116 (aset up lc uc))
2cf2fc27 117 ;; Clear out the extra slots so that they will be
2e46e874
KH
118 ;; recomputed from the main (downcase) table and upcase table.
119 (set-char-table-extra-slot table 1 nil)
120 (set-char-table-extra-slot table 2 nil)
121 (modify-syntax-entry lc "w " (standard-syntax-table))
122 (modify-syntax-entry uc "w " (standard-syntax-table)))
123
124(defun set-upcase-syntax (uc lc table)
125 "Make character UC an upcase of character LC.
126It also modifies `standard-syntax-table' to give them the syntax of
127word constituents."
128 (aset table lc lc)
129 (let ((up (get-upcase-table table)))
130 (aset up uc uc)
131 (aset up lc uc))
132 ;; Clear out the extra slots so that they will be
133 ;; recomputed from the main (downcase) table and upcase table.
134 (set-char-table-extra-slot table 1 nil)
135 (set-char-table-extra-slot table 2 nil)
136 (modify-syntax-entry lc "w " (standard-syntax-table))
137 (modify-syntax-entry uc "w " (standard-syntax-table)))
138
139(defun set-downcase-syntax (uc lc table)
140 "Make character LC a downcase of character UC.
141It also modifies `standard-syntax-table' to give them the syntax of
142word constituents."
143 (aset table uc lc)
144 (aset table lc lc)
145 (let ((up (get-upcase-table table)))
146 (aset up uc uc))
147 ;; Clear out the extra slots so that they will be
148 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
149 (set-char-table-extra-slot table 1 nil)
150 (set-char-table-extra-slot table 2 nil)
a2535589 151 (modify-syntax-entry lc "w " (standard-syntax-table))
f46efdf9 152 (modify-syntax-entry uc "w " (standard-syntax-table)))
a2535589 153
8db3f421 154(defun set-case-syntax (c syntax table)
1a7c2dbf
KH
155 "Make character C case-invariant with syntax SYNTAX.
156This sets the entry for character C in TABLE, which is a string
8db3f421 157that will be used as the downcase part of a case table.
f46efdf9 158It also modifies `standard-syntax-table'.
a2535589 159SYNTAX should be \" \", \"w\", \".\" or \"_\"."
8db3f421 160 (aset table c c)
e1e89a70
KH
161 (let ((up (get-upcase-table table)))
162 (aset up c c))
2cf2fc27 163 ;; Clear out the extra slots so that they will be
e1e89a70 164 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
165 (set-char-table-extra-slot table 1 nil)
166 (set-char-table-extra-slot table 2 nil)
f46efdf9 167 (modify-syntax-entry c syntax (standard-syntax-table)))
a2535589
JA
168
169(provide 'case-table)
c0274f38 170
cbee283d 171;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
c0274f38 172;;; case-table.el ends here