annotate lisp/language/tibet-util.el @ 18103:8e1553706b3d

[__NetBSD__]: Don't include filehdr.h, aouthdr.h scnhdr.h or syms.h. Add many other conditionalized definitions.
author Richard M. Stallman <rms@gnu.org>
date Mon, 02 Jun 1997 00:09:40 +0000
parents 73869115ae0a
children bd8b521f5218
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 Free Software Foundation, Inc.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
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.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 ;;; Code:
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
35 ;;;###autoload
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
36 (defun setup-tibetan-environment ()
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
37 (interactive)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
38 (setup-english-environment)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
39 (setq coding-category-iso-8-2 'tibetan)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
40
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
41 (setq-default buffer-file-coding-system 'iso-2022-7)
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
42
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
43 (setq default-input-method '("Tibetan" . "quail-tibetan-wylie"))
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
44
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
45 (setq sendmail-coding-system 'iso-2022-7
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
46 rmail-file-coding-system 'iso-2022-7))
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
47
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 ;;; This function makes a transcription string for
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 ;;; re-composing a character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 (defun tibetan-tibetan-to-transcription (ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 "Return a transcription string of Tibetan character CH"
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 (let ((char ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 (l (append tibetan-consonant-transcription-alist
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 tibetan-vowel-transcription-alist
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57 tibetan-precomposed-transcription-alist
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 tibetan-subjoined-transcription-alist))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59 decomp-l t-char trans str result)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 (if (eq (char-charset char) 'composition)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61 (setq decomp-l (decompose-composite-char char 'list nil))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 (setq decomp-l (cons char nil)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63 (setq str "")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 (while decomp-l
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 (setq t-char (char-to-string (car decomp-l)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66 (setq trans (car (rassoc t-char l)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 (setq str (concat str trans))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68 (setq decomp-l (cdr decomp-l)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 (setq result str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 ;;; This function translates transcription string into a string of
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 ;;; Tibetan characters.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 (defun tibetan-transcription-to-tibetan (transcription)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 "Translate Roman transcription into a sequence of Tibetan components."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 (let ((trans transcription)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 (lp tibetan-precomposed-transcription-alist)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 (l (append tibetan-consonant-transcription-alist
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 tibetan-vowel-transcription-alist
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 tibetan-subjoined-transcription-alist))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 (case-fold-search nil)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 substr t-char p-str t-str result)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 (setq substr "")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 (setq p-str "")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86 (setq t-str "")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87 (cond ((string-match tibetan-precomposed-regexp trans)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88 (setq substr (substring trans (match-beginning 0) (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 (setq trans (substring trans (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 (setq t-char (cdr (assoc substr lp)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91 (setq p-str t-char)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 (while (string-match tibetan-regexp trans)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 (setq substr (substring trans (match-beginning 0) (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94 (setq trans (substring trans 0 (match-beginning 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95 (setq t-char
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 (cdr (assoc substr l)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97 (setq t-str (concat t-char t-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 (setq result (concat p-str t-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 ;;; Functions for composing Tibetan character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104 ;;; A Tibetan syllable is typically structured as follows:
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 ;;; [Prefix] C [C+] V [M] [Suffix [Post suffix]]
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108 ;;; where C's are all vertically stacked, V appears below or above
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 ;;; consonant cluster and M is always put above the C[C+]V combination.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110 ;;; (Sanskrit visarga, though it is a vowel modifier, is considered
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111 ;;; to be a punctuation.)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113 ;;; Here are examples of the words "bsgrubs" and "h'uM"
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 ;;; $(7"72%q`"U1"7"G(B 2$(7"H`#A`"U0"_1(B
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 ;;; M
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 ;;; b s b s h
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119 ;;; g '
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 ;;; r u
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121 ;;; u
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 ;;; Consonants ''', 'w', 'y', 'r' take special forms when they are used
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 ;;; as subjoined consonant. Consonant 'r' takes another special form
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 ;;; when used as superjoined as in "rka", and so on, while it does not
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
126 ;;; change its form when conjoined with subjoined ''', 'w' or 'y'
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127 ;;; as in "rwa", "rya".
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130 ;;; As a Tibetan input method should avoid using conversion key,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 ;;; we use a "Tibetan glyph -> transcription -> Tibetan glyph"
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
132 ;;; translation at each key input.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
133 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
134 ;;; 1st stage - Check the preceding char.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
135 ;;; If the preceding char is Tibetan and composable, then
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
136 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
137 ;;; 2nd stage - Translate the preceding char into transcription
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
138 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
139 ;;; 3rd stage - Concatenate the transcription of preceding char
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
140 ;;; and the current input key.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
141 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
142 ;;; 4th stage - Re-translate the concatenated transcription into
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
143 ;;; a sequence of Tibetan letters.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
144 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
145 ;;; 5th stage - Convert leading consonants into one single precomposed char
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
146 ;;; if possible.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
147 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
148 ;;; 6th stage - Compose the consonants into one composite glyph.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
149 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
150 ;;; (If the current input is a vowel sign or a vowel modifier,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
151 ;;; then it is composed with preceding char without checking
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
152 ;;; except when the preceding char is a punctuation or a digit.)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
153 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
154 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
155
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
156 ;;; This function is used to avoid composition
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
157 ;;; between Tibetan and non-Tibetan chars.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
158
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
159 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
160 (defun tibetan-char-examin (ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
161 "Check if char CH is Tibetan character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
162 Returns non-nil if CH is Tibetan. Otherwise, returns nil."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
163 (let ((chr ch))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
164 (if (eq (char-charset chr) 'composition)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
165 (string-match "\\cq+" (decompose-composite-char chr))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
166 (string-match "\\cq" (char-to-string chr)))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
167
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
168 ;;; This is used to avoid composition between digits, signs, punctuations
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
169 ;;; and word constituents.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
170
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
171 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
172 (defun tibetan-composable-examin (ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
173 "Check if Tibetan char CH is composable.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
174 Returns t if CH is a composable char \(i.e. neither punctuation nor digit)."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
175 (let ((chr ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
176 chstr)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
177 (if (eq (char-charset chr) 'composition)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
178 (setq chstr (decompose-composite-char chr))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
179 (setq chstr (char-to-string chr)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
180 (not (string-match "[$(7!1(B-$(7!o"f$(8!;!=!?!@!A!D"`(B]" chstr))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
181
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
182
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
183 ;;; This checks if a character to be composed contains already
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
184 ;;; one or more vowels / vowel modifiers. If the character contains
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
185 ;;; them, then no more consonant should be added.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
186
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
187 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
188 (defun tibetan-complete-char-examin (ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
189 "Check if composite char CH contains one or more vowel/vowel modifiers.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
190 Returns non-nil, if CH contains vowel/vowel modifiers."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
191 (let ((chr ch)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
192 chstr)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
193 (if (eq (char-charset chr) 'composition)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
194 (setq chstr (decompose-composite-char chr))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
195 (setq chstr (char-to-string chr)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
196 (string-match "[$(7!g!e"Q(B-$(7"^"_(B-$(7"l(B]" chstr)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
197
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
198 ;;; This function makes a composite character consisting of two characters
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
199 ;;; vertically stacked.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
200
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
201 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
202 (defun tibetan-vertical-stacking (first second upward)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
203 "Return a vertically stacked composite char consisting of FIRST and SECOND.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
204 If UPWARD is non-nil, then SECOND is put above FIRST."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
205 (if upward
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
206 (compose-chars first '(tc . bc) second)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
207 (compose-chars first '(bc . tc) second)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
208
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
209 ;;; This function makes a composite char from a string.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
210 ;;; Note that this function returns a string, not a char.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
211
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
212 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
213 (defun tibetan-compose-string (str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
214 "Compose a sequence of Tibetan character components into a composite character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
215 Returns a string containing a composite character."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
216 (let ((t-str str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
217 f-str s-str f-ch s-ch rest composed result)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
218 ;;Make sure no redundant vowel sign is present.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
219 (if (string-match
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
220 "^\\(.+\\)\\($(7"Q(B\\)\\([$(7!I!g!e"Q(B-$(7"^"_(B-$(7"l(B]\\)" t-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
221 (setq t-str (concat
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
222 (match-string 1 t-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
223 (match-string 3 t-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
224 (if (string-match
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
225 "^\\(.+\\)\\([$(7!I!g!e"Q(B-$(7"^"_(B-$(7"l(B]\\)\\($(7"Q(B\\)" t-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
226 (setq t-str (concat
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
227 (match-string 1 t-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
228 (match-string 2 t-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
229 ;;Start conversion.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
230 (setq result "")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
231 ;; Consecutive base/precomposed consonants are reduced to the last one.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
232 (while (string-match "^\\([$(7"!(B-$(7"J$!(B-$(7%u(B]\\)\\([$(7"!(B-$(7"@"B(B-$(7"J$!(B-$(7%u(B].*\\)" t-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
233 (setq result (concat result (match-string 1 t-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
234 (setq t-str (match-string 2 t-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
235 ;; Vowel/vowel modifier, subjoined consonants are added one by one
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
236 ;; to the preceding element.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
237 (while
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
238 (string-match "^\\(.\\)\\([$(7"A#!(B-$(7#J!I!g!e"Q(B-$(7"^"_(B-$(7"l(B]\\)\\(.*\\)" t-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
239 (setq f-str (match-string 1 t-str))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
240 (setq f-ch (string-to-char f-str))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
241 (setq s-str (match-string 2 t-str))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
242 ;;Special treatment for 'a chung.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
243 ;;If 'a follows a consonant, then turned into its subjoined form.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
244 (if (and (string-match "$(7"A(B" s-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
245 (not (tibetan-complete-char-examin f-ch)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
246 (setq s-str "$(7#A(B"))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
247 (setq s-ch (string-to-char s-str))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
248 (setq rest (match-string 3 t-str))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
249 (cond ((string-match "\\c2" s-str);; upper vowel sign
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
250 (setq composed
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
251 (tibetan-vertical-stacking f-ch s-ch t)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
252 ((string-match "\\c3" s-str);; lower vowel sign
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
253 (setq composed
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
254 (tibetan-vertical-stacking f-ch s-ch nil)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
255 ;;Automatic conversion of ra-mgo (superscribed r).
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
256 ;;'r' is converted if followed by a subjoined consonant
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
257 ;;other than w, ', y, r.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
258 ((and (string-match "$(7"C(B" f-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
259 (not (string-match "[$(7#>#A#B#C(B]" s-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
260 (setq f-ch ?$(7#P(B)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
261 (setq composed
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
262 (tibetan-vertical-stacking f-ch s-ch nil)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
263 ((not (tibetan-complete-char-examin f-ch))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
264 ;;Initial base consonant is tranformed, if followed by
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
265 ;;a subjoined consonant, except when it is followed
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
266 ;;by a subscribed 'a.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
267 (if (and (string-match "[$(7"!(B-$(7"="?"@"D(B-$(7"J(B]" f-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
268 (not (string-match "$(7#A(B" s-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
269 (setq f-ch
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
270 (string-to-char
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
271 (cdr (assoc f-str tibetan-base-to-subjoined-alist)))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
272 (setq composed
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
273 (tibetan-vertical-stacking f-ch s-ch nil)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
274 (t
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
275 (setq composed s-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
276 (setq result (concat result f-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
277 (setq t-str (concat composed rest)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
278 (setq result (concat result t-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
279
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
280 ;;; quail <-> conversion interface.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
281
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
282 (defun tibetan-composition (pc key)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
283 "Interface to quail input method.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
284 Takes two arguments: char PC and string KEY, where PC is the preceding
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
285 character to be composed with current input KEY.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
286 Returns a string which is the result of composition."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
287 (let (trans cur-ch t-str result)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
288 ;; Make a tibetan character corresponding to current input key.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
289 (setq cur-ch (tibetan-transcription-to-tibetan key))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
290 ;; Check if the preceding character is Tibetan and composable.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
291 (cond ((and (tibetan-char-examin pc)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
292 (tibetan-composable-examin pc))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
293 ;;If Tibetan char corresponding to the current input key exists,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
294 (cond (cur-ch
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
295 ;; Then,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
296 ;; Convert the preceding character into transcription,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
297 ;; and concatenate it with the current input key,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
298 (setq trans (tibetan-tibetan-to-transcription pc))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
299 (setq trans (concat trans key))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
300 ;; Concatenated transcription is converted to
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
301 ;; a sequence of Tibetan characters,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
302 (setq t-str (tibetan-transcription-to-tibetan trans))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
303 ;; And it is composed into a composite character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
304 (setq result (tibetan-compose-string t-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
305 ;; Else,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
306 (t
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
307 ;; Simply concatenate the preceding character and
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
308 ;; the current input key.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
309 (setq result (char-to-string pc))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
310 (setq result (concat result key)))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
311 ;; If the preceding char is not Tibetan or not composable,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
312 (t
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
313 ;; pc = 0 means the point is at the beginning of buffer.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
314 (if (not (eq pc 0))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
315 (setq result (char-to-string pc)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
316 (if cur-ch
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
317 (setq result (concat result cur-ch))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
318 (setq result (concat result key))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
319 )))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
320
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
321
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
322 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
323 (defun tibetan-decompose-region (beg end)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
324 "Decompose Tibetan characters in the region BEG END into their components.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
325 Components are: base and subjoined consonants, vowel signs, vowel modifiers.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
326 One column punctuations are converted to their 2 column equivalents."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
327 (interactive "r")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
328 (let (ch-str ch-beg ch-end)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
329 (save-excursion
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
330 (save-restriction
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
331 (narrow-to-region beg end)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
332 (goto-char (point-min))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
333 ;; \\cq = Tibetan character
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
334 (while (re-search-forward "\\cq" nil t)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
335 (setq ch-str (buffer-substring-no-properties
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
336 (match-beginning 0) (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
337 ;; Save the points. Maybe, using save-match-data is preferable.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
338 ;; But in order not to lose the trace(because the body is too long),
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
339 ;; we save the points in variables.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
340 (setq ch-beg (match-beginning 0))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
341 (setq ch-end (match-end 0))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
342 ;; Here starts the decomposition.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
343 (cond
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
344 ;; 1 column punctuations -> 2 column equivalent
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
345 ((string-match "[$(8!D!;!=!?!@!A"`(B]" ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
346 (setq ch-str
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
347 (car (rassoc ch-str tibetan-precomposition-rule-alist))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
348 ;; Decomposition of composite character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
349 ((eq (char-charset (string-to-char ch-str)) 'composition)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
350 ;; Make a string which consists of a sequence of
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
351 ;; components.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
352 (setq ch-str (decompose-composite-char (string-to-char ch-str)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
353 ;; Converts nyi zla into base elements.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
354 (cond ((string= ch-str "$(7#R#S#S#S(B")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
355 (setq ch-str "$(7!4!5!5(B"))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
356 ((string= ch-str "$(7#R#S#S(B")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
357 (setq ch-str "$(7!4!5(B"))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
358 ((string= ch-str "$(7#R#S!I(B")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
359 (setq ch-str "$(7!6(B"))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
360 ((string= ch-str "$(7#R#S(B")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
361 (setq ch-str "$(7!4(B")))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
362 ;; If the sequence of components starts with a subjoined consonants,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
363 (if (string-match "^\\([$(7#!(B-$(7#J(B]\\)\\(.*\\)$" ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
364 ;; then the first components is converted to its base form.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
365 (setq ch-str
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
366 (concat (car (rassoc (match-string 1 ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
367 tibetan-base-to-subjoined-alist))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
368 (match-string 2 ch-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
369 ;; If the sequence of components starts with a precomposed character,
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
370 (if (string-match "^\\([$(7$!(B-$(7%u(B]\\)\\(.*\\)$" ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
371 ;; then it is converted into a sequence of components.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
372 (setq ch-str
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
373 (concat (car (rassoc (match-string 1 ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
374 tibetan-precomposition-rule-alist))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
375 (match-string 2 ch-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
376 ;; Special treatment for superscribed r.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
377 (if (string-match "^$(7#P(B\\(.*\\)$" ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
378 (setq ch-str (concat "$(7"C(B" (match-string 1 ch-str))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
379 ;; Finally, the result of decomposition is inserted, and
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
380 ;; the composite character is deleted.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
381 (insert-and-inherit ch-str)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
382 (delete-region ch-beg ch-end))))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
383
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
384 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
385 (defun tibetan-compose-region (beg end)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
386 "Make composite chars from Tibetan character components in the region BEG END.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
387 Two column punctuations are converted to their 1 column equivalents."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
388 (interactive "r")
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
389 (let (str result)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
390 (save-excursion
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
391 (save-restriction
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
392 (narrow-to-region beg end)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
393 (goto-char (point-min))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
394 ;; First, sequence of components which has a precomposed equivalent
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
395 ;; is converted.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
396 (while (re-search-forward
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
397 tibetan-precomposition-rule-regexp nil t)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
398 (setq str (buffer-substring-no-properties
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
399 (match-beginning 0) (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
400 (save-match-data
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
401 (insert-and-inherit
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
402 (cdr (assoc str tibetan-precomposition-rule-alist))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
403 (delete-region (match-beginning 0) (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
404 (goto-char (point-min))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
405 ;; Then, composable elements are put into a composite character.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
406 (while (re-search-forward
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
407 "[$(7"!(B-$(7"J$!(B-$(7%u(B]+[$(7#!(B-$(7#J!I!g!e"Q(B-$(7"^"_(B-$(7"l(B]+"
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
408 nil t)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
409 (setq str (buffer-substring-no-properties
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
410 (match-beginning 0) (match-end 0)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
411 (save-match-data
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
412 (setq result (tibetan-compose-string str))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
413 (insert-and-inherit result))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
414 (delete-region (match-beginning 0) (match-end 0)))))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
415
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
416 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
417 ;;; This variable is used to avoid repeated decomposition.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
418 ;;;
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
419 (setq-default tibetan-decomposed nil)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
420
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
421 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
422 (defun tibetan-decompose-buffer ()
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
423 "Decomposes Tibetan characters in the buffer into their components.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
424 See also docstring of the function tibetan-decompose-region."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
425 (interactive)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
426 (make-local-variable 'tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
427 (cond ((not tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
428 (tibetan-decompose-region (point-min) (point-max))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
429 (setq tibetan-decomposed t))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
430
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
431 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
432 (defun tibetan-compose-buffer ()
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
433 "Composes Tibetan character components in the buffer.
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
434 See also docstring of the function tibetan-compose-region."
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
435 (interactive)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
436 (make-local-variable 'tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
437 (tibetan-compose-region (point-min) (point-max))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
438 (setq tibetan-decomposed nil))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
439
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
440 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
441 (defun tibetan-post-read-conversion (len)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
442 (save-excursion
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
443 (save-restriction
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
444 (let ((buffer-modified-p (buffer-modified-p)))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
445 (narrow-to-region (point) (+ (point) len))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
446 (tibetan-compose-region (point-min) (point-max))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
447 (set-buffer-modified-p buffer-modified-p)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
448 (point-max))))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
449 (make-local-variable 'tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
450 (setq tibetan-decomposed nil))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
451
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
452
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
453 ;;;###autoload
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
454 (defun tibetan-pre-write-conversion (from to)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
455 (setq tibetan-decomposed-temp tibetan-decomposed)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
456 (let ((old-buf (current-buffer))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
457 (work-buf (get-buffer-create " *tibetan-work*")))
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
458 (set-buffer work-buf)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
459 (erase-buffer)
17776
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
460 (if (stringp from)
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
461 (insert from)
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
462 (insert-buffer-substring old-buf from to))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
463 (if (not tibetan-decomposed-temp)
17776
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
464 (tibetan-decompose-region (point-min) (point-max)))
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
465 ;; Should return nil as annotations.
ece62fdeeebb (tibetan-pre-write-conversion): Make it work
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
466 nil))
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
467
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
468 (provide 'language/tibet-util)
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
469
17993
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
470 ;;; Local Variables:
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
471 ;;; generated-autoload-file: "../loaddefs.el"
73869115ae0a Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents: 17776
diff changeset
472 ;;; End:
17301
0b94fe381355 Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
473 ;;; language/tibet-util.el ends here.