(find-buffer-file-type-coding-system,
[bpt/emacs.git] / lisp / case-table.el
CommitLineData
c8472948 1;;; case-table.el --- code to extend the character set and support case tables.
e5167999 2
8f1204db 3;; Copyright (C) 1988, 1994 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
cc1cdd74
RS
37(defvar set-case-syntax-offset 0)
38
40f30b63
RS
39(defvar set-case-syntax-set-multibyte nil)
40
3f5ed7e4 41;;;###autoload
a2535589
JA
42(defun describe-buffer-case-table ()
43 "Describe the case table of the current buffer."
44 (interactive)
e6905346
RS
45 (let ((description (make-char-table 'case-table)))
46 (map-char-table
47 (function (lambda (key value)
adfb70a1 48 (aset
e6905346 49 description key
adfb70a1 50 (cond ((not (natnump value))
e6905346
RS
51 "case-invariant")
52 ((/= key (downcase key))
53 (concat "uppercase, matches "
54 (char-to-string (downcase key))))
55 ((/= key (upcase key))
56 (concat "lowercase, matches "
57 (char-to-string (upcase key))))
58 (t "case-invariant")))))
59 (current-case-table))
4536d484
RS
60 (save-excursion
61 (with-output-to-temp-buffer "*Help*"
62 (set-buffer standard-output)
e6905346 63 (describe-vector description)
383669af 64 (help-mode)))))
a2535589 65
e6905346
RS
66;;;###autoload
67(defun copy-case-table (case-table)
68 (let ((copy (copy-sequence case-table)))
69 ;; Clear out the extra slots so that they will be
70 ;; recomputed from the main (downcase) table.
71 (set-char-table-extra-slot copy 0 nil)
72 (set-char-table-extra-slot copy 1 nil)
73 (set-char-table-extra-slot copy 2 nil)
74 copy))
1a7c2dbf 75
c9e83877
RS
76(defsubst set-case-syntax-1 (char)
77 "Offset CHAR by `set-case-syntax-offset' if CHAR is a non-ASCII 8-bit char."
78 (if (and (>= char 128) (< char 256))
79 (+ char set-case-syntax-offset)
80 char))
81
3f5ed7e4 82;;;###autoload
8db3f421 83(defun set-case-syntax-delims (l r table)
a2535589 84 "Make characters L and R a matching pair of non-case-converting delimiters.
8db3f421
RS
85This sets the entries for L and R in TABLE, which is a string
86that will be used as the downcase part of a case table.
f46efdf9 87It also modifies `standard-syntax-table' to
03131799 88indicate left and right delimiters."
c9e83877
RS
89 (setq l (set-case-syntax-1 l))
90 (setq r (set-case-syntax-1 r))
8db3f421
RS
91 (aset table l l)
92 (aset table r r)
e6905346
RS
93 ;; Clear out the extra slots so that they will be
94 ;; recomputed from the main (downcase) table.
95 (set-char-table-extra-slot table 0 nil)
96 (set-char-table-extra-slot table 1 nil)
97 (set-char-table-extra-slot table 2 nil)
a2535589
JA
98 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
99 (standard-syntax-table))
a2535589 100 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
f46efdf9 101 (standard-syntax-table)))
a2535589 102
3f5ed7e4 103;;;###autoload
8db3f421 104(defun set-case-syntax-pair (uc lc table)
a2535589 105 "Make characters UC and LC a pair of inter-case-converting letters.
8db3f421
RS
106This sets the entries for characters UC and LC in TABLE, which is a string
107that will be used as the downcase part of a case table.
f46efdf9
RS
108It also modifies `standard-syntax-table' to give them the syntax of
109word constituents."
c9e83877
RS
110 (setq uc (set-case-syntax-1 uc))
111 (setq lc (set-case-syntax-1 lc))
8db3f421
RS
112 (aset table uc lc)
113 (aset table lc lc)
e6905346
RS
114 (set-char-table-extra-slot table 0 nil)
115 (set-char-table-extra-slot table 1 nil)
116 (set-char-table-extra-slot table 2 nil)
a2535589 117 (modify-syntax-entry lc "w " (standard-syntax-table))
f46efdf9 118 (modify-syntax-entry uc "w " (standard-syntax-table)))
a2535589 119
3f5ed7e4 120;;;###autoload
8db3f421 121(defun set-case-syntax (c syntax table)
1a7c2dbf
KH
122 "Make character C case-invariant with syntax SYNTAX.
123This sets the entry for character C in TABLE, which is a string
8db3f421 124that will be used as the downcase part of a case table.
f46efdf9 125It also modifies `standard-syntax-table'.
a2535589 126SYNTAX should be \" \", \"w\", \".\" or \"_\"."
c9e83877 127 (setq c (set-case-syntax-1 c))
8db3f421 128 (aset table c c)
e6905346
RS
129 (set-char-table-extra-slot table 0 nil)
130 (set-char-table-extra-slot table 1 nil)
131 (set-char-table-extra-slot table 2 nil)
f46efdf9 132 (modify-syntax-entry c syntax (standard-syntax-table)))
a2535589
JA
133
134(provide 'case-table)
c0274f38
ER
135
136;;; case-table.el ends here