Supertext - tk text widget with unlimited undo
Dispensing with the usual pleasantries, our intrepid hero points his
finger toward the code....
What is it?
Supertext is a package that provides a tk text widget with full undo
and the ability to execute procedures both before and after a text
widget command has been processed. Supertext may be used as-is, or for
the brave it may be used in place of the standard text widget.
How do I use it?
Arrange for the source to be included in your program, either via
autoloading, source'd, or included directly in your program. You may
then create a text widget using the command
Supertext::text. This command takes the exact same
arguments as the standard text command. In addition, it can accept two
additional arguments:
- -preproc proc
- request that the named procedure, proc be called before any
widget command (insert, delete, etc) is processed. The arguments to
the proc will be references to a variable which holds the widget
command, and a variable containing the list of arguments. These
references may be upvar'd to allow you to change the command on the
fly.
For example, you could write a proc that takes a special key such as
tab or escape, and do word completion by looking up the word and
(re)creating the command and arguments to insert the completed word.
- -postproc proc
- request that the named procedure, proc be called after any
widget command (insert, delete, etc) is processed. The arguments to
the proc will be references to a variable which holds the widget
command, and a variable containing the list of arguments.
One example of a use for this proc is to update a text editor
statusbar with the current line and column number.
Once you create the widget, use it just like a text widget. To request
that the last insert or delete be undone, use the "undo" widget
command, as in .text undo. Subsequent undo's will pull
previous items off the stack, until a non-undo action is requested or
there is nothing left to undo.
By default this command is bound
to Control-z for Windows and Macintosh, Control-_ for unix.
How do I override the standard text command?
Use the command Supertext::overrideTextWidget. This will
rename the text command to something that Supertext knows, then import
Supertext::text. Use at your own risk. I haven't tested this a
whole bunch, but it seems to work.
Why did you spend so much time doing this?
I have no idea.