Mercurial > emacs
annotate lisp/language/tibet-util.el @ 61351:e537b7c0d529
Move to the obsolete subdir.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 06 Apr 2005 14:06:27 +0000 |
parents | 695cf19ef79e |
children | 197607499a29 375f2633d815 |
rev | line source |
---|---|
36685 | 1 ;;; tibet-util.el --- utilities for Tibetan -*- coding: iso-2022-7bit; -*- |
17301 | 2 |
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 | 5 |
6 ;; Keywords: multilingual, Tibetan | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;; Author: Toru TOMABECHI, <Toru.Tomabechi@orient.unil.ch> | |
26 | |
27 ;; Created: Feb. 17. 1997 | |
28 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36685
diff
changeset
|
29 ;;; History: |
17301 | 30 ;; 1997.03.13 Modification in treatment of text properties; |
31 ;; Support for some special signs and punctuations. | |
26896 | 32 ;; 1999.10.25 Modification for a new composition way by K.Handa. |
17301 | 33 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36685
diff
changeset
|
34 ;;; Commentary: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36685
diff
changeset
|
35 |
17301 | 36 ;;; Code: |
37 | |
45032
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
38 (defconst tibetan-obsolete-glyphs |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
39 `(("$(7!=(B" . "$(8!=(B") ; 2 col <-> 1 col |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
40 ("$(7!?(B" . "$(8!?(B") |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
41 ("$(7!@(B" . "$(8!@(B") |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
42 ("$(7!A(B" . "$(8!A(B") |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
43 ("$(7"`(B" . "$(8"`(B") |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
44 ("$(7!;(B" . "$(8!;(B") |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
45 ("$(7!D(B" . "$(8!D(B") |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
46 ;; Yes these are dirty. But ... |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
47 ("$(7!>(B $(7!>(B" . ,(compose-string "$(7!>(B $(7!>(B" 0 3 [?$(7!>(B (Br . Bl) ? (Br . Bl) ?$(7!>(B])) |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
48 ("$(7!4!5!5(B" . ,(compose-string |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
49 "$(7#R#S#S#S(B" 0 4 |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
50 [?$(7#R(B (Br . Bl) ?$(7#S(B (Br . Bl) ?$(7#S(B (Br . Bl) ?$(7#S(B])) |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
51 ("$(7!4!5(B" . ,(compose-string "$(7#R#S#S(B" 0 3 [?$(7#R(B (Br . Bl) ?$(7#S(B (Br . Bl) ?$(7#S(B])) |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
52 ("$(7!6(B" . ,(compose-string "$(7#R#S!I(B" 0 3 [?$(7#R(B (Br . Bl) ?$(7#S(B (br . tr) ?$(7!I(B])) |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
53 ("$(7!4(B" . ,(compose-string "$(7#R#S(B" 0 2 [?$(7#R(B (Br . Bl) ?$(7#S(B])))) |
29a7076e3736
(tibetan-obsolete-glyphs): From tibetan.el.
Richard M. Stallman <rms@gnu.org>
parents:
42839
diff
changeset
|
54 |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17776
diff
changeset
|
55 ;;;###autoload |
26896 | 56 (defun tibetan-char-p (ch) |
57 "Check if char CH is Tibetan character. | |
58 Returns non-nil if CH is Tibetan. Otherwise, returns nil." | |
59 (memq (char-charset ch) '(tibetan tibetan-1-column))) | |
60 | |
61 ;;; Functions for Tibetan <-> Tibetan-transcription. | |
17301 | 62 |
63 ;;;###autoload | |
26896 | 64 (defun tibetan-tibetan-to-transcription (str) |
65 "Transcribe Tibetan string STR and return the corresponding Roman string." | |
66 (let (;; Accumulate transcriptions here in reverse order. | |
67 (trans nil) | |
68 (len (length str)) | |
69 (i 0) | |
70 ch this-trans) | |
71 (while (< i len) | |
29828 | 72 (let ((idx (string-match tibetan-precomposition-rule-regexp str i))) |
26896 | 73 (if (eq idx i) |
74 ;; Ith character and the followings matches precomposable | |
75 ;; Tibetan sequence. | |
76 (setq i (match-end 0) | |
77 this-trans | |
78 (car (rassoc | |
79 (cdr (assoc (match-string 0 str) | |
80 tibetan-precomposition-rule-alist)) | |
81 tibetan-precomposed-transcription-alist))) | |
82 (setq ch (substring str i (1+ i)) | |
83 i (1+ i) | |
84 this-trans | |
85 (car (or (rassoc ch tibetan-consonant-transcription-alist) | |
86 (rassoc ch tibetan-vowel-transcription-alist) | |
87 (rassoc ch tibetan-subjoined-transcription-alist))))) | |
88 (setq trans (cons this-trans trans)))) | |
89 (apply 'concat (nreverse trans)))) | |
17301 | 90 |
91 ;;;###autoload | |
26896 | 92 (defun tibetan-transcription-to-tibetan (str) |
93 "Convert Tibetan Roman string STR to Tibetan character string. | |
94 The returned string has no composition information." | |
95 (let (;; Case is significant. | |
17301 | 96 (case-fold-search nil) |
26896 | 97 (idx 0) |
98 ;; Accumulate Tibetan strings here in reverse order. | |
99 (t-str-list nil) | |
100 i subtrans) | |
101 (while (setq i (string-match tibetan-regexp str idx)) | |
102 (if (< idx i) | |
103 ;; STR contains a pattern that doesn't match Tibetan | |
104 ;; transcription. Include the pattern as is. | |
105 (setq t-str-list (cons (substring str idx i) t-str-list))) | |
106 (setq subtrans (match-string 0 str) | |
107 idx (match-end 0)) | |
108 (let ((t-char (cdr (assoc subtrans | |
109 tibetan-precomposed-transcription-alist)))) | |
110 (if t-char | |
111 ;; SUBTRANS corresponds to a transcription for | |
112 ;; precomposable Tibetan sequence. | |
113 (setq t-char (car (rassoc t-char | |
114 tibetan-precomposition-rule-alist))) | |
115 (setq t-char | |
116 (cdr | |
117 (or (assoc subtrans tibetan-consonant-transcription-alist) | |
118 (assoc subtrans tibetan-vowel-transcription-alist) | |
119 (assoc subtrans tibetan-modifier-transcription-alist) | |
120 (assoc subtrans tibetan-subjoined-transcription-alist))))) | |
121 (setq t-str-list (cons t-char t-str-list)))) | |
122 (if (< idx (length str)) | |
123 (setq t-str-list (cons (substring str idx) t-str-list))) | |
124 (apply 'concat (nreverse t-str-list)))) | |
17301 | 125 |
126 ;;; | |
26896 | 127 ;;; Functions for composing/decomposing Tibetan sequence. |
17301 | 128 ;;; |
129 ;;; A Tibetan syllable is typically structured as follows: | |
130 ;;; | |
131 ;;; [Prefix] C [C+] V [M] [Suffix [Post suffix]] | |
132 ;;; | |
133 ;;; where C's are all vertically stacked, V appears below or above | |
134 ;;; consonant cluster and M is always put above the C[C+]V combination. | |
135 ;;; (Sanskrit visarga, though it is a vowel modifier, is considered | |
136 ;;; to be a punctuation.) | |
137 ;;; | |
29828 | 138 ;;; Here are examples of the words "bsgrubs" and "hfauM" |
17301 | 139 ;;; |
29828 | 140 ;;; 4$(7"70"714%qx!"U0"G###C"U14"70"714"G0"G1(B 4$(7"Hx!"Rx!"Ur'"_0"H"R"U"_1(B |
17301 | 141 ;;; |
142 ;;; M | |
143 ;;; b s b s h | |
29828 | 144 ;;; g fa |
17301 | 145 ;;; r u |
146 ;;; u | |
147 ;;; | |
26896 | 148 ;;; Consonants `'' ($(7"A(B), `w' ($(7">(B), `y' ($(7"B(B), `r' ($(7"C(B) take special |
149 ;;; forms when they are used as subjoined consonant. Consonant `r' | |
150 ;;; takes another special form when used as superjoined in such a case | |
151 ;;; as "rka", while it does not change its form when conjoined with | |
152 ;;; subjoined `'', `w' or `y' as in "rwa", "rya". | |
153 | |
154 ;; Append a proper composition rule and glyph to COMPONENTS to compose | |
155 ;; CHAR with a composition that has COMPONENTS. | |
17301 | 156 |
26896 | 157 (defun tibetan-add-components (components char) |
158 (let ((last (last components)) | |
159 (stack-upper '(tc . bc)) | |
160 (stack-under '(bc . tc)) | |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
161 rule comp-vowel tmp) |
26896 | 162 ;; Special treatment for 'a chung. |
163 ;; If 'a follows a consonant, turn it into the subjoined form. | |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
164 ;; * Disabled by Tomabechi 2000/06/09 * |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
165 ;; Because in Unicode, $(7"A(B may follow directly a consonant without |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
45174
diff
changeset
|
166 ;; any intervening vowel, as in 4$(7"90"914""0"""Q14"A0"A1!;(B=4$(7"90"91(B 4$(7""0""1(B 4$(7"A0"A1(B not 4$(7"90"91(B 4$(7""0""1(B $(7"Q(B 4$(7"A0"A1(B |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
167 ;;(if (and (= char ?$(7"A(B) |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
168 ;; (aref (char-category-set (car last)) ?0)) |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
169 ;; (setq char ?$(7"R(B)) ;; modified for new font by Tomabechi 1999/12/10 |
17301 | 170 |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
171 ;; Composite vowel signs are decomposed before being added |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
172 ;; Added by Tomabechi 2000/06/08 |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
173 (if (memq char '(?$(7"T(B ?$(7"V(B ?$(7"W(B ?$(7"X(B ?$(7"Y(B ?$(7"Z(B ?$(7"b(B)) |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
174 (setq comp-vowel |
29828 | 175 (copy-sequence |
176 (cddr (assoc (char-to-string char) | |
177 tibetan-composite-vowel-alist))) | |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
178 char |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
179 (cadr (assoc (char-to-string char) |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
180 tibetan-composite-vowel-alist)))) |
26896 | 181 (cond |
182 ;; Compose upper vowel sign vertically over. | |
183 ((aref (char-category-set char) ?2) | |
184 (setq rule stack-upper)) | |
17301 | 185 |
26896 | 186 ;; Compose lower vowel sign vertically under. |
187 ((aref (char-category-set char) ?3) | |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
188 (if (eq char ?$(7"Q(B) ;; `$(7"Q(B' should not visible when composed. |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
189 (setq rule nil) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
190 (setq rule stack-under))) |
26896 | 191 ;; Transform ra-mgo (superscribed r) if followed by a subjoined |
192 ;; consonant other than w, ', y, r. | |
193 ((and (= (car last) ?$(7"C(B) | |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
194 (not (memq char '(?$(7#>(B ?$(7"R(B ?$(7#B(B ?$(7#C(B)))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
195 (setcar last ?$(7!"(B) ;; modified for newfont by Tomabechi 1999/12/10 |
26896 | 196 (setq rule stack-under)) |
197 ;; Transform initial base consonant if followed by a subjoined | |
198 ;; consonant but 'a. | |
199 (t | |
200 (let ((laststr (char-to-string (car last)))) | |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
201 (if (and (/= char ?$(7"R(B) ;; modified for new font by Tomabechi |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
202 (string-match "[$(7"!(B-$(7"="?"@"D(B-$(7"J"K(B]" laststr)) |
26896 | 203 (setcar last (string-to-char |
204 (cdr (assoc (char-to-string (car last)) | |
205 tibetan-base-to-subjoined-alist))))) | |
206 (setq rule stack-under)))) | |
17301 | 207 |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
208 (if rule |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
209 (setcdr last (list rule char))) |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
210 ;; Added by Tomabechi 2000/06/08 |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
211 (if comp-vowel |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
212 (nconc last comp-vowel)) |
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
213 )) |
17301 | 214 |
215 ;;;###autoload | |
216 (defun tibetan-compose-string (str) | |
26896 | 217 "Compose Tibetan string STR." |
218 (let ((idx 0)) | |
219 ;; `$(7"A(B' is included in the pattern for subjoined consonants | |
220 ;; because we treat it specially in tibetan-add-components. | |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
221 ;; (This feature is removed by Tomabechi 2000/06/08) |
26896 | 222 (while (setq idx (string-match tibetan-composable-pattern str idx)) |
223 (let ((from idx) | |
224 (to (match-end 0)) | |
225 components) | |
226 (if (eq (string-match tibetan-precomposition-rule-regexp str idx) idx) | |
227 (setq idx (match-end 0) | |
228 components | |
229 (list (string-to-char | |
230 (cdr | |
231 (assoc (match-string 0 str) | |
232 tibetan-precomposition-rule-alist))))) | |
233 (setq components (list (aref str idx)) | |
234 idx (1+ idx))) | |
235 (while (< idx to) | |
236 (tibetan-add-components components (aref str idx)) | |
237 (setq idx (1+ idx))) | |
238 (compose-string str from to components)))) | |
239 str) | |
17301 | 240 |
19553
e63ba5228950
(tibetan-composition): Add autoload cookies.
Kenichi Handa <handa@m17n.org>
parents:
19366
diff
changeset
|
241 ;;;###autoload |
26896 | 242 (defun tibetan-compose-region (beg end) |
243 "Compose Tibetan text the region BEG and END." | |
17301 | 244 (interactive "r") |
26896 | 245 (let (str result chars) |
17301 | 246 (save-excursion |
247 (save-restriction | |
248 (narrow-to-region beg end) | |
249 (goto-char (point-min)) | |
26896 | 250 ;; `$(7"A(B' is included in the pattern for subjoined consonants |
251 ;; because we treat it specially in tibetan-add-components. | |
29596
c3845ffcb423
Convert all tibetan-1-column characters
Kenichi Handa <handa@m17n.org>
parents:
29363
diff
changeset
|
252 ;; (This feature is removed by Tomabechi 2000/06/08) |
26896 | 253 (while (re-search-forward tibetan-composable-pattern nil t) |
254 (let ((from (match-beginning 0)) | |
255 (to (match-end 0)) | |
256 components) | |
257 (goto-char from) | |
258 (if (looking-at tibetan-precomposition-rule-regexp) | |
259 (progn | |
260 (setq components | |
261 (list (string-to-char | |
262 (cdr | |
263 (assoc (match-string 0) | |
264 tibetan-precomposition-rule-alist))))) | |
265 (goto-char (match-end 0))) | |
266 (setq components (list (char-after from))) | |
267 (forward-char 1)) | |
268 (while (< (point) to) | |
269 (tibetan-add-components components (following-char)) | |
270 (forward-char 1)) | |
271 (compose-region from to components))))))) | |
17301 | 272 |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
273 (defvar tibetan-decompose-precomposition-alist |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
274 (mapcar (function (lambda (x) (cons (string-to-char (cdr x)) (car x)))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
275 tibetan-precomposition-rule-alist)) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
276 |
17301 | 277 ;;;###autoload |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
278 (defun tibetan-decompose-region (from to) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
279 "Decompose Tibetan text in the region FROM and TO. |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
280 This is different from decompose-region because precomposed Tibetan characters |
42839 | 281 are decomposed into normal Tibetan character sequences." |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
282 (interactive "r") |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
283 (save-restriction |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
284 (narrow-to-region from to) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
285 (decompose-region from to) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
286 (goto-char from) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
287 (while (not (eobp)) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
288 (let* ((char (following-char)) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
289 (slot (assq char tibetan-decompose-precomposition-alist))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
290 (if slot |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
291 (progn |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
292 (delete-char 1) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
293 (insert (cdr slot))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
294 (forward-char 1)))))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
295 |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
296 |
26896 | 297 ;;;###autoload |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
298 (defun tibetan-decompose-string (str) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
299 "Decompose Tibetan string STR. |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
300 This is different from decompose-string because precomposed Tibetan characters |
42839 | 301 are decomposed into normal Tibetan character sequences." |
29363
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
302 (let ((new "") |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
303 (len (length str)) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
304 (idx 0) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
305 char slot) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
306 (while (< idx len) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
307 (setq char (aref str idx) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
308 slot (assq (aref str idx) tibetan-decompose-precomposition-alist) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
309 new (concat new (if slot (cdr slot) (char-to-string char))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
310 idx (1+ idx))) |
1ebd8db9c3dc
(tibetan-add-components): Fixes for new
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
311 new)) |
26896 | 312 |
313 ;;;###autoload | |
314 (defun tibetan-composition-function (from to pattern &optional string) | |
315 (if string | |
316 (tibetan-compose-string string) | |
317 (tibetan-compose-region from to)) | |
318 (- to from)) | |
17301 | 319 |
320 ;;; | |
321 ;;; This variable is used to avoid repeated decomposition. | |
322 ;;; | |
323 (setq-default tibetan-decomposed nil) | |
324 | |
325 ;;;###autoload | |
326 (defun tibetan-decompose-buffer () | |
327 "Decomposes Tibetan characters in the buffer into their components. | |
26896 | 328 See also the documentation of the function `tibetan-decompose-region'." |
17301 | 329 (interactive) |
330 (make-local-variable 'tibetan-decomposed) | |
331 (cond ((not tibetan-decomposed) | |
332 (tibetan-decompose-region (point-min) (point-max)) | |
333 (setq tibetan-decomposed t)))) | |
334 | |
335 ;;;###autoload | |
336 (defun tibetan-compose-buffer () | |
337 "Composes Tibetan character components in the buffer. | |
338 See also docstring of the function tibetan-compose-region." | |
339 (interactive) | |
340 (make-local-variable 'tibetan-decomposed) | |
341 (tibetan-compose-region (point-min) (point-max)) | |
342 (setq tibetan-decomposed nil)) | |
343 | |
344 ;;;###autoload | |
345 (defun tibetan-post-read-conversion (len) | |
346 (save-excursion | |
347 (save-restriction | |
348 (let ((buffer-modified-p (buffer-modified-p))) | |
349 (narrow-to-region (point) (+ (point) len)) | |
350 (tibetan-compose-region (point-min) (point-max)) | |
351 (set-buffer-modified-p buffer-modified-p) | |
20107
4595a463b105
(tibetan-post-read-conversion): Return
Kenichi Handa <handa@m17n.org>
parents:
19553
diff
changeset
|
352 (make-local-variable 'tibetan-decomposed) |
4595a463b105
(tibetan-post-read-conversion): Return
Kenichi Handa <handa@m17n.org>
parents:
19553
diff
changeset
|
353 (setq tibetan-decomposed nil) |
4595a463b105
(tibetan-post-read-conversion): Return
Kenichi Handa <handa@m17n.org>
parents:
19553
diff
changeset
|
354 (- (point-max) (point-min)))))) |
17301 | 355 |
356 | |
357 ;;;###autoload | |
358 (defun tibetan-pre-write-conversion (from to) | |
359 (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
|
360 (let ((old-buf (current-buffer))) |
23545
0d25c6f765ab
(tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23522
diff
changeset
|
361 (set-buffer (generate-new-buffer " *temp*")) |
0d25c6f765ab
(tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23522
diff
changeset
|
362 (if (stringp from) |
0d25c6f765ab
(tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23522
diff
changeset
|
363 (insert from) |
0d25c6f765ab
(tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23522
diff
changeset
|
364 (insert-buffer-substring old-buf from to)) |
0d25c6f765ab
(tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23522
diff
changeset
|
365 (if (not tibetan-decomposed-temp) |
0d25c6f765ab
(tibetan-pre-write-conversion): Cancel previous
Kenichi Handa <handa@m17n.org>
parents:
23522
diff
changeset
|
366 (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
|
367 ;; Should return nil as annotations. |
ece62fdeeebb
(tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
368 nil)) |
17301 | 369 |
45174
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
370 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
371 ;;; |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
372 ;;; Unicode-related definitions. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
45174
diff
changeset
|
373 ;;; |
45174
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
374 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
375 (defvar tibetan-canonicalize-for-unicode-alist |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
376 '(("$(7"Q(B" . "") ;; remove vowel a |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
377 ("$(7"T(B" . "$(7"R"S(B") ;; decompose vowels whose use is ``discouraged'' in Unicode 3.0 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
378 ("$(7"V(B" . "$(7"R"U(B") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
379 ("$(7"W(B" . "$(7#C"a(B") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
380 ("$(7"X(B" . "$(7#C"R"a(B") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
381 ("$(7"Y(B" . "$(7#D"a(B") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
382 ("$(7"Z(B" . "$(7#D"R"a(B") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
383 ("$(7"b(B" . "$(7"R"a(B")) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
384 "Rules for canonicalizing Tibetan vowels for Unicode.") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
385 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
386 (defvar tibetan-canonicalize-for-unicode-regexp |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
387 "[$(7"Q"T"V"W"X"Y"Z"b(B]" |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
388 "Regexp for Tibetan vowels to be canonicalized in Unicode.") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
389 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
390 (defun tibetan-canonicalize-for-unicode-region (from to) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
391 (save-restriction |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
392 (narrow-to-region from to) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
393 (goto-char from) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
394 (while (re-search-forward tibetan-canonicalize-for-unicode-regexp nil t) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
395 (let ( |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
396 ;;(from (match-beginning 0)) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
397 ;;(to (match-end 0)) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
398 (canonical-form |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
399 (cdr (assoc (match-string 0) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
400 tibetan-canonicalize-for-unicode-alist)))) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
401 ;;(goto-char from) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
402 ;;(delete-region from to) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
403 ;;(insert canonical-form) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
404 (replace-match canonical-form) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
405 )))) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
406 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
407 (defvar tibetan-strict-unicode t |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
408 "*Flag to control Tibetan canonicalizing for Unicode. |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
409 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
410 If non-nil, the vowel a is removed and composite vowels are decomposed |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
411 before writing buffer in Unicode. See also |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
412 `tibetan-canonicalize-for-unicode-regexp' and |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
413 `tibetan-canonicalize-for-unicode-alist'.") |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
414 |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
415 ;;;###autoload |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
416 (defun tibetan-pre-write-canonicalize-for-unicode (from to) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
417 (let ((old-buf (current-buffer)) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
418 (strict-unicode tibetan-strict-unicode)) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
419 (set-buffer (generate-new-buffer " *temp*")) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
420 (if (stringp from) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
421 (insert from) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
422 (insert-buffer-substring old-buf from to)) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
423 (if strict-unicode |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
424 (tibetan-canonicalize-for-unicode-region (point-min) (point-max))) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
425 ;; Should return nil as annotations. |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
426 nil)) |
15af34d3b6f7
(tibetan-canonicalize-for-unicode-alist)
Kenichi Handa <handa@m17n.org>
parents:
45032
diff
changeset
|
427 |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
17993
diff
changeset
|
428 (provide 'tibet-util) |
17301 | 429 |
52401 | 430 ;;; arch-tag: 7a7333e8-1584-446c-b39c-a02b9def265d |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36685
diff
changeset
|
431 ;;; tibet-util.el ends here |