help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: scripting input methods (was back (batch) translate chars to keyboar


From: Rustom Mody
Subject: Re: scripting input methods (was back (batch) translate chars to keyboard events)
Date: Mon, 13 Feb 2012 16:36:13 +0530

On Mon, Feb 13, 2012 at 1:47 PM, Jambunathan K <kjambunathan@gmail.com> wrote:

Rustom

Try this:

(defun translate-to-hindi (filename)
 (interactive "fFile to be translated: ")
 (with-temp-buffer
   (switch-to-buffer (current-buffer))
   (setq buffer-file-coding-system 'utf-8)
   (set-input-method "devanagari-itrans" t)
   (execute-kbd-macro
    (with-temp-buffer
      (insert-file-contents filename)
      (buffer-string)))

   (write-file
    (concat (file-name-sans-extension filename)
            "-hi" (file-name-extension filename t)))))


One question about the code above:
Why do you need the switch-to-buffer?
I tried removing it -- does not work
The doc for switch-to-buffer warns against using it in lisp suggesting set-buffer instead.
I tried that -- does not work. My current code is this:

(defvar input-method "devanagari-itrans")
(defun translate-to-hindi (filename)
 (interactive "fFile to be translated: ")
 (let ((inp (with-temp-buffer
        (insert-file-contents filename)
        (buffer-string)))
       (out-file-name (concat (file-name-sans-extension filename)
                   "-hi" (file-name-extension filename t))))
   (with-temp-buffer
     (switch-to-buffer (current-buffer))
     (setq buffer-file-coding-system 'utf-8)
     (set-input-method input-method t)
     (execute-kbd-macro inp)
     (write-file out-file-name))))



reply via email to

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