diff options
Diffstat (limited to 'lisp/language')
| -rw-r--r-- | lisp/language/japan-util.el | 119 |
1 files changed, 62 insertions, 57 deletions
diff --git a/lisp/language/japan-util.el b/lisp/language/japan-util.el index 16790ed7da8..bdc33addd1c 100644 --- a/lisp/language/japan-util.el +++ b/lisp/language/japan-util.el | |||
| @@ -82,9 +82,9 @@ HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.") | |||
| 82 | (if (> (length hiragana) 1) | 82 | (if (> (length hiragana) 1) |
| 83 | (let ((hira (aref hiragana 0))) | 83 | (let ((hira (aref hiragana 0))) |
| 84 | (put-char-code-property | 84 | (put-char-code-property |
| 85 | hira 'composition | 85 | hira 'kana-composition |
| 86 | (cons (cons (aref hiragana 1) katakana) | 86 | (cons (cons (aref hiragana 1) katakana) |
| 87 | (get-char-code-property hira 'composition))))) | 87 | (get-char-code-property hira 'kana-composition))))) |
| 88 | (put-char-code-property hiragana 'katakana katakana) | 88 | (put-char-code-property hiragana 'katakana katakana) |
| 89 | (put-char-code-property hiragana 'jisx0201 jisx0201))) | 89 | (put-char-code-property hiragana 'jisx0201 jisx0201))) |
| 90 | (when (integerp katakana) | 90 | (when (integerp katakana) |
| @@ -95,9 +95,9 @@ HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.") | |||
| 95 | (if (> (length jisx0201) 1) | 95 | (if (> (length jisx0201) 1) |
| 96 | (let ((kana (aref jisx0201 0))) | 96 | (let ((kana (aref jisx0201 0))) |
| 97 | (put-char-code-property | 97 | (put-char-code-property |
| 98 | kana 'composition | 98 | kana 'kana-composition |
| 99 | (cons (cons (aref jisx0201 1) katakana) | 99 | (cons (cons (aref jisx0201 1) katakana) |
| 100 | (get-char-code-property kana 'composition))))) | 100 | (get-char-code-property kana 'kana-composition))))) |
| 101 | (put-char-code-property jisx0201 'hiragana hiragana) | 101 | (put-char-code-property jisx0201 'hiragana hiragana) |
| 102 | (put-char-code-property jisx0201 'katakana katakana) | 102 | (put-char-code-property jisx0201 'katakana katakana) |
| 103 | (put-char-code-property jisx0201 'jisx0208 katakana))))) | 103 | (put-char-code-property jisx0201 'jisx0208 katakana))))) |
| @@ -218,6 +218,12 @@ The argument object is not altered--the value is a copy." | |||
| 218 | (or (get-char-code-property obj 'jisx0208) | 218 | (or (get-char-code-property obj 'jisx0208) |
| 219 | obj))) | 219 | obj))) |
| 220 | 220 | ||
| 221 | (defun japanese-replace-region (from to string) | ||
| 222 | "Replace the region specified by FROM and TO to STRING." | ||
| 223 | (goto-char from) | ||
| 224 | (insert string) | ||
| 225 | (delete-char (- to from))) | ||
| 226 | |||
| 221 | ;;;###autoload | 227 | ;;;###autoload |
| 222 | (defun japanese-katakana-region (from to &optional hankaku) | 228 | (defun japanese-katakana-region (from to &optional hankaku) |
| 223 | "Convert Japanese `hiragana' chars in the region to `katakana' chars. | 229 | "Convert Japanese `hiragana' chars in the region to `katakana' chars. |
| @@ -226,21 +232,21 @@ of which charset is `japanese-jisx0201-kana'." | |||
| 226 | (interactive "r\nP") | 232 | (interactive "r\nP") |
| 227 | (save-restriction | 233 | (save-restriction |
| 228 | (narrow-to-region from to) | 234 | (narrow-to-region from to) |
| 229 | (goto-char (point-min)) | 235 | (save-excursion |
| 230 | (while (re-search-forward "\\cH\\|\\cK" nil t) | 236 | (goto-char (point-min)) |
| 231 | (let* ((kana (preceding-char)) | 237 | (while (re-search-forward "\\cH\\|\\cK" nil t) |
| 232 | (composition (get-char-code-property kana 'composition)) | 238 | (let* ((kana (preceding-char)) |
| 233 | next slot) | 239 | (composition (get-char-code-property kana 'kana-composition)) |
| 234 | (if (and composition (setq slot (assq (following-char) composition))) | 240 | next slot) |
| 235 | (progn | 241 | (if (and composition (setq slot (assq (following-char) composition))) |
| 236 | (delete-region (match-beginning 0) (1+ (point))) | 242 | (japanese-replace-region (match-beginning 0) (1+ (point)) |
| 237 | (insert (cdr slot))) | 243 | (cdr slot)) |
| 238 | (let ((kata (get-char-code-property | 244 | (let ((kata (get-char-code-property |
| 239 | kana (if hankaku 'jisx0201 'katakana)))) | 245 | kana (if hankaku 'jisx0201 'katakana)))) |
| 240 | (if kata | 246 | (if kata |
| 241 | (progn | 247 | (japanese-replace-region (match-beginning 0) (point) |
| 242 | (delete-region (match-beginning 0) (match-end 0)) | 248 | kata))))))))) |
| 243 | (insert kata))))))))) | 249 | |
| 244 | 250 | ||
| 245 | ;;;###autoload | 251 | ;;;###autoload |
| 246 | (defun japanese-hiragana-region (from to) | 252 | (defun japanese-hiragana-region (from to) |
| @@ -248,20 +254,20 @@ of which charset is `japanese-jisx0201-kana'." | |||
| 248 | (interactive "r") | 254 | (interactive "r") |
| 249 | (save-restriction | 255 | (save-restriction |
| 250 | (narrow-to-region from to) | 256 | (narrow-to-region from to) |
| 251 | (goto-char (point-min)) | 257 | (save-excursion |
| 252 | (while (re-search-forward "\\cK\\|\\ck" nil t) | 258 | (goto-char (point-min)) |
| 253 | (let* ((kata (preceding-char)) | 259 | (while (re-search-forward "\\cK\\|\\ck" nil t) |
| 254 | (composition (get-char-code-property kata 'composition)) | 260 | (let* ((kata (preceding-char)) |
| 255 | next slot) | 261 | (composition (get-char-code-property kata 'kana-composition)) |
| 256 | (if (and composition (setq slot (assq (following-char) composition))) | 262 | next slot) |
| 257 | (progn | 263 | (if (and composition (setq slot (assq (following-char) composition))) |
| 258 | (delete-region (match-beginning 0) (1+ (point))) | 264 | (japanese-replace-region (match-beginning 0) (1+ (point)) |
| 259 | (insert (get-char-code-property (cdr slot) 'hiragana))) | 265 | (get-char-code-property |
| 260 | (let ((hira (get-char-code-property kata 'hiragana))) | 266 | (cdr slot) 'hiragana)) |
| 261 | (if hira | 267 | (let ((hira (get-char-code-property kata 'hiragana))) |
| 262 | (progn | 268 | (if hira |
| 263 | (delete-region (match-beginning 0) (match-end 0)) | 269 | (japanese-replace-region (match-beginning 0) (point) |
| 264 | (insert hira))))))))) | 270 | hira))))))))) |
| 265 | 271 | ||
| 266 | ;;;###autoload | 272 | ;;;###autoload |
| 267 | (defun japanese-hankaku-region (from to &optional ascii-only) | 273 | (defun japanese-hankaku-region (from to &optional ascii-only) |
| @@ -272,16 +278,16 @@ Optional argument ASCII-ONLY non-nil means to convert only to ASCII char." | |||
| 272 | (interactive "r\nP") | 278 | (interactive "r\nP") |
| 273 | (save-restriction | 279 | (save-restriction |
| 274 | (narrow-to-region from to) | 280 | (narrow-to-region from to) |
| 275 | (goto-char (point-min)) | 281 | (save-excursion |
| 276 | (while (re-search-forward "\\cj" nil t) | 282 | (goto-char (point-min)) |
| 277 | (let* ((zenkaku (preceding-char)) | 283 | (while (re-search-forward "\\cj" nil t) |
| 278 | (hankaku (or (get-char-code-property zenkaku 'ascii) | 284 | (let* ((zenkaku (preceding-char)) |
| 279 | (and (not ascii-only) | 285 | (hankaku (or (get-char-code-property zenkaku 'ascii) |
| 280 | (get-char-code-property zenkaku 'jisx0201))))) | 286 | (and (not ascii-only) |
| 281 | (if hankaku | 287 | (get-char-code-property zenkaku 'jisx0201))))) |
| 282 | (progn | 288 | (if hankaku |
| 283 | (delete-region (match-beginning 0) (match-end 0)) | 289 | (japanese-replace-region (match-beginning 0) (match-end 0) |
| 284 | (insert hankaku))))))) | 290 | hankaku))))))) |
| 285 | 291 | ||
| 286 | ;;;###autoload | 292 | ;;;###autoload |
| 287 | (defun japanese-zenkaku-region (from to) | 293 | (defun japanese-zenkaku-region (from to) |
| @@ -291,20 +297,19 @@ Optional argument ASCII-ONLY non-nil means to convert only to ASCII char." | |||
| 291 | (interactive "r") | 297 | (interactive "r") |
| 292 | (save-restriction | 298 | (save-restriction |
| 293 | (narrow-to-region from to) | 299 | (narrow-to-region from to) |
| 294 | (goto-char (point-min)) | 300 | (save-excursion |
| 295 | (while (re-search-forward "\\ca\\|\\ck" nil t) | 301 | (goto-char (point-min)) |
| 296 | (let* ((hankaku (preceding-char)) | 302 | (while (re-search-forward "\\ca\\|\\ck" nil t) |
| 297 | (composition (get-char-code-property hankaku 'composition)) | 303 | (let* ((hankaku (preceding-char)) |
| 298 | next slot) | 304 | (composition (get-char-code-property hankaku 'kana-composition)) |
| 299 | (if (and composition (setq slot (assq (following-char) composition))) | 305 | next slot) |
| 300 | (progn | 306 | (if (and composition (setq slot (assq (following-char) composition))) |
| 301 | (delete-region (match-beginning 0) (1+ (point))) | 307 | (japanese-replace-region (match-beginning 0) (1+ (point)) |
| 302 | (insert (cdr slot))) | 308 | (cdr slot)) |
| 303 | (let ((zenkaku (japanese-zenkaku hankaku))) | 309 | (let ((zenkaku (japanese-zenkaku hankaku))) |
| 304 | (if zenkaku | 310 | (if zenkaku |
| 305 | (progn | 311 | (japanese-replace-region (match-beginning 0) (match-end 0) |
| 306 | (delete-region (match-beginning 0) (match-end 0)) | 312 | zenkaku))))))))) |
| 307 | (insert zenkaku))))))))) | ||
| 308 | 313 | ||
| 309 | ;;;###autoload | 314 | ;;;###autoload |
| 310 | (defun read-hiragana-string (prompt &optional initial-input) | 315 | (defun read-hiragana-string (prompt &optional initial-input) |