Could Emacs be rewritten in Python?

Carl Banks imbosol-1049731965 at aerojockey.com
Mon Apr 7 12:53:59 EDT 2003


Beni Cherniavsky wrote:
>> Next three functions are "save-current-buffer", "with-current-buffer",
>> and "with-temp-buffer".  These are actually not functions, but special
>> forms and macros.  Python has no analogue to these (barring some
>> obscure metaclass tricks).  Depending on the form, it might be useful
>> to have a corresponding method in Python, or it might be better to
>> think about a more Pythonic way to do it.  I haven't thought about it
>> too much, but off hand, I'd say I'd choose the latter in this case.
>> In fact, these seem to be mostly a convenience, so I wouldn't bother
>> to include them.
>>
> This is not a tiny issue trivial to give up.  This kind of macros is
> the heart of elisp programming.  The normal way to e.g. find another
> place in the buffer is to use functions that actually *move the point*
> and record the new position - all this inside `save-excursions'.
> Ditto for other tasks.  Elisp has a very imperative, plumbing style.
> It's very common for functions to actually change things.

This is kind of what Greg Ewing was trying to say.  I objected to the
idea that we should get rid of the notion of current buffer, but
certianly he was right on about having a "Pythonic" layer.

The idea is *not* to do excursions or switch current buffers; rather,
if you want to do something at another point or in another buffer, use
functions from the Pythonic layer that don't need to move the point or
switch the buffer.

In any case, with-style macros that don't bind new variables don't do
anything you can't do with try ... finally construct.
with_current_buffer could be replaced by:

    set_current_buffer(whatever)
    try:
        do_stuff_that_you_wanted_to_do_in_with_current_buffer()
    finally:
        set_current_buffer(original_buffer)


-- 
CARL BANKS




More information about the Python-list mailing list