root/trunk/lisp/language/ethio-util.el

Revision 4220, 70.1 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

  • Property svn:eol-style set to LF
Line 
1 ;;; ethio-util.el --- utilities for Ethiopic -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 1997, 1998, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;;   Free Software Foundation, Inc.
5 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
6 ;;   2006, 2007, 2008
7 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
8 ;;   Registration Number H14PRO021
9
10 ;; Keywords: mule, multilingual, Ethiopic
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;; Author: TAKAHASHI Naoto <ntakahas@m17n.org>
30
31 ;;; Commentary:
32
33 ;;; Code:
34
35 (defvar rmail-current-message)
36 (defvar rmail-message-vector)
37
38 ;; Information for exiting Ethiopic environment.
39 (defvar exit-ethiopic-environment-data nil)
40
41 ;;;###autoload
42 (defun setup-ethiopic-environment-internal ()
43   (let ((key-bindings '((" " . ethio-insert-space)
44                         ([?\S- ] . ethio-insert-ethio-space)
45                         ([?\C-'] . ethio-gemination)
46
47                         ;; these old bindings conflict
48                         ;; with Emacs' binding policy
49
50                         ;; ([f2] . ethio-toggle-space)
51                         ;; ([S-f2] . ethio-replace-space) ; as requested
52                         ;; ([f3] . ethio-toggle-punctuation)
53                         ;; ([f4] . ethio-sera-to-fidel-buffer)
54                         ;; ([S-f4] . ethio-sera-to-fidel-region)
55                         ;; ([C-f4] . ethio-sera-to-fidel-mail-or-marker)
56                         ;; ([f5] . ethio-fidel-to-sera-buffer)
57                         ;; ([S-f5] . ethio-fidel-to-sera-region)
58                         ;; ([C-f5] . ethio-fidel-to-sera-mail-or-marker)
59                         ;; ([f6] . ethio-modify-vowel)
60                         ;; ([f7] . ethio-replace-space)
61                         ;; ([f8] . ethio-input-special-character)
62
63                         ;; this is the rewritten bindings
64
65                         ([f3] . ethio-fidel-to-sera-buffer)
66                         ([S-f3] . ethio-fidel-to-sera-region)
67                         ([C-f3] . ethio-fidel-to-sera-mail-or-marker)
68                         ([f4] . ethio-sera-to-fidel-buffer)
69                         ([S-f4] . ethio-sera-to-fidel-region)
70                         ([C-f4] . ethio-sera-to-fidel-mail-or-marker)
71                         ([S-f5] . ethio-toggle-punctuation)
72                         ([S-f6] . ethio-modify-vowel)
73                         ([S-f7] . ethio-replace-space)
74                         ([S-f8] . ethio-input-special-character)
75                         ([C-f9] . ethio-toggle-space)
76                         ([S-f9] . ethio-replace-space) ; as requested
77                         ))
78         kb)
79     (while key-bindings
80       (setq kb (car (car key-bindings)))
81       (setq exit-ethiopic-environment-data
82             (cons (cons kb (global-key-binding kb))
83                   exit-ethiopic-environment-data))
84       (global-set-key kb (cdr (car key-bindings)))
85       (setq key-bindings (cdr key-bindings))))
86
87   (add-hook 'quail-activate-hook 'ethio-select-a-translation)
88   (add-hook 'find-file-hook 'ethio-find-file)
89   (add-hook 'write-file-functions 'ethio-write-file)
90   (add-hook 'after-save-hook 'ethio-find-file))
91
92 (defun exit-ethiopic-environment ()
93   "Exit Ethiopic language environment."
94   (while exit-ethiopic-environment-data
95     (global-set-key (car (car exit-ethiopic-environment-data))
96                     (cdr (car exit-ethiopic-environment-data)))
97     (setq exit-ethiopic-environment-data
98           (cdr exit-ethiopic-environment-data)))
99
100   (remove-hook 'quail-activate-hook 'ethio-select-a-translation)
101   (remove-hook 'find-file-hook 'ethio-find-file)
102   (remove-hook 'write-file-functions 'ethio-write-file)
103   (remove-hook 'after-save-hook 'ethio-find-file))
104
105 ;;
106 ;; ETHIOPIC UTILITY FUNCTIONS
107 ;;
108
109 ;; If the filename ends in ".sera", editing is done in fidel
110 ;; but file I/O is done in SERA.
111 ;;
112 ;; If the filename ends in ".java", editing is done in fidel
113 ;; but file I/O is done in the \uXXXX style, where XXXX is
114 ;; the Unicode codepoint for the Ethiopic character.
115 ;;
116 ;; If the filename ends in ".tex", editing is done in fidel
117 ;; but file I/O is done in EthioTeX format.
118 ;;
119 ;; To automatically convert Ethiopic text to SERA format when sending mail,
120 ;;   (add-hook 'mail-send-hook 'ethio-fidel-to-sera-mail)
121 ;;
122 ;; To automatically convert SERA format to Ethiopic when receiving mail,
123 ;;   (add-hook 'rmail-show-message-hook 'ethio-sera-to-fidel-mail)
124 ;;
125 ;; To automatically convert Ethiopic text to SERA format when posting news,
126 ;;   (add-hook 'news-inews-hook 'ethio-fidel-to-sera-mail)
127
128 ;;
129 ;; users' preference
130 ;;
131
132 (defvar ethio-primary-language 'tigrigna
133   "*Symbol that defines the primary language in SERA --> FIDEL conversion.
134 The value should be one of: `tigrigna', `amharic' or `english'.")
135
136 (defvar ethio-secondary-language 'english
137   "*Symbol that defines the secondary language in SERA --> FIDEL conversion.
138 The value should be one of: `tigrigna', `amharic' or `english'.")
139
140 (defvar ethio-use-colon-for-colon nil
141   "*Non-nil means associate ASCII colon with Ethiopic colon.
142 If nil, associate ASCII colon with Ethiopic word separator, i.e., two
143 vertically stacked dots.  All SERA <--> FIDEL converters refer this
144 variable.")
145
146 (defvar ethio-use-three-dot-question nil
147   "*Non-nil means associate ASCII question mark with Ethiopic old style question mark (three vertically stacked dots).
148 If nil, associate ASCII question mark with Ethiopic stylized question
149 mark.  All SERA <--> FIDEL converters refer this variable.")
150
151 (defvar ethio-quote-vowel-always nil
152   "*Non-nil means always put an apostrophe before an isolated vowel (except at word initial) in FIDEL --> SERA conversion.
153 If nil, put an apostrophe only between a sixth-form consonant and an
154 isolated vowel.")
155
156 (defvar ethio-W-sixth-always nil
157   "*Non-nil means convert the Wu-form of a 12-form consonant to \"W'\" instead of \"Wu\" in FIDEL --> SERA conversion.")
158
159 (defvar ethio-numeric-reduction 0
160   "*Degree of reduction in converting Ethiopic digits into Arabic digits.
161 Should be 0, 1 or 2.
162 For example, ({10}{9}{100}{80}{7}) is converted into:
163     `10`9`100`80`7  if `ethio-numeric-reduction' is 0,
164     `109100807      if `ethio-numeric-reduction' is 1,
165     `10900807       if `ethio-numeric-reduction' is 2.")
166
167 (defvar ethio-implicit-period-conversion t
168   "*Non-nil means replacing the Ethiopic dot at the end of an Ethiopic sentence
169 with an Ethiopic full stop.")
170
171 (defvar ethio-java-save-lowercase nil
172   "*Non-nil means save Ethiopic characters in lowercase hex numbers to Java files.
173 If nil, use uppercases.")
174
175 ;;
176 ;; SERA to FIDEL
177 ;;
178
179 (defconst ethio-sera-to-fidel-table
180   [
181    nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
182    nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
183 ;;; SP
184    (" "
185     (?: (if ethio-use-colon-for-colon " $(3$l(B" "$(3$h(B")
186         (32 (if ethio-use-colon-for-colon " $(3$l(B " "$(3$h(B"))
187         (?- " $(3$m(B")
188         (?: " $(3$i(B")
189         (?| (if ethio-use-colon-for-colon " $(3$l(B|" " $(3$h(B|")
190             (?: " $(3$o(B"))))
191
192 ;;; !   "   #   $   %   &    '
193    nil nil nil nil nil nil ("" (?' "$(3%s(B"))
194 ;;; (   )   *   +    ,      -               .
195    nil nil nil nil ("$(3$j(B") ("-" (?: "$(3$l(B")) ("$(3%u(B")
196 ;;;  /   0   1   2   3   4   5   6   7   8   9
197     nil nil nil nil nil nil nil nil nil nil nil
198 ;;; :
199    ((if ethio-use-colon-for-colon "$(3$l(B" "$(3$h(B")
200     (32 (if ethio-use-colon-for-colon "$(3$l(B " "$(3$h(B"))
201     (?- "$(3$m(B")
202     (?: "$(3$i(B")
203     (?| (if ethio-use-colon-for-colon "$(3$l(B|" "$(3$h(B|")
204         (?: "$(3$o(B")))
205 ;;;  ;      <              =    >
206    ("$(3$k(B") ("<" (?< "$(3%v(B")) nil (">" (?> "$(3%w(B"))
207 ;;; ?
208    ((if ethio-use-three-dot-question "$(3$n(B" "$(3%x(B"))
209 ;;; @
210     nil
211 ;;; A
212    ("$(3"f(B" (?2 "$(3#8(B"))
213 ;;; B
214    ("$(3"((B" (?e "$(3"#(B") (?u "$(3"$(B") (?i "$(3"%(B") (?a "$(3"&(B") (?E "$(3"'(B") (?o "$(3")(B")
215          (?W "$(3%b(B" (?e "$(3%2(B") (?u "$(3%b(B") (?i "$(3%B(B") (?a "$(3"*(B") (?E "$(3%R(B")))
216 ;;; C
217    ("$(3$4(B" (?e "$(3$/(B") (?u "$(3$0(B") (?i "$(3$1(B") (?a "$(3$2(B") (?E "$(3$3(B") (?o "$(3$5(B")
218          (?W "$(3$6(B" (?a "$(3$6(B")
219                   (?e "$(3$4%n(B") (?u "$(3$4%r(B") (?i "$(3$4%o(B") (?E "$(3$4%q(B")))
220 ;;; D
221    ("$(3#b(B" (?e "$(3#](B") (?u "$(3#^(B") (?i "$(3#_(B") (?a "$(3#`(B") (?E "$(3#a(B") (?o "$(3#c(B")
222          (?W "$(3#d(B" (?a "$(3#d(B")
223                   (?e "$(3#b%n(B") (?u "$(3#b%r(B") (?i "$(3#b%o(B") (?E "$(3#b%q(B")))
224 ;;; E
225    ("$(3"g(B" (?2 "$(3#9(B"))
226 ;;; F
227    ("$(3$T(B" (?e "$(3$O(B") (?u "$(3$P(B") (?i "$(3$Q(B") (?a "$(3$R(B") (?E "$(3$S(B") (?o "$(3$U(B")
228          (?W "$(3%d(B" (?e "$(3%4(B") (?u "$(3%d(B") (?i "$(3%D(B") (?a "$(3$V(B") (?E "$(3%T(B"))
229          (?Y "$(3$a(B" (?a "$(3$a(B")))
230 ;;; G
231    ("$(3$$(B" (?e "$(3#}(B") (?u "$(3#~(B") (?i "$(3$!(B") (?a "$(3$"(B") (?E "$(3$#(B") (?o "$(3$%(B")
232          (?W "$(3%c(B" (?e "$(3%3(B") (?u "$(3%c(B") (?i "$(3%C(B") (?a "$(3$&(B") (?E "$(3%S(B")))
233 ;;; H
234    ("$(3!6(B" (?e "$(3!1(B") (?u "$(3!2(B") (?i "$(3!3(B") (?a "$(3!4(B") (?E "$(3!5(B") (?o "$(3!7(B")
235          (?W "$(3!8(B" (?a "$(3!8(B")
236                   (?e "$(3!6%n(B") (?u "$(3!6%r(B") (?i "$(3!6%o(B") (?E "$(3!6%q(B")))
237 ;;; I
238    ("$(3"h(B" (?2 "$(3#:(B"))
239 ;;; J
240    ("$(3#j(B" (?e "$(3#e(B") (?u "$(3#f(B") (?i "$(3#g(B") (?a "$(3#h(B") (?E "$(3#i(B") (?o "$(3#k(B")
241          (?W "$(3#l(B" (?a "$(3#l(B")
242                   (?e "$(3#j%n(B") (?u "$(3#j%r(B") (?i "$(3#j%o(B") (?E "$(3#j%q(B")))
243 ;;; K
244    ("$(3#"(B" (?e "$(3"{(B") (?u "$(3"|(B") (?i "$(3"}(B") (?a "$(3"~(B") (?E "$(3#!(B") (?o "$(3##(B")
245          (?W "$(3#*(B" (?e "$(3#%(B") (?u "$(3#*(B") (?i "$(3#'(B") (?a "$(3#((B") (?E "$(3#)(B")))
246 ;;; L
247    ("$(3!.(B" (?e "$(3!)(B") (?u "$(3!*(B") (?i "$(3!+(B") (?a "$(3!,(B") (?E "$(3!-(B") (?o "$(3!/(B")
248          (?W "$(3!0(B" (?a "$(3!0(B")
249                   (?e "$(3!.%n(B") (?u "$(3!.%r(B") (?i "$(3!.%o(B") (?E "$(3!.%q(B")))
250 ;;; M
251    ("$(3!>(B" (?e "$(3!9(B") (?u "$(3!:(B") (?i "$(3!;(B") (?a "$(3!<(B") (?E "$(3!=(B") (?o "$(3!?(B")
252          (?W "$(3%a(B" (?e "$(3%1(B") (?u "$(3%a(B") (?i "$(3%A(B") (?a "$(3!@(B") (?E "$(3%Q(B"))
253          (?Y "$(3$_(B" (?a "$(3$_(B")))
254 ;;; N
255    ("$(3"`(B" (?e "$(3"[(B") (?u "$(3"\(B") (?i "$(3"](B") (?a "$(3"^(B") (?E "$(3"_(B") (?o "$(3"a(B")
256          (?W "$(3"b(B" (?a "$(3"b(B")
257                   (?e "$(3"`%n(B") (?u "$(3"`%r(B") (?i "$(3"`%o(B") (?E "$(3"`%q(B")))
258 ;;; O
259    ("$(3"i(B" (?2 "$(3#;(B"))
260 ;;; P
261    ("$(3$<(B" (?e "$(3$7(B") (?u "$(3$8(B") (?i "$(3$9(B") (?a "$(3$:(B") (?E "$(3$;(B") (?o "$(3$=(B")
262          (?W "$(3$>(B" (?a "$(3$>(B")
263                   (?e "$(3$<%n(B") (?u "$(3$<%r(B") (?i "$(3$<%o(B") (?E "$(3$<%q(B")))
264 ;;; Q
265    ("$(3!v(B" (?e "$(3!q(B") (?u "$(3!r(B") (?i "$(3!s(B") (?a "$(3!t(B") (?E "$(3!u(B") (?o "$(3!w(B")
266          (?W "$(3!~(B" (?e "$(3!y(B") (?u "$(3!~(B") (?i "$(3!{(B") (?a "$(3!|(B") (?E "$(3!}(B")))
267 ;;; R
268    ("$(3!N(B" (?e "$(3!I(B") (?u "$(3!J(B") (?i "$(3!K(B") (?a "$(3!L(B") (?E "$(3!M(B") (?o "$(3!O(B")
269          (?W "$(3!P(B" (?a "$(3!P(B")
270                   (?e "$(3!N%n(B") (?u "$(3!N%r(B") (?i "$(3!N%o(B") (?E "$(3!N%q(B"))
271          (?Y "$(3$`(B" (?a "$(3$`(B")))
272 ;;; S
273    ("$(3$D(B" (?e "$(3$?(B") (?u "$(3$@(B") (?i "$(3$A(B") (?a "$(3$B(B") (?E "$(3$C(B") (?o "$(3$E(B")
274          (?W "$(3$F(B" (?a "$(3$F(B")
275                   (?e "$(3$D%n(B") (?u "$(3$D%r(B") (?i "$(3$D%o(B") (?E "$(3$D%q(B"))
276          (?2 "$(3$L(B"
277              (?e "$(3$G(B") (?u "$(3$H(B") (?i "$(3$I(B") (?a "$(3$J(B") (?E "$(3$K(B") (?o "$(3$M(B")
278              (?W "$(3$F(B" (?a "$(3$F(B")
279                  (?e "$(3$L%n(B") (?u "$(3$L%r(B") (?i "$(3$L%o(B") (?E "$(3$L%q(B"))))
280 ;;; T
281    ("$(3$,(B" (?e "$(3$'(B") (?u "$(3$((B") (?i "$(3$)(B") (?a "$(3$*(B") (?E "$(3$+(B") (?o "$(3$-(B")
282          (?W "$(3$.(B" (?a "$(3$.(B")
283                   (?e "$(3$,%n(B") (?u "$(3$,%r(B") (?i "$(3$,%o(B") (?E "$(3$,%q(B")))
284 ;;; U
285    ("$(3"d(B" (?2 "$(3#6(B"))
286 ;;; V
287    ("$(3"0(B" (?e "$(3"+(B") (?u "$(3",(B") (?i "$(3"-(B") (?a "$(3".(B") (?E "$(3"/(B") (?o "$(3"1(B")
288          (?W "$(3"2(B" (?a "$(3"2(B")
289                   (?e "$(3"0%n(B") (?u "$(3"0%r(B") (?i "$(3"0%o(B") (?E "$(3"0%q(B")))
290 ;;; W
291    ("$(3%r(B" (?e "$(3%n(B") (?u "$(3%r(B") (?i "$(3%o(B") (?a "$(3%p(B") (?E "$(3%q(B"))
292 ;;; X
293    ("$(3%N(B" (?e "$(3%I(B") (?u "$(3%J(B") (?i "$(3%K(B") (?a "$(3%L(B") (?E "$(3%M(B") (?o "$(3%O(B"))
294 ;;; Y
295    ("$(3#R(B" (?e "$(3#M(B") (?u "$(3#N(B") (?i "$(3#O(B") (?a "$(3#P(B") (?E "$(3#Q(B") (?o "$(3#S(B")
296          (?W "$(3#T(B" (?a "$(3#T(B")
297                   (?e "$(3#R%n(B") (?u "$(3#R%r(B") (?i "$(3#R%o(B") (?E "$(3#R%q(B")))
298 ;;; Z
299    ("$(3#J(B" (?e "$(3#E(B") (?u "$(3#F(B") (?i "$(3#G(B") (?a "$(3#H(B") (?E "$(3#I(B") (?o "$(3#K(B")
300          (?W "$(3#L(B" (?a "$(3#L(B")
301                   (?e "$(3#J%n(B") (?u "$(3#J%r(B") (?i "$(3#J%o(B") (?E "$(3#J%q(B")))
302 ;;; [   \   ]   ^   _
303    nil nil nil nil nil
304 ;;; `
305    (""
306     (?: "$(3$h(B")
307     (?? (if ethio-use-three-dot-question "$(3%x(B" "$(3$n(B"))
308     (?! "$(3%t(B")
309     (?e "$(3#5(B") (?u "$(3#6(B") (?U "$(3#6(B") (?i "$(3#7(B") (?a "$(3#8(B") (?A "$(3#8(B")
310         (?E "$(3#9(B") (?I "$(3#:(B") (?o "$(3#;(B") (?O "$(3#;(B")
311     (?g "$(3%^(B"
312         (?e "$(3%Y(B") (?u "$(3%Z(B") (?i "$(3%[(B") (?a "$(3%\(B") (?E "$(3%](B") (?o "$(3%_(B"))
313     (?h "$(3"H(B"
314         (?e "$(3"C(B") (?u "$(3"D(B") (?i "$(3"E(B") (?a "$(3"F(B") (?E "$(3"G(B") (?o "$(3"I(B")
315                   (?W "$(3"P(B" (?e "$(3"K(B") (?u "$(3"P(B") (?i "$(3"M(B") (?a "$(3"N(B") (?E "$(3"O(B")))
316     (?k "$(3%>(B"
317         (?e "$(3%9(B") (?u "$(3%:(B") (?i "$(3%;(B") (?a "$(3%<(B") (?E "$(3%=(B") (?o "$(3%?(B"))
318     (?s "$(3!F(B"
319         (?e "$(3!A(B") (?u "$(3!B(B") (?i "$(3!C(B") (?a "$(3!D(B") (?E "$(3!E(B") (?o "$(3!G(B")
320         (?W "$(3!H(B" (?a "$(3!H(B")
321                    (?e "$(3!F%n(B") (?u "$(3!F%r(B") (?i "$(3!F%o(B") (?E "$(3!F%q(B")))
322     (?S "$(3$L(B"
323         (?e "$(3$G(B") (?u "$(3$H(B") (?i "$(3$I(B") (?a "$(3$J(B") (?E "$(3$K(B") (?o "$(3$M(B")
324         (?W "$(3$F(B" (?a "$(3$F(B")
325                  (?e "$(3$L%n(B") (?u "$(3$L%r(B") (?i "$(3$L%o(B") (?E "$(3$L%q(B")))
326     (?q "$(3%.(B" (?e "$(3%)(B") (?u "$(3%*(B") (?i "$(3%+(B") (?a "$(3%,(B") (?E "$(3%-(B") (?o "$(3%/(B")))
327 ;;; a
328    ("$(3"f(B" (?2 "$(3#8(B"))
329 ;;; b
330    ("$(3"((B" (?e "$(3"#(B") (?u "$(3"$(B") (?i "$(3"%(B") (?a "$(3"&(B") (?E "$(3"'(B") (?o "$(3")(B")
331          (?W "$(3%b(B" (?e "$(3%2(B") (?u "$(3%b(B") (?i "$(3%B(B") (?a "$(3"*(B") (?E "$(3%R(B")))
332 ;;; c
333    ("$(3"@(B" (?e "$(3";(B") (?u "$(3"<(B") (?i "$(3"=(B") (?a "$(3">(B") (?E "$(3"?(B") (?o "$(3"A(B")
334          (?W "$(3"B(B" (?a "$(3"B(B")
335                   (?e "$(3"@%n(B") (?u "$(3"@%r(B") (?i "$(3"@%o(B") (?E "$(3"@%q(B")))
336 ;;; d
337    ("$(3#Z(B" (?e "$(3#U(B") (?u "$(3#V(B") (?i "$(3#W(B") (?a "$(3#X(B") (?E "$(3#Y(B") (?o "$(3#[(B")
338          (?W "$(3#\(B" (?a "$(3#\(B")
339                   (?e "$(3#Z%o(B") (?u "$(3#Z%r(B") (?i "$(3#Z%p(B") (?E "$(3#Z%q(B")))
340 ;;; e
341    ("$(3"c(B" (?2 "$(3#5(B") (?a "$(3"j(B"))
342 ;;; f
343    ("$(3$T(B" (?e "$(3$O(B") (?u "$(3$P(B") (?i "$(3$Q(B") (?a "$(3$R(B") (?E "$(3$S(B") (?o "$(3$U(B")
344          (?W "$(3%d(B" (?e "$(3%4(B") (?u "$(3%d(B") (?i "$(3%D(B") (?a "$(3$V(B") (?E "$(3%T(B"))
345          (?Y "$(3$a(B" (?a "$(3$a(B")))
346 ;;; g
347    ("$(3#r(B" (?e "$(3#m(B") (?u "$(3#n(B") (?i "$(3#o(B") (?a "$(3#p(B") (?E "$(3#q(B") (?o "$(3#s(B")
348          (?W "$(3#z(B" (?e "$(3#u(B") (?u "$(3#z(B") (?i "$(3#w(B") (?a "$(3#x(B") (?E "$(3#y(B"))
349          (?2 "$(3%^(B" (?e "$(3%Y(B") (?u "$(3%Z(B") (?i "$(3%[(B") (?a "$(3%\(B") (?E "$(3%](B") (?o "$(3%_(B")))
350 ;;; h
351    ("$(3!&(B" (?e "$(3!!(B") (?u "$(3!"(B") (?i "$(3!#(B") (?a "$(3!$(B") (?E "$(3!%(B") (?o "$(3!'(B")
352          (?W "$(3"P(B" (?e "$(3"K(B") (?u "$(3"P(B") (?i "$(3"M(B") (?a "$(3"N(B") (?E "$(3"O(B"))
353          (?2 "$(3"H(B" (?e "$(3"C(B") (?u "$(3"D(B") (?i "$(3"E(B") (?a "$(3"F(B") (?E "$(3"G(B") (?o "$(3"I(B")
354                   (?W "$(3"P(B" (?e "$(3"K(B") (?u "$(3"P(B") (?i "$(3"M(B") (?a "$(3"N(B") (?E "$(3"O(B"))))
355 ;;; i
356    ("$(3"e(B" (?2 "$(3#7(B"))
357 ;;; j
358    ("$(3#j(B" (?e "$(3#e(B") (?u "$(3#f(B") (?i "$(3#g(B") (?a "$(3#h(B") (?E "$(3#i(B") (?o "$(3#k(B")
359          (?W "$(3#l(B" (?a "$(3#l(B")
360                   (?e "$(3#j%n(B") (?u "$(3#j%r(B") (?i "$(3#j%o(B") (?E "$(3#j%q(B")))
361 ;;; k
362    ("$(3"p(B" (?e "$(3"k(B") (?u "$(3"l(B") (?i "$(3"m(B") (?a "$(3"n(B") (?E "$(3"o(B") (?o "$(3"q(B")
363          (?W "$(3"x(B" (?e "$(3"s(B") (?u "$(3"x(B") (?i "$(3"u(B") (?a "$(3"v(B") (?E "$(3"w(B"))
364          (?2 "$(3%>(B" (?e "$(3%9(B") (?u "$(3%:(B") (?i "$(3%;(B") (?a "$(3%<(B") (?E "$(3%=(B") (?o "$(3%?(B")))
365 ;;; l
366    ("$(3!.(B" (?e "$(3!)(B") (?u "$(3!*(B") (?i "$(3!+(B") (?a "$(3!,(B") (?E "$(3!-(B") (?o "$(3!/(B")
367          (?W "$(3!0(B" (?a "$(3!0(B")
368                   (?e "$(3!.%n(B") (?u "$(3!.%r(B") (?i "$(3!.%o(B") (?E "$(3!.%q(B")))
369 ;;; m
370    ("$(3!>(B" (?e "$(3!9(B") (?u "$(3!:(B") (?i "$(3!;(B") (?a "$(3!<(B") (?E "$(3!=(B") (?o "$(3!?(B")
371          (?W "$(3%a(B" (?e "$(3%1(B") (?u "$(3%a(B") (?i "$(3%A(B") (?a "$(3!@(B") (?E "$(3%Q(B"))
372          (?Y "$(3$_(B" (?a "$(3$_(B")))
373 ;;; n
374    ("$(3"X(B" (?e "$(3"S(B") (?u "$(3"T(B") (?i "$(3"U(B") (?a "$(3"V(B") (?E "$(3"W(B") (?o "$(3"Y(B")
375          (?W "$(3"Z(B" (?a "$(3"Z(B")
376                   (?e "$(3"X%n(B") (?u "$(3"X%r(B") (?i "$(3"X%o(B") (?E "$(3"X%q(B")))
377 ;;; o
378    ("$(3"i(B" (?2 "$(3#;(B"))
379 ;;; p
380    ("$(3$\(B" (?e "$(3$W(B") (?u "$(3$X(B") (?i "$(3$Y(B") (?a "$(3$Z(B") (?E "$(3$[(B") (?o "$(3$](B")
381          (?W "$(3%e(B" (?e "$(3%5(B") (?u "$(3%e(B") (?i "$(3%E(B") (?a "$(3$^(B") (?E "$(3%U(B")))
382 ;;; q
383    ("$(3!f(B" (?e "$(3!a(B") (?u "$(3!b(B") (?i "$(3!c(B") (?a "$(3!d(B") (?E "$(3!e(B") (?o "$(3!g(B")
384          (?W "$(3!n(B" (?e "$(3!i(B") (?u "$(3!n(B") (?i "$(3!k(B") (?a "$(3!l(B") (?E "$(3!m(B"))
385          (?2 "$(3%.(B" (?e "$(3%)(B") (?u "$(3%*(B") (?i "$(3%+(B") (?a "$(3%,(B") (?E "$(3%-(B") (?o "$(3%/(B")))
386 ;;; r
387    ("$(3!N(B" (?e "$(3!I(B") (?u "$(3!J(B") (?i "$(3!K(B") (?a "$(3!L(B") (?E "$(3!M(B") (?o "$(3!O(B")
388          (?W "$(3!P(B" (?a "$(3!P(B")
389                   (?e "$(3!N%n(B") (?u "$(3!N%r(B") (?i "$(3!N%o(B") (?E "$(3!N%q(B"))
390          (?Y "$(3$`(B" (?a "$(3$`(B")))
391 ;;; s
392    ("$(3!V(B" (?e "$(3!Q(B") (?u "$(3!R(B") (?i "$(3!S(B") (?a "$(3!T(B") (?E "$(3!U(B") (?o "$(3!W(B")
393          (?W "$(3!X(B" (?a "$(3!X(B")
394                   (?e "$(3!V%n(B") (?u "$(3!V%r(B") (?i "$(3!V%o(B") (?E "$(3!V%q(B"))
395          (?2 "$(3!F(B" (?e "$(3!A(B") (?u "$(3!B(B") (?i "$(3!C(B") (?a "$(3!D(B") (?E "$(3!E(B") (?o "$(3!G(B")
396                   (?W "$(3!H(B" (?a "$(3!H(B")
397                            (?e "$(3!F%n(B") (?u "$(3!F%r(B") (?i "$(3!F%o(B") (?E "$(3!F%q(B"))))
398 ;;; t
399    ("$(3"8(B" (?e "$(3"3(B") (?u "$(3"4(B") (?i "$(3"5(B") (?a "$(3"6(B") (?E "$(3"7(B") (?o "$(3"9(B")
400          (?W "$(3":(B" (?a "$(3":(B")
401                   (?e "$(3"8%n(B") (?u "$(3"8%r(B") (?i "$(3"8%o(B") (?E "$(3"8%q(B")))
402 ;;; u
403    ("$(3"d(B" (?2 "$(3#6(B"))
404 ;;; v
405    ("$(3"0(B" (?e "$(3"+(B") (?u "$(3",(B") (?i "$(3"-(B") (?a "$(3".(B") (?E "$(3"/(B") (?o "$(3"1(B")
406          (?W "$(3"2(B" (?a "$(3"2(B")
407                   (?e "$(3"0%n(B") (?u "$(3"0%r(B") (?i "$(3"0%o(B") (?E "$(3"0%q(B")))
408 ;;; w
409    ("$(3#2(B" (?e "$(3#-(B") (?u "$(3#.(B") (?i "$(3#/(B") (?a "$(3#0(B") (?E "$(3#1(B") (?o "$(3#3(B")
410          (?W "$(3%p(B" (?e "$(3%n(B") (?u "$(3%r(B") (?i "$(3%o(B") (?a "$(3%p(B") (?E "$(3%q(B")))
411 ;;; x
412    ("$(3!^(B" (?e "$(3!Y(B") (?u "$(3!Z(B") (?i "$(3![(B") (?a "$(3!\(B") (?E "$(3!](B") (?o "$(3!_(B")
413          (?W "$(3!`(B" (?a "$(3!`(B")
414                   (?e "$(3!^%n(B") (?u "$(3!^%r(B") (?i "$(3!^%o(B") (?E "$(3!^%q(B")))
415 ;;; y
416    ("$(3#R(B" (?e "$(3#M(B") (?u "$(3#N(B") (?i "$(3#O(B") (?a "$(3#P(B") (?E "$(3#Q(B") (?o "$(3#S(B")
417          (?W "$(3#T(B" (?a "$(3#T(B")
418                   (?e "$(3#R%n(B") (?u "$(3#R%r(B") (?i "$(3#R%o(B") (?E "$(3#R%q(B")))
419 ;;; z
420    ("$(3#B(B" (?e "$(3#=(B") (?u "$(3#>(B") (?i "$(3#?(B") (?a "$(3#@(B") (?E "$(3#A(B") (?o "$(3#C(B")
421          (?W "$(3#D(B" (?a "$(3#D(B")
422                   (?e "$(3#B%n(B") (?u "$(3#B%r(B") (?i "$(3#B%o(B") (?E "$(3#B%q(B")))
423 ;;; {   |   }   ~  DEL
424    nil nil nil nil nil
425    ])
426
427 ;; To avoid byte-compiler warnings.  It should never be set globally.
428 (defvar ethio-sera-being-called-by-w3)
429 ;; This variable will be bound by some third-party package.
430 (defvar sera-being-called-by-w3)
431
432 ;;;###autoload
433 (defun ethio-sera-to-fidel-region (beg end &optional secondary force)
434   "Convert the characters in region from SERA to FIDEL.
435 The variable `ethio-primary-language' specifies the primary language
436 and `ethio-secondary-language' specifies the secondary.
437
438 If the 3rd parameter SECONDARY is given and non-nil, assume the region
439 begins with the secondary language; otherwise with the primary
440 language.
441
442 If the 4th parameter FORCE is given and non-nil, perform conversion
443 even if the buffer is read-only.
444
445 See also the descriptions of the variables
446 `ethio-use-colon-for-colon' and
447 `ethio-use-three-dot-question'."
448
449   (interactive "r\nP")
450   (save-restriction
451     (narrow-to-region beg end)
452     (ethio-sera-to-fidel-buffer secondary force)))
453
454 ;;;###autoload
455 (defun ethio-sera-to-fidel-buffer (&optional secondary force)
456   "Convert the current buffer from SERA to FIDEL.
457
458 The variable `ethio-primary-language' specifies the primary
459 language and `ethio-secondary-language' specifies the secondary.
460
461 If the 1st optional parameter SECONDARY is non-nil, assume the buffer
462 begins with the secondary language; otherwise with the primary
463 language.
464
465 If the 2nd optional parametr FORCE is non-nil, perform conversion even if the
466 buffer is read-only.
467
468 See also the descriptions of the variables
469 `ethio-use-colon-for-colon' and
470 `ethio-use-three-dot-question'."
471
472   (interactive "P")
473
474   (if (and buffer-read-only
475            (not force)
476            (not (y-or-n-p "Buffer is read-only.  Force to convert? ")))
477       (error ""))
478
479   (let ((ethio-primary-language ethio-primary-language)
480         (ethio-secondary-language ethio-secondary-language)
481         (ethio-use-colon-for-colon ethio-use-colon-for-colon)
482         (ethio-use-three-dot-question ethio-use-three-dot-question)
483         ;; The above four variables may be changed temporary
484         ;; by tilde escapes during conversion.  So we bind them to other
485         ;; variables but of the same names.
486         (buffer-read-only nil)
487         (case-fold-search nil)
488         current-language
489         next-language)
490
491     (setq current-language
492           (if secondary
493               ethio-secondary-language
494             ethio-primary-language))
495
496     (goto-char (point-min))
497
498     (while (not (eobp))
499       (setq next-language
500             (cond
501              ((eq current-language 'english)
502               (ethio-sera-to-fidel-english))
503              ((eq current-language 'amharic)
504               (ethio-sera-to-fidel-ethio 'amharic))
505              ((eq current-language 'tigrigna)
506               (ethio-sera-to-fidel-ethio 'tigrigna))
507              (t                         ; we don't know what to do
508               (ethio-sera-to-fidel-english))))
509
510       (setq current-language
511             (cond
512
513              ;; when language tag is explicitly specified
514              ((not (eq next-language 'toggle))
515               next-language)
516
517              ;; found a toggle in a primary language section
518              ((eq current-language ethio-primary-language)
519               ethio-secondary-language)
520
521              ;; found a toggle in a secondary, third, fourth, ...
522              ;; language section
523              (t
524               ethio-primary-language))))
525
526     ;; If ethio-implicit-period-conversion is non-nil, the
527     ;; Ethiopic dot "$(3%u(B" at the end of an Ethiopic sentence is