From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Peter Heslin Newsgroups: gmane.emacs.devel Subject: Re: Using quail input methods to translate buffer text. Date: Fri, 07 Jul 2006 13:25:45 +0100 Message-ID: <87y7v5fvp2.fsf@dur.ac.uk> References: <87k66rlqys.fsf@heslin.eclipse.co.uk> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1152274539 2099 80.91.229.2 (7 Jul 2006 12:15:39 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 7 Jul 2006 12:15:39 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 07 14:15:35 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FypF2-0007hT-6X for ged-emacs-devel@m.gmane.org; Fri, 07 Jul 2006 14:15:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FypF1-0001HP-JA for ged-emacs-devel@m.gmane.org; Fri, 07 Jul 2006 08:15:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FypEp-0001Gi-Ao for emacs-devel@gnu.org; Fri, 07 Jul 2006 08:15:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FypEl-0001GH-Cz for emacs-devel@gnu.org; Fri, 07 Jul 2006 08:15:13 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FypEl-0001GE-AR for emacs-devel@gnu.org; Fri, 07 Jul 2006 08:15:11 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FypFA-0000uc-KM for emacs-devel@gnu.org; Fri, 07 Jul 2006 08:15:36 -0400 Original-Received: from root by ciao.gmane.org with local (Exim 4.43) id 1FypEc-0007dN-J0 for emacs-devel@gnu.org; Fri, 07 Jul 2006 14:15:02 +0200 Original-Received: from class03.dur.ac.uk ([129.234.72.3]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Jul 2006 14:15:02 +0200 Original-Received: from p.j.heslin by class03.dur.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Jul 2006 14:15:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 50 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: class03.dur.ac.uk User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:/NO6auYHKrh+RIcEJ+lW5CLhpic= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:56716 Archived-At: Kenichi Handa writes: > We don't have such a function, but this will work in many > cases. Thank you very much! This function will be extremely useful on a daily basis (and I would guess also to others converting text from legacy encodings to Unicode). I append below a version of your function which suits my working habits. The only problem I have noticed so far is this: if it encounters an end-of-line at a point where it is still looking for possible keystrokes to modify the current character, then the function stops there and does not process the rest of the string. I have worked around this for my purposes by appending a space to every line before conversion, but I hope there is a cleaner solution. (defun my-quail-conv (beg end) (interactive "r") (save-excursion (with-output-to-temp-buffer "*conversion output*" (princ (my-quail-conv-string current-input-method (replace-regexp-in-string "$" " " (buffer-substring-no-properties beg end))))))) (defun my-quail-conv-string (input-method key-string) (let ((str "") (old-input-method current-input-method)) (activate-input-method input-method) (setq unread-command-events (string-to-list key-string)) (while unread-command-events (let ((key (car unread-command-events)) events) (setq unread-command-events (cdr unread-command-events)) (setq events (funcall input-method-function key)) (dolist (elt events) (if (integerp elt) (setq str (concat str (string elt))))))) (activate-input-method old-input-method) (decode-coding-string (encode-coding-string str 'utf-8) 'utf-8))) Thanks again, Peter -- Peter Heslin (http://www.dur.ac.uk/p.j.heslin)