emacs-devel
[Top][All Lists]

## Re: [conversion fails]

 From: Michael Welsh Duggan Subject: Re: [conversion fails] Date: Tue, 13 Feb 2018 15:58:35 -0500 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

```Uwe Brauer <address@hidden> writes:

>    > Uwe Brauer <address@hidden> writes:
>
>    > [...]
>
>
>    > 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.
>
> I cried victory to earlier, there seems more corner cases.
>
> Take the following examples
>
> 1 )En a)rxh=| h)=n o( lo'gos, kai` o( lo'gos h)=n pro`s to`n qeo'n,
> kai` qeo`s h)=n o( lo'gos.
>
> Should be translated to
> 1 Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ θεὸς ἦν ὁ
> λόγος.

Yup.  This version seems to do the trick, though:

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

I'll work on the inverse function in a bit.

--
Michael Welsh Duggan
{"ft_lang_label":"__label__en","ft_lang_prob":0.5731603,"math_prob":0.8999091,"size":2836,"snap":"2019-26-2019-30","text_gpt3_token_len":976,"char_repetition_ratio":0.1917373,"word_repetition_ratio":0.18993135,"special_character_ratio":0.34943584,"punctuation_ratio":0.15384616,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9526878,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-22T14:59:38Z\",\"WARC-Record-ID\":\"<urn:uuid:b6361c16-fde2-49ad-b385-83a89888ae04>\",\"Content-Length\":\"9139\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e0907095-3dd8-4f84-8e3e-aea61b71cd2a>\",\"WARC-Concurrent-To\":\"<urn:uuid:6bf90a03-2689-4120-92c5-9627867d328e>\",\"WARC-IP-Address\":\"209.51.188.17\",\"WARC-Target-URI\":\"https://lists.gnu.org/archive/html/emacs-devel/2018-02/msg00377.html\",\"WARC-Payload-Digest\":\"sha1:3BBGY64LR5QOWYDNEGQI4NL4ZKZEVM57\",\"WARC-Block-Digest\":\"sha1:POPAOMLTZPP62X3HFMFJ2QSJZRNHIBBP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195528037.92_warc_CC-MAIN-20190722133851-20190722155851-00088.warc.gz\"}"}