From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rustom Mody Newsgroups: gmane.emacs.help Subject: Re: scripting input methods (was back (batch) translate chars to keyboard events) Date: Mon, 13 Feb 2012 16:36:13 +0530 Message-ID: References: <81y5s7w3ix.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=14dae9340aed790f3c04b8d6778e X-Trace: dough.gmane.org 1329131191 1918 80.91.229.3 (13 Feb 2012 11:06:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 13 Feb 2012 11:06:31 +0000 (UTC) To: Jambunathan K , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 13 12:06:28 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rwtjl-0002TE-IX for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2012 12:06:26 +0100 Original-Received: from localhost ([::1]:35702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rwtjl-0006ij-2Z for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2012 06:06:25 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:55014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rwtjf-0006i5-Ad for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 06:06:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rwtja-0000Cs-N6 for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 06:06:19 -0500 Original-Received: from mail-tul01m020-f169.google.com ([209.85.214.169]:53458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rwtja-0000Ce-I9 for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 06:06:14 -0500 Original-Received: by obbta7 with SMTP id ta7so7914934obb.0 for ; Mon, 13 Feb 2012 03:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=8uycnoTL1Vt40/qh0pv6KLkkKbmreq3qnuxCJa+v7kY=; b=paP2J+4NgaCPL3BuDXGxrCMHBYBX5EUSvvVkVDn0fNZhIcReiX8Te7byDjs2+G/NYF QrswvUSyRXay0bXE4HILLX9hovMC7qNR13CmXU1C4aAVgo/KanvDSyOfz1RgzLBfPOcC 46gkw4qRfcF9tccXCYZ1s6JaQ2eQT8BF0gOx0= Original-Received: by 10.50.208.1 with SMTP id ma1mr29949519igc.4.1329131173777; Mon, 13 Feb 2012 03:06:13 -0800 (PST) Original-Received: by 10.231.200.2 with HTTP; Mon, 13 Feb 2012 03:06:13 -0800 (PST) In-Reply-To: <81y5s7w3ix.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83729 Archived-At: --14dae9340aed790f3c04b8d6778e Content-Type: text/plain; charset=ISO-8859-1 On Mon, Feb 13, 2012 at 1:47 PM, Jambunathan K 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)))) --14dae9340aed790f3c04b8d6778e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Mon, Feb 13, 2012 at 1:47 PM, Jambunathan K <= span dir=3D"ltr"><kjambunathan= @gmail.com> wrote:

Rustom

Try this:

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

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


One question about the cod= e 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 li= sp suggesting set-buffer instead.
I tried that -- does not work. My current code is this:

(defvar inpu= t-method "devanagari-itrans")
(defun translate-to-hindi (filen= ame)
=A0(interactive "fFile to be translated: ")
=A0(let ((= inp (with-temp-buffer
=A0=A0=A0 =A0=A0=A0 (insert-file-contents filename)
=A0=A0=A0 =A0=A0=A0 = (buffer-string)))
=A0=A0=A0=A0=A0=A0 (out-file-name (concat (file-name-s= ans-extension filename)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0= "-hi" (file-name-extension filename t))))
=A0=A0 (with-temp-b= uffer
=A0=A0=A0=A0 (switch-to-buffer (current-buffer))
=A0=A0=A0=A0 (setq buf= fer-file-coding-system 'utf-8)
=A0=A0=A0=A0 (set-input-method input-= method t)
=A0=A0=A0=A0 (execute-kbd-macro inp)
=A0=A0=A0=A0 (write-fi= le out-file-name))))


--14dae9340aed790f3c04b8d6778e--