emacs-devel
[Top][All Lists]
Advanced

[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 23:36:09 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Kenichi Handa <address@hidden> writes:

> Currently I think there's no clean solution.  Even appending
> a space doesn't work for some input methods.  

OK, so I tried a different approach.  I borrowed some lines of this code
from quail.el without fully understanding the data structures, so it may
be wrong, but it seems to work for my simple purposes.  Are there any
problems with this approach?


(defun my-quail-conv (beg end)
  (interactive "r")
  (save-excursion
    (let ((output))
      (goto-char beg)
      (while (< (point) end)
        (multiple-value-bind (trans map)
            (my-quail-conv-get-trans-and-map (quail-map) 0)
          (setf output (concat output
                               (or 
                                (if map
                                    (my-quail-conv-get-compound-char trans map)
                                  trans)
                                (char-to-string (char-after)))))
          (forward-char)))
      (with-output-to-temp-buffer "*conversion output*"
        (princ output)))))


(defun my-quail-conv-get-compound-char (trans map)
  (multiple-value-bind (next-trans next-map)
      (my-quail-conv-get-trans-and-map map 1)
    (cond
     (next-map
      (forward-char)
      (my-quail-conv-get-compound-char next-trans next-map))
     (next-trans
      (forward-char)
      next-trans)
     (t
      trans))))

(defun my-quail-conv-get-trans-and-map (alist offset)
  (let* ((ch (char-after (+ offset (point))))
         (map (cdr (assq ch alist)))
         (trans (and map (quail-get-translation
                          (car map) (char-to-string ch) 1))))
    (if (consp trans)
        (setq trans (aref (cdr trans) 0)))
    (setq trans
          (etypecase trans
            (string trans)
            (null trans)
            (integer (char-to-string trans))))
    (values trans (cdr map))))

-- 
Peter Heslin (http://www.dur.ac.uk/p.j.heslin)





reply via email to

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