1 ;;; ethio-util.el --- utilities for Ethiopic -*- coding: utf-8; -*-
3 ;; Copyright (C) 1997, 1998, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
5 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
6 ;; 2006, 2007, 2008, 2009
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H14PRO021
9 ;; Copyright (C) 2005, 2006
10 ;; National Institute of Advanced Industrial Science and Technology (AIST)
11 ;; Registration Number: H15PRO110
13 ;; Keywords: mule, multilingual, Ethiopic
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software: you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation, either version 3 of the License, or
20 ;; (at your option) any later version.
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;; Author: TAKAHASHI Naoto <ntakahas@m17n.org>
38 ;; Information for exiting Ethiopic environment.
39 (defvar exit-ethiopic-environment-data nil
)
42 (defun setup-ethiopic-environment-internal ()
43 (let ((key-bindings '((" " . ethio-insert-space
)
44 ([?\S-
] . ethio-insert-ethio-space
)
45 ;; ([?\C-'] . ethio-gemination)
46 ([f3] . ethio-fidel-to-sera-buffer)
47 ([S-f3] . ethio-fidel-to-sera-region)
48 ([C-f3] . ethio-fidel-to-sera-marker)
49 ([f4] . ethio-sera-to-fidel-buffer)
50 ([S-f4] . ethio-sera-to-fidel-region)
51 ([C-f4] . ethio-sera-to-fidel-marker)
52 ([S-f5] . ethio-toggle-punctuation)
53 ([S-f6] . ethio-modify-vowel)
54 ([S-f7] . ethio-replace-space)
55 ;; ([S-f8] . ethio-input-special-character) ; deprecated
56 ([C-f9] . ethio-toggle-space)
57 ([S-f9] . ethio-replace-space) ; as requested
61 (setq kb (car (car key-bindings)))
62 (setq exit-ethiopic-environment-data
63 (cons (cons kb (global-key-binding kb))
64 exit-ethiopic-environment-data))
65 (global-set-key kb (cdr (car key-bindings)))
66 (setq key-bindings (cdr key-bindings))))
68 (add-hook 'find-file-hook 'ethio-find-file)
69 (add-hook 'write-file-functions 'ethio-write-file)
70 (add-hook 'after-save-hook 'ethio-find-file))
72 (defun exit-ethiopic-environment ()
73 "Exit Ethiopic language environment."
74 (while exit-ethiopic-environment-data
75 (global-set-key (car (car exit-ethiopic-environment-data))
76 (cdr (car exit-ethiopic-environment-data)))
77 (setq exit-ethiopic-environment-data
78 (cdr exit-ethiopic-environment-data)))
80 (remove-hook 'find-file-hook 'ethio-find-file)
81 (remove-hook 'write-file-functions 'ethio-write-file)
82 (remove-hook 'after-save-hook 'ethio-find-file))
85 ;; ETHIOPIC UTILITY FUNCTIONS
88 ;; If the filename ends in ".sera", editing is done in fidel
89 ;; but file I/O is done in SERA.
91 ;; If the filename ends in ".java", editing is done in fidel
92 ;; but file I/O is done in the \uXXXX style, where XXXX is
93 ;; the Unicode codepoint for the Ethiopic character.
95 ;; If the filename ends in ".tex", editing is done in fidel
96 ;; but file I/O is done in EthioTeX format.
102 (defvar ethio-primary-language 'tigrigna
103 "*Symbol that defines the primary language in SERA --> FIDEL conversion.
104 The value should be one of: `tigrigna', `amharic' or `english'.")
106 (defvar ethio-secondary-language 'english
107 "*Symbol that defines the secondary language in SERA --> FIDEL conversion.
108 The value should be one of: `tigrigna', `amharic' or `english'.")
110 (defvar ethio-use-colon-for-colon nil
111 "*Non-nil means associate ASCII colon with Ethiopic colon.
112 If nil, associate ASCII colon with Ethiopic word separator, i.e., two
113 vertically stacked dots. All SERA <--> FIDEL converters refer this
116 (defvar ethio-use-three-dot-question nil
117 "*Non-nil means associate ASCII question mark with Ethiopic old style question mark (three vertically stacked dots).
118 If nil, associate ASCII question mark with Ethiopic stylized question
119 mark. All SERA <--> FIDEL converters refer this variable.")
121 (defvar ethio-quote-vowel-always nil
122 "*Non-nil means always put an apostrophe before an isolated vowel (except at word initial) in FIDEL --> SERA conversion.
123 If nil, put an apostrophe only between a 6th-form consonant and an
126 (defvar ethio-W-sixth-always nil
127 "*Non-nil means convert the Wu-form of a 12-form consonant to \"W'\" instead of \"Wu\" in FIDEL --> SERA conversion.")
129 (defvar ethio-numeric-reduction 0
130 "*Degree of reduction in converting Ethiopic digits into Arabic digits.
132 For example, ({10}{9}{100}{80}{7}) is converted into:
133 `10`9`100`80`7 if `ethio-numeric-reduction' is 0,
134 `109100807 if `ethio-numeric-reduction' is 1,
135 `10900807 if `ethio-numeric-reduction' is 2.")
137 (defvar ethio-java-save-lowercase nil
138 "*Non-nil means save Ethiopic characters in lowercase hex numbers to Java files.
139 If nil, use uppercases.")
141 (defun ethio-prefer-amharic-p ()
142 (or (eq ethio-primary-language 'amharic)
143 (and (not (eq ethio-primary-language 'tigrigna))
144 (eq ethio-secondary-language 'amharic))))
146 (defun ethio-prefer-amharic (arg)
149 (robin-modify-package "ethiopic-sera" "'a" ?አ)
150 (robin-modify-package "ethiopic-sera" "a" "አ")
151 (robin-modify-package "ethiopic-sera" "'A" ?ኣ)
152 (robin-modify-package "ethiopic-sera" "A" "ኣ"))
153 (robin-modify-package "ethiopic-sera" "'A" ?አ)
154 (robin-modify-package "ethiopic-sera" "A" "አ")
155 (robin-modify-package "ethiopic-sera" "'a" ?ኣ)
156 (robin-modify-package "ethiopic-sera" "a" "ኣ")))
158 (defun ethio-use-colon-for-colon (arg)
161 (robin-modify-package "ethiopic-sera" ":" ?፥)
162 (robin-modify-package "ethiopic-sera" "`:" ?፡))
163 (robin-modify-package "ethiopic-sera" " : " ?፡)
164 (robin-modify-package "ethiopic-sera" ":" "፡")
165 (robin-modify-package "ethiopic-sera" "-:" ?፥)))
167 (defun ethio-use-three-dot-question (arg)
170 (robin-modify-package "ethiopic-sera" "?" ?፧)
171 (robin-modify-package "ethiopic-sera" "`?" ??))
172 (robin-modify-package "ethiopic-sera" "?" ??)
173 (robin-modify-package "ethiopic-sera" "`?" ?፧)))
175 (defun ethio-adjust-robin ()
176 (ethio-prefer-amharic (ethio-prefer-amharic-p))
177 (ethio-use-colon-for-colon ethio-use-colon-for-colon)
178 (ethio-use-three-dot-question ethio-use-three-dot-question))
180 (add-hook 'robin-activate-hook 'ethio-adjust-robin)
187 (defun ethio-sera-to-fidel-buffer (&optional secondary force)
188 "Convert the current buffer from SERA to FIDEL.
190 The variable `ethio-primary-language' specifies the primary
191 language and `ethio-secondary-language' specifies the secondary.
193 If the 1st optional argument SECONDARY is non-nil, assume the
194 buffer begins with the secondary language; otherwise with the
197 If the 2nd optional argument FORCE is non-nil, perform conversion
198 even if the buffer is read-only.
200 See also the descriptions of the variables
201 `ethio-use-colon-for-colon' and `ethio-use-three-dot-question'."
204 (ethio-sera-to-fidel-region (point-min) (point-max) secondary force))
206 ;; To avoid byte-compiler warnings. It should never be set globally.
207 (defvar ethio-sera-being-called-by-w3)
208 ;; This variable will be bound by some third-party package.
209 (defvar sera-being-called-by-w3)
212 (defun ethio-sera-to-fidel-region (begin end &optional secondary force)
213 "Convert the characters in region from SERA to FIDEL.
215 The variable `ethio-primary-language' specifies the primary
216 language and `ethio-secondary-language' specifies the secondary.
218 If the 3rd argument SECONDARY is given and non-nil, assume the
219 region begins with the secondary language; otherwise with the
222 If the 4th argument FORCE is given and non-nil, perform
223 conversion even if the buffer is read-only.
225 See also the descriptions of the variables
226 `ethio-use-colon-for-colon' and `ethio-use-three-dot-question'."
229 (if (and buffer-read-only
231 (not (y-or-n-p "Buffer is read-only. Force to convert? ")))
234 (let ((ethio-primary-language ethio-primary-language)
235 (ethio-secondary-language ethio-secondary-language)
236 ;; The above two variables may be changed temporarily by tilde
237 ;; escapes during conversion. We bind them to the variables
238 ;; of the same names so that the original values are restored
239 ;; when this function exits.
240 (buffer-read-only nil)
241 (lang (if secondary ethio-secondary-language ethio-primary-language))
244 (ethio-use-colon-for-colon ethio-use-colon-for-colon)
245 (ethio-use-three-dot-question ethio-use-three-dot-question)
248 (narrow-to-region begin end)
249 (goto-char (point-min))
254 (ethio-prefer-amharic t)
255 (ethio-sera-to-fidel-region-ethio 'amharic))
257 (ethio-prefer-amharic nil)
258 (ethio-sera-to-fidel-region-ethio 'tigrigna))
260 (ethio-sera-to-fidel-region-noethio))))
263 (if (eq lang ethio-primary-language)
264 ethio-secondary-language
265 ethio-primary-language)
268 ;; Restore user's preference.
269 (ethio-adjust-robin))
271 (defun ethio-sera-to-fidel-region-noethio ()
272 "Return next language as symbol: amharic, tigrigna, toggle or nil."
276 ;; No more "\", i.e. nothing to do.
277 ((not (search-forward "\\" nil 0))
280 ;; Hereafter point is put after a "\".
281 ;; First delete that "\", then check the following chars.
284 ((progn (delete-char -1) (setq lflag (ethio-process-language-flag)))
287 ;; "\\" : leave the second "\" and continue in the same language.
288 ((= (following-char) ?\\)
292 ;; "\ " : delete the following " " and toggle the language.
293 ((= (following-char) 32)
297 ;; A "\" but not a special sequence: simply toggle the language.
301 (defun ethio-sera-to-fidel-region-ethio (lang)
302 "Return next language as symbol: amharic, tigrigna, toggle or nil."
306 (if (re-search-forward "\\(`[1-9][0-9]*\\)\\|[\\<&]" nil t)
309 (robin-convert-region (point-min) (point-max) "ethiopic-sera")
310 (goto-char (point-max)))
314 ((= (following-char) ?`)
316 (ethio-process-digits)
320 (if (or (and (boundp 'ethio-sera-being-called-by-w3)
321 ethio-sera-being-called-by-w3)
322 (and (boundp 'sera-being-called-by-w3)
323 sera-being-called-by-w3))
324 (search-forward (if (= (following-char) ?<) ">" ";") nil 0)
331 ;; Now we must be looking at a "\".
332 ;; First delete that "\", then check the following chars.
334 ((progn (delete-char 1) (= (following-char) 32))
338 ((looking-at "[,.;:'`?\\]+")
339 (goto-char (match-end 0))
342 ((/= (following-char) ?~)
345 ;; Now we must be looking at a "~".
347 ((setq lflag (ethio-process-language-flag))
350 ;; Delete the following "~" and check the following chars.
352 ((progn (delete-char 1) (looking-at "! ?"))
354 (if (re-search-forward "\\\\~! ?" nil 0)
360 (ethio-use-colon-for-colon t)
365 (ethio-use-colon-for-colon nil)
370 (ethio-use-three-dot-question t)
373 ((looking-at "\\? ?")
375 (ethio-use-three-dot-question nil)
378 ;; Unknown tilde escape. Recover the deleted chars.
383 (defun ethio-process-language-flag nil
384 "Process a language flag of the form \"~lang\" or \"~lang1~lang2\".
386 If looking at \"~lang1~lang2\", set `ethio-primary-language' and
387 `ethio-secondary-language' based on \"lang1\" and \"lang2\".
388 Then delete the language flag \"~lang1~lang2\" from the buffer.
389 Return value is the new primary language.
391 If looking at \"~lang\", delete that language flag \"~lang\" from
392 the buffer and return that language. In this case
393 `ethio-primary-language' and `ethio-secondary-language' are left
396 If an unsupported language flag is found, just return nil without
404 "~\\([a-z][a-z][a-z]?\\)~\\([a-z][a-z][a-z]?\\)[ \t\n\\]")
405 (setq lang1 (ethio-flag-to-language (match-string 1)))
406 (setq lang2 (ethio-flag-to-language (match-string 2))))
407 (setq ethio-primary-language lang1
408 ethio-secondary-language lang2)
409 (delete-region (point) (match-end 2))
410 (if (= (following-char) 32)
412 ethio-primary-language)
415 ((and (looking-at "~\\([a-z][a-z][a-z]?\\)[ \t\n\\]")
416 (setq lang1 (ethio-flag-to-language (match-string 1))))
417 (delete-region (point) (match-end 1))
418 (if (= (following-char) 32)
426 (defun ethio-flag-to-language (flag)
428 ((or (string= flag "en") (string= flag "eng")) 'english)
429 ((or (string= flag "ti") (string= flag "tir")) 'tigrigna)
430 ((or (string= flag "am") (string= flag "amh")) 'amharic)
433 (defun ethio-process-digits nil
434 "Convert Arabic digits to Ethiopic digits."
436 (while (and (>= (setq ch (following-char)) ?1)
440 ;; count up following zeros
442 (while (= (following-char) ?0)
448 ;; first digit is 10, 20, ..., or 90
450 (insert (aref [?፲ ?፳ ?፴ ?፵ ?፶ ?፷ ?፸ ?፹ ?፺] (- ch ?1)))
453 ;; first digit is 2, 3, ..., or 9
455 (insert (aref [?፪ ?፫ ?፬ ?፭ ?፮ ?፯ ?፰ ?፱] (- ch ?2))))
466 (insert-char ?፼ (/ z 4)))))
469 (defun ethio-sera-to-fidel-marker (&optional force)
470 "Convert the regions surrounded by \"<sera>\" and \"</sera>\" from SERA to FIDEL.
471 Assume that each region begins with `ethio-primary-language'.
472 The markers \"<sera>\" and \"</sera>\" themselves are not deleted."
474 (if (and buffer-read-only
476 (not (y-or-n-p "Buffer is read-only. Force to convert? ")))
479 (goto-char (point-min))
480 (while (search-forward "<sera>" nil t)
481 (ethio-sera-to-fidel-region
483 (if (search-forward "</sera>" nil t)
493 (defun ethio-language-to-flag (lang)
495 ((eq lang 'english) "eng")
496 ((eq lang 'tigrigna) "tir")
497 ((eq lang 'amharic) "amh")
501 (defun ethio-fidel-to-sera-buffer (&optional secondary force)
502 "Replace all the FIDEL characters in the current buffer to the SERA format.
503 The variable `ethio-primary-language' specifies the primary
504 language and `ethio-secondary-language' specifies the secondary.
506 If the 1st optional argument SECONDARY is non-nil, try to convert the
507 region so that it begins with the secondary language; otherwise with the
510 If the 2nd optional argument FORCE is non-nil, convert even if the
513 See also the descriptions of the variables
514 `ethio-use-colon-for-colon', `ethio-use-three-dot-question',
515 `ethio-quote-vowel-always' and `ethio-numeric-reduction'."
518 (ethio-fidel-to-sera-region (point-min) (point-max) secondary force))
521 (defun ethio-fidel-to-sera-region (begin end &optional secondary force)
522 "Replace all the FIDEL characters in the region to the SERA format.
524 The variable `ethio-primary-language' specifies the primary
525 language and `ethio-secondary-language' specifies the secondary.
527 If the 3rd argument SECONDARY is given and non-nil, convert
528 the region so that it begins with the secondary language; otherwise with
529 the primary language.
531 If the 4th argument FORCE is given and non-nil, convert even if the
534 See also the descriptions of the variables
535 `ethio-use-colon-for-colon', `ethio-use-three-dot-question',
536 `ethio-quote-vowel-always' and `ethio-numeric-reduction'."
539 (if (and buffer-read-only
541 (not (y-or-n-p "Buffer is read-only. Force to convert? ")))
545 (narrow-to-region begin end)
547 (let ((buffer-read-only nil)
549 ethio-secondary-language
550 ethio-primary-language))
551 (flag (if (ethio-prefer-amharic-p) "\\~amh " "\\~tir "))
554 (goto-char (point-min))
556 (unless (eq mode 'english)
557 (setq mode 'ethiopic))
558 (if (and (eq mode 'english) (looking-at "\\ce"))
559 (setq mode 'ethiopic))
560 (if (and (eq mode 'ethiopic) (looking-at "\\Ce"))
561 (setq mode 'english))
562 (insert (if (eq mode 'english) "\\~eng " flag))
566 (if (eq mode 'english)
568 (if (re-search-forward "\\(\\ce\\|\\\\\\)" nil 0)
571 ((eq (following-char) ?\\)
576 (setq mode 'ethiopic))))
578 ;; If we reach here, mode is ethiopic.
580 (if (re-search-forward "[a-z,.;:'`?\\<&]" nil 0)
583 (narrow-to-region p (point))
584 (robin-invert-region (point-min) (point-max) "ethiopic-sera")
586 ;; ethio-quote-vowel-alwyas
587 (goto-char (point-min))
588 (while (re-search-forward "'[eauio]" nil t)
591 (setq ch (preceding-char))
592 (if (or (and (>= ch ?a) (<= ch ?z))
593 (and (>= ch ?A) (<= ch ?Z)))
594 (if (and (not ethio-quote-vowel-always)
595 (memq ch '(?e ?a ?u ?i ?o ?E ?A ?I)))
599 ;; ethio-W-sixth-always
600 (unless ethio-W-sixth-always
601 (goto-char (point-min))
602 (while (search-forward "W'" nil t)
606 ;; ethio-numeric-reduction
607 (when (> ethio-numeric-reduction 0)
608 (goto-char (point-min))
609 (while (re-search-forward "\\([0-9]\\)`\\([0-9]\\)" nil t)
610 (replace-match "\\1\\2")
612 (when (= ethio-numeric-reduction 2)
613 (goto-char (point-min))
614 (while (re-search-forward "\\([0-9]\\)1\\(0+\\)" nil t)
615 (replace-match "\\1\\2")))
617 (goto-char (point-max)))
620 ((looking-at "[a-z]")
622 (setq mode 'english))
623 ((looking-at "[,.;:'`\\]+")
625 (goto-char (1+ (match-end 0))))
626 ((= (following-char) ??)
627 (if ethio-use-three-dot-question
631 (if (or (and (boundp 'ethio-sera-being-called-by-w3)
632 ethio-sera-being-called-by-w3)
633 (and (boundp 'sera-being-called-by-w3)
634 sera-being-called-by-w3))
635 (search-forward (if (= (following-char) ?<) ">" "&") nil 0)
636 (forward-char 1)))))))))
639 (defun ethio-fidel-to-sera-marker (&optional force)
640 "Convert the regions surrounded by \"<sera>\" and \"</sera>\" from FIDEL to SERA.
641 The markers \"<sera>\" and \"</sera>\" themselves are not deleted."
644 (if (and buffer-read-only
646 (not (y-or-n-p "Buffer is read-only. Force to convert? ")))
649 (goto-char (point-min))
650 (while (search-forward "<sera>" nil t)
651 (ethio-fidel-to-sera-region
653 (if (search-forward "</sera>" nil t)
660 ;; vowel modification
664 (defun ethio-modify-vowel nil
665 "Modify the vowel of the FIDEL that is under the cursor."
668 (let ((consonant (ethio-get-consonant (following-char)))
671 (error "") ; not an Ethiopic char
672 (setq vowel (read-char "Modify vowel to: "))
674 (if (and (string= consonant "'") (= vowel ?W))
677 (narrow-to-region (point) (point))
678 (insert consonant vowel)
679 (robin-convert-region (point-min) (point-max) "ethiopic-sera"))))))
681 (defun ethio-get-consonant (ch)
682 "Return the consonant part of CH's SERA spelling in ethiopic-sera."
683 (let ((sera (get-char-code-property ch 'ethiopic-sera)))
686 ((= ch ?ኧ) "'") ; Only this has two vowel letters.
689 (if (memq (preceding-char) '(?e ?u ?i ?a ?o ?E ?I ?A ?'))
691 (buffer-substring (point-min) (point-max)))))))
698 (defun ethio-replace-space (ch begin end)
699 "Replace ASCII spaces with Ethiopic word separators in the region.
701 In the specified region, replace word separators surrounded by two
702 Ethiopic characters, depending on the first argument CH, which should
705 If CH = 1, word separator will be replaced with an ASCII space.
706 If CH = 2, with two ASCII spaces.
707 If CH = 3, with the Ethiopic colon-like word separator.
709 The 2nd and 3rd arguments BEGIN and END specify the region."
711 (interactive "*cReplace spaces to: 1 (sg col), 2 (dbl col), 3 (Ethiopic)\nr")
712 (if (not (memq ch '(?1 ?2 ?3)))
716 (narrow-to-region begin end)
720 ;; an Ethiopic word separator --> an ASCII space
721 (goto-char (point-min))
722 (while (search-forward "፡" nil t)
725 ;; two ASCII spaces between Ethiopic characters --> an ASCII space
726 (goto-char (point-min))
727 (while (re-search-forward "\\(\\ce\\) \\(\\ce\\)" nil t)
728 (replace-match "\\1 \\2")
732 ;; An Ethiopic word separator --> two ASCII spaces
733 (goto-char (point-min))
734 (while (search-forward "፡" nil t)
737 ;; An ASCII space between Ethiopic characters --> two ASCII spaces
738 (goto-char (point-min))
739 (while (re-search-forward "\\(\\ce\\) \\(\\ce\\)" nil t)
740 (replace-match "\\1 \\2")
744 ;; One or two ASCII spaces between Ethiopic characters
745 ;; --> An Ethiopic word separator
746 (goto-char (point-min))
747 (while (re-search-forward "\\(\\ce\\) ?\\(\\ce\\)" nil t)
748 (replace-match "\\1፡\\2")
751 ;; Three or more ASCII spaces between Ethiopic characters
752 ;; --> An Ethiopic word separator + (N - 2) ASCII spaces
753 (goto-char (point-min))
754 (while (re-search-forward "\\(\\ce\\) \\( +\\ce\\)" nil t)
755 (replace-match "\\1፡\\2")
756 (forward-char -1)))))))
762 ;; This function is deprecated.
764 (defun ethio-input-special-character (arg)
765 "This function is deprecated."
766 (interactive "*cInput number: 1. 2. 3. 4. 5.")
786 (defun ethio-fidel-to-tex-buffer nil
787 "Convert each fidel characters in the current buffer into a fidel-tex command."
789 (let ((buffer-read-only nil)
792 ;; Special treatment for geminated characters.
793 ;; Geminated characters la", etc. change into \geminateG{\laG}, etc.
794 (goto-char (point-min))
795 (while (re-search-forward "፟\\|" nil t)
796 (setq comp (find-composition (match-beginning 0)))
798 (replace-match "\\\\geminateG{}" t)
799 (decompose-region (car comp) (cadr comp))
802 (insert "\\geminateG{")
806 ;; Special Ethiopic punctuations.
807 (goto-char (point-min))
808 (while (re-search-forward "\\ce[»\\.\\?]\\|«\\ce" nil t)
810 ((= (setq ch (preceding-char)) ?\»)
812 (insert "\\rquoteG"))
825 ;; Ethiopic characters to TeX macros
826 (robin-invert-region (point-min) (point-max) "ethiopic-tex")
828 (goto-char (point-min))
829 (set-buffer-modified-p nil)))
832 (defun ethio-tex-to-fidel-buffer nil
833 "Convert fidel-tex commands in the current buffer into fidel chars."
835 (let ((buffer-read-only nil)
838 ;; TeX macros to Ethiopic characters
839 (robin-convert-region (point-min) (point-max) "ethiopic-tex")
841 ;; compose geminated characters
842 (goto-char (point-min))
843 (while (re-search-forward "\\\\geminateG{\\(\\ce?\\)}" nil t)
844 (replace-match "\\1፟"))
846 ;; remove redundant braces, if any
847 (goto-char (point-min))
848 (while (re-search-forward "{\\(\\ce\\)}" nil t)
849 (replace-match "\\1"))
851 (goto-char (point-min))
852 (set-buffer-modified-p nil)))
859 (defun ethio-fidel-to-java-buffer nil
860 "Convert Ethiopic characters into the Java escape sequences.
862 Each escape sequence is of the form \\uXXXX, where XXXX is the
863 character's codepoint (in hex) in Unicode.
865 If `ethio-java-save-lowercase' is non-nil, use [0-9a-f].
866 Otherwise, [0-9A-F]."
869 (goto-char (point-min))
870 (while (re-search-forward "[ሀ-፼]" nil t)
871 (setq ucode (preceding-char))
872 (delete-backward-char 1)
874 (format (if ethio-java-save-lowercase "\\u%4x" "\\u%4X")
878 (defun ethio-java-to-fidel-buffer nil
879 "Convert the Java escape sequences into corresponding Ethiopic characters."
880 (let ((case-fold-search t)
882 (goto-char (point-min))
883 (while (re-search-forward "\\\\u\\([0-9a-f][0-9a-f][0-9a-f][0-9a-f]\\)" nil t)
884 (setq ucode (read (concat "#x" (match-string 1))))
885 (when (and (>= ucode #x1200) (<= ucode #x137f))
886 (replace-match (char-to-string ucode))))))
893 (defun ethio-find-file nil
894 "Transliterate file content into Ethiopic dependig on filename suffix."
897 ((string-match "\\.sera$" (buffer-file-name))
899 (ethio-sera-to-fidel-buffer nil 'force)
900 (set-buffer-modified-p nil)))
902 ((string-match "\\.html$" (buffer-file-name))
903 (let ((ethio-sera-being-called-by-w3 t))
905 (ethio-sera-to-fidel-marker 'force)
906 (goto-char (point-min))
907 (while (re-search-forward "&[lr]aquo;" nil t)
908 (if (= (char-after (1+ (match-beginning 0))) ?l)
910 (replace-match "»")))
911 (set-buffer-modified-p nil))))
913 ((string-match "\\.tex$" (buffer-file-name))
915 (ethio-tex-to-fidel-buffer)
916 (set-buffer-modified-p nil)))
918 ((string-match "\\.java$" (buffer-file-name))
920 (ethio-java-to-fidel-buffer)
921 (set-buffer-modified-p nil)))
927 (defun ethio-write-file nil
928 "Transliterate Ethiopic characters in ASCII depending on the file extension."
931 ((string-match "\\.sera$" (buffer-file-name))
933 (ethio-fidel-to-sera-buffer nil 'force)
934 (goto-char (point-min))
935 (ethio-record-user-preference)
936 (set-buffer-modified-p nil)))
938 ((string-match "\\.html$" (buffer-file-name))
940 (let ((ethio-sera-being-called-by-w3 t))
941 (ethio-fidel-to-sera-marker 'force)
942 (goto-char (point-min))
943 (while (re-search-forward "[«»]" nil t)
944 (replace-match (if (= (preceding-char) ?«) "«" "»")))
945 (goto-char (point-min))
946 (if (search-forward "<sera>" nil t)
947 (ethio-record-user-preference))
948 (set-buffer-modified-p nil))))
950 ((string-match "\\.tex$" (buffer-file-name))
952 (ethio-fidel-to-tex-buffer)
953 (set-buffer-modified-p nil)))
955 ((string-match "\\.java$" (buffer-file-name))
957 (ethio-fidel-to-java-buffer)
958 (set-buffer-modified-p nil)))
963 (defun ethio-record-user-preference nil
964 (insert (if ethio-use-colon-for-colon "\\~-: " "\\~`: ")
965 (if ethio-use-three-dot-question "\\~`| " "\\~? ")))
968 ;; Ethiopic word separator vs. ASCII space
971 (defvar ethio-prefer-ascii-space t)
972 (make-variable-buffer-local 'ethio-prefer-ascii-space)
974 (defun ethio-toggle-space nil
975 "Toggle ASCII space and Ethiopic separator for keyboard input."
977 (setq ethio-prefer-ascii-space
978 (not ethio-prefer-ascii-space)))
980 (defun ethio-insert-space (arg)
981 "Insert ASCII spaces or Ethiopic word separators depending on context.
983 If the current word separator (indicated in mode-line) is the ASCII space,
984 insert an ASCII space. With ARG, insert that many ASCII spaces.
986 If the current word separator is the colon-like Ethiopic word
987 separator and the point is preceded by `an Ethiopic punctuation mark
988 followed by zero or more ASCII spaces', then insert also an ASCII
989 space. With ARG, insert that many ASCII spaces.
991 Otherwise, insert a colon-like Ethiopic word separator. With ARG, insert that
992 many Ethiopic word separators."
996 (ethio-prefer-ascii-space
997 (insert-char 32 arg))
999 (skip-chars-backward " ")
1000 (memq (preceding-char)
1001 '(?፡ ?። ?፣ ?፤ ?፥ ?፦ ?፧ ?፨ ? ? ? ? ?)))
1002 (insert-char 32 arg))
1004 (insert-char ?፡ arg))))
1007 (defun ethio-insert-ethio-space (arg)
1008 "Insert the Ethiopic word delimiter (the colon-like character).
1009 With ARG, insert that many delimiters."
1011 (insert-char ?፡ arg))
1018 (defun ethio-composition-function (pos to font-object string)
1020 (let ((pattern "\\ce\\(፟\\|\\)"))
1023 (eq (string-match pattern string pos) pos))
1024 (prog1 (match-end 0)
1025 (compose-string string pos (match-end 0))))
1026 (if (>= pos (point-min))
1029 (if (looking-at pattern)
1030 (prog1 (match-end 0)
1031 (compose-region pos (match-end 0)))))))))
1033 ;; This function is not used any more.
1034 (defun ethio-gemination nil
1035 "Compose the character before the point with the Ethiopic gemination mark.
1036 If the character is already composed, decompose it and remove the gemination
1039 (let ((ch (preceding-char)))
1041 ((and (= ch ?) (find-composition (1- (point))))
1042 (decompose-region (- (point) 2) (point)))
1043 ((and (>= ch #x1200) (<= ch #x137f))
1045 (compose-region (- (point) 2) (point)))
1053 (robin-define-package "ethiopic-sera"
1054 "SERA transliteration system for Ethiopic."
1060 ("hE" ?ሄ) ("hee" "ሄ")
1064 ("le" ?ለ) ("Le" "ለ")
1065 ("lu" ?ሉ) ("Lu" "ሉ")
1066 ("li" ?ሊ) ("Li" "ሊ")
1067 ("la" ?ላ) ("La" "ላ")
1068 ("lE" ?ሌ) ("LE" "ሌ") ("lee" "ሌ") ("Lee" "ሌ")
1070 ("lo" ?ሎ) ("Lo" "ሎ")
1071 ("lWa" ?ሏ) ("LWa" "ሏ") ("lW" "ሏ") ("LW" "ሏ")
1077 ("HE" ?ሔ) ("Hee" "ሔ")
1080 ("HWa" ?ሗ) ("HW" "ሗ")
1082 ("me" ?መ) ("Me" "መ")
1083 ("mu" ?ሙ) ("Mu" "ሙ")
1084 ("mi" ?ሚ) ("Mi" "ሚ")
1085 ("ma" ?ማ) ("Ma" "ማ")
1086 ("mE" ?ሜ) ("ME" "ሜ") ("mee" "ሜ") ("Mee" "ሜ")
1088 ("mo" ?ሞ) ("Mo" "ሞ")
1089 ("mWa" ?ሟ) ("MWa" "ሟ") ("mW" "ሟ") ("MW" "ሟ")
1091 ("`se" ?ሠ) ("sse" "ሠ") ("s2e" "ሠ")
1092 ("`su" ?ሡ) ("ssu" "ሡ") ("s2u" "ሡ")
1093 ("`si" ?ሢ) ("ssi" "ሢ") ("s2i" "ሢ")
1094 ("`sa" ?ሣ) ("ssa" "ሣ") ("s2a" "ሣ")
1095 ("`sE" ?ሤ) ("ssE" "ሤ") ("s2E" "ሤ")
1096 ("`see" "ሤ") ("ssee" "ሤ") ("s2ee" "ሤ")
1097 ("`s" ?ሥ) ("ss" "ሥ") ("s2" "ሥ")
1098 ("`so" ?ሦ) ("sso" "ሦ") ("s2o" "ሦ")
1099 ("`sWa" ?ሧ) ("ssWa" "ሧ") ("s2Wa" "ሧ")
1100 ("`sW" "ሧ") ("ssW" "ሧ") ("s2W" "ሧ")
1102 ("re" ?ረ) ("Re" "ረ")
1103 ("ru" ?ሩ) ("Ru" "ሩ")
1104 ("ri" ?ሪ) ("Ri" "ሪ")
1105 ("ra" ?ራ) ("Ra" "ራ")
1106 ("rE" ?ሬ) ("RE" "ሬ") ("ree" "ሬ") ("Ree" "ሬ")
1108 ("ro" ?ሮ) ("Ro" "ሮ")
1109 ("rWa" ?ሯ) ("RWa" "ሯ") ("rW" "ሯ") ("RW" "ሯ")
1115 ("sE" ?ሴ) ("see" "ሴ")
1118 ("sWa" ?ሷ) ("sW" "ሷ")
1124 ("xE" ?ሼ) ("xee" "ሼ")
1127 ("xWa" ?ሿ) ("xW" "ሿ")
1133 ("qE" ?ቄ) ("qee" "ቄ")
1138 ("qWa" ?ቋ) ("qW" "ቋ")
1139 ("qWE" ?ቌ) ("qWee" "ቌ")
1140 ("qW'" ?ቍ) ("qWu" "ቍ")
1146 ("QE" ?ቔ) ("Qee" "ቔ")
1151 ("QWa" ?ቛ) ("QW" "ቛ")
1152 ("QWE" ?ቜ) ("QWee" "ቜ")
1153 ("QW'" ?ቝ) ("QWu" "ቝ")
1155 ("be" ?በ) ("Be" "በ")
1156 ("bu" ?ቡ) ("Bu" "ቡ")
1157 ("bi" ?ቢ) ("Bi" "ቢ")
1158 ("ba" ?ባ) ("Ba" "ባ")
1159 ("bE" ?ቤ) ("BE" "ቤ") ("bee" "ቤ") ("Bee" "ቤ")
1161 ("bo" ?ቦ) ("Bo" "ቦ")
1162 ("bWa" ?ቧ) ("BWa" "ቧ") ("bW" "ቧ") ("BW" "ቧ")
1164 ("ve" ?ቨ) ("Ve" "ቨ")
1165 ("vu" ?ቩ) ("Vu" "ቩ")
1166 ("vi" ?ቪ) ("Vi" "ቪ")
1167 ("va" ?ቫ) ("Va" "ቫ")
1168 ("vE" ?ቬ) ("VE" "ቬ") ("vee" "ቬ") ("Vee" "ቬ")
1170 ("vo" ?ቮ) ("Vo" "ቮ")
1171 ("vWa" ?ቯ) ("VWa" "ቯ") ("vW" "ቯ") ("VW" "ቯ")
1177 ("tE" ?ቴ) ("tee" "ቴ")
1180 ("tWa" ?ቷ) ("tW" "ቷ")
1186 ("cE" ?ቼ) ("cee" "ቼ")
1189 ("cWa" ?ቿ) ("cW" "ቿ")
1191 ("`he" ?ኀ) ("hhe" "ኀ") ("h2e" "ኀ")
1192 ("`hu" ?ኁ) ("hhu" "ኁ") ("h2u" "ኁ")
1193 ("`hi" ?ኂ) ("hhi" "ኂ") ("h2i" "ኂ")
1194 ("`ha" ?ኃ) ("hha" "ኃ") ("h2a" "ኃ")
1195 ("`hE" ?ኄ) ("hhE" "ኄ") ("h2E" "ኄ")
1196 ("`hee" "ኄ") ("hhee" "ኄ") ("h2ee" "ኄ")
1197 ("`h" ?ኅ) ("hh" "ኅ") ("h2" "ኅ")
1198 ("`ho" ?ኆ) ("hho" "ኆ") ("h2o" "ኆ")
1199 ("`hWe" ?ኈ) ("hhWe" "ኈ") ("h2We" "ኈ") ("hWe" "ኈ")
1200 ("`hWi" ?ኊ) ("hhWi" "ኊ") ("h2Wi" "ኊ") ("hWi" "ኊ")
1201 ("`hWa" ?ኋ) ("hhWa" "ኋ") ("h2Wa" "ኋ") ("hWa" "ኋ")
1202 ("`hW" "ኋ") ("hhW" "ኋ") ("h2W" "ኋ")
1203 ("`hWE" ?ኌ) ("hhWE" "ኌ") ("h2WE" "ኌ") ("hWE" "ኌ")
1204 ("`hWee" "ኌ") ("hhWee" "ኌ") ("h2Wee" "ኌ") ("hWee" "ኌ")
1205 ("`hW'" ?ኍ) ("hhW'" "ኍ") ("h2W'" "ኍ") ("hW'" "ኍ")
1206 ("`hWu" "ኍ") ("hhWu" "ኍ") ("h2Wu" "ኍ") ("hWu" "ኍ")
1212 ("nE" ?ኔ) ("nee" "ኔ")
1215 ("nWa" ?ኗ) ("nW" "ኗ")
1221 ("NE" ?ኜ) ("Nee" "ኜ")
1224 ("NWa" ?ኟ) ("NW" "ኟ")
1227 ("'u" ?ኡ) ("u" "ኡ") ("'U" "ኡ") ("U" "ኡ")
1231 ("'I" ?እ) ("I" "እ") ("'e" "እ") ("e" "እ")
1232 ("'o" ?ኦ) ("o" "ኦ") ("'O" "ኦ") ("O" "ኦ")
1233 ("'ea" ?ኧ) ("ea" "ኧ")
1239 ("kE" ?ኬ) ("kee" "ኬ")
1244 ("kWa" ?ኳ) ("kW" "ኳ")
1245 ("kWE" ?ኴ) ("kWee" "ኴ")
1246 ("kW'" ?ኵ) ("kWu" "ኵ")
1252 ("KE" ?ኼ) ("Kee" "ኼ")
1257 ("KWa" ?ዃ) ("KW" "ዃ")
1258 ("KWE" ?ዄ) ("KWee" "ዄ")
1259 ("KW'" ?ዅ) ("KWu" "ዅ")
1265 ("wE" ?ዌ) ("wee" "ዌ")
1269 ("`e" ?ዐ) ("ae" "ዐ") ("aaa" "ዐ") ("e2" "ዐ")
1270 ("`u" ?ዑ) ("uu" "ዑ") ("u2" "ዑ") ("`U" "ዑ") ("UU" "ዑ") ("U2" "ዑ")
1271 ("`i" ?ዒ) ("ii" "ዒ") ("i2" "ዒ")
1272 ("`a" ?ዓ) ("aa" "ዓ") ("a2" "ዓ") ("`A" "ዓ") ("AA" "ዓ") ("A2" "ዓ")
1273 ("`E" ?ዔ) ("EE" "ዔ") ("E2" "ዔ")
1274 ("`I" ?ዕ) ("II" "ዕ") ("I2" "ዕ") ("ee" "ዕ")
1275 ("`o" ?ዖ) ("oo" "ዖ") ("o2" "ዖ") ("`O" "ዖ") ("OO" "ዖ") ("O2" "ዖ")
1281 ("zE" ?ዜ) ("zee" "ዜ")
1284 ("zWa" ?ዟ) ("zW" "ዟ")
1290 ("ZE" ?ዤ) ("Zee" "ዤ")
1293 ("ZWa" ?ዧ) ("ZW" "ዧ")
1295 ("ye" ?የ) ("Ye" "የ")
1296 ("yu" ?ዩ) ("Yu" "ዩ")
1297 ("yi" ?ዪ) ("Yi" "ዪ")
1298 ("ya" ?ያ) ("Ya" "ያ")
1299 ("yE" ?ዬ) ("YE" "ዬ") ("yee" "ዬ") ("Yee" "ዬ")
1301 ("yo" ?ዮ) ("Yo" "ዮ")
1307 ("dE" ?ዴ) ("dee" "ዴ")
1310 ("dWa" ?ዷ) ("dW" "ዷ")
1316 ("DE" ?ዼ) ("Dee" "ዼ")
1319 ("DWa" ?ዿ) ("DW" "ዿ")
1321 ("je" ?ጀ) ("Je" "ጀ")
1322 ("ju" ?ጁ) ("Ju" "ጁ")
1323 ("ji" ?ጂ) ("Ji" "ጂ")
1324 ("ja" ?ጃ) ("Ja" "ጃ")
1325 ("jE" ?ጄ) ("JE" "ጄ") ("jee" "ጄ") ("Jee" "ጄ")
1327 ("jo" ?ጆ) ("Jo" "ጆ")
1328 ("jWa" ?ጇ) ("jW" "ጇ") ("JWa" "ጇ") ("JW" "ጇ")
1334 ("gE" ?ጌ) ("gee" "ጌ")
1339 ("gWa" ?ጓ) ("gW" "ጓ")
1340 ("gWE" ?ጔ) ("gWee" "ጔ")
1341 ("gW'" ?ጕ) ("gWu" "ጕ")
1347 ("GE" ?ጜ) ("Gee" "ጜ")
1355 ("TE" ?ጤ) ("Tee" "ጤ")
1358 ("TWa" ?ጧ) ("TW" "ጧ")
1364 ("CE" ?ጬ) ("Cee" "ጬ")
1367 ("CWa" ?ጯ) ("CW" "ጯ")
1373 ("PE" ?ጴ) ("Pee" "ጴ")
1376 ("PWa" ?ጷ) ("PW" "ጷ")
1382 ("SE" ?ጼ) ("See" "ጼ")
1385 ("SWa" ?ጿ) ("`SWa" "ጿ") ("SSWa" "ጿ") ("S2Wa" "ጿ")
1386 ("SW" "ጿ") ("`SW" "ጿ") ("SSW" "ጿ") ("S2W" "ጿ")
1388 ("`Se" ?ፀ) ("SSe" "ፀ") ("S2e" "ፀ")
1389 ("`Su" ?ፁ) ("SSu" "ፁ") ("S2u" "ፁ")
1390 ("`Si" ?ፂ) ("SSi" "ፂ") ("S2i" "ፂ")
1391 ("`Sa" ?ፃ) ("SSa" "ፃ") ("S2a" "ፃ")
1392 ("`SE" ?ፄ) ("SSE" "ፄ") ("S2E" "ፄ")
1393 ("`See" "ፄ") ("SSee" "ፄ") ("S2ee" "ፄ")
1394 ("`S" ?ፅ) ("SS" "ፅ") ("S2" "ፅ")
1395 ("`So" ?ፆ) ("SSo" "ፆ") ("S2o" "ፆ")
1397 ("fe" ?ፈ) ("Fe" "ፈ")
1398 ("fu" ?ፉ) ("Fu" "ፉ")
1399 ("fi" ?ፊ) ("Fi" "ፊ")
1400 ("fa" ?ፋ) ("Fa" "ፋ")
1401 ("fE" ?ፌ) ("FE" "ፌ") ("fee" "ፌ") ("Fee" "ፌ")
1403 ("fo" ?ፎ) ("Fo" "ፎ")
1404 ("fWa" ?ፏ) ("FWa" "ፏ") ("fW" "ፏ") ("FW" "ፏ")
1410 ("pE" ?ፔ) ("pee" "ፔ")
1413 ("pWa" ?ፗ) ("pW" "ፗ")
1415 ("rYa" ?ፘ) ("RYa" "ፘ") ("rY" "ፘ") ("RY" "ፘ")
1416 ("mYa" ?ፙ) ("MYa" "ፙ") ("mY" "ፙ") ("MY" "ፙ")
1417 ("fYa" ?ፚ) ("FYa" "ፚ") ("fY" "ፚ") ("FY" "ፚ")
1419 (" : " ?፡) (":" "፡") ("`:" "፡")
1425 ("`?" ?፧) ("??" "፧")
1426 (":|:" ?፨) ("**" "፨")
1428 ;; Explicit syllable delimiter
1431 ;; Quick ASCII input
1496 (register-input-method
1497 "ethiopic-sera" "Ethiopic"
1498 'robin-use-package "et" "An input method for Ethiopic.")
1500 (robin-define-package "ethiopic-tex"
1501 "TeX transliteration system for Ethiopic."
1503 ("\\heG" ?ሀ) ; U+1200 ..
1520 ("\\HeG" ?ሐ) ; U+1210 ..
1537 ("\\sseG" ?ሠ) ; U+1220 ..
1554 ("\\seG" ?ሰ) ; U+1230 ..
1571 ("\\qeG" ?ቀ) ; U+1240 ..
1588 ("\\QeG" ?ቐ) ; U+1250 ..
1605 ("\\beG" ?በ) ; U+1260 ..
1622 ("\\teG" ?ተ) ; U+1270 ..
1639 ("\\hheG" ?ኀ) ; U+1280 ..
1656 ("\\neG" ?ነ) ; U+1290 ..
1673 ("\\eG" ?አ) ; U+12A0 ..
1690 ("\\kWeG" ?ኰ) ; U+12B0 ..
1707 ("\\KWeG" ?ዀ) ; U+12C0 ..
1724 ("\\eeG" ?ዐ) ; U+12D0 ..
1741 ("\\ZeG" ?ዠ) ; U+12E0 ..
1758 ("\\deG" ?ደ) ; U+12F0 ..
1775 ("\\jeG" ?ጀ) ; U+1300 ..
1792 ("\\gWeG" ?ጐ) ; U+1310 ..
1809 ("\\TeG" ?ጠ) ; U+1320 ..
1826 ("\\PeG" ?ጰ) ; U+1330 ..
1843 ("\\SSeG" ?ፀ) ; U+1340 ..
1860 ("\\peG" ?ፐ) ; U+1350 ..
1877 ;; reserved ; U+1360 ..
1894 ("\\smntG" ?፰) ; U+1370 ..
1912 ;; private extension
1915 ("\\yWaG" ?) ; U+1A00EF (was U+12EF)
1917 ("\\GWaG" ?) ; U+1A011F (was U+131F)
1919 ("\\qqeG" ?) ; U+1A0180 .. (was U+1380 ..)
1936 ("\\kkeG" ?) ; U+1A0190 .. (was U+1390 ..)
1953 ("\\XeG" ?) ; U+1A01A0 .. (was U+13A0 ..)
1970 ("\\ggeG" ?) ; U+1A01B0 .. (was U+13B0 ..)
1987 ("\\ornamentG" ?) ; U+1A01C0 .. (was U+FDF0 ..)
1997 ;; Gemination () is handled in a special way.
2000 ;; Assign reverse conversion to Fidel chars.
2001 ;; Then override forward conversion with ASCII chars.
2002 ;; ASCII chars should not have reverse conversions.
2003 ("\\dotG" ?) ("\\dotG" ".")
2004 ("\\lquoteG" ?) ("\\lquoteG" "«")
2005 ("\\rquoteG" ?) ("\\rquoteG" "»")
2006 ("\\qmarkG" ?) ("\\qmarkG" "?")
2009 ;; New characters in Unicode 4.1.
2011 ;; In forward conversion, these characters override the old private
2012 ;; extensions above. The old private extensions still keep their
2013 ;; reverse conversion.
2069 ;; The ethiopic-tex package is not used for keyboard input, therefore
2070 ;; not registered with the register-input-method function.
2072 (provide 'ethio-util)
2074 ;;; ethio-util.el ends here
2076 ;; arch-tag: c8feb3d6-39bf-4b0a-b6ef-26f03fbc8140
2077 ;;; ethio-util.el ends here