]> git.eshelyaron.com Git - emacs.git/commitdiff
Make pinyin to Chinese character mapping available to elisp
authorEric Abrahamsen <eric@ericabrahamsen.net>
Wed, 30 Jan 2019 20:31:49 +0000 (12:31 -0800)
committerEric Abrahamsen <eric@ericabrahamsen.net>
Sun, 24 Feb 2019 18:57:05 +0000 (10:57 -0800)
* leim/Makefile.in: Build the file pinyin.el from pinyin.map.
* lisp/international/titdic-cnv.el (pinyin-convert): New function that
  writes the library pinyin.el, containing a new constant
  `pinyin-character-map'.
* .gitignore: Ignore the generated pinyin.el file.

.gitignore
leim/Makefile.in
lisp/international/titdic-cnv.el

index 81d3adfb57ea22248f71467102a78acb582990f7..355824f3903aa33d11d6b0043e066e40ab955916 100644 (file)
@@ -199,6 +199,7 @@ lisp/international/charscript.el
 lisp/international/cp51932.el
 lisp/international/eucjp-ms.el
 lisp/international/uni-*.el
+lisp/language/pinyin.el
 
 # Documentation.
 *.aux
index c2fc8c41f237186df29c49f5ff96c07035762579..4307d5008767af464d553638dd60ea811a4a5330 100644 (file)
@@ -84,7 +84,8 @@ MISC= \
        ${leimdir}/quail/PY.el          \
        ${leimdir}/quail/ZIRANMA.el     \
        ${leimdir}/quail/CTLau.el       \
-       ${leimdir}/quail/CTLau-b5.el
+       ${leimdir}/quail/CTLau-b5.el    \
+       ${srcdir}/../lisp/language/pinyin.el
 
 ## All the generated .el files.
 TIT_MISC = ${TIT_GB} ${TIT_BIG5} ${MISC}
@@ -142,6 +143,9 @@ ${leimdir}/ja-dic/ja-dic.el: $(srcdir)/SKK-DIC/SKK-JISYO.L
        $(AM_V_GEN)$(RUN_EMACS) -batch -l ja-dic-cnv \
          -f batch-skkdic-convert -dir "$(leimdir)/ja-dic" "$<"
 
+${srcdir}/../lisp/language/pinyin.el: ${srcdir}/MISC-DIC/pinyin.map
+       $(AM_V_GEN)${RUN_EMACS} -l titdic-cnv -f pinyin-convert $< $@
+
 
 .PHONY: bootstrap-clean distclean maintainer-clean extraclean
 
index 2ce2c527b95c360459f98e76dfedfbf38048a9ca..e6065fb0f76d6e8b1961b8b5eb833a125313a34f 100644 (file)
@@ -1203,6 +1203,38 @@ to store generated Quail packages."
        (miscdic-convert filename dir))))
   (kill-emacs 0))
 
+(defun pinyin-convert ()
+  "Convert text file pinyin.map into an elisp library.
+The library is named pinyin.el, and contains the constant
+`pinyin-character-map'."
+  (let ((src-file (car command-line-args-left))
+        (dst-file (cadr command-line-args-left))
+        (coding-system-for-write 'utf-8-unix))
+    (with-temp-file dst-file
+      (insert ";; This file is automatically generated from pinyin.map,\
+ by the\n;; function pinyin-convert.\n\n")
+      (insert "(defconst pinyin-character-map\n'(")
+      (let ((pos (point)))
+        (insert-file-contents src-file)
+        (goto-char pos)
+        (re-search-forward "^[a-z]")
+        (beginning-of-line)
+        (delete-region pos (point))
+        (while (not (eobp))
+          (insert "(\"")
+          (skip-chars-forward "a-z")
+          (insert "\" . \"")
+          (delete-char 1)
+          (end-of-line)
+          (while (= (preceding-char) ?\r)
+           (delete-char -1))
+          (insert "\")")
+          (forward-line 1)))
+      (insert ")\n\"An alist holding correspondences between pinyin syllables\
+ and\nChinese characters.\")\n\n")
+      (insert "(provide 'pinyin)\n"))
+    (kill-emacs 0)))
+
 ;; Prevent "Local Variables" above confusing Emacs.
 \f