This chapter describes the widgets commands that are used to
manipulate annotations like marks, images, or embedded windows. See
section
for an overview about the types of available
widget annotations.
Marks (including the special marks insert and current) are manipulated by the mark widget command. The general syntax of the command is
pathName mark option ?arg arg ...?
The exact behavior of the command depends on the option argument that follows the mark command.
The following forms of the command are currently supported:
If the index argument for the mark next is the name of a mark, then the search for the next mark begins immediately after that mark. This can still return a mark at the same position if there are multiple marks at the same index. These semantics mean that the mark next operation can be used to step through all the marks in an sgml widget in the same order as the mark information returned by the dump operation. If a mark has been set to the special end index, then it appears to be after the end with respect to the mark nextoperation. An empty string is returned if there are no marks after index.
If the index argument for the mark previous command is the name of a mark, then the search for the next mark begins immediately before that mark. This can still return a mark at the same position if there are multiple marks at the same index. These semantics mean that the mark previous operation can be used to step through all the marks in a text widget in the reverse order as the mark information returned by the dump operation. If index is specified in numerical form, then the search for the previous mark begins with the character just before that index. An empty string is returned if there are no marks before index.
![]() |
It is not possible to remove the insertion cursor with the mark unset command. |
The command
pathName tag add tagName index1 ?index2 index1
index2 ...?
Associates the tag tagName with all of the characters starting with index1 and ending just before index2 (the character at index2 isn't tagged). A single command may contain any number of index1 - index2 pairs. If the last index2 is omitted then the single character at index1 is tagged. If there are no characters in the specified range (e.g. index1 is past the end of the file or index2 is less than or equal to index1) then the command has no effect.
Tag annotations are removed with the tag remove widget command.
pathname tag remove tagName index1
?index2 index1 index2 ...?
This command removes the tag tagName from all of the characters starting at index1 and ending just before index2 (the character at index2 isn't affected).
A single command may contain any number of index1 - index2 pairs. If the last index2 is omitted then the tag is removed from the single character at index1.
If there are no characters in the specified range (e.g. index1 is past the end of the file or index2 is less than or equal to index1) then the command has no effect.
The tag remove command returns an empty string.
Removing a tag from a range of text does not destroy the information about the tag, even if no characters are associated with the tag annotation any more after removing the tag. Tag annotations can be completely deleted by using the command
pathname tag delete tagName ?tagName
...?
The tag delete command deletes all tag information for each of the tagName arguments. The command removes the tags from all characters in the file and also deletes any other information associated with the tags, such as bindings and display information. The command returns an empty string.
The list of defined tag annotations can be retrieved with the tag names widget command. The command has the general form
and returns a list consisting of the names of all the tags that have been assigned to the character position at index.
If index is omitted, then the return value will describe all of the tags that exist for the text (this includes all tags that have been named in a tag widget command but haven't been deleted by a tag delete widget command, even if no characters are currently marked with the tag).
The resulting list will be sorted in order from lowest priority to highest priority.
Tag annotations in the sgml widget can be searched by using the tag prevrange and tag nextrange commands. The general form of the commands is
pathName tag prevrange tagName index1 ?index2?
The tag prevrange command searches for a range of characters tagged with tagName where the first character of the range is before the character at index1 and no earlier than the character at index2 (a range starting at index2 will be considered). If several matching ranges exist, the one closest to index1 is chosen.
The command's return value is a list containing two elements, which are the index of the first character of the range and the index of the character just after the last one in the range. If no matching range is found then the return value is an empty string.
If index2 is not given then it defaults to the beginning of the text.
The command
pathName tag nextrange tagName index1 ?index2?
searches the text for a range of characters tagged with tagName where the first character of the range is no earlier than the character at index1 and no later than the character just before index2 (a range starting at index2 will not be considered). If several matching ranges exist, the first one is chosen.
The command's return value is a list containing two elements, which are the index of the first character of the range and the index of the character just after the last one in the range. If no matching range is found then the return value is an empty string.
If index2 is not given then it defaults to the end of the text.
All ranges that have been tagged with a tag annotation can be retrieved with the command
This command returns a list describing all of the ranges of text that have been tagged with tagName.
The first two elements of the list describe the first tagged range in the text, the next two elements describe the second range, and so on.
The first element of each pair contains the index of the first character of the range, and the second element of the pair contains the index of the character just after the last one in the range.
If there are no characters tagged with tagName then an empty string is returned.
Tag annotations can be configured with the command
pathname tag configure tagName
?option? ?value option value ...?
This command is similar to the configure widget command except
that it modifies options associated with the tag given by tagName
instead of modifying options for the overall sgml widget.
If no option is specified, the command returns a list describing
all of the available options for tagName.
If option is specified with no value, then the
command returns a list describing the one named option (this list will
be identical to the corresponding sublist of the value returned if no
option is specified).
If one or more option - value pairs are specified,
then the command modifies the given option(s) to have the given value(s) in
tagName; in this case the command returns an empty string.
See section
for details on the options available for tags.
The current value of a tag configuration option can be retrieved with the tag cget widget command:
pathname tag cget tagName option
The command returns the current value of the option named option associated with the tag given by tagName. Option may have any of the values accepted by the tag configure widget command.
It is possible for a range of text to be tagged with several tag annotations at once. In this case, the tag priority is used to determine how the text should be displayed if conflicting display options have been specified for these tags.
The priority of a tag annotation can be changed with the commands tag raise and tag lower:
pathName tag raise tagName ?aboveThis?
changes the priority of tag tagName so that it is just higher in priority than the tag whose name is aboveThis. If aboveThis is omitted, then tagName's priority is changed to make it highest priority of all tags.
To lower the priority of a tag annotation,
pathName tag lower tagName ?belowThis?
can be used. The command changes the priority of tag tagName so that it is just lower in priority than the tag whose name is belowThis. If belowThis is omitted, then tagName's priority is changed to make it lowest priority of all tags.
The priority of tag annotations is only relevant for conflicting display options. If a particular display option hasn't been specified for a particular tag annotation, or if it is specified as an empty string, then that option will never be used; the next-highest-priority tag's option will be used instead.
The following options are currently supported for tag annotations:
Color specifies the background color to use for characters
associated with the tag. It may have any of the forms described in
section
.
Bitmap specifies a bitmap that is used as a stipple pattern for
the background. It may have any of the forms described in
section
. If bitmap hasn't been specified, or if it is
specified as an empty string, then a solid fill will be used for the
background.
Pixels specifies the width of a 3-D border to draw around the
background. It may have any of the forms described in
section
. This option is used in conjunction with the
-relief option to give a 3-D appearance to the background for
characters; it is ignored unless the -background option has
been set for the tag.
Bitmap specifies a bitmap that is used as a stipple pattern
when drawing text and other foreground information such as
underlines. It may have any of the forms described in
section
. If bitmap hasn't been specified, or if
it is specified as an empty string, then a solid fill will be used.
FontName is the name of a font to use for drawing characters. It may have any of the forms allowed by Tk.
Color specifies the color to use when drawing text and other foreground information such as underlines.
If the first character of a display line has a tag for which this option has been specified, then justify determines how to justify the line. It must be one of left, right, or center. If a line wraps, then the justification for each line on the display is determined by the first character of that display line.
If the first character of a text line has a tag for which this option has been specified, then pixels specifies how much the line should be indented from the left edge of the window. Pixels may have any of the standard forms for screen distances. If a line of text wraps, this option only applies to the first line on the display; the -lmargin2 option controls the indentation for subsequent lines.
If the first character of a display line has a tag for which this option has been specified, and if the display line is not the first for its text line (i.e., the text line has wrapped), then pixels specifies how much the line should be indented from the left edge of the window. Pixels may have any of the standard forms for screen distances. This option is only used when wrapping is enabled, and it only applies to the second and later display lines for a text line.
Pixels specifies an amount by which the text's baseline should be offset vertically from the baseline of the overall line, in pixels. For example, a positive offset can be used for superscripts and a negative offset can be used for subscripts. Pixels may have any of the standard forms for screen distances.
Specifies whether or not to draw a horizontal rule through the middle
of characters. Boolean may have any of the forms described in
section
.
Relief specifies the 3-D relief to use for drawing backgrounds,
in any of the forms described in section
. This option
is used in conjunction with the -borderwidth option to give a
3-D appearance to the background for characters; it is ignored unless
the -background option has been set for the tag.
If the first character of a display line has a tag for which this option has been specified, then pixels specifies how wide a margin to leave between the end of the line and the right edge of the window. Pixels may have any of the standard forms for screen distances. This option is only used when wrapping is enabled. If a text line wraps, the right margin for each line on the display is determined by the first character of that display line.
Pixels specifies how much additional space should be left above each text line, using any of the standard forms for screen distances. If a line wraps, this option only applies to the first line on the display.
For lines that wrap, this option specifies how much additional space to leave between the display lines for a single text line. Pixels may have any of the standard forms for screen distances.
Pixels specifies how much additional space should be left below each text line, using any of the standard forms for screen distances. If a line wraps, this option only applies to the last line on the display.
TabList specifies a set of tab stops in the same form as for the -tabs option for the sgml widget. This option only applies to a display line if it applies to the first character on that display line. If this option is specified as an empty string, it cancels the option, leaving it unspecified for the tag (the default). If the option is specified as a non-empty string that is an empty list, such as -tabs { } , then it requests default 8-character tabs as described for the tags widget option.
Boolean specifies whether or not to draw an underline underneath
characters. It may have any of the forms described in section
.
Mode specifies how to handle lines that are wider than the text's window. It has the same legal values as the -wrap option for the sgml widget: none, char, or word . If this tag option is specified, it overrides the -wrap option for the text widget.
The tag bind command associates a script with a given tag tagName. It has the general form
pathName tag bind tagName ?sequence?
?script?
Whenever an event sequence occurs for a character that has been tagged with tagName, the script will be invoked. This widget command is similar to thebind command except that it operates on characters ranges rather than entire widgets. See the bind manual entry for complete details on the syntax of sequence and the substitutions performed on script before invoking it.
If all arguments for the tag bind command are specified then a new binding is created, replacing any existing binding for the same sequence and tagName (if the first character of script is ``+'' then script augments an existing binding rather than replacing it).
In this case the return value is an empty string. If script is omitted then the command returns the script associated with tagName and sequence (an error occurs if there is no such binding). If both script and sequence are omitted then the command returns a list of all the sequences for which bindings have been defined for tagName.
The only events for which bindings may be specified are those related to the mouse and keyboard, such as Enter, Leave, ButtonPress, Motion, and KeyPress.
Event bindings for an sgml widget use the current mark
described in section
above.
An Enter event triggers for a tag when the tag first becomes present on the current character, and a Leave event triggers for a tag when it ceases to be present on the current character.
Enter and Leave events can happen either because the current mark moved or because the character at that position changed.
Note that these events are different than Enter and Leave events for windows. Mouse and keyboard events are directed to the current character.
It is possible for the current character to have multiple tags, and for each of them to have a binding for a particular event sequence. When this occurs, one binding is invoked for each tag, in order from lowest-priority to highest priority. If there are multiple matching bindings for a single tag, then the most specific binding is chosen (see the manual entry for the bind command for details).
continue and break commands within binding scripts are processed in the same way as for bindings created with the bind command.
If bindings are created for the widget as a whole using the bind command, then those bindings will supplement the tag bindings. The tag bindings will be invoked first, followed by bindings for the window as a whole.
The window command is used to manipulate embedded window annotations. The command has the general form pathName window option ?arg arg ...? where the behavior of the command depends on the option argument that follows the window argument. The following forms of the command are currently supported:
Embedded windows are created with the command
pathname window create index ?option value ...?
This command creates a new window annotation, which will appear
in the widget at the position given by index.
Any number of option-value pairs may be specified to
configure the annotation.
See section
for information on the options that
are supported. The command returns an empty string.
The window names command returns a list whose elements are the names of all windows currently embedded in the widget. The general form of the command is
The result returned by the command is a proper Tcl list containing the names of all windows that are embedded in the widget.
Embedded windows are configured with the window configure widget command. The command has the following general form:
pathname window configure index ?option value ...?
The command is used to query or modify the configuration options for an embedded window.
If no option is specified, returns a list describing all of the available options for the embedded window at index. If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified).
If one or more option-value pairs are specified, then
the command modifies the given option(s) to have the given value(s); in
this case the command returns an empty string.
See section
for information on the options that
are supported.
The current value of a specific configuration option for an embedded value can be retrieved with the window cget command. The command has the general form
pathname window cget index option
where index identifies the embedded window, and option
specifies a particular configuration option, which must be one of
the ones listed in the section
.
When an embedded window is added to an sgml widget with the window create widget command, several configuration options may be associated with it. These options may be modified later with the window configure widget command. The following options are currently supported:
If the window is not as tall as the line in which it is displayed, this option determines where the window is displayed in the line.
Where must have one of the values top (align the top of the window with the top of the line), center (center the window within the range of the line), bottom (align the bottom of the window with the bottom of the line's area), or baseline (align the bottom of the window with the baseline of the line).
Specifies a Tcl script that may be evaluated to create the window for the annotation. If no -window option has been specified for the annotation this script will be evaluated when the annotation is about to be displayed on the screen.
Script must create a window for the annotation and return the name of that window as its result. If the annotation's window should ever be deleted, script will be evaluated again the next time the annotation is displayed.
Pixels specifies the amount of extra space to leave on each side of the embedded window. It may have any of the usual forms defined for a screen distance.
Pixels specifies the amount of extra space to leave on the top and on the bottom of the embedded window. It may have any of the usual forms defined for a screen distance.
If the requested height of the embedded window is less than the height of the line in which it is displayed, this option can be used to specify whether the window should be stretched vertically to fill its line. If the -pady option has been specified as well, then the requested padding will be retained even if the window is stretched.
Specifies the name of a window to display in the annotation.
When an embedded image is added to an sgml widget with the image create widget command, a name unique to this instance of the image is returned. This name may then be used to refer to this image instance. The name is taken to be the value of the -name option (described below). If the -name option is not provided, the -image name is used instead. If the imageName is already in use in the sgml widget, then #nn is added to the end of the imageName, where nn is an arbitrary integer. This insures the imageName is unique. Once this name is assigned to this instance of the image, it does not change, even though the -image or -name values can be changed with image configure.
Embedded images are mere annotations that are not considered to be
part of the sgml document. It is possible to attach images to sgml
elements and entity references. Please refer to the configuration
options for elements (section
) and entities
(section
) for more details.
Image annotations are created with the image create widget command. This command has the general form
pathname image create index ?option value ...?
The command creates a new image annotation, which will appear in the document at the position given by index. The command returns a unique identifier that may be used as an index to refer to this image.
When an embedded image is added to an sgml widget with the
pcrmimage create widget command, several configuration options
may be associated with it. These options may be modified later with
the pcrmimage configure widget command. The supported options are
described in section
.
The list of all embedded images in an sgml widget can be retrieved with the image names widget command:
The command returns a list whose elements are the names of all images currently embedded in the widget.
pathName image configure index ?option value ...?
The image configure command is used to query or modify the configuration options for an embedded image.
If no option is specified, the command returns a list describing all of the available options for the embedded image at index. If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified).
If one or more option-value pairs are specified, then
the command modifies the given option(s) to have the given value(s); in
this case the command returns an empty string.
See section
for information on the options that
are supported.
The current value of a specific configuration option for an image can be retrieved with the image cget command. The command has the general form
pathname image cget index option
where index identifies the embedded image, and option
specifies a particular configuration option, which must be one of
the ones listed in the section
.
The following configuration options are currently supported for embedded images:
If the image is not as tall as the line in which it is displayed, this option determines where the image is displayed in the line. Where must have one of the values top (align the top of the image with the top of the line), center (center the image within the range of the line), bottom (align the bottom of the image with the bottom of the line's area), or baseline (align the bottom of the image with the baseline of the line).
Specifies the name of the Tk image to display in the annotation. If image is not a valid Tk image, then an error is returned.
Specifies the name by which this image instance may be referenced in the sgml widget. If ImageName is not supplied, then the name of the Tk image is used instead. If the imageName is already in use, #nn is appended to the end of the name as described above.
Pixels specifies the amount of extra space to leave on each side of the embedded image. It may have any of the usual forms defined for a screen distance.
Pixels specifies the amount of extra space to leave on the top and on the bottom of the embedded image. It may have any of the usual forms defined for a screen distance.