diff options
| author | Kenichi Handa | 1999-12-15 00:46:54 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1999-12-15 00:46:54 +0000 |
| commit | c595d8887d0bbc2c0f8389a14d79e766fee1455e (patch) | |
| tree | 9ee6ef740ccd372dd000b7c36d7885f88b6c6689 | |
| parent | 817e162fea669bc352b6c85314856d10147290ea (diff) | |
| download | emacs-c595d8887d0bbc2c0f8389a14d79e766fee1455e.tar.gz emacs-c595d8887d0bbc2c0f8389a14d79e766fee1455e.zip | |
(thai-category-table): Use
make-category-table, not copy-category-table, to initialize it.
(thai-composition-pattern): New variable.
(thai-with-thai-category-table): New macro.
(thai-compose-region, thai-compose-string): Rewritten.
(thai-post-read-conversion): Rewritten.
(thai-pre-write-conversion): Deleted.
(thai-composition-function): New function.
| -rw-r--r-- | lisp/language/thai-util.el | 128 |
1 files changed, 51 insertions, 77 deletions
diff --git a/lisp/language/thai-util.el b/lisp/language/thai-util.el index 2c891d0d992..04b48a6af13 100644 --- a/lisp/language/thai-util.el +++ b/lisp/language/thai-util.el | |||
| @@ -32,11 +32,22 @@ | |||
| 32 | 32 | ||
| 33 | ;; Setting information of Thai characters. | 33 | ;; Setting information of Thai characters. |
| 34 | 34 | ||
| 35 | (defvar thai-category-table (copy-category-table)) | 35 | (defconst thai-category-table (make-category-table)) |
| 36 | (or (category-docstring ?+ thai-category-table) | 36 | (define-category ?c "Thai consonant" thai-category-table) |
| 37 | (define-category ?+ "Thai consonant" thai-category-table)) | 37 | (define-category ?v "Thai upper/lower vowel" thai-category-table) |
| 38 | (or (category-docstring ?- thai-category-table) | 38 | (define-category ?t "Thai tone" thai-category-table) |
| 39 | (define-category ?- "Thai diacritical mark" thai-category-table)) | 39 | |
| 40 | ;; The general composing rules are as follows: | ||
| 41 | ;; | ||
| 42 | ;; T | ||
| 43 | ;; V T V T | ||
| 44 | ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C | ||
| 45 | ;; v v | ||
| 46 | ;; | ||
| 47 | ;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark. | ||
| 48 | |||
| 49 | (defvar thai-composition-pattern "\\cc\\(\\ct\\|\\cv\\ct?\\)" | ||
| 50 | "Regular expression matching a Thai composite sequence.") | ||
| 40 | 51 | ||
| 41 | (let ((l '((?,T!(B consonant "LETTER KO KAI") ; 0xA1 | 52 | (let ((l '((?,T!(B consonant "LETTER KO KAI") ; 0xA1 |
| 42 | (?,T"(B consonant "LETTER KHO KHAI") ; 0xA2 | 53 | (?,T"(B consonant "LETTER KHO KHAI") ; 0xA2 |
| @@ -135,16 +146,17 @@ | |||
| 135 | )) | 146 | )) |
| 136 | elm) | 147 | elm) |
| 137 | (while l | 148 | (while l |
| 138 | (setq elm (car l)) | 149 | (setq elm (car l) l (cdr l)) |
| 139 | (let ((ptype (nth 1 elm))) | 150 | (let ((char (car elm)) |
| 140 | (put-char-code-property (car elm) 'phonetic-type ptype) | 151 | (ptype (nth 1 elm))) |
| 141 | (if (eq ptype 'consonant) | 152 | (put-char-code-property char 'phonetic-type ptype) |
| 142 | (modify-category-entry (car elm) ?+ thai-category-table) | 153 | (cond ((eq ptype 'consonant) |
| 143 | (if (memq ptype '(vowel-upper vowel-lower tone)) | 154 | (modify-category-entry char ?c thai-category-table)) |
| 144 | (modify-category-entry (car elm) ?- thai-category-table)))) | 155 | ((memq ptype '(vowel-upper vowel-lower)) |
| 145 | (put-char-code-property (car elm) 'name (nth 2 elm)) | 156 | (modify-category-entry char ?v thai-category-table)) |
| 146 | (setq l (cdr l)))) | 157 | ((eq ptype 'tone) |
| 147 | 158 | (modify-category-entry char ?t thai-category-table))) | |
| 159 | (put-char-code-property char 'name (nth 2 elm))))) | ||
| 148 | 160 | ||
| 149 | ;;;###autoload | 161 | ;;;###autoload |
| 150 | (defun thai-compose-region (beg end) | 162 | (defun thai-compose-region (beg end) |
| @@ -154,33 +166,20 @@ positions (integers or markers) specifying the region." | |||
| 154 | (interactive "r") | 166 | (interactive "r") |
| 155 | (save-restriction | 167 | (save-restriction |
| 156 | (narrow-to-region beg end) | 168 | (narrow-to-region beg end) |
| 157 | (decompose-region (point-min) (point-max)) | ||
| 158 | (goto-char (point-min)) | 169 | (goto-char (point-min)) |
| 159 | (let ((current-ctbl (category-table))) | 170 | (with-category-table thai-category-table |
| 160 | (set-category-table thai-category-table) | 171 | (while (re-search-forward thai-composition-pattern nil t) |
| 161 | (unwind-protect | 172 | (compose-region (match-beginning 0) (match-end 0)))))) |
| 162 | (while (re-search-forward "\\c+\\c-+" nil t) | ||
| 163 | (compose-region (match-beginning 0) (match-end 0))) | ||
| 164 | (set-category-table current-ctbl))))) | ||
| 165 | 173 | ||
| 166 | ;;;###autoload | 174 | ;;;###autoload |
| 167 | (defun thai-compose-string (string) | 175 | (defun thai-compose-string (string) |
| 168 | "Compose Thai characters in STRING and return the resulting string." | 176 | "Compose Thai characters in STRING and return the resulting string." |
| 169 | (let ((current-ctbl (category-table))) | 177 | (with-category-table thai-category-table |
| 170 | (set-category-table thai-category-table) | 178 | (let ((idx 0)) |
| 171 | (unwind-protect | 179 | (while (setq idx (string-match thai-composition-pattern string idx)) |
| 172 | (let ((idx 0) | 180 | (compose-string string idx (match-end 0)) |
| 173 | (new "")) | 181 | (setq idx (match-end 0))))) |
| 174 | (while (string-match "\\c+\\c-+" string idx) | 182 | string) |
| 175 | (if (< idx (match-beginning 0)) | ||
| 176 | (setq new | ||
| 177 | (concat new (substring string idx (match-beginning 0))))) | ||
| 178 | (setq new (concat new (compose-string (match-string 0 string)))) | ||
| 179 | (setq idx (match-end 0))) | ||
| 180 | (if (< idx (length string)) | ||
| 181 | (setq new (concat new (substring string idx)))) | ||
| 182 | new) | ||
| 183 | (set-category-table current-ctbl)))) | ||
| 184 | 183 | ||
| 185 | ;;;###autoload | 184 | ;;;###autoload |
| 186 | (defun thai-compose-buffer () | 185 | (defun thai-compose-buffer () |
| @@ -190,48 +189,23 @@ positions (integers or markers) specifying the region." | |||
| 190 | 189 | ||
| 191 | ;;;###autoload | 190 | ;;;###autoload |
| 192 | (defun thai-post-read-conversion (len) | 191 | (defun thai-post-read-conversion (len) |
| 193 | (save-excursion | 192 | (thai-compose-region (point) (+ (point) len)) |
| 194 | (save-restriction | 193 | len) |
| 195 | (let ((buffer-modified-p (buffer-modified-p)) | ||
| 196 | (category-table (category-table)) | ||
| 197 | (buf (current-buffer)) | ||
| 198 | (workbuf (generate-new-buffer "*thai-work*")) | ||
| 199 | (pos (point)) | ||
| 200 | start end str) | ||
| 201 | (save-excursion | ||
| 202 | (set-buffer workbuf) | ||
| 203 | (setq buffer-undo-list t)) | ||
| 204 | (narrow-to-region pos (+ pos len)) | ||
| 205 | (set-category-table thai-category-table) | ||
| 206 | (unwind-protect | ||
| 207 | (progn | ||
| 208 | (while (re-search-forward "\\c+\\c-+" nil t) | ||
| 209 | (setq start (match-beginning 0) | ||
| 210 | end (point) | ||
| 211 | str (compose-string (buffer-substring start end))) | ||
| 212 | (set-buffer workbuf) | ||
| 213 | (if (< pos start) | ||
| 214 | (insert-buffer-substring buf pos start)) | ||
| 215 | (insert str) | ||
| 216 | (set-buffer buf) | ||
| 217 | (setq pos end)) | ||
| 218 | (delete-region (point-min) (point)) | ||
| 219 | (insert-buffer-substring workbuf)) | ||
| 220 | (set-category-table category-table) | ||
| 221 | (kill-buffer workbuf)) | ||
| 222 | (set-buffer-modified-p buffer-modified-p) | ||
| 223 | (- (point-max) (point-min)))))) | ||
| 224 | 194 | ||
| 225 | ;;;###autoload | 195 | ;;;###autoload |
| 226 | (defun thai-pre-write-conversion (from to) | 196 | (defun thai-composition-function (from to pattern &optional string) |
| 227 | (let ((old-buf (current-buffer))) | 197 | "Compose Thai text in the region FROM and TO. |
| 228 | (set-buffer (generate-new-buffer " *temp*")) | 198 | The text matches the regular expression PATTERN. |
| 229 | (if (stringp from) | 199 | Optional 4th argument STRING, if non-nil, is a string containing text |
| 230 | (insert from) | 200 | to compose. |
| 231 | (insert-buffer-substring old-buf from to)) | 201 | |
| 232 | (decompose-region (point-min) (point-max)) | 202 | The return value is number of composed characters."a |
| 233 | ;; Should return nil as annotations. | 203 | (if (< (1+ from) to) |
| 234 | nil)) | 204 | (prog1 (- to from) |
| 205 | (if string | ||
| 206 | (compose-string from to) | ||
| 207 | (compose-region from to)) | ||
| 208 | (- to from)))) | ||
| 235 | 209 | ||
| 236 | ;; | 210 | ;; |
| 237 | (provide 'thai-util) | 211 | (provide 'thai-util) |