The jtext.tcl library is distributed as part of the jstools package. It provides wrappers around the widget commands that manipulate the contents of a text widget, building additional functionality on top of them
This document describes jtext.tcl version 3.6/3.0.
Usage
Accessing the Library
In order to use the jtext.tcl library, it (and any other libraries it depends on) must be in your Tcl auto_path, described in tclvars(n). Information about how to arrange that, and other conventions common to the jstools libraries, is in the Usage section of The jstools Libraries.
Using jtext.tcl as an Interface to the Text Widget
The purpose of the jtext.tcl library is as an interface to the text widget allowing additional functionality to be built on top of the it's widget command. For instance, j:text:insert_string, along with the jtexttags.tcl library, can support the notion of a set of `current tags' automatically applied to newly¡inserted text. My main goal with this library is to use it to build a general undo facility, allowing an arbitrary number of changes to a text widget to be undone and redone by journaling changes to the text widget. (This is not yet supported.) This means that it's very important that if an application uses the jtext.tcl procedures with a particular text widget, all changes to that widget must be made through the jtext.tcl procedures.
The jtext.tcl library also keeps track of the state of the text widget - whether it's `clean' or `dirty'. This will only be accurate if all your accesses to the widget are through the jtext.tcl library.
(Actions that don't affect the contents of the text widget in any way, or that you don't care about being able to undo, don't need to go through the library. For instance, there's no j:text:get procedure, because there's no need to journal pathname get commands.)
Credits and Copyright
Author
Jay Sekora
js@bu.edu
http://shore.net/~js/
Copyright
The library is copyright ⌐ 1992-1994 by Jay Sekora, but may be freely copied and modified for non¡commercial purposes. (Please contact me if you want to use it for a commercial purpose, this may be OK under some circumstances.)
Overview
Procedures
j:text:insert_string - insert text into text widget at insert point
j:text:move - move insert mark in text widget to a particular position
j:text:delete - delete a range of characters in a text widget
j:text:replace - replace a range of characters in a text widget with a string
j:text:mark_dirty - specify that a text widget has been modified
j:text:mark_clean - specify that a text widget has been saved
j:text:is_dirty - true if a text widget has been modified since it was saved
j:text:has_selection - true if there is a selection in a text widget
j:text:insert_touches_selection - true if insert point touches or is in selection
See Also
jtexttags.tcl
j:text:insert_string
Usage
j:text:insert_string w text
Arguments
w is the text widget to insert into
text is the text to insert
Description
This procedure inserts text into w at w's insert point.
If w has been configured for use with the jtexttags.tcl library (specifically, if a tag¡list has been set for it with j:tag:set_tags, or j:tag:set_tag), then the text will be inserted with w's current tag list (and no other tags); see the jtexttags.tcl documentation for more about this.
If J_PREFS(typeover)is true - if the user has selected `Typing replaces selection' on the Global Preferences panel - then if (1) there is a selection in w and (2) the insert point is within or adjacent to the selection, the selection will be deleted and replaced by text. (The requirement that the insert point be in or next to the selection is so that the user can't inadvertently delete text distant from the place in the document where sie's working, possibly without realising it.)
j:text:move
Usage
j:text:move t index
Arguments
t is the text widget whose insert point is being changed
index is the new position of the insert point
Description
This procedure moved text widget t's insert point to index. index can be in any of the legal forms for a text widget index; see text(n) for details.
j:text:delete
Usage
j:text:delete t from to
Arguments
t is the text widget whose insert point is being changed
from is the index of the first character in t to delete
to is the index of the character after the last character in t to delete
Description
This procedure deletes all characters in t from from, inclusive, to to, exclusive. (I.e., the character at from and any characters between from and to will be deleted, but the char at to itself won't be.) from and to can be in any of the legal forms for a text widget index; see text(n) for details.
j:text:replace
Usage
j:text:replace t from to string
Arguments
t is the text widget you want to replace text in
from is the index of the first character to replace
to is the index of the character after the last character to replace
string is the string to insert in t in place of the range from from to to
Description
This procedure replaces a sequence of character in text widget t with string. After being inserted, string will have all (and only) the tags that the character at from had before the replacement. The insertion point is left after string.
j:text:mark_dirty
Usage
j:text:mark_dirty t
Argument
t is the text widget which has been changed
Description
This procedure marks the text widget t as having been changed. It should be used after all actions that modify the contents of the widget. It's intended for applications such as editors, which need to know whether a document has been modified since it was last saved.
All the jtext.tcl procedures that modify text call this properly, so you should never need to set it yourself.
j:text:mark_clean
Usage
j:text:mark_clean t
Argument
t is the text widget which no longer has pending changes
Description
This procedure marks the text widget t as not having pending changes. Typically, this is used after an application has saved the widget's contents into a file, or is done with the widget. It's intended for applications such as editors, which need to know whether a document has been modified since it was last saved.
j:text:is_dirty
Usage
j:text:is_dirty t
Argument
t is the text widget whose state you want to query
Description
This procedure returns true (1) if the text widget t has pending changes (i.e., if its contents have been changed since it was created or since it was last marked clean with j:text:mark_clean). Otherwise it returns false (0).
j:text:has_selection
Usage
j:text:has_selection t
Argument
t is the text widget whose situation you want to query
Description
This procedure returns true (1) if there is currently a selection in text widget t. Otherwise it returns false (0).
j:text:insert_touches_selection
Usage
j:text:insert_touches_selection t
Argument
t is the text widget whose situation you want to query
Description
This procedure returns true (1) if there is currently a selection in text widget t and t's insert point is within or next to the selection. Otherwise it returns false (0).
Evolution
Feel free to report bugs (and feature requests) to me, <js@bu.edu>, and I will try to deal with them. Also, feel free to fix bugs or add features on your own and let me know how you did it.
Bugs and Misfeatures
* The interaction of j:text:insert_string with J_PREFS(typeover) is for the benefit of keyboard bindings and other changes based on user actions. It's not appropriate for other uses. There should really be a bindings¡specific version of j:text:insert_string (perhaps j:text:type?) and a generic one.
Changes Since Version 3.6/2.0
* This library is new with version 3.6/3.0.
Future Directions
* As mentioned above in Usage, I hope to implement a generalised undo facility in this library.