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: scripting input methods (was back (batch) translate chars to keyboard events) Date: Mon, 13 Feb 2012 12:50:28 +0530 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=14dae934052b23b80f04b8d35041 X-Trace: dough.gmane.org 1329117645 4225 80.91.229.3 (13 Feb 2012 07:20:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 13 Feb 2012 07:20:45 +0000 (UTC) To: nicholas.dokos@hp.com, help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 13 08:20:44 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 1RwqDK-0001PS-MX for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2012 08:20:43 +0100 Original-Received: from localhost ([::1]:47586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwqDI-0002PB-Kq for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Feb 2012 02:20:40 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:48083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwqDA-0002Ov-0v for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 02:20:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RwqD8-0002hH-7r for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 02:20:31 -0500 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:61606) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwqD7-0002h9-W7 for help-gnu-emacs@gnu.org; Mon, 13 Feb 2012 02:20:30 -0500 Original-Received: by iagz16 with SMTP id z16so4581756iag.0 for ; Sun, 12 Feb 2012 23:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=rsIrn40iBYa13CZPJ73r+27sr+mSOlNXPdXfQHEd3vI=; b=mVyqliQNoS/aSyUrQ9BhnvNnFV4u6PyDIzbaMEnSIXlNw6uhY2PjUXgRUIUMzSTM8k n6XwpK4eWs7Bq2v3ak48ZJ8TZ5He9lSqxhaZUWeEbkG43hShgcWcbSM9N4r9kn+fQhV0 4P52DLrvkdeD6FspjgdRHR/tSLcAUiVWEa91Q= Original-Received: by 10.50.217.129 with SMTP id oy1mr28533641igc.4.1329117628970; Sun, 12 Feb 2012 23:20:28 -0800 (PST) Original-Received: by 10.231.200.2 with HTTP; Sun, 12 Feb 2012 23:20:28 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.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:83724 Archived-At: --14dae934052b23b80f04b8d35041 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > > Rustom Mody wrote: > I have some bunch of sanskrit (devanagari) to type. It would be easiest > for me if I could have the > English (roman) as well as the sanskrit (devanagari). > > For example using the devanagari-itrans input method I can write the > gayatri mantra using > > OM bhUrbhuvaH suvaH > tatsaviturvarenyam > bhargo devasya dhImahi > dhiyo yonaH prachodayAt > > and emacs produces *on the fly* (ie I cant see/edit the above) > > =E0=A5=90 =E0=A4=AD=E0=A5=82=E0=A4=B0=E0=A5=8D=E0=A4=AD=E0=A5=81=E0=A4= =B5=E0=A4=83 =E0=A4=B8=E0=A5=81=E0=A4=B5=E0=A4=83 > =E0=A4=A4=E0=A4=A4=E0=A5=8D=E0=A4=B8=E0=A4=B5=E0=A4=BF=E0=A4=A4=E0=A5= =81=E0=A4=B0=E0=A5=8D=E0=A4=B5=E0=A4=B0=E0=A5=87=E0=A4=A3=E0=A5=8D=E0=A4=AF= =E0=A4=AE=E0=A5=8D > =E0=A4=AD=E0=A4=B0=E0=A5=8D=E0=A4=97=E0=A5=8B =E0=A4=A6=E0=A5=87=E0=A4= =B5=E0=A4=B8=E0=A5=8D=E0=A4=AF =E0=A4=A7=E0=A5=80=E0=A4=AE=E0=A4=B9=E0=A4= =BF > =E0=A4=A7=E0=A4=BF=E0=A4=AF=E0=A5=8B =E0=A4=AF=E0=A5=8B=E0=A4=A8=E0=A4= =83 =E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF=E0=A4= =BE=E0=A4=A4=E0=A5=8D > > Can I do it in batch mode? ie write the first in a file and run some > command on it to produce the second? > > > On Mon, Feb 13, 2012 at 9:45 AM, Nick Dokos wrote: > > > Yup, it can be done, probably in multiple ways but here is one. > > I saw your question on the python list and did a bit of digging: I came > up with a method that probably will work but will require more work to > flesh out. The key was that input methods read events one at a time and > (from the Elisp manual): > > -- Function: read-event &optional prompt inherit-input-method seconds > This function reads and returns the next event of command input, > waiting if necessary until an event is available. Events can come > directly from the user or from a keyboard macro. > > So if you could get the text to become the body of a keyboard macro, > you could change the input method, execute the macro and that would > submit the text to the input method as if you had typed it. > > Trying the theory, I started a keyboard macro, typed in OM and a newline > and ended the keyboard macro. I can then switch the input method to > devanagari-itrans, execute the macro and presto! I get the proper symbol > (at least to my untrained eyes). > > You can insert the definition of a macro in a buffer (and name it, edit i= t, > save it to a file and load the file later, and execute the macro by name = as > if it were a function (which it is, strictly speaking). The OM macro abov= e > turns out to look like this : > > (fset 'om > (lambda (&optional arg) "Keyboard macro." (interactive "p") > (kmacro-exec-ring-item (quote ([79 77 return] 0 "%d")) arg))) > > > I would change the python (or whatever) program to produce the whole > fset form into a file, then start emacs, load the file, switch input > method and execute the macro: M-x om. > > Nick > Thanks for your efforts Nick! Some questions: 1. Why fset? I can get the following to work (defun om (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item '([79 77 return] 0 "%d") arg)) so assuming its just a stylistic question. [If not please enlighten] By 'work' I mean after this definition, M-x om inserts =E0=A5=90 into the b= uffer if devanagari-itrans is active. So far so good After that I am a bit stuck: 2. kmacro-exec-ring-item has just this much documentation. kmacro-exec-ring-item is a compiled Lisp function in `kmacro.el'. (kmacro-exec-ring-item ITEM ARG) Execute item ITEM from the macro ring. Does not take me far :-( 3. I guess this is really the same as the above question... You say > > So all you need to do is produce that vector of ascii values in there. I > wrote a trivial python program to produce the ascii codes of your text > and stuffed the output into the vector, reevaluated the fset, and > executed the macro with a result that looks suspiciously like the one in > your email. > > The python (or elisp) to a text (ASCII-only) string to its ASCII is 1 line: >>> def Ascii(str): return [ord(c) for c in str] I ran this on my file and got: [79, 77, 32, 98, 104, 85, 114, 98, 104, 117, 118, 97, 72, 32, 115, 117, 118, 97, 72, 10, 116, 97, 116, 115, 97, 118, 105, 116, 117, 114, 118, 97, 114, 101, 110, 121, 97, 109, 10, 98, 104, 97, 114, 103, 111, 32, 100, 101, 118, 97, 115, 121, 97, 32, 100, 104, 73, 109, 97, 104, 105, 10, 100, 104, 105, 121, 111, 32, 121, 111, 110, 97, 72, 32, 112, 114, 97, 99, 104, 111, 100, 97, 121, 65, 116, 10] Ok so remove the commas, ADD A 'return' after to last 10 (Whats that??) And it almost works ie I get the devanagari output followed by a elisp error: Debugger entered--Lisp error: (void-variable =E0=A4=AA=E0=A5=8D=E0=A4=B0=E0= =A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF=E0=A4=BE=E0=A4=A4=E0=A5=8D) eval(=E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF=E0= =A4=BE=E0=A4=A4=E0=A5=8D) eval-last-sexp-1(t) eval-last-sexp(t) eval-print-last-sexp() call-interactively(eval-print-last-sexp nil nil) execute-kbd-macro([79 77 32 98 104 85 114 98 104 117 118 97 72 32 115 117 118 97 72 116 97 116 115 97 118 105 116 117 114 118 97 114 101 110 121 97 109 98 104 97 114 103 111 32 100 101 118 97 115 121 ...] 1 kmacro-loop-setup-function) kmacro-exec-ring-item(([79 77 32 98 104 85 114 98 104 117 118 97 72 32 115 117 118 97 72 116 97 116 115 97 118 105 116 117 114 118 97 114 101 110 121 97 109 98 104 97 114 103 111 32 100 101 118 97 115 121 ...] 0 "%d") 1) om(1) call-interactively(om t nil) execute-extended-command(nil) call-interactively(execute-extended-command nil nil) The =E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF=E0=A4= =BE=E0=A4=A4=E0=A5=8D is the devanagari of the last line: prachodayAt If I remove the 10 (newline?) it seems to work without the elisp error I guess the problem would be solved if some more suitable function than I wonder if there is some better function than kmacro-exec-ring-item could be found for this? --14dae934052b23b80f04b8d35041 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
<= div class=3D"h5">Rustom Mody <r= ustompmody@gmail.com> wrote:
I have some bunch of sanskrit (devanagari) to type. =C2=A0It would be easie= st for me if I could have the
English (roman) as well as the sanskrit (devanagari).

For example using the devanagari-itrans input method I can write the gayatr= i mantra using

OM bhUrbhuvaH suvaH
tatsaviturvarenyam
bhargo devasya dhImahi
dhiyo yonaH prachodayAt

and emacs produces *on the fly* (ie I cant see/edit the above)

=C2=A0 =E0=A5=90 =E0=A4=AD=E0=A5=82=E0=A4=B0=E0=A5=8D=E0=A4=AD=E0=A5=81=E0=A4=B5= =E0=A4=83 =E0=A4=B8=E0=A5=81=E0=A4=B5=E0=A4=83
=C2=A0 =E0=A4=A4=E0=A4=A4=E0=A5=8D=E0=A4=B8=E0=A4=B5=E0=A4=BF=E0=A4=A4=E0=A5=81=E0= =A4=B0=E0=A5=8D=E0=A4=B5=E0=A4=B0=E0=A5=87=E0=A4=A3=E0=A5=8D=E0=A4=AF=E0=A4= =AE=E0=A5=8D
=C2=A0 =E0=A4=AD=E0=A4=B0=E0=A5=8D=E0=A4=97=E0=A5=8B =E0=A4=A6=E0=A5=87=E0=A4=B5= =E0=A4=B8=E0=A5=8D=E0=A4=AF =E0=A4=A7=E0=A5=80=E0=A4=AE=E0=A4=B9=E0=A4=BF=C2=A0 =E0=A4=A7=E0=A4=BF=E0=A4=AF=E0=A5=8B =E0=A4=AF=E0=A5=8B=E0=A4=A8=E0=A4=83 = =E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF=E0=A4=BE=E0= =A4=A4=E0=A5=8D

Can I do it in batch mode? ie write the first in a file and run some co= mmand on it to produce the second?






On Mon, Feb 13, 2012 at 9= :45 AM, Nick Dokos <nicholas.dokos@hp.com> wrote:


Yup, it can be done, probably in multiple ways but here is one.=

I saw your question on the python list and did a bit of digging: I came
up with a method that probably will work but will require more work to
flesh out. The key was that input methods read events one at a time and
(from the Elisp manual):

=C2=A0-- Function: read-event &optional prompt inherit-input-method sec= onds
=C2=A0 =C2=A0 This function reads and returns the next event of command in= put,
=C2=A0 =C2=A0 waiting if necessary until an event is available. =C2=A0Even= ts can come
=C2=A0 =C2=A0 directly from the user or from a keyboard macro.

So if you could get the text to become the body of a keyboard macro,
you could change the input method, execute the macro and that would
submit the text to the input method as if you had typed it.

Trying the theory, I started a keyboard macro, typed in OM and a newline and ended the keyboard macro. I can then switch the input method to
devanagari-itrans, execute the macro and presto! I get the proper symbol (at least to my untrained eyes).

You can insert the definition of a macro in a buffer (and name it, edit it,=
save it to a file and load the file later, and execute the macro by name as=
if it were a function (which it is, strictly speaking). The OM macro above<= br> turns out to look like this :

(fset 'om
=C2=A0 (lambda (&optional arg) "Keyboard macro." (interactiv= e "p") (kmacro-exec-ring-item (quote ([79 77 return] 0 "%d&q= uot;)) arg)))


=C2=A0
I would change the python (or whatever) program to produce the whole
fset form into a file, then start emacs, load the file, switch input
method and execute the macro: M-x om.

Nick


Thanks for your efforts Nick!
S= ome questions:
1. Why fset?=C2=A0

I can get the following to wor= k

(defun om (&optional arg)
=C2=A0 "Keyboard macro.&quo= t;
=C2=A0 (interactive "p")
=C2=A0 (kmacro-exec-ring-item '([= 79 77 return] 0 "%d") arg))

so assuming its just a stylist= ic question. [If not please enlighten]
By 'work' I mean after th= is definition, M-x om inserts =E0=A5=90 into the buffer if devanagari-itran= s is active. So far so good

After that I am a bit stuck:
2. kmacro-exec-ring-item has just this = much documentation.

kmacro-exec-ring-item is a compiled Lisp functi= on in `kmacro.el'.

(kmacro-exec-ring-item ITEM ARG)

Execu= te item ITEM from the macro ring.

Does not take me far :-(

3.=C2=A0 I guess this is re= ally the same as the above question...
You say
=C2=A0
So all you need to do is produce that vector of ascii values in there. I wrote a trivial python program to produce the ascii codes of your text
and stuffed the output into the vector, reevaluated the fset, and
executed the macro with a result that looks suspiciously like the one in your email.


The python (or elisp) to a text (ASCII-only) string to its ASCII is 1 line:=

>>> def Ascii(str): return [ord(c) for c in str]

I = ran this on my file and got:
[79, 77, 32, 98, 104, 85, 114, 98, 104, 117= , 118, 97, 72, 32, 115, 117, 118, 97, 72, 10, 116, 97, 116, 115, 97, 118, 1= 05, 116, 117, 114, 118, 97, 114, 101, 110, 121, 97, 109, 10, 98, 104, 97, 1= 14, 103, 111, 32, 100, 101, 118, 97, 115, 121, 97, 32, 100, 104, 73, 109, 9= 7, 104, 105, 10, 100, 104, 105, 121, 111, 32, 121, 111, 110, 97, 72, 32, 11= 2, 114, 97, 99, 104, 111, 100, 97, 121, 65, 116, 10]

Ok so remove the commas, ADD A 'return'=C2=A0 after to last 10 = (Whats that??)
And it almost works
ie I get the devanagari output fol= lowed by a elisp error:

Debugger entered--Lisp error: (void-variable= =E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF=E0=A4=BE= =E0=A4=A4=E0=A5=8D)
=C2=A0 eval(=E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0=A4=AF= =E0=A4=BE=E0=A4=A4=E0=A5=8D)
=C2=A0 eval-last-sexp-1(t)
=C2=A0 eval-l= ast-sexp(t)
=C2=A0 eval-print-last-sexp()
=C2=A0 call-interactively(e= val-print-last-sexp nil nil)
=C2=A0 execute-kbd-macro([79 77 32 98 104 8= 5 114 98 104 117 118 97 72 32 115 117 118 97 72 116 97 116 115 97 118 105 1= 16 117 114 118 97 114 101 110 121 97 109 98 104 97 114 103 111 32 100 101 1= 18 97 115 121 ...] 1 kmacro-loop-setup-function)
=C2=A0 kmacro-exec-ring-item(([79 77 32 98 104 85 114 98 104 117 118 97 72 = 32 115 117 118 97 72 116 97 116 115 97 118 105 116 117 114 118 97 114 101 1= 10 121 97 109 98 104 97 114 103 111 32 100 101 118 97 115 121 ...] 0 "= %d") 1)
=C2=A0 om(1)
=C2=A0 call-interactively(om t nil)
=C2=A0 execute-exten= ded-command(nil)
=C2=A0 call-interactively(execute-extended-command nil = nil)

The =E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=9A=E0=A5=8B=E0=A4=A6=E0= =A4=AF=E0=A4=BE=E0=A4=A4=E0=A5=8D is the devanagari of the last line: prach= odayAt
If I remove the 10 (newline?) it seems to work without the elisp = error

I guess the problem would be solved if some more suitable function than=
I wonder if there is some better function than kmacro-exec-ring-item co= uld be found for this?
--14dae934052b23b80f04b8d35041--