next up previous contents index
Next: 10. Index commands Up: II. Widget Commands Previous: 8. Text modification commands   Contents   Index

9. Annotation commands

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.

9.1 Marks

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:



The mark command


mark gravity markName ?direction?
  Returns or sets the gravity of mark markName. If direction is not specified, returns left or right to indicate which of its adjacent characters markName is attached to. If direction is specified, it must be left or right; the gravity of markName is set to the given value.
mark names
  Returns a list with the names of all the marks that are currently set.
mark next index
  Returns the name of the next mark at or after index.
mark previous index
  Returns the name of the mark at or before index.
mark set markName index
  Sets the mark named markName to a position just before the character at index. If markName already exists, it is moved from its old position; if it doesn't exist, a new mark is created. This command returns an empty string.
mark unset markName ?markName markName ...?
  Remove the mark corresponding to each of the markName arguments. The removed marks will not be usable in indices and will not be returned by future calls to ``pathName mark names''. This command returns an empty string.


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.

\epsfbox{images/attn.eps} It is not possible to remove the insertion cursor with the mark unset command.

9.2 Tags

The tag widget command is used to manipulate tag annotations in the sgml widget. The exact behavior of the command depends on the option argument that follows the tag command. The following forms of the command are currently supported:



The tag command


tag add tagName index1 ?index2 index1 index2 ...?
  Add the tag tagName to all of the characters starting with index1 and ending just before index2.
tag bind tagName ?sequence? ?script?
  Query or set the event bindings associated with the tag given by tagname.
tag cget tagName option
  Returns the value of a configuration option for tagName.
tag configure tagName ?option? ?value option value ...?
  Query or modify the configuration options for a tag annotation.
tag delete tagName ?tagName ...?
  Deletes all tag information for each of the tagName arguments.
tag lower tagName ?belowThis?
  Lowers priority of tag tagName just below belowThis or below all other tags.
tag names ?index?
  Returns a list with the names of all the tags at the character position index or a list of all defined tags if index is omitted.
tag nextrange tagName index1 ?index2?
  Search for tagName after index1, but not later than index2.
tag prevrange tagName index1 ?index2?
  Search for tagname before index1, but not earlier than index2
tag raise tagName ?aboveThis?
  Raises the priority of tagName just above aboveThis or above all other tags.
tag ranges tagName
  Returns a list describing all of the ranges of text that have been tagged with tagName.
tag remove tagName index1 ?index2 index1 index2 ...?
  Remove the tag tagName from all of the characters starting at index1 and ending just before index2.


9.2.0.1 Adding tag annotations

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.

9.2.0.2 Removing tag annotations

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.

9.2.0.3 Searching for tag annotations

The list of defined tag annotations can be retrieved with the tag names widget command. The command has the general form


pathname tag names ?index?

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


pathName tag ranges tagName

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.

9.2.0.4 Configuring tag annotations

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.

9.2.0.5 Tag annotation priorities

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.


9.2.1 Tag configuration options

The following options are currently supported for tag annotations:

9.2.2 Tag bindings

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.

9.3 Windows

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:



The window command


window cget index option
  Returns the value of a configuration option for the window at index.
window configure index ?option value ...?
  Query or modify the configuration options for an embedded window.
window create index ?option value ...?
  Creates a new window annotation at index.
window names
  Returns the names of all windows currently embedded in the widget.


9.3.0.1 Creating window annotations

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.

9.3.0.2 Enumerating windows

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


pathname window names

The result returned by the command is a proper Tcl list containing the names of all windows that are embedded in the widget.

9.3.0.3 Configuring embedded windows

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 [*].


9.3.1 Configuration options for embedded windows

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:

9.4 Images

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.



The image command


image cget index option
  Returns the value of a configuration option for an embedded image at index.
image configure index ?option value ...?
  Query or modify the configuration options for an embedded image.
image create index ?option value ...?
  Creates a new image annotation, at index.
image names
  Returns the names of all images currently embedded in the widget.


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.

9.4.0.1 Creating images

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 [*].

9.4.0.2 Enumerating images

The list of all embedded images in an sgml widget can be retrieved with the image names widget command:


pathName image names

The command returns a list whose elements are the names of all images currently embedded in the widget.

9.4.0.3 Configuring images

The configuration options for an image annotation can be changed by using the image configure command:


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 [*].


9.4.1 Image configuration options

The following configuration options are currently supported for embedded images:


next up previous contents index
Next: 10. Index commands Up: II. Widget Commands Previous: 8. Text modification commands   Contents   Index
TkSGML Reference Manual