From: Kenichi Handa <handa@m17n.org>
Cc: miles@gnu.org, emacs-devel@gnu.org
Subject: Re: reverting CJK input methods
Date: Sat, 8 May 2004 11:56:11 +0900 (JST) [thread overview]
Message-ID: <200405080256.LAA27566@etlken.m17n.org> (raw)
In-Reply-To: <20040430.185042.217838345.wl@gnu.org> (message from Werner LEMBERG on Fri, 30 Apr 2004 18:50:42 +0200 (CEST))
[-- Attachment #1: Type: text/plain, Size: 5201 bytes --]
In article <20040430.185042.217838345.wl@gnu.org>, Werner LEMBERG <wl@gnu.org> writes:
>> Oops, please try the attached new one.
> It works, thanks! But I think it is too slow. On my laptop, testing
> chinese-4corner, it takes up to two seconds until the result is
> displayed. Maybe input methods with more than, say, six to seven
> thousand elements should use the inverse map.
I still insist on generating a key strings to type on demand
instead of generating a decode-map at loading an input
method because the generation anyway takes some time.
So, I decided to generate a halfly cooked decode-map on
demand, which results in, I hope, reasonable speed for M-x
quail-show-key both at the first attempt and the succeeding
attemts.
Please try the attached new one after byte-compiling it.
> Is it possible to get *all* possible input sequences? For example, 说
> (shuo1) can also be input as `yue4' in chinese-tonepy, and this is
> what your code currently returns.
Yes, the new code shows all key strings.
---
Ken'ichi HANDA
handa@m17n.org
(require 'quail)
;; Add KEY (string) to the element of TABLE (char-table) for CHAR if
;; it is not yet stored.
(defsubst quail-store-decode-map-key (table char key)
(let ((elt (aref table char)))
(if elt
(if (consp elt)
(or (member key elt)
(aset table char (cons key elt)))
(or (string= key elt)
(aset table char (list key elt))))
(aset table char key))))
;; Helper function for quail-gen-decode-map. Store key strings to
;; type each character under MAP in TABLE (char-table). MAP is an
;; element of the current Quail map reached by typing keys in KEY
;; (string).
(defun quail-gen-decode-map1 (map key table)
(when (and (consp map) (listp (cdr map)))
(let ((trans (car map)))
(cond ((integerp trans)
(quail-store-decode-map-key table trans key))
((stringp trans)
(dotimes (i (length trans))
(quail-store-decode-map-key table (aref trans i) key)))
((or (vectorp trans)
(and (consp trans)
(setq trans (cdr trans))))
(dotimes (i (length trans))
(let ((elt (aref trans i)))
(if (stringp elt)
(if (= (length elt) 1)
(quail-store-decode-map-key table (aref elt 0) key))
(quail-store-decode-map-key table elt key)))))))
(if (> (length key) 1)
(dolist (elt (cdr map))
(quail-gen-decode-map1 (cdr elt) key table))
(dolist (elt (cdr map))
(quail-gen-decode-map1 (cdr elt) (format "%s%c" key (car elt))
table)))))
(put 'quail-decode-map 'char-table-extra-slots 0)
;; Generate a decode map (char-table) for the current Quail map.
(defun quail-gen-decode-map ()
(let ((table (make-char-table 'quail-decode-map nil)))
(dolist (elt (cdr (quail-map)))
(quail-gen-decode-map1 (cdr elt) (string (car elt)) table))
table))
;; Helper function for quail-find-key. Prepend key strings to type
;; for inputting CHAR by the current input method to KEY-LIST and
;; return the result. MAP is an element of the current Quail map
;; reached by typing keys in KEY.
(defun quail-find-key1 (map key char key-list)
(let ((trans (car map))
(found-here nil))
(cond ((stringp trans)
(setq found-here
(and (= (length trans) 1) (= (aref trans 0) char))))
((or (vectorp trans) (consp trans))
(if (consp trans)
(setq trans (cdr trans)))
(setq found-here
(catch 'tag
(dotimes (i (length trans))
(let ((target (aref trans i)))
(if (integerp target)
(if (= target char)
(throw 'tag t))
(if (and (= (length target) 1)
(= (aref target 0) char))
(throw 'tag t))))))))
((integerp trans)
(if (= trans char)
(setq found-here t))))
(if found-here
(setq key-list (cons key key-list)))
(if (> (length key) 1)
(dolist (elt (cdr map))
(setq key-list
(quail-find-key1 (cdr elt) (format "%s%c" key (car elt))
char key-list))))
key-list))
(defun quail-find-key (char)
"Return a list of key strings to type for inputting CHAR."
(let ((decode-map (or (quail-decode-map)
(setcar (nthcdr 10 quail-current-package)
(quail-gen-decode-map))))
(key-list nil))
(if (consp decode-map)
(let ((str (string char)))
(mapc #'(lambda (elt)
(if (string= str (car elt))
(setq key-list (cons (cdr elt) key-list))))
(cdr decode-map)))
(let ((key-head (aref decode-map char)))
(if (stringp key-head)
(setq key-list (quail-find-key1
(quail-lookup-key key-head nil t)
key-head char nil))
(mapc #'(lambda (elt)
(setq key-list
(quail-find-key1
(quail-lookup-key elt nil t) elt char key-list)))
key-head))))
key-list))
(defun quail-show-key ()
"Show a list of key strings to type for inputting a character at point."
(interactive)
(let* ((char (following-char))
(key-list (quail-find-key char)))
(if key-list
(message "To input `%c', type \"%s\""
char
(mapconcat 'identity key-list "\", \""))
(message "%c can't be input by the current input method" char))))
[-- Attachment #2: Type: text/plain, Size: 141 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel
next prev parent reply other threads:[~2004-05-08 2:56 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-29 13:03 reverting CJK input methods Werner LEMBERG
2004-04-30 1:42 ` Kenichi Handa
2004-04-30 2:03 ` Miles Bader
2004-04-30 2:59 ` Miles Bader
2004-04-30 11:27 ` Juri Linkov
2004-04-30 13:26 ` Kenichi Handa
2004-05-01 8:22 ` Juri Linkov
2004-05-02 1:57 ` Kenichi Handa
2004-05-06 5:05 ` with-output-to-temp-buffer [Re: reverting CJK input methods] Kenichi Handa
2004-05-06 11:48 ` Richard Stallman
2004-05-06 13:10 ` Kenichi Handa
2004-05-06 14:27 ` Stefan Monnier
2004-05-06 15:49 ` Kevin Rodgers
2004-05-06 16:50 ` Stefan Monnier
2004-05-06 20:57 ` Kevin Rodgers
2004-05-07 1:53 ` Kenichi Handa
2004-05-08 1:20 ` Richard Stallman
2004-05-10 12:13 ` Kenichi Handa
2004-05-10 14:28 ` Stefan Monnier
2004-05-11 7:04 ` Richard Stallman
2004-05-11 7:49 ` David Kastrup
2004-05-12 7:51 ` Richard Stallman
2004-05-11 13:39 ` erase-buffer (was: with-output-to-temp-buffer) Stefan Monnier
2004-05-11 14:44 ` erase-buffer Juri Linkov
2004-05-11 16:17 ` erase-buffer Juri Linkov
2004-05-11 15:32 ` erase-buffer (was: with-output-to-temp-buffer) David Kastrup
2004-05-11 16:22 ` Kevin Rodgers
2004-05-11 19:30 ` Stefan Monnier
2004-05-12 21:10 ` Kevin Rodgers
2004-05-11 19:37 ` Juanma Barranquero
2004-05-11 18:14 ` Juanma Barranquero
2004-05-11 23:06 ` Kenichi Handa
2004-05-11 23:26 ` Miles Bader
2004-05-12 19:42 ` Richard Stallman
2004-05-12 22:34 ` Miles Bader
2004-05-14 9:21 ` Richard Stallman
2004-05-11 23:34 ` Stefan Monnier
2004-05-11 23:47 ` Kenichi Handa
2004-05-12 19:40 ` Richard Stallman
2004-05-11 1:45 ` with-output-to-temp-buffer [Re: reverting CJK input methods] Luc Teirlinck
2004-05-11 2:34 ` Kenichi Handa
2004-05-11 7:01 ` David Kastrup
2004-05-11 6:55 ` Kim F. Storm
2004-05-11 8:00 ` Kenichi Handa
2004-05-12 7:51 ` Richard Stallman
2004-04-30 5:06 ` reverting CJK input methods Kenichi Handa
2004-04-30 16:50 ` Werner LEMBERG
2004-05-01 9:07 ` Miles Bader
2004-05-01 17:18 ` Werner LEMBERG
2004-05-08 2:56 ` Kenichi Handa [this message]
2004-05-08 16:38 ` Werner LEMBERG
2004-05-10 4:40 ` Kenichi Handa
2004-05-12 2:42 ` Kenichi Handa
2004-05-12 8:32 ` Werner LEMBERG
2004-05-12 11:10 ` Kenichi Handa
2004-05-01 17:21 ` Werner LEMBERG
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=200405080256.LAA27566@etlken.m17n.org \
--to=handa@m17n.org \
--cc=emacs-devel@gnu.org \
--cc=miles@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).