[Idle-dev] Improving behaviour when moving across and deleting words

Weeble clockworksaint at gmail.com
Mon Jan 26 13:21:11 CET 2009


Often I find that IDLE just isn't doing what I expect when I hold down
Control and either press Left or Right to move the cursor
word-by-word, or press Delete or BackSpace to delete a word adjacent
to the cursor. I've also observed that it behaves differently under
Windows and Linux.

Here are some examples. I'll use ^ to denote the cursor position:

spam = [^
    1,
    2,
    3]

Press Control+Delete. Result:

spam = [^2,
    3]

Expected:

spam = [^1,
    2,
    3]

Here's another:

eggs^ = ((1,2,3),(2))

Press Control+Delete. Result:

eggs2,3),(2))

Expected:

eggs^ ((1,2,3),(2))

I think the problem is that I expect it to delete to the end of the
current token or to the end of the current block of whitespace, when
instead it deletes everything up to the next letter or digit, then
that entire "word", *then* everything up to the *next* letter or
digit. Control+BackSpace, Control+Left and Control+Right have similar
issues to varying degrees. I've noticed that Control+Left and
Control+Right on Windows will (more or less) move backwards and
forwards between the beginning of each "word", but on Linux
Control+Left moves backwards to the beginning of a word, and
Control+Right moves forwards to the end of a word, meaning that they
stop in different places when moving backwards from when moving
forwards. As far as I can tell, the discrepancy is a deliberate
"feature" of Tk. For example, see this excerpt from text.tcl:

# ::tk::TextNextWord --
# Returns the index of the next word position after a given position in the
# text.  The next word is platform dependent and may be either the next
# end-of-word position or the next start-of-word position after the next
# end-of-word position.
#
# Arguments:
# w -		The text window in which the cursor is to move.
# start -	Position at which to start search.

if {$tcl_platform(platform) eq "windows"}  {
    proc ::tk::TextNextWord {w start} {
	TextNextPos $w [TextNextPos $w $start tcl_endOfWord] \
		tcl_startOfNextWord
    }
} else {
    proc ::tk::TextNextWord {w start} {
	TextNextPos $w $start tcl_endOfWord
    }
}

Do we really want this platform-dependent distinction in IDLE? I
suspect that all these behaviours make more sense for a general text
editor/word processor than they do for a source code editor.

I would be happy to work up some patches to change the behaviour, but
I don't think there's a lot of point until some agreement can be
reached on what the behaviour should be. Perhaps my expectations are
way off and this behaviour actually feels natural to some.

I also had a look at providing this behaviour in an extension, but I
found a few problems:
    * An extension can provide events for skip-word-left and
skip-word-right and bind them by default to Control-Left and
Control-Right in the configuration file, because there are no default
bindings for those keys. But it can't do anything for Control-Delete
or Control-BackSpace because IDLE already has bindings for them.
    * It doesn't seem possible in the UI to unbind an action. You have
to bind it to obscure keys instead. This makes it quite tricky even to
manually bind Control-Delete or Control-BackSpace to my new actions.
    * An extension doesn't seem particularly useful anyway, because
users would still have to poke around in their Python directory and
edit at least one file to install it.

Note that this is all with Tk 8.5. It's possible some things have
changed since Tk 8.4.


More information about the IDLE-dev mailing list