annotate lisp/language/tibet-util.el @ 28498:809168962c9b

Provide facilities for inserting space before left parentheses and uncapitalization of identifiers. (glasses-mode): Try to remove old overlays in all cases.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 04 Apr 2000 15:01:53 +0000
parents 55576e0788b1
children 60eb71a9f901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17315
a3ca5e15c82a Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents: 17301
diff changeset
1 ;;; tibet-util.el --- Support for inputting Tibetan characters
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
18377
8b4a66c66dd6 Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 18309
diff changeset
4 ;; Licensed to the Free Software Foundation.
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
5
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
6 ;; Keywords: multilingual, Tibetan
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
7
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
9
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
13 ;; any later version.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
14
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
19
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25 ;; Author: Toru TOMABECHI, <Toru.Tomabechi@orient.unil.ch>
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27 ;; Created: Feb. 17. 1997
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29 ;; History:
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 ;; 1997.03.13 Modification in treatment of text properties;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31 ;; Support for some special signs and punctuations.
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
32 ;; 1999.10.25 Modification for a new composition way by K.Handa.
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 ;;; Code:
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
36 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
37 (defun setup-tibetan-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
38 (interactive)
22987
708271862495 (setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents: 20738
diff changeset
39 (set-language-environment "Tibetan"))
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
40
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
41 ;;;###autoload
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
42 (defun tibetan-char-p (ch)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
43 "Check if char CH is Tibetan character.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
44 Returns non-nil if CH is Tibetan. Otherwise, returns nil."
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
45 (memq (char-charset ch) '(tibetan tibetan-1-column)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
46
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
47 ;;; Functions for Tibetan <-> Tibetan-transcription.
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 ;;;###autoload
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
50 (defun tibetan-tibetan-to-transcription (str)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
51 "Transcribe Tibetan string STR and return the corresponding Roman string."
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
52 (let (;; Accumulate transcriptions here in reverse order.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
53 (trans nil)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
54 (len (length str))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
55 (i 0)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
56 ch this-trans)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
57 (while (< i len)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
58 (let ((idx (string-match tibetan-precomposition-rule-alist str i)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
59 (if (eq idx i)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
60 ;; Ith character and the followings matches precomposable
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
61 ;; Tibetan sequence.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
62 (setq i (match-end 0)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
63 this-trans
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
64 (car (rassoc
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
65 (cdr (assoc (match-string 0 str)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
66 tibetan-precomposition-rule-alist))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
67 tibetan-precomposed-transcription-alist)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
68 (setq ch (substring str i (1+ i))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
69 i (1+ i)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
70 this-trans
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
71 (car (or (rassoc ch tibetan-consonant-transcription-alist)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
72 (rassoc ch tibetan-vowel-transcription-alist)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
73 (rassoc ch tibetan-subjoined-transcription-alist)))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
74 (setq trans (cons this-trans trans))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
75 (apply 'concat (nreverse trans))))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 ;;;###autoload
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
78 (defun tibetan-transcription-to-tibetan (str)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
79 "Convert Tibetan Roman string STR to Tibetan character string.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
80 The returned string has no composition information."
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
81 (let (;; Case is significant.
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 (case-fold-search nil)
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
83 (idx 0)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
84 ;; Accumulate Tibetan strings here in reverse order.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
85 (t-str-list nil)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
86 i subtrans)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
87 (while (setq i (string-match tibetan-regexp str idx))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
88 (if (< idx i)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
89 ;; STR contains a pattern that doesn't match Tibetan
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
90 ;; transcription. Include the pattern as is.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
91 (setq t-str-list (cons (substring str idx i) t-str-list)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
92 (setq subtrans (match-string 0 str)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
93 idx (match-end 0))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
94 (let ((t-char (cdr (assoc subtrans
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
95 tibetan-precomposed-transcription-alist))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
96 (if t-char
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
97 ;; SUBTRANS corresponds to a transcription for
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
98 ;; precomposable Tibetan sequence.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
99 (setq t-char (car (rassoc t-char
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
100 tibetan-precomposition-rule-alist)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
101 (setq t-char
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
102 (cdr
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
103 (or (assoc subtrans tibetan-consonant-transcription-alist)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
104 (assoc subtrans tibetan-vowel-transcription-alist)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
105 (assoc subtrans tibetan-modifier-transcription-alist)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
106 (assoc subtrans tibetan-subjoined-transcription-alist)))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
107 (setq t-str-list (cons t-char t-str-list))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
108 (if (< idx (length str))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
109 (setq t-str-list (cons (substring str idx) t-str-list)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
110 (apply 'concat (nreverse t-str-list))))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 ;;;
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
113 ;;; Functions for composing/decomposing Tibetan sequence.
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 ;;; A Tibetan syllable is typically structured as follows:
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 ;;; [Prefix] C [C+] V [M] [Suffix [Post suffix]]
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119 ;;; where C's are all vertically stacked, V appears below or above
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 ;;; consonant cluster and M is always put above the C[C+]V combination.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121 ;;; (Sanskrit visarga, though it is a vowel modifier, is considered
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 ;;; to be a punctuation.)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 ;;; Here are examples of the words "bsgrubs" and "h'uM"
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 ;;;
28478
55576e0788b1 Fix encoding of the file.
Kenichi Handa <handa@m17n.org>
parents: 26896
diff changeset
126 ;;; 4$(7"70"714%qx!"U0"G###C"U14"70"714"G0"G1(B 4$(7"Hx!#Ax!"Ur'"_0"H"A"U"_1(B
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128 ;;; M
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129 ;;; b s b s h
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130 ;;; g '
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 ;;; r u
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
132 ;;; u
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
133 ;;;
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
134 ;;; Consonants `'' ($(7"A(B), `w' ($(7">(B), `y' ($(7"B(B), `r' ($(7"C(B) take special
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
135 ;;; forms when they are used as subjoined consonant. Consonant `r'
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
136 ;;; takes another special form when used as superjoined in such a case
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
137 ;;; as "rka", while it does not change its form when conjoined with
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
138 ;;; subjoined `'', `w' or `y' as in "rwa", "rya".
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
139
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
140 ;; Append a proper composition rule and glyph to COMPONENTS to compose
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
141 ;; CHAR with a composition that has COMPONENTS.
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
142
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
143 (defun tibetan-add-components (components char)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
144 (let ((last (last components))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
145 (stack-upper '(tc . bc))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
146 (stack-under '(bc . tc))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
147 rule)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
148 ;; Special treatment for 'a chung.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
149 ;; If 'a follows a consonant, turn it into the subjoined form.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
150 (if (and (= char ?$(7"A(B)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
151 (aref (char-category-set (car last)) ?0))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
152 (setq char ?$(7#A(B))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
153
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
154 (cond
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
155 ;; Compose upper vowel sign vertically over.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
156 ((aref (char-category-set char) ?2)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
157 (setq rule stack-upper))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
158
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
159 ;; Compose lower vowel sign vertically under.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
160 ((aref (char-category-set char) ?3)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
161 (setq rule stack-under))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
162
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
163 ;; Transform ra-mgo (superscribed r) if followed by a subjoined
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
164 ;; consonant other than w, ', y, r.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
165 ((and (= (car last) ?$(7"C(B)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
166 (not (memq char '(?$(7#>(B ?$(7#A(B ?$(7#B(B ?$(7#C(B))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
167 (setcar last ?$(7#P(B)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
168 (setq rule stack-under))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
169
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
170 ;; Transform initial base consonant if followed by a subjoined
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
171 ;; consonant but 'a.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
172 (t
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
173 (let ((laststr (char-to-string (car last))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
174 (if (and (/= char ?$(7#A(B)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
175 (string-match "[$(7"!(B-$(7"="?"@"D(B-$(7"J(B]" laststr))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
176 (setcar last (string-to-char
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
177 (cdr (assoc (char-to-string (car last))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
178 tibetan-base-to-subjoined-alist)))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
179 (setq rule stack-under))))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
180
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
181 (setcdr last (list rule char))))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
182
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
183 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
184 (defun tibetan-compose-string (str)
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
185 "Compose Tibetan string STR."
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
186 (let ((idx 0))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
187 ;; `$(7"A(B' is included in the pattern for subjoined consonants
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
188 ;; because we treat it specially in tibetan-add-components.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
189 (while (setq idx (string-match tibetan-composable-pattern str idx))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
190 (let ((from idx)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
191 (to (match-end 0))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
192 components)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
193 (if (eq (string-match tibetan-precomposition-rule-regexp str idx) idx)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
194 (setq idx (match-end 0)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
195 components
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
196 (list (string-to-char
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
197 (cdr
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
198 (assoc (match-string 0 str)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
199 tibetan-precomposition-rule-alist)))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
200 (setq components (list (aref str idx))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
201 idx (1+ idx)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
202 (while (< idx to)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
203 (tibetan-add-components components (aref str idx))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
204 (setq idx (1+ idx)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
205 (compose-string str from to components))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
206 str)
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
207
19553
e63ba5228950 (tibetan-composition): Add autoload cookies.
Kenichi Handa <handa@m17n.org>
parents: 19366
diff changeset
208 ;;;###autoload
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
209 (defun tibetan-compose-region (beg end)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
210 "Compose Tibetan text the region BEG and END."
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
211 (interactive "r")
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
212 (let (str result chars)
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
213 (save-excursion
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
214 (save-restriction
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
215 (narrow-to-region beg end)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
216 (goto-char (point-min))
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
217 ;; `$(7"A(B' is included in the pattern for subjoined consonants
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
218 ;; because we treat it specially in tibetan-add-components.
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
219 (while (re-search-forward tibetan-composable-pattern nil t)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
220 (let ((from (match-beginning 0))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
221 (to (match-end 0))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
222 components)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
223 (goto-char from)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
224 (if (looking-at tibetan-precomposition-rule-regexp)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
225 (progn
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
226 (setq components
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
227 (list (string-to-char
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
228 (cdr
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
229 (assoc (match-string 0)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
230 tibetan-precomposition-rule-alist)))))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
231 (goto-char (match-end 0)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
232 (setq components (list (char-after from)))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
233 (forward-char 1))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
234 (while (< (point) to)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
235 (tibetan-add-components components (following-char))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
236 (forward-char 1))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
237 (compose-region from to components)))))))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
238
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
239 ;;;###autoload
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
240 (defalias 'tibetan-decompose-region 'decompose-region)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
241 ;;;###autoload
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
242 (defalias 'tibetan-decompose-string 'decompose-string)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
243
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
244 ;;;###autoload
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
245 (defun tibetan-composition-function (from to pattern &optional string)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
246 (if string
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
247 (tibetan-compose-string string)
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
248 (tibetan-compose-region from to))
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
249 (- to from))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
250
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
251 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
252 ;;; This variable is used to avoid repeated decomposition.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
253 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
254 (setq-default tibetan-decomposed nil)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
255
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
256 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
257 (defun tibetan-decompose-buffer ()
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
258 "Decomposes Tibetan characters in the buffer into their components.
26896
d48416a42048 Most functions rewritten.
Kenichi Handa <handa@m17n.org>
parents: 24159
diff changeset
259 See also the documentation of the function `tibetan-decompose-region'."
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
260 (interactive)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
261 (make-local-variable 'tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
262 (cond ((not tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
263 (tibetan-decompose-region (point-min) (point-max))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
264 (setq tibetan-decomposed t))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
265
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
266 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
267 (defun tibetan-compose-buffer ()
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
268 "Composes Tibetan character components in the buffer.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
269 See also docstring of the function tibetan-compose-region."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
270 (interactive)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
271 (make-local-variable 'tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
272 (tibetan-compose-region (point-min) (point-max))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
273 (setq tibetan-decomposed nil))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
274
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
275 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
276 (defun tibetan-post-read-conversion (len)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
277 (save-excursion
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
278 (save-restriction
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
279 (let ((buffer-modified-p (buffer-modified-p)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
280 (narrow-to-region (point) (+ (point) len))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
281 (tibetan-compose-region (point-min) (point-max))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
282 (set-buffer-modified-p buffer-modified-p)
20107
4595a463b105 (tibetan-post-read-conversion): Return
Kenichi Handa <handa@m17n.org>
parents: 19553
diff changeset
283 (make-local-variable 'tibetan-decomposed)
4595a463b105 (tibetan-post-read-conversion): Return
Kenichi Handa <handa@m17n.org>
parents: 19553
diff changeset
284 (setq tibetan-decomposed nil)
4595a463b105 (tibetan-post-read-conversion): Return
Kenichi Handa <handa@m17n.org>
parents: 19553
diff changeset
285 (- (point-max) (point-min))))))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
286
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
287
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
288 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
289 (defun tibetan-pre-write-conversion (from to)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
290 (setq tibetan-decomposed-temp tibetan-decomposed)
23522
0f86fe9632e0 (tibetan-pre-write-conversion): Use with-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 22987
diff changeset
291 (let ((old-buf (current-buffer)))
23545
0d25c6f765ab (tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents: 23522
diff changeset
292 (set-buffer (generate-new-buffer " *temp*"))
0d25c6f765ab (tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents: 23522
diff changeset
293 (if (stringp from)
0d25c6f765ab (tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents: 23522
diff changeset
294 (insert from)
0d25c6f765ab (tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents: 23522
diff changeset
295 (insert-buffer-substring old-buf from to))
0d25c6f765ab (tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents: 23522
diff changeset
296 (if (not tibetan-decomposed-temp)
0d25c6f765ab (tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents: 23522
diff changeset
297 (tibetan-decompose-region (point-min) (point-max)))
17776
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
298 ;; Should return nil as annotations.
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
299 nil))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
300
18309
bd8b521f5218 Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents: 17993
diff changeset
301 (provide 'tibet-util)
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
302
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
303 ;;; language/tibet-util.el ends here.