*** empty log message ***
[emacs.git] / leim / quail / indian.el
blob8bec02cdfcfe77c598ded33dce4e0b6422c62c00
1 ;;; indian.el --- Quail packages for inputting Indian
3 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
5 ;; Author: KAWABATA, Taichi <kawabata@m17n.org>
7 ;; Keywords: multilingual, input method, Indian, Devanagari
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; History:
30 ;; 2000.12.12
31 ;; Totally re-written from devanagari.el to handle multiple Indian Scripts.
33 ;;; Code:
35 (require 'quail)
36 (require 'devan-util)
37 (require 'ind-util)
39 (defun quail-indian-preceding-char-position (position)
40 "Return the position of preceding composite character."
41 (let (prec-composed)
42 (if (char-valid-p (char-before position)) ;; range o.k.
43 (if (setq prec-composed (find-composition (1- position)))
44 (car prec-composed)
45 (1- position))
46 nil)))
48 (defvar quail-indian-update-preceding-char nil)
49 (make-variable-frame-local 'quail-indian-update-preceding-char)
51 ;;; update function
53 ;; CONTROL-FLAG is integer (n)
54 ;; quail-current-key :: keyboard input.
55 ;; Only first n can be translated.
56 ;; quail-current-string :: corresonding string. Translated when last
57 ;; time CONTROL-FLAG is nil.
58 ;; todo :: (1) put last (len-n) char to unrread-command-event.
59 ;; (2) put translated string to quail-current-string.
61 ;; CONTROL-FLAG is t (terminate) or nil (proceed the translation)
62 ;; quail-current-key :: keyboard input.
63 ;; quail-current-string :: corresponding string. Created by database.
64 ;; todo :: (1) put modified translated string to quail-current-string.
66 (defun quail-indian-update-translation (control-flag)
67 ;;(message "input control-flag=%s, string=%s, key=%s"
68 ;; control-flag quail-current-str quail-current-key)
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 ;; reset quail-indian-update-preceding-char if it's initial.
73 (if (= (overlay-start quail-overlay) (overlay-end quail-overlay))
74 (setq quail-indian-update-preceding-char nil))
75 ;; set quial-indian-update-preceding-char if appropriate.
76 (let* (prec-char-position composition-regexp
77 prec-char-str candidate-str match-pos match-end)
78 (when (and quail-current-str
79 (null input-method-use-echo-area)
80 (null input-method-exit-on-first-char)
81 (setq prec-char-position
82 (quail-indian-preceding-char-position
83 (overlay-start quail-overlay)))
84 (setq composition-regexp
85 (if prec-char-position
86 (caar (elt composition-function-table
87 (char-after prec-char-position)))))
88 ;; (null quail-indian-update-preceding-char)
89 (setq prec-char-str
90 (buffer-substring prec-char-position
91 (overlay-start quail-overlay))
92 candidate-str (concat prec-char-str quail-current-str)
93 match-pos (string-match composition-regexp candidate-str)
94 match-end (match-end 0))
95 (> match-end (length prec-char-str)))
96 (setq quail-indian-update-preceding-char prec-char-str)
97 (delete-region prec-char-position
98 (overlay-start quail-overlay))))
99 ;; make quail-current-str string when possible.
100 (if (null quail-current-str)
101 (setq quail-current-str ""))
102 ;; set quail-current-str unless control-flag is number.
103 (if (numberp control-flag)
104 (setq quail-indian-update-preceding-char nil
105 quail-current-str
106 (if (equal quail-current-str "")
107 (substring quail-current-key 0 control-flag)
108 (indian-compose-string quail-current-str))
109 unread-command-events
110 (string-to-list
111 (substring quail-current-key control-flag)))
112 (if quail-indian-update-preceding-char
113 (setq quail-current-str
114 (concat quail-indian-update-preceding-char
115 quail-current-str)))
116 (setq quail-current-str
117 (indian-compose-string quail-current-str)))
118 (when (eq t control-flag)
119 ;; reset preceding-char if translation is terminated.
120 (setq quail-indian-update-preceding-char nil))
121 ;; compose to previous char if it looks possible.
122 ;;(message " out control-flag=%s, string=%s, key=%s"
123 ;; control-flag quail-current-str quail-current-key)
124 control-flag)
127 ;;; Input by transliteration
130 (defun quail-define-indian-trans-package (hashtbls pkgname
131 lang title doc)
132 (funcall 'quail-define-package pkgname lang title t doc
133 nil nil nil nil nil nil t nil
134 'quail-indian-update-translation)
135 (maphash
136 (lambda (key val)
137 (quail-defrule key (if (= (length val) 1)
138 (string-to-char val)
139 (vector val))))
140 (cdr hashtbls)))
142 ;; This needs to be seen by quail-update-leim-list-file, but cannot be
143 ;; commented out because quail-update-leim-list-file ignores
144 ;; commented-out lines.
145 (if nil
146 (quail-define-package "devanagari-itrans" "Devanagari" "DevIT" t "Devanagari ITRANS"))
147 (quail-define-indian-trans-package
148 indian-dev-itrans-v5-hash "devanagari-itrans" "Devanagari" "DevIT"
149 "Devanagari transliteration by ITRANS method.")
151 (if nil
152 (quail-define-package "devanagari-kyoto-harvard" "Devanagari" "DevKH" t "Devanagari Kyoto-Harvard"))
153 (quail-define-indian-trans-package
154 indian-dev-kyoto-harvard-hash
155 "devanagari-kyoto-harvard" "Devanagari" "DevKH"
156 "Devanagari transliteration by Kyoto-Harvard method.")
158 (if nil
159 (quail-define-package "devanagari-aiba" "Devanagari" "DevAB" t "Devanagari Aiba"))
160 (quail-define-indian-trans-package
161 indian-dev-aiba-hash "devanagari-aiba" "Devanagari" "DevAB"
162 "Devanagari transliteration by Aiba-method.")
165 ;;; Input by Inscript
168 (defun quail-indian-flatten-list (lst)
169 "Flatten the nested LIST so that there would be no innner list."
170 (if (listp lst)
171 (apply 'append (mapcar 'quail-indian-flatten-list lst))
172 (list lst)))
174 (defun quail-define-inscript-package (char-table key-table pkgname lang title
175 docstring)
176 (setq char-table (quail-indian-flatten-list char-table))
177 (setq key-table (quail-indian-flatten-list key-table))
178 (funcall 'quail-define-package pkgname lang title nil docstring
179 nil nil nil nil nil nil nil nil
180 'quail-indian-update-translation)
181 (dolist (key key-table)
182 (let ((val (pop char-table)))
183 (if (and key val)
184 (quail-defrule
185 (if (char-valid-p key) (char-to-string key) key)
186 (if (stringp val) (vector val) val))))))
190 (defvar inscript-dev-keytable
192 (;; VOWELS (18)
193 (?D nil) (?E ?e) (?F ?f) (?R ?r) (?G ?g) (?T ?t)
194 (?+ ?=) ("F]" "f]") (?! ?@) (?Z ?z) (?S ?s) (?W ?w)
195 (?| ?\\) (?~ ?`) (?A ?a) (?Q ?q) ("+]" "=]") ("R]" "r]"))
196 (;; CONSONANTS (42)
197 ?k ?K ?i ?I ?U ;; GRUTTALS
198 ?\; ?: ?p ?P ?} ;; PALATALS
199 ?' ?\" ?\[ ?{ ?C ;; CEREBRALS
200 ?l ?L ?o ?O ?v ?V ;; DENTALS
201 ?h ?H ?y ?Y ?c ;; LABIALS
202 ?/ ?j ?J ?n ?N "N]" ?b ;; SEMIVOWELS
203 ?M ?< ?m ?u ;; SIBILANTS
204 "k]" "K]" "i]" "p]" "[]" "{]" "H]" "/]" ;; NUKTAS
205 ?% ?&)
206 (;; Misc Symbols (7)
207 ?X ?x ?_ ">]" ?d "X]" ?>)
208 (;; Digits
209 ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)
210 (;; Inscripts
211 ?# ?$ ?^ ?* ?\])))
213 (if nil
214 (quail-define-package "devanagari-inscript" "Devanagari" "DevIS" t "Devanagari keyboard Inscript"))
215 (quail-define-inscript-package
216 indian-dev-base-table inscript-dev-keytable
217 "devanagari-inscript" "Devanagari" "DevIS"
218 "Devanagari keyboard Inscript.")
220 ;;; indian.el ends here