gnus-article-html: Decode contents by charset.
[emacs.git] / lisp / case-table.el
blob1e5974d7d1afa1faccb21a5841f8dd821ef2da16
1 ;;; case-table.el --- code to extend the character set and support case tables
3 ;; Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Howard Gayle
7 ;; Maintainer: FSF
8 ;; Keywords: i18n
9 ;; Package: emacs
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
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.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
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
35 ;;; Code:
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 (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)))))))
62 (current-case-table))
63 (save-excursion
64 (with-output-to-temp-buffer "*Help*"
65 (set-buffer standard-output)
66 (describe-vector description)
67 (help-mode)))))
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))))))
82 (defun copy-case-table (case-table)
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)))
89 (set-char-table-extra-slot copy 1 nil)
90 (set-char-table-extra-slot copy 2 nil)
91 copy))
93 (defun set-case-syntax-delims (l r table)
94 "Make characters L and R a matching pair of non-case-converting delimiters.
95 This sets the entries for L and R in TABLE, which is a string
96 that will be used as the downcase part of a case table.
97 It also modifies `standard-syntax-table' to
98 indicate left and right delimiters."
99 (aset table l l)
100 (aset table r r)
101 (let ((up (get-upcase-table table)))
102 (aset up l l)
103 (aset up r r))
104 ;; Clear out the extra slots so that they will be
105 ;; recomputed from the main (downcase) table and upcase table.
106 (set-char-table-extra-slot table 1 nil)
107 (set-char-table-extra-slot table 2 nil)
108 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
109 (standard-syntax-table))
110 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
111 (standard-syntax-table)))
113 (defun set-case-syntax-pair (uc lc table)
114 "Make characters UC and LC a pair of inter-case-converting letters.
115 This sets the entries for characters UC and LC in TABLE, which is a string
116 that will be used as the downcase part of a case table.
117 It also modifies `standard-syntax-table' to give them the syntax of
118 word constituents."
119 (aset table uc lc)
120 (aset table lc lc)
121 (let ((up (get-upcase-table table)))
122 (aset up uc uc)
123 (aset up lc uc))
124 ;; Clear out the extra slots so that they will be
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)))
131 (defun set-upcase-syntax (uc lc table)
132 "Make character UC an upcase of character LC.
133 It also modifies `standard-syntax-table' to give them the syntax of
134 word 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)))
146 (defun set-downcase-syntax (uc lc table)
147 "Make character LC a downcase of character UC.
148 It also modifies `standard-syntax-table' to give them the syntax of
149 word 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.
156 (set-char-table-extra-slot table 1 nil)
157 (set-char-table-extra-slot table 2 nil)
158 (modify-syntax-entry lc "w " (standard-syntax-table))
159 (modify-syntax-entry uc "w " (standard-syntax-table)))
161 (defun set-case-syntax (c syntax table)
162 "Make character C case-invariant with syntax SYNTAX.
163 This sets the entry for character C in TABLE, which is a string
164 that will be used as the downcase part of a case table.
165 It also modifies `standard-syntax-table'.
166 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
167 (aset table c c)
168 (let ((up (get-upcase-table table)))
169 (aset up c c))
170 ;; Clear out the extra slots so that they will be
171 ;; recomputed from the main (downcase) table and upcase table.
172 (set-char-table-extra-slot table 1 nil)
173 (set-char-table-extra-slot table 2 nil)
174 (modify-syntax-entry c syntax (standard-syntax-table)))
176 (provide 'case-table)
178 ;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
179 ;;; case-table.el ends here