Merge from emacs--devo--0
[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,
d7a0267c 4;; 2005, 2006, 2007 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
a2535589
JA
38(defun describe-buffer-case-table ()
39 "Describe the case table of the current buffer."
40 (interactive)
e6905346
RS
41 (let ((description (make-char-table 'case-table)))
42 (map-char-table
43 (function (lambda (key value)
064808ae
KH
44 (if (consp key)
45 (set-char-table-range description key "case-invariant")
46 (aset
47 description key
48 (cond ((not (natnump value))
49 "case-invariant")
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"))))))
e6905346 57 (current-case-table))
4536d484
RS
58 (save-excursion
59 (with-output-to-temp-buffer "*Help*"
60 (set-buffer standard-output)
e6905346 61 (describe-vector description)
383669af 62 (help-mode)))))
a2535589 63
e1e89a70
KH
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)))
70 (unwind-protect
71 (progn
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))))))
76
e6905346 77(defun copy-case-table (case-table)
e1e89a70
KH
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.
82 (if up
83 (set-char-table-extra-slot copy 0 (copy-sequence up)))
e6905346
RS
84 (set-char-table-extra-slot copy 1 nil)
85 (set-char-table-extra-slot copy 2 nil)
86 copy))
1a7c2dbf 87
8db3f421 88(defun set-case-syntax-delims (l r table)
a2535589 89 "Make characters L and R a matching pair of non-case-converting delimiters.
8db3f421
RS
90This sets the entries for L and R in TABLE, which is a string
91that will be used as the downcase part of a case table.
f46efdf9 92It also modifies `standard-syntax-table' to
03131799 93indicate left and right delimiters."
8db3f421
RS
94 (aset table l l)
95 (aset table r r)
e1e89a70
KH
96 (let ((up (get-upcase-table table)))
97 (aset up l l)
98 (aset up r r))
e6905346 99 ;; Clear out the extra slots so that they will be
e1e89a70 100 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
101 (set-char-table-extra-slot table 1 nil)
102 (set-char-table-extra-slot table 2 nil)
a2535589
JA
103 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
104 (standard-syntax-table))
a2535589 105 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
f46efdf9 106 (standard-syntax-table)))
a2535589 107
8db3f421 108(defun set-case-syntax-pair (uc lc table)
a2535589 109 "Make characters UC and LC a pair of inter-case-converting letters.
8db3f421
RS
110This sets the entries for characters UC and LC in TABLE, which is a string
111that will be used as the downcase part of a case table.
f46efdf9
RS
112It also modifies `standard-syntax-table' to give them the syntax of
113word constituents."
8db3f421
RS
114 (aset table uc lc)
115 (aset table lc lc)
2e46e874
KH
116 (let ((up (get-upcase-table table)))
117 (aset up uc uc)
118 (aset up lc uc))
2cf2fc27 119 ;; Clear out the extra slots so that they will be
2e46e874
KH
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)))
125
126(defun set-upcase-syntax (uc lc table)
127 "Make character UC an upcase of character LC.
128It also modifies `standard-syntax-table' to give them the syntax of
129word constituents."
130 (aset table lc lc)
131 (let ((up (get-upcase-table table)))
132 (aset up uc uc)
133 (aset up lc uc))
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)))
140
141(defun set-downcase-syntax (uc lc table)
142 "Make character LC a downcase of character UC.
143It also modifies `standard-syntax-table' to give them the syntax of
144word constituents."
145 (aset table uc lc)
146 (aset table lc lc)
147 (let ((up (get-upcase-table table)))
148 (aset up uc uc))
149 ;; Clear out the extra slots so that they will be
150 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
151 (set-char-table-extra-slot table 1 nil)
152 (set-char-table-extra-slot table 2 nil)
a2535589 153 (modify-syntax-entry lc "w " (standard-syntax-table))
f46efdf9 154 (modify-syntax-entry uc "w " (standard-syntax-table)))
a2535589 155
8db3f421 156(defun set-case-syntax (c syntax table)
1a7c2dbf
KH
157 "Make character C case-invariant with syntax SYNTAX.
158This sets the entry for character C in TABLE, which is a string
8db3f421 159that will be used as the downcase part of a case table.
f46efdf9 160It also modifies `standard-syntax-table'.
a2535589 161SYNTAX should be \" \", \"w\", \".\" or \"_\"."
8db3f421 162 (aset table c c)
e1e89a70
KH
163 (let ((up (get-upcase-table table)))
164 (aset up c c))
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)
f46efdf9 169 (modify-syntax-entry c syntax (standard-syntax-table)))
a2535589
JA
170
171(provide 'case-table)
c0274f38 172
6b61353c 173;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
c0274f38 174;;; case-table.el ends here