Sync to HEAD
[bpt/emacs.git] / lisp / case-table.el
1 ;;; case-table.el --- code to extend the character set and support case tables
2
3 ;; Copyright (C) 1988, 1994 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 copy-case-table (case-table)
64 (let ((copy (copy-sequence case-table)))
65 ;; Clear out the extra slots so that they will be
66 ;; recomputed from the main (downcase) table.
67 (set-char-table-extra-slot copy 0 nil)
68 (set-char-table-extra-slot copy 1 nil)
69 (set-char-table-extra-slot copy 2 nil)
70 copy))
71
72 (defun set-case-syntax-delims (l r table)
73 "Make characters L and R a matching pair of non-case-converting delimiters.
74 This sets the entries for L and R in TABLE, which is a string
75 that will be used as the downcase part of a case table.
76 It also modifies `standard-syntax-table' to
77 indicate left and right delimiters."
78 (aset table l l)
79 (aset table r r)
80 ;; Clear out the extra slots so that they will be
81 ;; recomputed from the main (downcase) table.
82 (set-char-table-extra-slot table 0 nil)
83 (set-char-table-extra-slot table 1 nil)
84 (set-char-table-extra-slot table 2 nil)
85 (modify-syntax-entry l (concat "(" (char-to-string r) " ")
86 (standard-syntax-table))
87 (modify-syntax-entry r (concat ")" (char-to-string l) " ")
88 (standard-syntax-table)))
89
90 (defun set-case-syntax-pair (uc lc table)
91 "Make characters UC and LC a pair of inter-case-converting letters.
92 This sets the entries for characters UC and LC in TABLE, which is a string
93 that will be used as the downcase part of a case table.
94 It also modifies `standard-syntax-table' to give them the syntax of
95 word constituents."
96 (aset table uc lc)
97 (aset table lc lc)
98 (set-char-table-extra-slot table 0 nil)
99 (set-char-table-extra-slot table 1 nil)
100 (set-char-table-extra-slot table 2 nil)
101 (modify-syntax-entry lc "w " (standard-syntax-table))
102 (modify-syntax-entry uc "w " (standard-syntax-table)))
103
104 (defun set-case-syntax (c syntax table)
105 "Make character C case-invariant with syntax SYNTAX.
106 This sets the entry for character C in TABLE, which is a string
107 that will be used as the downcase part of a case table.
108 It also modifies `standard-syntax-table'.
109 SYNTAX should be \" \", \"w\", \".\" or \"_\"."
110 (aset table c c)
111 (set-char-table-extra-slot table 0 nil)
112 (set-char-table-extra-slot table 1 nil)
113 (set-char-table-extra-slot table 2 nil)
114 (modify-syntax-entry c syntax (standard-syntax-table)))
115
116 (provide 'case-table)
117
118 ;;; arch-tag: 3c2cf885-2c9a-449a-9972-2e269191896d
119 ;;; case-table.el ends here