From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Welsh Duggan Newsgroups: gmane.emacs.devel Subject: Re: [conversion fails] Date: Tue, 13 Feb 2018 19:21:35 -0500 Message-ID: <87d118o1yo.fsf@md5i.com> References: <878tcbdpf3.fsf@mat.ucm.es> <876078p1gy.fsf@md5i.com> <87tvurldff.fsf@mat.ucm.es> <87wozmnhny.fsf@md5i.com> <8760750vz4.fsf_-_@mat.ucm.es> <87po5aoocr.fsf@md5i.com> <87sha6o5ij.fsf@mat.ucm.es> <87lgfxo8qb.fsf@md5i.com> <87h8qll1be.fsf@mat.ucm.es> <87h8qkobd0.fsf@md5i.com> <878tbwbm9r.fsf@mat.ucm.es> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1518567608 13077 195.159.176.226 (14 Feb 2018 00:20:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Feb 2018 00:20:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 14 01:20:04 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elknf-0002Jz-E3 for ged-emacs-devel@m.gmane.org; Wed, 14 Feb 2018 01:19:51 +0100 Original-Received: from localhost ([::1]:38507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elkpf-0005en-Jp for ged-emacs-devel@m.gmane.org; Tue, 13 Feb 2018 19:21:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elkpQ-0005db-6x for emacs-devel@gnu.org; Tue, 13 Feb 2018 19:21:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elkpN-0003Gd-01 for emacs-devel@gnu.org; Tue, 13 Feb 2018 19:21:40 -0500 Original-Received: from md5i.com ([75.151.244.229]:42230) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elkpM-0003Dg-Qx for emacs-devel@gnu.org; Tue, 13 Feb 2018 19:21:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=md5i.com; s=dkim; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References: Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=GkgvIUQ65NU+7PFtK8G2qcNCEalWld0lbN23XQgc5Cw=; b=cXEmb0qMwavnCnP3enLQNmW98P ou60ZLq+1AbBWqvvF7/GKpxvqU9SULPMLSneDvdIw5t09rGQMZEPLB/3H6F9+2xtzglov+bx1Eq98 eEarW038DbvQcM8vNZx9OCQpQ; Original-Received: from md5i by md5i.com with local (Exim 4.90) (envelope-from ) id 1elkpM-00077O-1e for emacs-devel@gnu.org; Tue, 13 Feb 2018 19:21:36 -0500 In-Reply-To: <878tbwbm9r.fsf@mat.ucm.es> (Uwe Brauer's message of "Tue, 13 Feb 2018 22:41:20 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 75.151.244.229 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222734 Archived-At: Uwe Brauer writes: > > Uwe Brauer writes: > > > Yup. This version seems to do the trick, though: > > WOW, that works like CHARM, > > > Thanks a lot a lot. I run more test, most of the test files I have and > everything seems flawless. That is simply great. I am really grateful. > I could never ever have come up with something like this. > > Honestly I think that should be part of quail. > > > > I'll work on the inverse function in a bit. > > That would also be great! Here you go. I've included both, because this accentuate-region is an improvement on the last one, especially if an error happens during mid-translation. (defun accentuate-region (start end) "Replace the region by using it as keys using the current input method" (interactive "r") (save-mark-and-excursion (when (< (mark) (point)) (exchange-point-and-mark)) (let ((tend (1+ (point))) def) (while (<= tend (mark)) (let* ((candx (buffer-substring (point) tend)) (mapx (quail-lookup-key candx)) (defx (and mapx (quail-map-definition mapx)))) (if (null mapx) (progn (if def (let* ((end (1- tend)) (len (- end (point)))) (delete-region (point) end) (insert (quail-get-current-str len def)) (setq tend (point))) (forward-char)) (setq def nil)) (if (and defx (null (cdr mapx))) (progn (delete-region (point) tend) (insert (quail-get-current-str (length candx) defx)) (setq def nil tend (point))) (setq def defx))) (incf tend))) (when def (let ((len (- (mark) (point)))) (delete-region (point) (mark)) (insert (quail-get-current-str (- (mark) (point)) def))))))) (defun unaccentuate-region (start end) "Perform the reverse operation of typing in the current input method. Replace the region with the keys used to type that text using the current input method" (interactive "r") (save-mark-and-excursion (when (< (mark) (point)) (exchange-point-and-mark)) (while (< (point) (mark)) (condition-case nil (let ((keys (quail-find-key (following-char)))) (if (consp keys) (progn (delete-char 1) (insert (car keys))) (forward-char))))))) Sadly, I can't add these to quail, since it is too difficult to get a copyright disclaimer from my place of work. (It can be done, but has to be done separately for every bit of code I contribute.) Also, Handa-san would almost certainly be able to write better versions than these that can exploit the non-public interfaces in quail. -- Michael Welsh Duggan (md5i@md5i.com)