Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-11
[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
e1e89a70 3;; Copyright (C) 1988, 1994, 2005 Free Software Foundation, Inc.
3a801d0c 4
e5167999
ER
5;; Author: Howard Gayle
6;; Maintainer: FSF
a1d15b3e 7;; Keywords: i18n
a2535589
JA
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
a2535589
JA
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
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)
064808ae
KH
43 (if (consp key)
44 (set-char-table-range description key "case-invariant")
45 (aset
46 description key
47 (cond ((not (natnump value))
48 "case-invariant")
49 ((/= key (downcase key))
50 (concat "uppercase, matches "
51 (char-to-string (downcase key))))
52 ((/= key (upcase key))
53 (concat "lowercase, matches "
54 (char-to-string (upcase key))))
55 (t "case-invariant"))))))
e6905346 56 (current-case-table))
4536d484
RS
57 (save-excursion
58 (with-output-to-temp-buffer "*Help*"
59 (set-buffer standard-output)
e6905346 60 (describe-vector description)
383669af 61 (help-mode)))))
a2535589 62
e1e89a70
KH
63(defun get-upcase-table (case-table)
64 "Return the upcase table of CASE-TABLE."
65 (or (char-table-extra-slot case-table 0)
66 ;; Setup all extra slots of CASE-TABLE by temporarily selecting
67 ;; it as the standard case table.
68 (let ((old (standard-case-table)))
69 (unwind-protect
70 (progn
71 (set-standard-case-table case-table)
72 (char-table-extra-slot case-table 0))
73 (or (eq case-table old)
74 (set-standard-case-table old))))))
75
e6905346 76(defun copy-case-table (case-table)
e1e89a70
KH
77 (let ((copy (copy-sequence case-table))
78 (up (char-table-extra-slot case-table 0)))
79 ;; Clear out the extra slots (except for upcase table) so that
80 ;; they will be recomputed from the main (downcase) table.
81 (if up
82 (set-char-table-extra-slot copy 0 (copy-sequence up)))
e6905346
RS
83 (set-char-table-extra-slot copy 1 nil)
84 (set-char-table-extra-slot copy 2 nil)
85 copy))
1a7c2dbf 86
8db3f421 87(defun set-case-syntax-delims (l r table)
a2535589 88 "Make characters L and R a matching pair of non-case-converting delimiters.
8db3f421
RS
89This sets the entries for L and R in TABLE, which is a string
90that will be used as the downcase part of a case table.
f46efdf9 91It also modifies `standard-syntax-table' to
03131799 92indicate left and right delimiters."
8db3f421
RS
93 (aset table l l)
94 (aset table r r)
e1e89a70
KH
95 (let ((up (get-upcase-table table)))
96 (aset up l l)
97 (aset up r r))
e6905346 98 ;; Clear out the extra slots so that they will be
e1e89a70 99 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
100 (set-char-table-extra-slot table 1 nil)
101 (set-char-table-extra-slot table 2 nil)
a2535589
JA
102 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
103 (standard-syntax-table))
a2535589 104 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
f46efdf9 105 (standard-syntax-table)))
a2535589 106
8db3f421 107(defun set-case-syntax-pair (uc lc table)
a2535589 108 "Make characters UC and LC a pair of inter-case-converting letters.
8db3f421
RS
109This sets the entries for characters UC and LC in TABLE, which is a string
110that will be used as the downcase part of a case table.
f46efdf9
RS
111It also modifies `standard-syntax-table' to give them the syntax of
112word constituents."
8db3f421
RS
113 (aset table uc lc)
114 (aset table lc lc)
2cf2fc27
RS
115 ;; Clear out the extra slots so that they will be
116 ;; recomputed from the main (downcase) table.
e6905346
RS
117 (set-char-table-extra-slot table 0 nil)
118 (set-char-table-extra-slot table 1 nil)
119 (set-char-table-extra-slot table 2 nil)
a2535589 120 (modify-syntax-entry lc "w " (standard-syntax-table))
f46efdf9 121 (modify-syntax-entry uc "w " (standard-syntax-table)))
a2535589 122
8db3f421 123(defun set-case-syntax (c syntax table)
1a7c2dbf
KH
124 "Make character C case-invariant with syntax SYNTAX.
125This sets the entry for character C in TABLE, which is a string
8db3f421 126that will be used as the downcase part of a case table.
f46efdf9 127It also modifies `standard-syntax-table'.
a2535589 128SYNTAX should be \" \", \"w\", \".\" or \"_\"."
8db3f421 129 (aset table c c)
e1e89a70
KH
130 (let ((up (get-upcase-table table)))
131 (aset up c c))
2cf2fc27 132 ;; Clear out the extra slots so that they will be
e1e89a70 133 ;; recomputed from the main (downcase) table and upcase table.
e6905346
RS
134 (set-char-table-extra-slot table 1 nil)
135 (set-char-table-extra-slot table 2 nil)
f46efdf9 136 (modify-syntax-entry c syntax (standard-syntax-table)))
a2535589
JA
137
138(provide 'case-table)
c0274f38 139
6b61353c 140;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
c0274f38 141;;; case-table.el ends here