[Top][All Lists]

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

Re: Using quail input methods to translate buffer text.

From: Peter Heslin
Subject: Re: Using quail input methods to translate buffer text.
Date: Fri, 07 Jul 2006 13:25:45 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Kenichi Handa <address@hidden> 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")
    (with-output-to-temp-buffer "*conversion output*"
      (princ (my-quail-conv-string
              (replace-regexp-in-string "$" " "
                                        (buffer-substring-no-properties beg 

(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))
        (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 Heslin (http://www.dur.ac.uk/p.j.heslin)

reply via email to

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