Rustom Mody <rustompmody@gmail.com> 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)
ॐ भूर्भुवः सुवः
तत्सवितुर्वरेण्यम्
भर्गो देवस्य धीमहि
धियो योनः प्रचोदयात्
Can I do it in batch mode? ie write the first in a file and run some command on it to produce the second?
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 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
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
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.