2019-01-07 21:18:40 -05:00
|
|
|
|
;;; japan-util.el --- utilities for Japanese
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2020-01-01 00:19:43 +00:00
|
|
|
|
;; Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
2006-12-13 01:13:58 +00:00
|
|
|
|
;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
2011-01-02 15:50:46 -08:00
|
|
|
|
;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
2005-05-16 07:03:28 +00:00
|
|
|
|
;; National Institute of Advanced Industrial Science and Technology (AIST)
|
|
|
|
|
;; Registration Number H14PRO021
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;; Keywords: mule, multilingual, Japanese
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2001-07-15 19:53:53 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
1998-08-10 06:42:41 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun setup-japanese-environment-internal ()
|
2019-01-09 16:16:46 -08:00
|
|
|
|
(prefer-coding-system (if (memq system-type '(windows-nt ms-dos cygwin))
|
|
|
|
|
'japanese-shift-jis
|
|
|
|
|
'utf-8))
|
2009-06-30 01:52:12 +00:00
|
|
|
|
(use-cjk-char-width-table 'ja_JP))
|
1997-05-28 03:39:03 +00:00
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(defconst japanese-kana-table
|
2019-01-07 21:18:40 -05:00
|
|
|
|
'((?あ ?ア ?ア) (?い ?イ ?イ) (?う ?ウ ?ウ) (?え ?エ ?エ) (?お ?オ ?オ)
|
|
|
|
|
(?か ?カ ?カ) (?き ?キ ?キ) (?く ?ク ?ク) (?け ?ケ ?ケ) (?こ ?コ ?コ)
|
|
|
|
|
(?さ ?サ ?サ) (?し ?シ ?シ) (?す ?ス ?ス) (?せ ?セ ?セ) (?そ ?ソ ?ソ)
|
|
|
|
|
(?た ?タ ?タ) (?ち ?チ ?チ) (?つ ?ツ ?ツ) (?て ?テ ?テ) (?と ?ト ?ト)
|
|
|
|
|
(?な ?ナ ?ナ) (?に ?ニ ?ニ) (?ぬ ?ヌ ?ヌ) (?ね ?ネ ?ネ) (?の ?ノ ?ノ)
|
|
|
|
|
(?は ?ハ ?ハ) (?ひ ?ヒ ?ヒ) (?ふ ?フ ?フ) (?へ ?ヘ ?ヘ) (?ほ ?ホ ?ホ)
|
|
|
|
|
(?ま ?マ ?マ) (?み ?ミ ?ミ) (?む ?ム ?ム) (?め ?メ ?メ) (?も ?モ ?モ)
|
|
|
|
|
(?や ?ヤ ?ヤ) (?ゆ ?ユ ?ユ) (?よ ?ヨ ?ヨ)
|
|
|
|
|
(?ら ?ラ ?ラ) (?り ?リ ?リ) (?る ?ル ?ル) (?れ ?レ ?レ) (?ろ ?ロ ?ロ)
|
|
|
|
|
(?わ ?ワ ?ワ) (?ゐ ?ヰ "イ") (?ゑ ?ヱ "エ") (?を ?ヲ ?ヲ)
|
|
|
|
|
(?ん ?ン ?ン)
|
|
|
|
|
(?が ?ガ "ガ") (?ぎ ?ギ "ギ") (?ぐ ?グ "グ") (?げ ?ゲ "ゲ") (?ご ?ゴ "ゴ")
|
|
|
|
|
(?ざ ?ザ "ザ") (?じ ?ジ "ジ") (?ず ?ズ "ズ") (?ぜ ?ゼ "ゼ") (?ぞ ?ゾ "ゾ")
|
|
|
|
|
(?だ ?ダ "ダ") (?ぢ ?ヂ "ヂ") (?づ ?ヅ "ヅ") (?で ?デ "デ") (?ど ?ド "ド")
|
|
|
|
|
(?ば ?バ "バ") (?び ?ビ "ビ") (?ぶ ?ブ "ブ") (?べ ?ベ "ベ") (?ぼ ?ボ "ボ")
|
|
|
|
|
(?ぱ ?パ "パ") (?ぴ ?ピ "ピ") (?ぷ ?プ "プ") (?ぺ ?ペ "ペ") (?ぽ ?ポ "ポ")
|
|
|
|
|
(?ぁ ?ァ ?ァ) (?ぃ ?ィ ?ィ) (?ぅ ?ゥ ?ゥ) (?ぇ ?ェ ?ェ) (?ぉ ?ォ ?ォ)
|
|
|
|
|
(?っ ?ッ ?ッ)
|
|
|
|
|
(?ゃ ?ャ ?ャ) (?ゅ ?ュ ?ュ) (?ょ ?ョ ?ョ)
|
|
|
|
|
(?ゎ ?ヮ "ワ")
|
|
|
|
|
(?ゝ ?ヽ) (?ゞ ?ヾ)
|
|
|
|
|
("う゛" ?ヴ "ヴ") (nil ?ヵ "カ") (nil ?ヶ "ケ"))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
"Japanese JISX0208 Kana character table.
|
|
|
|
|
Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where
|
|
|
|
|
HIRAGANA and KATAKANA belong to `japanese-jisx0208',
|
|
|
|
|
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
|
1998-06-23 00:30:05 +00:00
|
|
|
|
(if (stringp hiragana)
|
|
|
|
|
(if (> (length hiragana) 1)
|
|
|
|
|
(let ((hira (aref hiragana 0)))
|
|
|
|
|
(put-char-code-property
|
1998-07-19 05:17:35 +00:00
|
|
|
|
hira 'kana-composition
|
1998-06-23 00:30:05 +00:00
|
|
|
|
(cons (cons (aref hiragana 1) katakana)
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(get-char-code-property hira 'kana-composition)))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(put-char-code-property hiragana 'katakana katakana)
|
1998-06-23 00:30:05 +00:00
|
|
|
|
(put-char-code-property hiragana 'jisx0201 jisx0201)))
|
|
|
|
|
(when (integerp katakana)
|
|
|
|
|
(put-char-code-property katakana 'hiragana hiragana)
|
|
|
|
|
(put-char-code-property katakana 'jisx0201 jisx0201))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(if jisx0201
|
1998-06-23 00:30:05 +00:00
|
|
|
|
(if (stringp jisx0201)
|
|
|
|
|
(if (> (length jisx0201) 1)
|
|
|
|
|
(let ((kana (aref jisx0201 0)))
|
|
|
|
|
(put-char-code-property
|
1998-07-19 05:17:35 +00:00
|
|
|
|
kana 'kana-composition
|
1998-06-23 00:30:05 +00:00
|
|
|
|
(cons (cons (aref jisx0201 1) katakana)
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(get-char-code-property kana 'kana-composition)))))
|
1998-06-23 00:30:05 +00:00
|
|
|
|
(put-char-code-property jisx0201 'hiragana hiragana)
|
|
|
|
|
(put-char-code-property jisx0201 'katakana katakana)
|
|
|
|
|
(put-char-code-property jisx0201 'jisx0208 katakana)))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defconst japanese-symbol-table
|
2019-01-07 21:18:40 -05:00
|
|
|
|
'((?\ ?\ ) (?, ?, ?、) (?. ?. ?。) (?、 ?, ?、) (?。 ?. ?。) (?・ nil ?・)
|
|
|
|
|
(?: ?:) (?; ?\;) (?? ??) (?! ?!) (?゛ nil ?゙) (?゜ nil ?゚)
|
|
|
|
|
(?´ ?') (?` ?`) (?^ ?^) (?_ ?_) (?ー ?- ?ー) (?— ?-) (?‐ ?-)
|
|
|
|
|
(?/ ?/) (?\ ?\\) (?〜 ?~) (?| ?|) (?‘ ?`) (?’ ?') (?“ ?\") (?” ?\")
|
|
|
|
|
(?\( ?\() (?\) ?\)) (?\[ ?\[) (?\] ?\]) (?\{ ?{) (?\} ?})
|
|
|
|
|
(?〈 ?<) (?〉 ?>) (?\「 nil ?\「) (?\」 nil ?\」)
|
|
|
|
|
(?+ ?+) (?− ?-) (?= ?=) (?< ?<) (?> ?>)
|
|
|
|
|
(?′ ?') (?″ ?\") (?¥ ?\\) (?$ ?$) (?% ?%) (?# ?#) (?& ?&) (?* ?*)
|
|
|
|
|
(?@ ?@)
|
2009-08-27 07:22:47 +00:00
|
|
|
|
;; cp932-2-byte
|
|
|
|
|
(#x2015 ?-) (#xFF5E ?~) (#xFF0D ?-))
|
2009-11-13 06:21:38 +00:00
|
|
|
|
"Japanese JISX0208 and CP932 symbol character table.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
Each element is of the form (SYMBOL ASCII HANKAKU), where SYMBOL
|
2009-11-13 06:21:38 +00:00
|
|
|
|
belongs to `japanese-jisx0208' or `cp932', ASCII belongs to `ascii',
|
|
|
|
|
and HANKAKU belongs to `japanese-jisx0201-kana'.")
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;; 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)
|
2009-11-13 06:21:38 +00:00
|
|
|
|
(if (encode-char jisx0208 'japanese-jisx0208)
|
|
|
|
|
(put-char-code-property ascii 'jisx0208 jisx0208))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(if jisx0201
|
|
|
|
|
(progn
|
|
|
|
|
(put-char-code-property jisx0208 'jisx0201 jisx0201)
|
2009-11-13 06:21:38 +00:00
|
|
|
|
(if (encode-char jisx0208 'japanese-jisx0208)
|
|
|
|
|
(put-char-code-property jisx0201 'jisx0208 jisx0208))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defconst japanese-alpha-numeric-table
|
2019-01-07 21:18:40 -05:00
|
|
|
|
'((?0 . ?0) (?1 . ?1) (?2 . ?2) (?3 . ?3) (?4 . ?4)
|
|
|
|
|
(?5 . ?5) (?6 . ?6) (?7 . ?7) (?8 . ?8) (?9 . ?9)
|
|
|
|
|
(?A . ?A) (?B . ?B) (?C . ?C) (?D . ?D) (?E . ?E)
|
|
|
|
|
(?F . ?F) (?G . ?G) (?H . ?H) (?I . ?I) (?J . ?J)
|
|
|
|
|
(?K . ?K) (?L . ?L) (?M . ?M) (?N . ?N) (?O . ?O)
|
|
|
|
|
(?P . ?P) (?Q . ?Q) (?R . ?R) (?S . ?S) (?T . ?T)
|
|
|
|
|
(?U . ?U) (?V . ?V) (?W . ?W) (?X . ?X) (?Y . ?Y) (?Z . ?Z)
|
|
|
|
|
(?a . ?a) (?b . ?b) (?c . ?c) (?d . ?d) (?e . ?e)
|
|
|
|
|
(?f . ?f) (?g . ?g) (?h . ?h) (?i . ?i) (?j . ?j)
|
|
|
|
|
(?k . ?k) (?l . ?l) (?m . ?m) (?n . ?n) (?o . ?o)
|
|
|
|
|
(?p . ?p) (?q . ?q) (?r . ?r) (?s . ?s) (?t . ?t)
|
|
|
|
|
(?u . ?u) (?v . ?v) (?w . ?w) (?x . ?x) (?y . ?y) (?z . ?z))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
"Japanese JISX0208 alpha numeric character table.
|
2016-06-01 08:33:05 +09:00
|
|
|
|
Each element is of the form (ALPHA-NUMERIC . ASCII), where ALPHA-NUMERIC
|
1997-02-20 07:02:49 +00:00
|
|
|
|
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)))
|
|
|
|
|
|
|
|
|
|
;; Convert string STR by FUNC and return a resulting string.
|
|
|
|
|
(defun japanese-string-conversion (str func &rest args)
|
|
|
|
|
(let ((buf (get-buffer-create " *Japanese work*")))
|
* textmodes/two-column.el (2C-split):
* textmodes/texnfo-upd.el (texinfo-multi-file-included-list):
* textmodes/tex-mode.el (tex-set-buffer-directory):
* textmodes/spell.el (spell-region, spell-string):
* textmodes/reftex.el (reftex-erase-buffer):
(reftex-get-file-buffer-force, reftex-kill-temporary-buffers):
* textmodes/reftex-toc.el (reftex-toc-promote-action):
* textmodes/reftex-sel.el (reftex-get-offset, reftex-insert-docstruct)
(reftex-select-item):
* textmodes/reftex-ref.el (reftex-label-info-update)
(reftex-offer-label-menu):
* textmodes/reftex-index.el (reftex-index-change-entry)
(reftex-index-phrases-info):
* textmodes/reftex-global.el (reftex-create-tags-file)
(reftex-save-all-document-buffers, reftex-ensure-write-access):
* textmodes/reftex-dcr.el (reftex-echo-ref, reftex-echo-cite)
(reftex-view-crossref-from-bibtex):
* textmodes/reftex-cite.el (reftex-bibtex-selection-callback)
(reftex-extract-bib-entries-from-thebibliography)
(reftex-all-used-citation-keys, reftex-create-bibtex-file):
* textmodes/refbib.el (r2b-capitalize-title):
(r2b-convert-buffer, r2b-help):
* textmodes/page-ext.el (pages-directory)
(pages-directory-goto-with-mouse):
* textmodes/bibtex.el (bibtex-validate-globally):
* textmodes/bib-mode.el (bib-capitalize-title):
* textmodes/artist.el (artist-clear-buffer, artist-system):
* progmodes/xscheme.el (global-set-scheme-interaction-buffer):
(local-set-scheme-interaction-buffer, xscheme-process-filter)
(verify-xscheme-buffer, xscheme-enter-interaction-mode)
(xscheme-enter-debugger-mode, xscheme-debugger-mode-p)
(xscheme-send-control-g-interrupt, xscheme-start-process)
(xscheme-process-sentinel, xscheme-cd):
* progmodes/verilog-mode.el (verilog-read-always-signals)
(verilog-set-define, verilog-getopt-file)
(verilog-module-inside-filename-p):
* progmodes/sh-script.el:
* progmodes/python.el (python-pdbtrack-get-source-buffer)
(python-pdbtrack-grub-for-buffer, python-execute-file):
* progmodes/octave-inf.el (inferior-octave):
* progmodes/idlwave.el (idlwave-scan-user-lib-files)
(idlwave-shell-compile-helper-routines, idlwave-set-local)
(idlwave-display-completion-list-xemacs, idlwave-list-abbrevs)
(idlwave-display-completion-list-emacs, idlwave-list-load-path-shadows)
(idlwave-completion-fontify-classes, idlwave-display-calling-sequence):
* progmodes/idlw-shell.el (idlwave-shell-examine-display-clear)
(idlwave-shell-filter, idlwave-shell-examine-highlight)
(idlwave-shell-sentinel, idlwave-shell-filter-directory)
(idlwave-shell-display-line, idlwave-shell-set-bp-in-module)
(idlwave-shell-examine-display, idlwave-shell-run-region)
(idlwave-shell-filter-bp, idlwave-shell-save-and-action)
(idlwave-shell-sources-filter, idlwave-shell-goto-next-error):
* progmodes/idlw-help.el (idlwave-help-get-special-help)
(idlwave-help-get-help-buffer):
* progmodes/gud.el (gud-basic-call, gud-find-class)
(gud-tooltip-activate-mouse-motions-if-enabled):
* progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe):
* progmodes/ebrowse.el (ebrowse-member-table, ebrowse-save-tree-as)
(ebrowse-view-exit-fn, ebrowse-tags-list-members-in-file)
(ebrowse-tags-next-file):
* progmodes/ebnf2ps.el (ebnf-generate-eps, ebnf-generate-eps)
(ebnf-eps-production-list, ebnf-begin-file, ebnf-log)
(ebnf-eps-finish-and-write):
* progmodes/cpp.el (cpp-edit-save):
* progmodes/cperl-mode.el (cperl-pod-to-manpage):
* progmodes/cc-defs.el (c-emacs-features):
* progmodes/antlr-mode.el (antlr-invalidate-context-cache)
(antlr-directory-dependencies):
* progmodes/ada-xref.el (ada-gnat-parse-gpr, ada-get-ali-file-name)
(ada-run-application, ada-find-in-src-path, ada-goto-parent)
(ada-find-any-references, ada-make-filename-from-adaname)
(ada-make-body-gnatstub):
* obsolete/rnews.el (news-list-news-groups):
* obsolete/resume.el (resume-suspend-hook,resume-write-buffer-to-file):
* obsolete/iso-acc.el (iso-acc-minibuf-setup):
* net/rcirc.el (rcirc-debug):
* net/newst-treeview.el (newsticker--treeview-list-add-item)
(newsticker--treeview-list-clear, newsticker-treeview-browse-url)
(newsticker--treeview-list-update-faces, newsticker-treeview-save)
(newsticker--treeview-item-show-text, newsticker--treeview-item-show)
(newsticker--treeview-tree-update-tag,newsticker--treeview-buffer-init)
(newsticker-treeview-show-item, newsticker--treeview-unfold-node)
(newsticker--treeview-list-clear-highlight)
(newsticker--treeview-list-update-highlight)
(newsticker--treeview-list-highlight-start)
(newsticker--treeview-tree-update-highlight)
(newsticker--treeview-get-selected-item)
(newsticker-treeview-mark-list-items-old)
(newsticker--treeview-set-current-node):
* net/newst-plainview.el (newsticker--buffer-set-uptodate):
* net/newst-backend.el (newsticker--get-news-by-funcall)
(newsticker--get-news-by-wget, newsticker--image-get)
(newsticker--image-sentinel):
* net/mairix.el (mairix-rmail-fetch-field, mairix-gnus-fetch-field):
* net/eudcb-ph.el (eudc-ph-do-request, eudc-ph-open-session):
(eudc-ph-close-session):
* net/eudc.el (eudc-save-options):
* language/thai-word.el (thai-update-word-table):
* language/japan-util.el (japanese-string-conversion):
* international/titdic-cnv.el (tsang-quick-converter)
(ziranma-converter, ctlau-converter):
* international/mule-cmds.el (describe-language-environment):
* international/ja-dic-cnv.el (skkdic-convert-okuri-ari)
(skkdic-convert-postfix, skkdic-convert-prefix):
(skkdic-convert-okuri-nasi, skkdic-convert):
* emacs-lisp/re-builder.el (reb-update-overlays):
* emacs-lisp/pp.el (pp-to-string, pp-display-expression):
* emacs-lisp/gulp.el (gulp-send-requests):
* emacs-lisp/find-gc.el (trace-call-tree):
* emacs-lisp/eieio-opt.el (eieio-browse, eieio-describe-class)
(eieio-describe-generic):
* emacs-lisp/eieio-base.el (eieio-persistent-read):
* emacs-lisp/edebug.el (edebug-outside-excursion):
* emacs-lisp/debug.el (debugger-make-xrefs):
* emacs-lisp/cust-print.el (custom-prin1-to-string):
* emacs-lisp/chart.el (chart-new-buffer):
* emacs-lisp/authors.el (authors-scan-el, authors-scan-change-log):
Use with-current-buffer.
* textmodes/artist.el (artist-system): Don't call
copy-sequence on a fresh string.
* progmodes/idlw-shell.el (easymenu setup): Use dolist.
2009-10-31 02:38:34 +00:00
|
|
|
|
(with-current-buffer buf
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(erase-buffer)
|
|
|
|
|
(insert str)
|
|
|
|
|
(apply func 1 (point) args)
|
|
|
|
|
(buffer-string))))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-katakana (obj &optional hankaku)
|
|
|
|
|
"Convert argument to Katakana and return that.
|
|
|
|
|
The argument may be a character or string. The result has the same type.
|
|
|
|
|
The argument object is not altered--the value is a copy.
|
|
|
|
|
Optional argument HANKAKU t means to convert to `hankaku' Katakana
|
2015-09-17 16:08:20 -07:00
|
|
|
|
\(`japanese-jisx0201-kana'), in which case return value
|
|
|
|
|
may be a string even if OBJ is a character if two Katakanas are
|
|
|
|
|
necessary to represent OBJ."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(if (stringp obj)
|
|
|
|
|
(japanese-string-conversion obj 'japanese-katakana-region hankaku)
|
|
|
|
|
(or (get-char-code-property obj (if hankaku 'jisx0201 'katakana))
|
|
|
|
|
obj)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-hiragana (obj)
|
|
|
|
|
"Convert argument to Hiragana and return that.
|
|
|
|
|
The argument may be a character or string. The result has the same type.
|
|
|
|
|
The argument object is not altered--the value is a copy."
|
|
|
|
|
(if (stringp obj)
|
|
|
|
|
(japanese-string-conversion obj 'japanese-hiragana-region)
|
|
|
|
|
(or (get-char-code-property obj 'hiragana)
|
|
|
|
|
obj)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-hankaku (obj &optional ascii-only)
|
|
|
|
|
"Convert argument to `hankaku' and return that.
|
|
|
|
|
The argument may be a character or string. The result has the same type.
|
|
|
|
|
The argument object is not altered--the value is a copy.
|
|
|
|
|
Optional argument ASCII-ONLY non-nil means to return only ASCII character."
|
|
|
|
|
(if (stringp obj)
|
|
|
|
|
(japanese-string-conversion obj 'japanese-hankaku-region ascii-only)
|
2001-05-28 11:03:17 +00:00
|
|
|
|
(or (and (not ascii-only)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(get-char-code-property obj 'jisx0201))
|
2001-05-28 11:03:17 +00:00
|
|
|
|
(get-char-code-property obj 'ascii)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
obj)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-zenkaku (obj)
|
|
|
|
|
"Convert argument to `zenkaku' and return that.
|
|
|
|
|
The argument may be a character or string. The result has the same type.
|
|
|
|
|
The argument object is not altered--the value is a copy."
|
|
|
|
|
(if (stringp obj)
|
|
|
|
|
(japanese-string-conversion obj 'japanese-zenkaku-region)
|
|
|
|
|
(or (get-char-code-property obj 'jisx0208)
|
|
|
|
|
obj)))
|
|
|
|
|
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(defun japanese-replace-region (from to string)
|
|
|
|
|
"Replace the region specified by FROM and TO to STRING."
|
|
|
|
|
(goto-char from)
|
|
|
|
|
(insert string)
|
|
|
|
|
(delete-char (- to from)))
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-katakana-region (from to &optional hankaku)
|
|
|
|
|
"Convert Japanese `hiragana' chars in the region to `katakana' chars.
|
|
|
|
|
Optional argument HANKAKU t means to convert to `hankaku katakana' character
|
|
|
|
|
of which charset is `japanese-jisx0201-kana'."
|
|
|
|
|
(interactive "r\nP")
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region from to)
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (re-search-forward "\\cH\\|\\cK" nil t)
|
|
|
|
|
(let* ((kana (preceding-char))
|
2000-07-25 12:22:01 +00:00
|
|
|
|
(composition
|
|
|
|
|
(and (not hankaku)
|
|
|
|
|
(get-char-code-property kana 'kana-composition)))
|
1998-07-19 05:17:35 +00:00
|
|
|
|
next slot)
|
|
|
|
|
(if (and composition (setq slot (assq (following-char) composition)))
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (1+ (point))
|
|
|
|
|
(cdr slot))
|
|
|
|
|
(let ((kata (get-char-code-property
|
|
|
|
|
kana (if hankaku 'jisx0201 'katakana))))
|
|
|
|
|
(if kata
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (point)
|
|
|
|
|
kata)))))))))
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-hiragana-region (from to)
|
1998-06-23 00:30:05 +00:00
|
|
|
|
"Convert Japanese `katakana' chars in the region to `hiragana' chars."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(interactive "r")
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region from to)
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (re-search-forward "\\cK\\|\\ck" nil t)
|
|
|
|
|
(let* ((kata (preceding-char))
|
|
|
|
|
(composition (get-char-code-property kata 'kana-composition))
|
|
|
|
|
next slot)
|
|
|
|
|
(if (and composition (setq slot (assq (following-char) composition)))
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (1+ (point))
|
|
|
|
|
(get-char-code-property
|
|
|
|
|
(cdr slot) 'hiragana))
|
|
|
|
|
(let ((hira (get-char-code-property kata 'hiragana)))
|
|
|
|
|
(if hira
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (point)
|
|
|
|
|
hira)))))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun japanese-hankaku-region (from to &optional ascii-only)
|
|
|
|
|
"Convert Japanese `zenkaku' chars in the region to `hankaku' chars.
|
|
|
|
|
`Zenkaku' chars belong to `japanese-jisx0208'
|
|
|
|
|
`Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'.
|
|
|
|
|
Optional argument ASCII-ONLY non-nil means to convert only to ASCII char."
|
|
|
|
|
(interactive "r\nP")
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region from to)
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (re-search-forward "\\cj" nil t)
|
|
|
|
|
(let* ((zenkaku (preceding-char))
|
2001-05-28 11:03:17 +00:00
|
|
|
|
(hankaku (or (and (not ascii-only)
|
|
|
|
|
(get-char-code-property zenkaku 'jisx0201))
|
|
|
|
|
(get-char-code-property zenkaku 'ascii))))
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(if hankaku
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (match-end 0)
|
|
|
|
|
hankaku)))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
1998-11-16 06:26:27 +00:00
|
|
|
|
(defun japanese-zenkaku-region (from to &optional katakana-only)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
"Convert hankaku' chars in the region to Japanese `zenkaku' chars.
|
|
|
|
|
`Zenkaku' chars belong to `japanese-jisx0208'
|
1998-11-16 06:26:27 +00:00
|
|
|
|
`Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'.
|
|
|
|
|
Optional argument KATAKANA-ONLY non-nil means to convert only KATAKANA char."
|
|
|
|
|
(interactive "r\nP")
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region from to)
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
1998-11-16 06:26:27 +00:00
|
|
|
|
(while (or (and katakana-only
|
|
|
|
|
(re-search-forward "\\ck" nil t))
|
|
|
|
|
(and (not katakana-only)
|
|
|
|
|
(re-search-forward "\\ca\\|\\ck" nil t)))
|
1998-07-19 05:17:35 +00:00
|
|
|
|
(let* ((hankaku (preceding-char))
|
|
|
|
|
(composition (get-char-code-property hankaku 'kana-composition))
|
|
|
|
|
next slot)
|
|
|
|
|
(if (and composition (setq slot (assq (following-char) composition)))
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (1+ (point))
|
|
|
|
|
(cdr slot))
|
|
|
|
|
(let ((zenkaku (japanese-zenkaku hankaku)))
|
|
|
|
|
(if zenkaku
|
|
|
|
|
(japanese-replace-region (match-beginning 0) (match-end 0)
|
|
|
|
|
zenkaku)))))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun read-hiragana-string (prompt &optional initial-input)
|
|
|
|
|
"Read a Hiragana string from the minibuffer, prompting with string PROMPT.
|
|
|
|
|
If non-nil, second arg INITIAL-INPUT is a string to insert before reading."
|
1997-09-10 07:42:08 +00:00
|
|
|
|
(read-multilingual-string prompt initial-input "japanese-hiragana"))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;
|
1997-06-18 13:06:17 +00:00
|
|
|
|
(provide 'japan-util)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;; japan-util.el ends here
|