interpreter improvements

Skip Montanaro skip at pobox.com
Thu Jul 26 19:09:13 EDT 2001


    Quinn> You don't have to know the language to cut and paste and edit
    Quinn> blocks, you just need a mouse and a terminal which doesn't think
    Quinn> it's still a teletype.  My "other observation" above was taking
    Quinn> the position that readline is the wrong solution.  I don't use
    Quinn> readline if I can avoid it, and happily cut and paste and edit
    Quinn> blocks in the top level, and then cut and paste them right into
    Quinn> the editor, or the other way around.

If you're sitting at the interpreter prompt where do you cut-n-paste to with
your mouse?  If I entered this at the prompt:

    for i in range(10):
        ... line 1 ...
        ... line 2 ...
        ... line 3 ...
        ... line 4 ...
        ... line 5 ...
        x = math.sin(y)

only to have the interpreter tell me I forgot to "import math", it would be
nice to execute the import, then with two Ctl-P keystrokes back up into the
for loop and have the whole block pop into a mini-editor to be reexecuted
upon exit.  I believe this is what IDLE is supposed to do.  No prompt
fiddling required.

    Quinn> It does require turning off the '>>> ' and '... ' prompts (which
    Quinn> python won't let you do without hacking pythonrun.c (I think)
    Quinn> which I think is a bug), but it's my opinion that this is the
    Quinn> correct behaviour anyway (no prompt).

No need to hack pythonrun.c, just set sys.ps1 and sys.ps2 to empty strings.
Of course, with smart history retrieval you wouldn't need to do that.

    Quinn> It's also convenient for return values to be printed like

    Quinn> 2 + 2
    Quinn> #-> 4

    Quinn> since that doesn't mess up a cut and paste and is easily filtered
    Quinn> out.

That's an interesting enhancement but doesn't help with the ps1/ps2 thing.
They do offer nice feedback to the user about what's expected, so for most
situations users won't turn them off before they make a mistake that needs
to be repaired.

    Quinn> I greatly prefer not building special language-awareness into a
    Quinn> mechanism, because then it can work in a simple and uniform
    Quinn> manner for every application and language that involves text, as
    Quinn> opposed to having an ad-hoc intrusive only-works-on-one-editor
    Quinn> complicated and hard to get right mechanism.

Neither solution is ideal, but if you want language awareness you need to
either build it into the interpreter or build some configurable layer on top
of something like readline that you can customize via a config file, in much
the same way that you can train emacs about syntax highlighting.

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list