*** empty log message ***
[emacs.git] / leim / quail / indian.el
blob90f84c2df0909299fcb2e76c8159a71ac4210ead
1 ;;; indian.el --- Quail packages for inputting Indian
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
6 ;; Author: KAWABATA, Taichi <kawabata@m17n.org>
8 ;; Keywords: multilingual, input method, Indian, Devanagari
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; History:
31 ;; 2000.12.12
32 ;; Totally re-written from devanagari.el to handle multiple Indian Scripts.
34 ;;; Code:
36 (require 'quail)
37 (require 'devan-util)
38 (require 'ind-util)
40 (defun quail-indian-preceding-char-position (position)
41 "Return the position of preceding composite character."
42 (let (prec-composed)
43 (if (char-valid-p (char-before position)) ;; range o.k.
44 (if (setq prec-composed (find-composition (1- position)))
45 (car prec-composed)
46 (1- position))
47 nil)))
49 (defvar quail-indian-update-preceding-char nil)
51 ;; Input value ::
52 ;; CONTROL-FLAG is integer `n'
53 ;; quail-current-key :: keyboard input.
54 ;; Only first `n' can be translated.
55 ;; quail-current-str :: corresonding string.
56 ;; jobs :: (1) put last (len-n) char to unrread-command-event.
57 ;; (2) put translated string to quail-current-str.
59 ;; CONTROL-FLAG is t (terminate) or nil (proceed the translation)
60 ;; quail-current-key :: keyboard input.
61 ;; quail-current-str :: corresponding string.
62 ;; jobs :: (1) put modified translated string to quail-current-str.
64 ;; When non-nil value is returned from quail-translation-update-function,
65 ;; the quail-current-str is split to characters and put into event queue,
66 ;; with `compose-last-char' event with composition info at the end.
68 (defun quail-indian-update-translation (control-flag)
69 ;; make quail-current-str string when possible.
70 (if (char-valid-p quail-current-str)
71 (setq quail-current-str (char-to-string quail-current-str)))
72 ;(message "\n input control-flag=%s, str=%s, key=%s q-ind-upd-prec-char=%s"
73 ; control-flag quail-current-str quail-current-key
74 ; quail-indian-update-preceding-char)
75 ;; reset quail-indian-update-preceding-char if it's initial.
76 (if (= (overlay-start quail-overlay) (overlay-end quail-overlay))
77 (setq quail-indian-update-preceding-char nil))
78 ;; Check the preceding character of the quail region. If the
79 ;; preceding character can be composed with quail-current-str, then
80 ;; grab that preceding character into the quail-current-str and
81 ;; remove that char from the region.
82 (let* (prec-char-position composition-regexp
83 prec-char-str candidate-str match-pos match-end)
84 (when (and quail-current-str
85 (null quail-indian-update-preceding-char)
86 (null input-method-use-echo-area)
87 (null input-method-exit-on-first-char)
88 (setq prec-char-position
89 (quail-indian-preceding-char-position
90 (overlay-start quail-overlay)))
91 (setq composition-regexp
92 (if prec-char-position
93 (caar (elt composition-function-table
94 (char-after prec-char-position)))))
95 (setq prec-char-str
96 (buffer-substring prec-char-position
97 (overlay-start quail-overlay))
98 candidate-str (concat prec-char-str quail-current-str)
99 match-pos (string-match composition-regexp candidate-str)
100 match-end (match-end 0))
101 (> match-end (length prec-char-str)))
102 (setq quail-indian-update-preceding-char prec-char-str)
103 (delete-region prec-char-position
104 (overlay-start quail-overlay))))
105 (setq quail-current-str
106 (indian-compose-string
107 (concat quail-indian-update-preceding-char
108 quail-current-str)))
109 (if (numberp control-flag)
110 (setq unread-command-events
111 (string-to-list
112 (substring quail-current-key control-flag))))
113 (when control-flag
114 (setq quail-indian-update-preceding-char nil))
115 ;(message "output control-flag=%s, str=%s, key=%s q-ind-upd-prec-char=%s"
116 ; control-flag quail-current-str quail-current-key
117 ; quail-indian-update-preceding-char)
118 control-flag)
121 ;;; Input by transliteration
124 (defun quail-define-indian-trans-package (hashtbls pkgname
125 lang title doc)
126 (funcall 'quail-define-package pkgname lang title t doc
127 nil nil nil nil nil nil t nil
128 'quail-indian-update-translation)
129 (maphash
130 (lambda (key val)
131 (quail-defrule key (if (= (length val) 1)
132 (string-to-char val)
133 (vector val))))
134 (cdr hashtbls)))
136 ;; This needs to be seen by quail-update-leim-list-file, but cannot be
137 ;; commented out because quail-update-leim-list-file ignores
138 ;; commented-out lines.
139 (if nil
140 (quail-define-package "devanagari-itrans" "Devanagari" "DevIT" t "Devanagari ITRANS"))
141 (quail-define-indian-trans-package
142 indian-dev-itrans-v5-hash "devanagari-itrans" "Devanagari" "DevIT"
143 "Devanagari transliteration by ITRANS method.")
145 (if nil
146 (quail-define-package "devanagari-kyoto-harvard" "Devanagari" "DevKH" t "Devanagari Kyoto-Harvard"))
147 (quail-define-indian-trans-package
148 indian-dev-kyoto-harvard-hash
149 "devanagari-kyoto-harvard" "Devanagari" "DevKH"
150 "Devanagari transliteration by Kyoto-Harvard method.")
152 (if nil
153 (quail-define-package "devanagari-aiba" "Devanagari" "DevAB" t "Devanagari Aiba"))
154 (quail-define-indian-trans-package
155 indian-dev-aiba-hash "devanagari-aiba" "Devanagari" "DevAB"
156 "Devanagari transliteration by Aiba-method.")
158 (if nil
159 (quail-define-package "punjabi-itrans" "Punjabi" "PnjIT" t "Punjabi ITRANS"))
160 (quail-define-indian-trans-package
161 indian-pnj-itrans-v5-hash "punjabi-itrans" "Punjabi" "PnjIT"
162 "Punjabi transliteration by ITRANS method.")
164 (if nil
165 (quail-define-package "gujarati-itrans" "Gujarati" "GjrIT" t "Gujarati ITRANS"))
166 (quail-define-indian-trans-package
167 indian-gjr-itrans-v5-hash "gujarati-itrans" "Gujarati" "GjrIT"
168 "Gujarati transliteration by ITRANS method.")
170 (if nil
171 (quail-define-package "oriya-itrans" "Oriya" "OriIT" t "Oriya ITRANS"))
172 (quail-define-indian-trans-package
173 indian-ori-itrans-v5-hash "oriya-itrans" "Oriya" "OriIT"
174 "Oriya transliteration by ITRANS method.")
176 (if nil
177 (quail-define-package "bengali-itrans" "Bengali" "BngIT" t "Bengali ITRANS"))
178 (quail-define-indian-trans-package
179 indian-bng-itrans-v5-hash "bengali-itrans" "Bengali" "BngIT"
180 "Bengali transliteration by ITRANS method.")
182 (if nil
183 (quail-define-package "assamese-itrans" "Assamese" "AsmIT" t "Assamese ITRANS"))
184 (quail-define-indian-trans-package
185 indian-asm-itrans-v5-hash "assamese-itrans" "Assamese" "AsmIT"
186 "Assamese transliteration by ITRANS method.")
188 (if nil
189 (quail-define-package "telugu-itrans" "Telugu" "TlgIT" t "Telugu ITRANS"))
190 (quail-define-indian-trans-package
191 indian-tlg-itrans-v5-hash "telugu-itrans" "Telugu" "TlgIT"
192 "Telugu transliteration by ITRANS method.")
194 (if nil
195 (quail-define-package "kannada-itrans" "Kannada" "KndIT" t "Kannada ITRANS"))
196 (quail-define-indian-trans-package
197 indian-knd-itrans-v5-hash "kannada-itrans" "Kannada" "KndIT"
198 "Kannada transliteration by ITRANS method.")
200 (if nil
201 (quail-define-package "malayalam-itrans" "Malayalam" "MlmIT" t "Malayalam ITRANS"))
202 (quail-define-indian-trans-package
203 indian-mlm-itrans-v5-hash "malayalam-itrans" "Malayalam" "MlmIT"
204 "Malayalam transliteration by ITRANS method.")
206 (if nil
207 (quail-define-package "tamil-itrans" "Tamil" "TmlIT" t "Tamil ITRANS"))
208 (quail-define-indian-trans-package
209 indian-tml-itrans-v5-hash "tamil-itrans" "Tamil" "TmlIT"
210 "Tamil transliteration by ITRANS method.")
214 ;;; Input by Inscript
217 (defun quail-indian-flatten-list (lst)
218 "Flatten the nested LIST so that there would be no innner list."
219 (if (listp lst)
220 (apply 'append (mapcar 'quail-indian-flatten-list lst))
221 (list lst)))
223 (defun quail-define-inscript-package (char-table key-table pkgname lang title
224 docstring)
225 (setq char-table (quail-indian-flatten-list char-table))
226 (setq key-table (quail-indian-flatten-list key-table))
227 (funcall 'quail-define-package pkgname lang title nil docstring
228 nil nil nil nil nil nil nil nil
229 'quail-indian-update-translation)
230 (dolist (key key-table)
231 (let ((val (pop char-table)))
232 (if (and key val)
233 (quail-defrule
234 (if (char-valid-p key) (char-to-string key) key)
235 (if (stringp val) (vector val) val))))))
239 (defvar inscript-dev-keytable
241 (;; VOWELS (18)
242 (?D nil) (?E ?e) (?F ?f) (?R ?r) (?G ?g) (?T ?t)
243 (?+ ?=) ("F]" "f]") (?! ?@) (?Z ?z) (?S ?s) (?W ?w)
244 (?| ?\\) (?~ ?`) (?A ?a) (?Q ?q) ("+]" "=]") ("R]" "r]"))
245 (;; CONSONANTS (42)
246 ?k ?K ?i ?I ?U ;; GRUTTALS
247 ?\; ?: ?p ?P ?} ;; PALATALS
248 ?' ?\" ?\[ ?{ ?C ;; CEREBRALS
249 ?l ?L ?o ?O ?v ?V ;; DENTALS
250 ?h ?H ?y ?Y ?c ;; LABIALS
251 ?/ ?j ?J ?n ?N "N]" ?b ;; SEMIVOWELS
252 ?M ?< ?m ?u ;; SIBILANTS
253 "k]" "K]" "i]" "p]" "[]" "{]" "H]" "/]" ;; NUKTAS
254 ?% ?&)
255 (;; Misc Symbols (7)
256 ?X ?x ?_ ">]" ?d "X]" ?>)
257 (;; Digits
258 ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)
259 (;; Inscripts
260 ?# ?$ ?^ ?* ?\])))
262 (if nil
263 (quail-define-package "devanagari-inscript" "Devanagari" "DevIS" t "Devanagari keyboard Inscript"))
264 (quail-define-inscript-package
265 indian-dev-base-table inscript-dev-keytable
266 "devanagari-inscript" "Devanagari" "DevIS"
267 "Devanagari keyboard Inscript.")
269 (if nil
270 (quail-define-package "punjabi-inscript" "Punjabi" "PnjIS" t "Punjabi keyboard Inscript"))
271 (quail-define-inscript-package
272 indian-pnj-base-table inscript-dev-keytable
273 "punjabi-inscript" "Punjabi" "PnjIS"
274 "Punjabi keyboard Inscript.")
276 (if nil
277 (quail-define-package "gujarati-inscript" "Gujarati" "GjrIS" t "Gujarati keyboard Inscript"))
278 (quail-define-inscript-package
279 indian-gjr-base-table inscript-dev-keytable
280 "gujarati-inscript" "Gujarati" "GjrIS"
281 "Gujarati keyboard Inscript.")
283 (if nil
284 (quail-define-package "oriya-inscript" "Oriya" "OriIS" t "Oriya keyboard Inscript"))
285 (quail-define-inscript-package
286 indian-ori-base-table inscript-dev-keytable
287 "oriya-inscript" "Oriya" "OriIS"
288 "Oriya keyboard Inscript.")
290 (if nil
291 (quail-define-package "bengali-inscript" "Bengali" "BngIS" t "Bengali keyboard Inscript"))
292 (quail-define-inscript-package
293 indian-bng-base-table inscript-dev-keytable
294 "bengali-inscript" "Bengali" "BngIS"
295 "Bengali keyboard Inscript.")
297 (if nil
298 (quail-define-package "assamese-inscript" "Assamese" "AsmIS" t "Assamese keyboard Inscript"))
299 (quail-define-inscript-package
300 indian-asm-base-table inscript-dev-keytable
301 "assamese-inscript" "Assamese" "AsmIS"
302 "Assamese keyboard Inscript.")
304 (if nil
305 (quail-define-package "telugu-inscript" "Telugu" "TlgIS" t "Telugu keyboard Inscript"))
306 (quail-define-inscript-package
307 indian-dev-base-table inscript-dev-keytable
308 "telugu-inscript" "Telugu" "TlgIS"
309 "Telugu keyboard Inscript.")
311 (if nil
312 (quail-define-package "kannada-inscript" "Kannada" "KndIS" t "Kannada keyboard Inscript"))
313 (quail-define-inscript-package
314 indian-knd-base-table inscript-dev-keytable
315 "kannada-inscript" "Kannada" "KndIS"
316 "Kannada keyboard Inscript.")
318 (if nil
319 (quail-define-package "malayalam-inscript" "Malayalam" "MlmIS" t "Malayalam keyboard Inscript"))
320 (quail-define-inscript-package
321 indian-mlm-base-table inscript-dev-keytable
322 "malayalam-inscript" "Malayalam" "MlmIS"
323 "Malayalam keyboard Inscript.")
325 (if nil
326 (quail-define-package "tamil-inscript" "Tamil" "TmlIS" t "Tamil keyboard Inscript"))
327 (quail-define-inscript-package
328 indian-tml-base-table inscript-dev-keytable
329 "tamil-inscript" "Tamil" "TmlIS"
330 "Tamil keyboard Inscript.")
332 ;;; arch-tag: 9e5a621e-f7d5-4fce-9543-0a51b407c940
333 ;;; indian.el ends here