]> code.delx.au - gnu-emacs/blob - lisp/case-table.el
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-25
[gnu-emacs] / lisp / case-table.el
1 ;;; case-table.el --- code to extend the character set and support case tables
2
3 ;; Copyright (C) 1988, 1994, 2005 Free Software Foundation, Inc.
4
5 ;; Author: Howard Gayle
6 ;; Maintainer: FSF
7 ;; Keywords: i18n
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
13 ;; the Free Software Foundation; either version 2, or (at your option)
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
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.
25
26 ;;; Commentary:
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
35 ;;; Code:
36
37 (defun describe-buffer-case-table ()
38 "Describe the case table of the current buffer."
39 (interactive)
40 (let ((description (make-char-table 'case-table)))
41 (map-char-table
42 (function (lambda (key value)
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"))))))
56 (current-case-table))
57 (save-excursion
58 (with-output-to-temp-buffer "*Help*"
59 (set-buffer standard-output)
60 (describe-vector description)
61 (help-mode)))))
62
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
76 (defun copy-case-table (case-table)
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)))
83 (set-char-table-extra-slot copy 1 nil)
84 (set-char-table-extra-slot copy 2 nil)
85 copy))
86
87 (defun set-case-syntax-delims (l r table)
88 "Make characters L and R a matching pair of non-case-converting delimiters.
89 This sets the entries for L and R in TABLE, which is a string
90 that will be used as the downcase part of a case table.
91 It also modifies `standard-syntax-table' to
92 indicate left and right delimiters."
93 (aset table l l)
94 (aset table r r)
95 (let ((up (get-upcase-table table)))
96 (aset up l l)
97 (aset up r r))
98 ;; Clear out the extra slots so that they will be
99 ;; recomputed from the main (downcase) table and upcase table.
100 (set-char-table-extra-slot table 1 nil)
101 (set-char-table-extra-slot table 2 nil)
102 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
103 (standard-syntax-table))
104 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
105 (standard-syntax-table)))
106
107 (defun set-case-syntax-pair (uc lc table)
108 "Make characters UC and LC a pair of inter-case-converting letters.
109 This sets the entries for characters UC and LC in TABLE, which is a string
110 that will be used as the downcase part of a case table.
111 It also modifies `standard-syntax-table' to give them the syntax of
112 word constituents."
113 (aset table uc lc)
114 (aset table lc lc)
115 (let ((up (get-upcase-table table)))
116 (aset up uc uc)
117 (aset up lc uc))
118 ;; Clear out the extra slots so that they will be
119 ;; recomputed from the main (downcase) table and upcase table.
120 (set-char-table-extra-slot table 1 nil)
121 (set-char-table-extra-slot table 2 nil)
122 (modify-syntax-entry lc "w " (standard-syntax-table))
123 (modify-syntax-entry uc "w " (standard-syntax-table)))
124
125 (defun set-upcase-syntax (uc lc table)
126 "Make character UC an upcase of character LC.
127 It also modifies `standard-syntax-table' to give them the syntax of
128 word constituents."
129 (aset table lc lc)
130 (let ((up (get-upcase-table table)))
131 (aset up uc uc)
132 (aset up lc uc))
133 ;; Clear out the extra slots so that they will be
134 ;; recomputed from the main (downcase) table and upcase table.
135 (set-char-table-extra-slot table 1 nil)
136 (set-char-table-extra-slot table 2 nil)
137 (modify-syntax-entry lc "w " (standard-syntax-table))
138 (modify-syntax-entry uc "w " (standard-syntax-table)))
139
140 (defun set-downcase-syntax (uc lc table)
141 "Make character LC a downcase of character UC.
142 It also modifies `standard-syntax-table' to give them the syntax of
143 word constituents."
144 (aset table uc lc)
145 (aset table lc lc)
146 (let ((up (get-upcase-table table)))
147 (aset up uc uc))
148 ;; Clear out the extra slots so that they will be
149 ;; recomputed from the main (downcase) table and upcase table.
150 (set-char-table-extra-slot table 1 nil)
151 (set-char-table-extra-slot table 2 nil)
152 (modify-syntax-entry lc "w " (standard-syntax-table))
153 (modify-syntax-entry uc "w " (standard-syntax-table)))
154
155 (defun set-case-syntax (c syntax table)
156 "Make character C case-invariant with syntax SYNTAX.
157 This sets the entry for character C in TABLE, which is a string
158 that will be used as the downcase part of a case table.
159 It also modifies `standard-syntax-table'.
160 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
161 (aset table c c)
162 (let ((up (get-upcase-table table)))
163 (aset up c c))
164 ;; Clear out the extra slots so that they will be
165 ;; recomputed from the main (downcase) table and upcase table.
166 (set-char-table-extra-slot table 1 nil)
167 (set-char-table-extra-slot table 2 nil)
168 (modify-syntax-entry c syntax (standard-syntax-table)))
169
170 (provide 'case-table)
171
172 ;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
173 ;;; case-table.el ends here