japan-util.el: Cosmetic changes

* lisp/language/japan-util.el (<toplevel>): Use `pcase-dolist` and `when`.
(japanese-string-conversion): Use `point-min`.
This commit is contained in:
Stefan Monnier 2025-03-31 10:21:58 -04:00
parent fa5cd6b4d9
commit b148e98de3

View file

@ -64,36 +64,30 @@ HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.")
;; Put properties 'katakana, 'hiragana, and 'jix0201 to each Japanese
;; kana characters for conversion among them.
(let ((l japanese-kana-table)
slot hiragana katakana jisx0201)
(while l
(setq slot (car l)
hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot)
l (cdr l))
(if hiragana
(if (stringp hiragana)
(if (> (length hiragana) 1)
(let ((hira (aref hiragana 0)))
(put-char-code-property
hira 'kana-composition
(cons (cons (aref hiragana 1) katakana)
(get-char-code-property hira 'kana-composition)))))
(put-char-code-property hiragana 'katakana katakana)
(put-char-code-property hiragana 'jisx0201 jisx0201)))
(when (integerp katakana)
(put-char-code-property katakana 'hiragana hiragana)
(put-char-code-property katakana 'jisx0201 jisx0201))
(if jisx0201
(if (stringp jisx0201)
(if (> (length jisx0201) 1)
(let ((kana (aref jisx0201 0)))
(put-char-code-property
kana 'kana-composition
(cons (cons (aref jisx0201 1) katakana)
(get-char-code-property kana 'kana-composition)))))
(put-char-code-property jisx0201 'hiragana hiragana)
(put-char-code-property jisx0201 'katakana katakana)
(put-char-code-property jisx0201 'jisx0208 katakana)))))
(pcase-dolist (`(,hiragana ,katakana ,jisx0201) japanese-kana-table)
(if hiragana
(if (stringp hiragana)
(if (length> hiragana 1)
(let ((hira (aref hiragana 0)))
(put-char-code-property
hira 'kana-composition
(cons (cons (aref hiragana 1) katakana)
(get-char-code-property hira 'kana-composition)))))
(put-char-code-property hiragana 'katakana katakana)
(put-char-code-property hiragana 'jisx0201 jisx0201)))
(put-char-code-property katakana 'hiragana hiragana)
(put-char-code-property katakana 'jisx0201 jisx0201)
(if jisx0201
(if (stringp jisx0201)
(if (length> jisx0201 1)
(let ((kana (aref jisx0201 0)))
(put-char-code-property
kana 'kana-composition
(cons (cons (aref jisx0201 1) katakana)
(get-char-code-property kana 'kana-composition)))))
(put-char-code-property jisx0201 'hiragana hiragana)
(put-char-code-property jisx0201 'katakana katakana)
(put-char-code-property jisx0201 'jisx0208 katakana))))
(defconst japanese-symbol-table
'((?\  ?\ ) (? ?,) (? ?.) (?、 nil ?、) (?。 nil ?。) (?・ nil ?・)
@ -114,22 +108,15 @@ and HANKAKU belongs to `japanese-jisx0201-kana'.")
;; Put properties 'jisx0208, 'jisx0201, and 'ascii to each Japanese
;; symbol and ASCII characters for conversion among them.
(let ((l japanese-symbol-table)
slot jisx0208 ascii jisx0201)
(while l
(setq slot (car l)
jisx0208 (car slot) ascii (nth 1 slot) jisx0201 (nth 2 slot)
l (cdr l))
(if ascii
(progn
(put-char-code-property jisx0208 'ascii ascii)
(if (encode-char jisx0208 'japanese-jisx0208)
(put-char-code-property ascii 'jisx0208 jisx0208))))
(if jisx0201
(progn
(put-char-code-property jisx0208 'jisx0201 jisx0201)
(if (encode-char jisx0208 'japanese-jisx0208)
(put-char-code-property jisx0201 'jisx0208 jisx0208))))))
(pcase-dolist (`(,jisx0208 ,ascii ,jisx0201) japanese-symbol-table)
(when ascii
(put-char-code-property jisx0208 'ascii ascii)
(if (encode-char jisx0208 'japanese-jisx0208)
(put-char-code-property ascii 'jisx0208 jisx0208)))
(when jisx0201
(put-char-code-property jisx0208 'jisx0201 jisx0201)
(if (encode-char jisx0208 'japanese-jisx0208)
(put-char-code-property jisx0201 'jisx0208 jisx0208))))
(defconst japanese-alpha-numeric-table
'((? . ?0) (? . ?1) (? . ?2) (? . ?3) (? . ?4)
@ -150,14 +137,9 @@ belongs to `japanese-jisx0208', ASCII belongs to `ascii'.")
;; Put properties 'jisx0208 and 'ascii to each Japanese alpha numeric
;; and ASCII characters for conversion between them.
(let ((l japanese-alpha-numeric-table)
slot jisx0208 ascii)
(while l
(setq slot (car l)
jisx0208 (car slot) ascii (cdr slot)
l (cdr l))
(put-char-code-property jisx0208 'ascii ascii)
(put-char-code-property ascii 'jisx0208 jisx0208)))
(pcase-dolist (`(,jisx0208 . ,ascii) japanese-alpha-numeric-table)
(put-char-code-property jisx0208 'ascii ascii)
(put-char-code-property ascii 'jisx0208 jisx0208))
;; Convert string STR by FUNC and return a resulting string.
(defun japanese-string-conversion (str func &rest args)
@ -165,7 +147,7 @@ belongs to `japanese-jisx0208', ASCII belongs to `ascii'.")
(with-current-buffer buf
(erase-buffer)
(insert str)
(apply func 1 (point) args)
(apply func (point-min) (point) args)
(buffer-string))))
;;;###autoload
@ -222,7 +204,7 @@ The argument object is not altered--the value is a copy."
(if (stringp string)
string
(string string))
0))
0))
;;;###autoload
(defun japanese-katakana-region (from to &optional hankaku)