pymacs! :-)

Paul Winkler slinkp23 at yahoo.com
Sat Sep 8 16:31:55 EDT 2001


On 08 Sep 2001 12:40:09 -0400, François Pinard <pinard at iro.umontreal.ca> wrote:
>[Paul Winkler]
>
>> You had written:
>
>> lisp.global_set_key([lisp.f7], lisp.manglers_break_on_whitespace)
>
>> So you want to put all the possible keys in the lisp namespace?  Seems
>> messy.
>
>My knowledge of English fails on me, here.  I do not understand your comment.
>Would you be kind enough to explain?
>Maybe you are worried with `[lisp.f7]' ?  There is nothing special with it.
>[item] is a Python list, which yields a LISP vector.  `lisp.f7' merely
>translates to the LISP symbol `f7'.  So, Python `[lisp.f7]' is LISP `[f7]'.

How does that happen? Will you have definitions in lisp.py for every
possible key or key combination? That seems very impractical and
messy.

I have not seen your code, so I don't know what would happen on the
lisp side as a result of calling lisp.global_set_key(), but if it's
simply that we create a string of lisp code and give it back to emacs
for evaluation, then the solution is very easy, and I've already
suggested it. Instead of the first argument being [lisp.f7], it would
be ['f7']. The string would simply be placed in the generated lisp
code in the appropriate place. This way, we would use the same
keybinding syntax in Python as we use in emacs. So to take a real
example from my .emacs file:

(global-set-key [M-f2] 'redo)

... might become something like, on the python side,

lisp.global_set_key(['M-f2'], lisp.redo)


>> And what about key combinations?  How would you say something like 'C-x w'?
>> I would suggest simply writing them as strings, and the programmer
>> will have to know the elisp way of naming them.  Example:
>
>> lisp.global_set_key(['C-x w'], lisp.manglers_break_on_whitespace)
>
>In LISP, this would be written:
>
>   (global-set-key "\C-xw" manglers-break-on-whitespace)
>
>Triggering this from Python requires that you write the string the
>Python way, and Python does not recognise the "\C-" escape.  Knowing
>that `C-x' is chr(0x18), one could write:
>
>   lisp.global_set_key('\x18w', lisp.manglers_break_on_whitespace)

IMHO this is a heavy burden to place on the person trying to write
python functions. I'm no dummy, I've been using linux and emacs for 5
years, writing python for 2 years, and I have no idea how I would find
out that C-x is equivalent to chr(0x18). It's not listed as such in
the ascii man page. Furthermore, there must be many combinations of
control, meta, and other keys that have no single-character
equivalent, so this is not a general solution.

>Maybe it could be useful to have a service function to help writing more
>LISP-looking strings in Python?

Yes, that's exactly what I'm suggesting.

--PW



More information about the Python-list mailing list