[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [conversion fails]

From: Michael Welsh Duggan
Subject: Re: [conversion fails]
Date: Mon, 12 Feb 2018 22:43:08 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Uwe Brauer <address@hidden> writes:

>    > I hacked up the following, which is minimally tested, but may work for
>    > you.  I tried to use public functions from quail, but the (null (cdr
>    > map)) is probably an implementation detail, and might break in a future
>    > version.  There are almost certainly better ways to write this function.
>    > If presented with an ambiguity (like above), it will choose the last
>    > remembered variant (defaulting to 1).


> I tested it with latin-1-pre and it worked, but I tried also
> greek-ibycus4
> And it should translate
> a)  to ἀ
> But it does not. So I am puzzled.

Right.  A corner case I missed.  Specifically, if the region ends on a
key sequence that encodes a valid character, but could be a prefix of
another character.

(defun accentuate-region (start end)
  "Replace the region by using it as keys using the current input method"
  (interactive "r")
    (goto-char start)
    (let* ((data (delete-and-extract-region start end))
           (size (length data))
           (idx 0) (cand ""))
      (while (< idx size)
        (let* ((next-cand (concat cand (list (aref data idx))))
               (map (quail-lookup-key next-cand))
               (def (and map (quail-map-definition map))))
          (if (null map)
                (insert next-cand)
                (setq cand ""))
            (if (and def (null (cdr map)))
                  (insert (quail-get-current-str (length next-cand) def))
                  (setq cand "")) 
              (setq cand next-cand)))
          (incf idx)))
      (let* ((map (quail-lookup-key cand))
             (def (and map (quail-map-definition map))))
        (if def
            (insert (quail-get-current-str (length cand) def))
          (insert cand))))))

Michael Welsh Duggan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]