all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Welsh Duggan <mwd@md5i.com>
To: emacs-devel@gnu.org
Subject: Re: [conversion fails]
Date: Tue, 13 Feb 2018 19:21:35 -0500	[thread overview]
Message-ID: <87d118o1yo.fsf@md5i.com> (raw)
In-Reply-To: <878tbwbm9r.fsf@mat.ucm.es> (Uwe Brauer's message of "Tue, 13 Feb 2018 22:41:20 +0100")

Uwe Brauer <oub@mat.ucm.es> writes:

>    > Uwe Brauer <oub@mat.ucm.es> 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)



  reply	other threads:[~2018-02-14  0:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 21:58 quail input methods and conversion functions Uwe Brauer
2018-02-08  4:08 ` Michael Welsh Duggan
2018-02-08 15:16   ` Uwe Brauer
2018-02-09 18:26     ` Michael Welsh Duggan
2018-02-10 14:18       ` [conversion fails] (was: quail input methods and conversion functions) Uwe Brauer
2018-02-12  3:53         ` [conversion fails] Michael Welsh Duggan
2018-02-12 10:07           ` Uwe Brauer
2018-02-12 10:40           ` Uwe Brauer
2018-02-13  3:43             ` Michael Welsh Duggan
2018-02-13  8:43               ` Uwe Brauer
2018-02-13  8:51               ` Uwe Brauer
2018-02-13 20:58                 ` Michael Welsh Duggan
2018-02-13 21:41                   ` Uwe Brauer
2018-02-14  0:21                     ` Michael Welsh Duggan [this message]
2018-02-14  9:08                       ` Uwe Brauer
2018-02-19 21:26                       ` [MELPA] (was: [conversion fails]) Uwe Brauer
2018-02-20  2:12                         ` [MELPA] Michael Welsh Duggan

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

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

  git send-email \
    --in-reply-to=87d118o1yo.fsf@md5i.com \
    --to=mwd@md5i.com \
    --cc=emacs-devel@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.