case-table.el 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. ;;; case-table.el --- code to extend the character set and support case tables
  2. ;; Copyright (C) 1988, 1994, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Howard Gayle
  4. ;; Maintainer: FSF
  5. ;; Keywords: i18n
  6. ;; Package: emacs
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; Written by:
  20. ;; TN/ETX/TX/UMG Howard Gayle UUCP : seismo!enea!erix!howard
  21. ;; Telefonaktiebolaget L M Ericsson Phone: +46 8 719 55 65
  22. ;; Ericsson Telecom Telex: 14910 ERIC S
  23. ;; S-126 25 Stockholm FAX : +46 8 719 64 82
  24. ;; Sweden
  25. ;;; Code:
  26. (defun describe-buffer-case-table ()
  27. "Describe the case table of the current buffer."
  28. (interactive)
  29. (let ((description (make-char-table 'case-table)))
  30. (map-char-table
  31. (function (lambda (key value)
  32. (if (not (natnump value))
  33. (if (consp key)
  34. (set-char-table-range description key "case-invariant")
  35. (aset description key "case-invariant"))
  36. (let (from to)
  37. (if (consp key)
  38. (setq from (car key) to (cdr key))
  39. (setq from (setq to key)))
  40. (while (<= from to)
  41. (aset
  42. description from
  43. (cond ((/= from (downcase from))
  44. (concat "uppercase, matches "
  45. (char-to-string (downcase from))))
  46. ((/= from (upcase from))
  47. (concat "lowercase, matches "
  48. (char-to-string (upcase from))))
  49. (t "case-invariant")))
  50. (setq from (1+ from)))))))
  51. (current-case-table))
  52. (save-excursion
  53. (with-output-to-temp-buffer "*Help*"
  54. (set-buffer standard-output)
  55. (describe-vector description)
  56. (help-mode)))))
  57. (defun get-upcase-table (case-table)
  58. "Return the upcase table of CASE-TABLE."
  59. (or (char-table-extra-slot case-table 0)
  60. ;; Setup all extra slots of CASE-TABLE by temporarily selecting
  61. ;; it as the standard case table.
  62. (let ((old (standard-case-table)))
  63. (unwind-protect
  64. (progn
  65. (set-standard-case-table case-table)
  66. (char-table-extra-slot case-table 0))
  67. (or (eq case-table old)
  68. (set-standard-case-table old))))))
  69. (defun copy-case-table (case-table)
  70. (let ((copy (copy-sequence case-table))
  71. (up (char-table-extra-slot case-table 0)))
  72. ;; Clear out the extra slots (except for upcase table) so that
  73. ;; they will be recomputed from the main (downcase) table.
  74. (if up
  75. (set-char-table-extra-slot copy 0 (copy-sequence up)))
  76. (set-char-table-extra-slot copy 1 nil)
  77. (set-char-table-extra-slot copy 2 nil)
  78. copy))
  79. (defun set-case-syntax-delims (l r table)
  80. "Make characters L and R a matching pair of non-case-converting delimiters.
  81. This sets the entries for L and R in TABLE, which is a string
  82. that will be used as the downcase part of a case table.
  83. It also modifies `standard-syntax-table' to
  84. indicate left and right delimiters."
  85. (aset table l l)
  86. (aset table r r)
  87. (let ((up (get-upcase-table table)))
  88. (aset up l l)
  89. (aset up r r))
  90. ;; Clear out the extra slots so that they will be
  91. ;; recomputed from the main (downcase) table and upcase table.
  92. (set-char-table-extra-slot table 1 nil)
  93. (set-char-table-extra-slot table 2 nil)
  94. (modify-syntax-entry l (concat "(" (char-to-string r) " ")
  95. (standard-syntax-table))
  96. (modify-syntax-entry r (concat ")" (char-to-string l) " ")
  97. (standard-syntax-table)))
  98. (defun set-case-syntax-pair (uc lc table)
  99. "Make characters UC and LC a pair of inter-case-converting letters.
  100. This sets the entries for characters UC and LC in TABLE, which is a string
  101. that will be used as the downcase part of a case table.
  102. It also modifies `standard-syntax-table' to give them the syntax of
  103. word constituents."
  104. (aset table uc lc)
  105. (aset table lc lc)
  106. (let ((up (get-upcase-table table)))
  107. (aset up uc uc)
  108. (aset up lc uc))
  109. ;; Clear out the extra slots so that they will be
  110. ;; recomputed from the main (downcase) table and upcase table.
  111. (set-char-table-extra-slot table 1 nil)
  112. (set-char-table-extra-slot table 2 nil)
  113. (modify-syntax-entry lc "w " (standard-syntax-table))
  114. (modify-syntax-entry uc "w " (standard-syntax-table)))
  115. (defun set-upcase-syntax (uc lc table)
  116. "Make character UC an upcase of character LC.
  117. It also modifies `standard-syntax-table' to give them the syntax of
  118. word constituents."
  119. (aset table lc lc)
  120. (let ((up (get-upcase-table table)))
  121. (aset up uc uc)
  122. (aset up lc uc))
  123. ;; Clear out the extra slots so that they will be
  124. ;; recomputed from the main (downcase) table and upcase table.
  125. (set-char-table-extra-slot table 1 nil)
  126. (set-char-table-extra-slot table 2 nil)
  127. (modify-syntax-entry lc "w " (standard-syntax-table))
  128. (modify-syntax-entry uc "w " (standard-syntax-table)))
  129. (defun set-downcase-syntax (uc lc table)
  130. "Make character LC a downcase of character UC.
  131. It also modifies `standard-syntax-table' to give them the syntax of
  132. word constituents."
  133. (aset table uc lc)
  134. (aset table lc lc)
  135. (let ((up (get-upcase-table table)))
  136. (aset up uc uc))
  137. ;; Clear out the extra slots so that they will be
  138. ;; recomputed from the main (downcase) table and upcase table.
  139. (set-char-table-extra-slot table 1 nil)
  140. (set-char-table-extra-slot table 2 nil)
  141. (modify-syntax-entry lc "w " (standard-syntax-table))
  142. (modify-syntax-entry uc "w " (standard-syntax-table)))
  143. (defun set-case-syntax (c syntax table)
  144. "Make character C case-invariant with syntax SYNTAX.
  145. This sets the entry for character C in TABLE, which is a string
  146. that will be used as the downcase part of a case table.
  147. It also modifies `standard-syntax-table'.
  148. SYNTAX should be \" \", \"w\", \".\" or \"_\"."
  149. (aset table c c)
  150. (let ((up (get-upcase-table table)))
  151. (aset up c c))
  152. ;; Clear out the extra slots so that they will be
  153. ;; recomputed from the main (downcase) table and upcase table.
  154. (set-char-table-extra-slot table 1 nil)
  155. (set-char-table-extra-slot table 2 nil)
  156. (modify-syntax-entry c syntax (standard-syntax-table)))
  157. (provide 'case-table)
  158. ;;; case-table.el ends here