unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: 34215@debbugs.gnu.org
Subject: bug#34215: 27.0.50; Provide elisp access to Chinese pinyin-to-character mapping
Date: Thu, 31 Jan 2019 11:35:32 -0800	[thread overview]
Message-ID: <87a7jghb7f.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87imyafyts.fsf@ericabrahamsen.net>

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

Robert Pluim <rpluim@gmail.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>>
>> Oh, after reading a couple of "make" tutorials, I see maybe the make
>> rule could be simplified to:
>>
>> ${leimdir}/../lisp/language/pinyin.el: ${srcdir}/MISC-DIC/pinyin.map
>>   $(AM_V_GEN)${RUN_EMACS} -l titdic-cnv -f pinyin-convert $< $0
>
> $@ , I think.

Ah, right you are, thanks. I was wondering why that wasn't working. This
version should do the trick; it also gitignores the generated file.

Eric

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-pinyin-to-Chinese-character-mapping-available-t.patch --]
[-- Type: text/x-patch, Size: 3372 bytes --]

From 2395d1a62e66206c04b7069d372fdb4f10787863 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Wed, 30 Jan 2019 12:31:49 -0800
Subject: [PATCH 1/2] Make pinyin to Chinese character mapping available to
 elisp

* 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                       |  1 +
 leim/Makefile.in                 |  6 +++++-
 lisp/international/titdic-cnv.el | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 53f41f0f3e..f3d5ccb0f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/leim/Makefile.in b/leim/Makefile.in
index c2fc8c41f2..4307d50087 100644
--- a/leim/Makefile.in
+++ b/leim/Makefile.in
@@ -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:
 	$(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
 
diff --git a/lisp/international/titdic-cnv.el b/lisp/international/titdic-cnv.el
index 2ce2c527b9..d33e9ff229 100644
--- a/lisp/international/titdic-cnv.el
+++ b/lisp/international/titdic-cnv.el
@@ -1203,6 +1203,38 @@ batch-miscdic-convert
 	(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-emacs))
+    (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
 
-- 
2.20.1


  reply	other threads:[~2019-01-31 19:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-27  5:34 bug#34215: 27.0.50; Provide elisp access to Chinese pinyin-to-character mapping Eric Abrahamsen
2019-01-27 15:41 ` Eli Zaretskii
2019-01-27 18:02   ` Eric Abrahamsen
2019-01-27 18:14     ` Eli Zaretskii
2019-01-27 19:18       ` Eric Abrahamsen
2019-01-27 19:48         ` Eli Zaretskii
2019-01-29 17:48           ` Eric Abrahamsen
2019-01-30 17:09             ` Eli Zaretskii
2019-01-30 20:33               ` Eric Abrahamsen
2019-01-30 20:48                 ` Eric Abrahamsen
2019-01-31  8:50                   ` Robert Pluim
2019-01-31 19:35                     ` Eric Abrahamsen [this message]
2019-02-01  9:48                       ` Eli Zaretskii
2019-02-01 16:27                         ` Eric Abrahamsen
2019-02-01 18:53                           ` Eli Zaretskii
2019-02-01 19:15                             ` Eric Abrahamsen
2019-02-24  5:36                         ` Eric Abrahamsen
2019-02-24 16:06                           ` Eli Zaretskii
2019-02-24 18:53                             ` Eric Abrahamsen
2019-02-24 19:12 ` bug#34215: Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a7jghb7f.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=34215@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).