Add "Package:" file headers to denote built-in packages.
[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,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3a801d0c 5
e5167999
ER
6;; Author: Howard Gayle
7;; Maintainer: FSF
a1d15b3e 8;; Keywords: i18n
bd78fa1d 9;; Package: emacs
a2535589
JA
10
11;; This file is part of GNU Emacs.
12
eb3fa2cf 13;; GNU Emacs is free software: you can redistribute it and/or modify
a2535589 14;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
a2535589
JA
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
eb3fa2cf 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a2535589 25
e5167999 26;;; Commentary:
a2535589
JA
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
e5167999
ER
35;;; Code:
36
a2535589
JA
37(defun describe-buffer-case-table ()
38 "Describe the case table of the current buffer."
39 (interactive)
e6905346
RS
40 (let ((description (make-char-table 'case-table)))
41 (map-char-table
42 (function (lambda (key value)
db170c74
KH
43 (if (not (natnump value))
44 (if (consp key)
45 (set-char-table-range description key "case-invariant")
46 (aset description key "case-invariant"))
47 (let (from to)
48 (if (consp key)
49 (setq from (car key) to (cdr key))
50 (setq from (setq to key)))
51 (while (<= from to)
52 (aset
53 description from
54 (cond ((/= from (downcase from))
55 (concat "uppercase, matches "
56 (char-to-string (downcase from))))
57 ((/= from (upcase from))
58 (concat "lowercase, matches "
59 (char-to-string (upcase from))))
60 (t "case-invariant")))
61 (setq from (1+ from)))))))
e6905346 62 (current-case-table))
4536d484
RS
63 (save-excursion
64 (with-output-to-temp-buffer "*Help*"
65 (set-buffer standard-output)
e6905346 66 (describe-vector description)
383669af 67 (help-mode)))))
a2535589 68
e1e89a70
KH
69(defun get-upcase-table (case-table)
70 "Return the upcase table of CASE-TABLE."
71 (or (char-table-extra-slot case-table 0)
72 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
73 ;; it as the standard case table.
74 (let ((old (standard-case-table)))
75 (unwind-protect
76 (progn
77 (set-standard-case-table case-table)
78 (char-table-extra-slot case-table 0))
79 (or (eq case-table old)
80 (set-standard-case-table old))))))
81
e6905346 82(defun copy-case-table (case-table)
e1e89a70
KH
83 (let ((copy (copy-sequence case-table))
84 (up (char-table-extra-slot case-table 0)))
85 ;; Clear out the extra slots (except for upcase table) so that
86 ;; they will be recomputed from the main (downcase) table.
87 (if up
88 (set-char-table-extra-slot copy 0 (copy-sequence up)))
e6905346
RS
89 (set-char-table-extra-slot copy 1 nil)
90 (set-char-table-extra-slot copy 2 nil)
91 copy))
1a7c2dbf 92
8db3f421 93(defun set-case-syntax-delims (l r table)
a2535589 94 "Make characters L and R a matching pair of non-case-converting delimiters.
8db3f421
RS
95This sets the entries for L and R in TABLE, which is a string
96that will be used as the downcase part of a case table.
f46efdf9 97It also modifies `standard-syntax-table' to
03131799 98indicate left and right delimiters."
8db3f421
RS
99 (aset table l l)
100 (aset table r r)
e1e89a70
KH
101 (let ((up (get-upcase-table table)))
102 (aset up l l)
103 (aset up r r))
e6905346 104 ;; Clear out the extra slots so that they will be
e1e89a70 105 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
106 (set-char-table-extra-slot table 1 nil)
107 (set-char-table-extra-slot table 2 nil)
a2535589
JA
108 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
109 (standard-syntax-table))
a2535589 110 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
f46efdf9 111 (standard-syntax-table)))
a2535589 112
8db3f421 113(defun set-case-syntax-pair (uc lc table)
a2535589 114 "Make characters UC and LC a pair of inter-case-converting letters.
8db3f421
RS
115This sets the entries for characters UC and LC in TABLE, which is a string
116that will be used as the downcase part of a case table.
f46efdf9
RS
117It also modifies `standard-syntax-table' to give them the syntax of
118word constituents."
8db3f421
RS
119 (aset table uc lc)
120 (aset table lc lc)
2e46e874
KH
121 (let ((up (get-upcase-table table)))
122 (aset up uc uc)
123 (aset up lc uc))
2cf2fc27 124 ;; Clear out the extra slots so that they will be
2e46e874
KH
125 ;; recomputed from the main (downcase) table and upcase table.
126 (set-char-table-extra-slot table 1 nil)
127 (set-char-table-extra-slot table 2 nil)
128 (modify-syntax-entry lc "w " (standard-syntax-table))
129 (modify-syntax-entry uc "w " (standard-syntax-table)))
130
131(defun set-upcase-syntax (uc lc table)
132 "Make character UC an upcase of character LC.
133It also modifies `standard-syntax-table' to give them the syntax of
134word constituents."
135 (aset table lc lc)
136 (let ((up (get-upcase-table table)))
137 (aset up uc uc)
138 (aset up lc uc))
139 ;; Clear out the extra slots so that they will be
140 ;; recomputed from the main (downcase) table and upcase table.
141 (set-char-table-extra-slot table 1 nil)
142 (set-char-table-extra-slot table 2 nil)
143 (modify-syntax-entry lc "w " (standard-syntax-table))
144 (modify-syntax-entry uc "w " (standard-syntax-table)))
145
146(defun set-downcase-syntax (uc lc table)
147 "Make character LC a downcase of character UC.
148It also modifies `standard-syntax-table' to give them the syntax of
149word constituents."
150 (aset table uc lc)
151 (aset table lc lc)
152 (let ((up (get-upcase-table table)))
153 (aset up uc uc))
154 ;; Clear out the extra slots so that they will be
155 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
156 (set-char-table-extra-slot table 1 nil)
157 (set-char-table-extra-slot table 2 nil)
a2535589 158 (modify-syntax-entry lc "w " (standard-syntax-table))
f46efdf9 159 (modify-syntax-entry uc "w " (standard-syntax-table)))
a2535589 160
8db3f421 161(defun set-case-syntax (c syntax table)
1a7c2dbf
KH
162 "Make character C case-invariant with syntax SYNTAX.
163This sets the entry for character C in TABLE, which is a string
8db3f421 164that will be used as the downcase part of a case table.
f46efdf9 165It also modifies `standard-syntax-table'.
a2535589 166SYNTAX should be \" \", \"w\", \".\" or \"_\"."
8db3f421 167 (aset table c c)
e1e89a70
KH
168 (let ((up (get-upcase-table table)))
169 (aset up c c))
2cf2fc27 170 ;; Clear out the extra slots so that they will be
e1e89a70 171 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
172 (set-char-table-extra-slot table 1 nil)
173 (set-char-table-extra-slot table 2 nil)
f46efdf9 174 (modify-syntax-entry c syntax (standard-syntax-table)))
a2535589
JA
175
176(provide 'case-table)
c0274f38 177
cbee283d 178;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
c0274f38 179;;; case-table.el ends here