add-log-current-defun): Skip the semicolon ``;'' for
[emacs.git] / leim / quail / indian.el
blob973c5ff12bbf0df6d063f8aee22abde8a3262335
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 2, 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)
50 (make-variable-frame-local 'quail-indian-update-preceding-char)
52 ;; Input value ::
53 ;; CONTROL-FLAG is integer `n'
54 ;; quail-current-key :: keyboard input.
55 ;; Only first `n' can be translated.
56 ;; quail-current-str :: corresonding string.
57 ;; jobs :: (1) put last (len-n) char to unrread-command-event.
58 ;; (2) put translated string to quail-current-str.
60 ;; CONTROL-FLAG is t (terminate) or nil (proceed the translation)
61 ;; quail-current-key :: keyboard input.
62 ;; quail-current-str :: corresponding string.
63 ;; jobs :: (1) put modified translated string to quail-current-str.
65 ;; When non-nil value is returned from quail-translation-update-function,
66 ;; the quail-current-str is split to characters and put into event queue,
67 ;; with `compose-last-char' event with composition info at the end.
69 (defun quail-indian-update-translation (control-flag)
70 ;; make quail-current-str string when possible.
71 (if (char-valid-p quail-current-str)
72 (setq quail-current-str (char-to-string quail-current-str)))
73 ;(message "\n input control-flag=%s, str=%s, key=%s q-ind-upd-prec-char=%s"
74 ; control-flag quail-current-str quail-current-key
75 ; quail-indian-update-preceding-char)
76 ;; reset quail-indian-update-preceding-char if it's initial.
77 (if (= (overlay-start quail-overlay) (overlay-end quail-overlay))
78 (setq quail-indian-update-preceding-char nil))
79 ;; Check the preceding character of the quail region. If the
80 ;; preceding character can be composed with quail-current-str, then
81 ;; grab that preceding character into the quail-current-str and
82 ;; remove that char from the region.
83 (let* (prec-char-position composition-regexp
84 prec-char-str candidate-str match-pos match-end)
85 (when (and quail-current-str
86 (null quail-indian-update-preceding-char)
87 (null input-method-use-echo-area)
88 (null input-method-exit-on-first-char)
89 (setq prec-char-position
90 (quail-indian-preceding-char-position
91 (overlay-start quail-overlay)))
92 (setq composition-regexp
93 (if prec-char-position
94 (caar (elt composition-function-table
95 (char-after prec-char-position)))))
96 (setq prec-char-str
97 (buffer-substring prec-char-position
98 (overlay-start quail-overlay))
99 candidate-str (concat prec-char-str quail-current-str)
100 match-pos (string-match composition-regexp candidate-str)
101 match-end (match-end 0))
102 (> match-end (length prec-char-str)))
103 (setq quail-indian-update-preceding-char prec-char-str)
104 (delete-region prec-char-position
105 (overlay-start quail-overlay))))
106 (setq quail-current-str
107 (indian-compose-string
108 (concat quail-indian-update-preceding-char
109 quail-current-str)))
110 (if (numberp control-flag)
111 (setq unread-command-events
112 (string-to-list
113 (substring quail-current-key control-flag))))
114 (when control-flag
115 (setq quail-indian-update-preceding-char nil))
116 ;(message "output control-flag=%s, str=%s, key=%s q-ind-upd-prec-char=%s"
117 ; control-flag quail-current-str quail-current-key
118 ; quail-indian-update-preceding-char)
119 control-flag)
122 ;;; Input by transliteration
125 (defun quail-define-indian-trans-package (hashtbls pkgname
126 lang title doc)
127 (funcall 'quail-define-package pkgname lang title t doc
128 nil nil nil nil nil nil t nil
129 'quail-indian-update-translation)
130 (maphash
131 (lambda (key val)
132 (quail-defrule key (if (= (length val) 1)
133 (string-to-char val)
134 (vector val))))
135 (cdr hashtbls)))
137 ;; This needs to be seen by quail-update-leim-list-file, but cannot be
138 ;; commented out because quail-update-leim-list-file ignores
139 ;; commented-out lines.
140 (if nil
141 (quail-define-package "devanagari-itrans" "Devanagari" "DevIT" t "Devanagari ITRANS"))
142 (quail-define-indian-trans-package
143 indian-dev-itrans-v5-hash "devanagari-itrans" "Devanagari" "DevIT"
144 "Devanagari transliteration by ITRANS method.")
146 (if nil
147 (quail-define-package "devanagari-kyoto-harvard" "Devanagari" "DevKH" t "Devanagari Kyoto-Harvard"))
148 (quail-define-indian-trans-package
149 indian-dev-kyoto-harvard-hash
150 "devanagari-kyoto-harvard" "Devanagari" "DevKH"
151 "Devanagari transliteration by Kyoto-Harvard method.")
153 (if nil
154 (quail-define-package "devanagari-aiba" "Devanagari" "DevAB" t "Devanagari Aiba"))
155 (quail-define-indian-trans-package
156 indian-dev-aiba-hash "devanagari-aiba" "Devanagari" "DevAB"
157 "Devanagari transliteration by Aiba-method.")
159 (if nil
160 (quail-define-package "punjabi-itrans" "Punjabi" "PnjIT" t "Punjabi ITRANS"))
161 (quail-define-indian-trans-package
162 indian-pnj-itrans-v5-hash "punjabi-itrans" "Punjabi" "PnjIT"
163 "Punjabi transliteration by ITRANS method.")
165 (if nil
166 (quail-define-package "gujarati-itrans" "Gujarati" "GjrIT" t "Gujarati ITRANS"))
167 (quail-define-indian-trans-package
168 indian-gjr-itrans-v5-hash "gujarati-itrans" "Gujarati" "GjrIT"
169 "Gujarati transliteration by ITRANS method.")
171 (if nil
172 (quail-define-package "oriya-itrans" "Oriya" "OriIT" t "Oriya ITRANS"))
173 (quail-define-indian-trans-package
174 indian-ori-itrans-v5-hash "oriya-itrans" "Oriya" "OriIT"
175 "Oriya transliteration by ITRANS method.")
177 (if nil
178 (quail-define-package "bengali-itrans" "Bengali" "BngIT" t "Bengali ITRANS"))
179 (quail-define-indian-trans-package
180 indian-bng-itrans-v5-hash "bengali-itrans" "Bengali" "BngIT"
181 "Bengali transliteration by ITRANS method.")
183 (if nil
184 (quail-define-package "assamese-itrans" "Assamese" "AsmIT" t "Assamese ITRANS"))
185 (quail-define-indian-trans-package
186 indian-asm-itrans-v5-hash "assamese-itrans" "Assamese" "AsmIT"
187 "Assamese transliteration by ITRANS method.")
189 (if nil
190 (quail-define-package "telugu-itrans" "Telugu" "TlgIT" t "Telugu ITRANS"))
191 (quail-define-indian-trans-package
192 indian-tlg-itrans-v5-hash "telugu-itrans" "Telugu" "TlgIT"
193 "Telugu transliteration by ITRANS method.")
195 (if nil
196 (quail-define-package "kannada-itrans" "Kannada" "KndIT" t "Kannada ITRANS"))
197 (quail-define-indian-trans-package
198 indian-knd-itrans-v5-hash "kannada-itrans" "Kannada" "KndIT"
199 "Kannada transliteration by ITRANS method.")
201 (if nil
202 (quail-define-package "malayalam-itrans" "Malayalam" "MlmIT" t "Malayalam ITRANS"))
203 (quail-define-indian-trans-package
204 indian-mlm-itrans-v5-hash "malayalam-itrans" "Malayalam" "MlmIT"
205 "Malayalam transliteration by ITRANS method.")
207 (if nil
208 (quail-define-package "tamil-itrans" "Tamil" "TmlIT" t "Tamil ITRANS"))
209 (quail-define-indian-trans-package
210 indian-tml-itrans-v5-hash "tamil-itrans" "Tamil" "TmlIT"
211 "Tamil transliteration by ITRANS method.")
215 ;;; Input by Inscript
218 (defun quail-indian-flatten-list (lst)
219 "Flatten the nested LIST so that there would be no innner list."
220 (if (listp lst)
221 (apply 'append (mapcar 'quail-indian-flatten-list lst))
222 (list lst)))
224 (defun quail-define-inscript-package (char-table key-table pkgname lang title
225 docstring)
226 (setq char-table (quail-indian-flatten-list char-table))
227 (setq key-table (quail-indian-flatten-list key-table))
228 (funcall 'quail-define-package pkgname lang title nil docstring
229 nil nil nil nil nil nil nil nil
230 'quail-indian-update-translation)
231 (dolist (key key-table)
232 (let ((val (pop char-table)))
233 (if (and key val)
234 (quail-defrule
235 (if (char-valid-p key) (char-to-string key) key)
236 (if (stringp val) (vector val) val))))))
240 (defvar inscript-dev-keytable
242 (;; VOWELS (18)
243 (?D nil) (?E ?e) (?F ?f) (?R ?r) (?G ?g) (?T ?t)
244 (?+ ?=) ("F]" "f]") (?! ?@) (?Z ?z) (?S ?s) (?W ?w)
245 (?| ?\\) (?~ ?`) (?A ?a) (?Q ?q) ("+]" "=]") ("R]" "r]"))
246 (;; CONSONANTS (42)
247 ?k ?K ?i ?I ?U ;; GRUTTALS
248 ?\; ?: ?p ?P ?} ;; PALATALS
249 ?' ?\" ?\[ ?{ ?C ;; CEREBRALS
250 ?l ?L ?o ?O ?v ?V ;; DENTALS
251 ?h ?H ?y ?Y ?c ;; LABIALS
252 ?/ ?j ?J ?n ?N "N]" ?b ;; SEMIVOWELS
253 ?M ?< ?m ?u ;; SIBILANTS
254 "k]" "K]" "i]" "p]" "[]" "{]" "H]" "/]" ;; NUKTAS
255 ?% ?&)
256 (;; Misc Symbols (7)
257 ?X ?x ?_ ">]" ?d "X]" ?>)
258 (;; Digits
259 ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)
260 (;; Inscripts
261 ?# ?$ ?^ ?* ?\])))
263 (if nil
264 (quail-define-package "devanagari-inscript" "Devanagari" "DevIS" t "Devanagari keyboard Inscript"))
265 (quail-define-inscript-package
266 indian-dev-base-table inscript-dev-keytable
267 "devanagari-inscript" "Devanagari" "DevIS"
268 "Devanagari keyboard Inscript.")
270 (if nil
271 (quail-define-package "punjabi-inscript" "Punjabi" "PnjIS" t "Punjabi keyboard Inscript"))
272 (quail-define-inscript-package
273 indian-pnj-base-table inscript-dev-keytable
274 "punjabi-inscript" "Punjabi" "PnjIS"
275 "Punjabi keyboard Inscript.")
277 (if nil
278 (quail-define-package "gujarati-inscript" "Gujarati" "GjrIS" t "Gujarati keyboard Inscript"))
279 (quail-define-inscript-package
280 indian-gjr-base-table inscript-dev-keytable
281 "gujarati-inscript" "Gujarati" "GjrIS"
282 "Gujarati keyboard Inscript.")
284 (if nil
285 (quail-define-package "oriya-inscript" "Oriya" "OriIS" t "Oriya keyboard Inscript"))
286 (quail-define-inscript-package
287 indian-ori-base-table inscript-dev-keytable
288 "oriya-inscript" "Oriya" "OriIS"
289 "Oriya keyboard Inscript.")
291 (if nil
292 (quail-define-package "bengali-inscript" "Bengali" "BngIS" t "Bengali keyboard Inscript"))
293 (quail-define-inscript-package
294 indian-bng-base-table inscript-dev-keytable
295 "bengali-inscript" "Bengali" "BngIS"
296 "Bengali keyboard Inscript.")
298 (if nil
299 (quail-define-package "assamese-inscript" "Assamese" "AsmIS" t "Assamese keyboard Inscript"))
300 (quail-define-inscript-package
301 indian-asm-base-table inscript-dev-keytable
302 "assamese-inscript" "Assamese" "AsmIS"
303 "Assamese keyboard Inscript.")
305 (if nil
306 (quail-define-package "telugu-inscript" "Telugu" "TlgIS" t "Telugu keyboard Inscript"))
307 (quail-define-inscript-package
308 indian-dev-base-table inscript-dev-keytable
309 "telugu-inscript" "Telugu" "TlgIS"
310 "Telugu keyboard Inscript.")
312 (if nil
313 (quail-define-package "kannada-inscript" "Kannada" "KndIS" t "Kannada keyboard Inscript"))
314 (quail-define-inscript-package
315 indian-knd-base-table inscript-dev-keytable
316 "kannada-inscript" "Kannada" "KndIS"
317 "Kannada keyboard Inscript.")
319 (if nil
320 (quail-define-package "malayalam-inscript" "Malayalam" "MlmIS" t "Malayalam keyboard Inscript"))
321 (quail-define-inscript-package
322 indian-mlm-base-table inscript-dev-keytable
323 "malayalam-inscript" "Malayalam" "MlmIS"
324 "Malayalam keyboard Inscript.")
326 (if nil
327 (quail-define-package "tamil-inscript" "Tamil" "TmlIS" t "Tamil keyboard Inscript"))
328 (quail-define-inscript-package
329 indian-tml-base-table inscript-dev-keytable
330 "tamil-inscript" "Tamil" "TmlIS"
331 "Tamil keyboard Inscript.")
333 ;;; arch-tag: 9e5a621e-f7d5-4fce-9543-0a51b407c940
334 ;;; indian.el ends here