From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#34215: 27.0.50; Provide elisp access to Chinese pinyin-to-character mapping Date: Wed, 30 Jan 2019 12:33:56 -0800 Message-ID: <87munhnavf.fsf@ericabrahamsen.net> References: <87imyafyts.fsf@ericabrahamsen.net> <83r2cy3y69.fsf@gnu.org> <87a7jmf06v.fsf@ericabrahamsen.net> <83ef8y3r40.fsf@gnu.org> <875zu9gb96.fsf@ericabrahamsen.net> <83a7jl51c5.fsf@gnu.org> <87va27cq35.fsf@ericabrahamsen.net> <83ftta138k.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="34759"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: 34215@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 30 21:35:28 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gowZz-0008nV-DZ for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Jan 2019 21:35:27 +0100 Original-Received: from localhost ([127.0.0.1]:43811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gowZs-0007Rj-TN for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Jan 2019 15:35:20 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gowZi-0007RW-Mu for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:35:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gowZe-0005SZ-3E for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:35:08 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gowZb-0005RZ-RO for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:35:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gowZa-0005bd-6R for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:35:03 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87imyafyts.fsf@ericabrahamsen.net> Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Jan 2019 20:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34215 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.154888045821483 (code B ref -1); Wed, 30 Jan 2019 20:35:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Jan 2019 20:34:18 +0000 Original-Received: from localhost ([127.0.0.1]:51965 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gowYs-0005aQ-4X for submit@debbugs.gnu.org; Wed, 30 Jan 2019 15:34:18 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60535) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gowYp-0005aD-Qo for submit@debbugs.gnu.org; Wed, 30 Jan 2019 15:34:16 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:37446) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gowYk-00057M-MC for submit@debbugs.gnu.org; Wed, 30 Jan 2019 15:34:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gowYj-0007JM-Dg for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:34:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gowYi-00056f-8a for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:34:09 -0500 Original-Received: from [195.159.176.226] (port=45186 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gowYi-00055w-0G for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 15:34:08 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1gowYf-0007MD-AN for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2019 21:34:05 +0100 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:vOZZjYtbwLz+W8tP9NHCagQny/Y= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:154905 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Eric Abrahamsen >> Date: Tue, 29 Jan 2019 09:48:30 -0800 >> >> I've attached a diff adding the conversion function itself, but I'm not >> familiar with makefiles and so far haven't been able to figure out how >> to call it. It looks like the invocation I want will look like: >> >> $(AM_V_GEN)${RUN_EMACS} -l titdic-cnv -f pinyin-convert \ >> ${srcdir}/MISC-DIC/pinyin.map ${srcdir}/../lisp/language/pinyin.el >> >> Where ${srcdir} is the leim directory, but I don't actually know how to >> get this code called by make... > > Add a target that is the file produced by this command, then make the > above command the recipe of that target. Similar to the > ${leimdir}/ja-dic/ja-dic.el target. > > But if the above doesn't help, someone else could do this part for > you. I've attached this as a commit patch -- it seems to work fine but I would appreciate it if you'd check it. >> > I understand, but I wonder if someone could try that for a while and >> > see if it makes better input method(s), before we decide to import it. >> >> FWIW, that mapping is used by the pyim package, which I believe is the >> most popular pinyin-based Chinese input method out there. I also use it >> via the system-wide input framework fcitx, and it works very well. > > Then I guess we will be fine importing the new version. Cool -- I'll file another report for this in a bit. >> +(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'." > > This writes out a .el file, but does it encode that file in UTF-8, > even if the locale's codeset is something other than UTF-8? If not, > you need to bind coding-system-for-write to UTF-8. > >> + (insert ";; This file is automatically generated from pinyin.map,\ >> + by the function pinyin-convert.") > > This line is too long, suggest to break it in two. > >> + (insert ")\n\"An alist holding correspondences between pinyin syllables\ >> + and Chinese characters.\")\n") > > Likewise here. Okay, I've fixed all of the above. Thanks for the pointers. Eric --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-pinyin-to-Chinese-character-mapping-available-t.patch >From 0aaa67f9717ae10b1dfd1c7f078400989123acb8 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Wed, 30 Jan 2019 12:31:49 -0800 Subject: [PATCH] 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'. --- leim/Makefile.in | 7 ++++++- lisp/international/titdic-cnv.el | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/leim/Makefile.in b/leim/Makefile.in index c2fc8c41f2..cd693d6d0d 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 \ + ${leimdir}/../lisp/language/pinyin.el ## All the generated .el files. TIT_MISC = ${TIT_GB} ${TIT_BIG5} ${MISC} @@ -142,6 +143,10 @@ ${leimdir}/ja-dic/ja-dic.el: $(AM_V_GEN)$(RUN_EMACS) -batch -l ja-dic-cnv \ -f batch-skkdic-convert -dir "$(leimdir)/ja-dic" "$<" +${leimdir}/../lisp/language/pinyin.el: ${srcdir}/MISC-DIC/pinyin.map + $(AM_V_GEN)${RUN_EMACS} -l titdic-cnv -f pinyin-convert \ + ${srcdir}/MISC-DIC/pinyin.map ${srcdir}/../lisp/language/pinyin.el + .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. -- 2.20.1 --=-=-=--