From: Rustom Mody <rustompmody@gmail.com>
To: Jambunathan K <kjambunathan@gmail.com>, help-gnu-emacs@gnu.org
Subject: Re: scripting input methods (was back (batch) translate chars to keyboard events)
Date: Mon, 13 Feb 2012 16:36:13 +0530 [thread overview]
Message-ID: <CAJ+Teoex4fy3nD2NsEfPW32TopMfF77R1ncihCG+Y1LqaPZY0g@mail.gmail.com> (raw)
In-Reply-To: <81y5s7w3ix.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]
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))))
[-- Attachment #2: Type: text/html, Size: 1866 bytes --]
next prev parent reply other threads:[~2012-02-13 11:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-13 7:20 scripting input methods (was back (batch) translate chars to keyboard events) Rustom Mody
2012-02-13 7:41 ` Rustom Mody
2012-02-13 8:17 ` Jambunathan K
2012-02-13 11:06 ` Rustom Mody [this message]
2012-02-13 15:47 ` Nick Dokos
2012-02-13 15:28 ` Nick Dokos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJ+Teoex4fy3nD2NsEfPW32TopMfF77R1ncihCG+Y1LqaPZY0g@mail.gmail.com \
--to=rustompmody@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=kjambunathan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).