Indices

Many of the widget commands for texts take one or more indices as arguments. An index is an expression used to indicate a particular place within a text, such as a place to insert characters or one endpoint of a range of characters to delete. Indices have the syntax

base modifier modifier modifier ...

Where base gives a starting point and the modifiers adjust the index from the starting point (e.g. move forward or backward one character). Every index must contain a base, but the modifiers are optional.

The base for an index must have one of the following forms:

(line . char)
Indicates char'th character on line line. Lines are numbered from 1 for consistency with other UNIX programs that use this numbering scheme. Within a line, characters are numbered from 0. If char is end then it refers to the newline character that ends the line.
(@ x y)
Indicates the character that covers the pixel whose x and y coordinates within the text's window are x and y.
end
Indicates the end of the text (the character just after the last newline).
mark
Indicates the character just after the mark whose name is mark.
(tag . first)
Indicates the first character in the text that has been tagged with tag. This form generates an error if no characters are currently tagged with tag.
(tag . last)
Indicates the character just after the last one in the text that has been tagged with tag. This form generates an error if no characters are currently tagged with tag.
#<widget>
Indicates the position of the embedded window #<widget>. This form generates an error if there is no such window embedded.
imageName
Indicates the position of the embedded image whose name is imageName. This form generates an error if there is no embedded image by the given name.

If the base could match more than one of the above forms, such as a mark and imageName both having the same value, then the form earlier in the above list takes precedence.

If modifiers follow the base index, each one of them must be used in one of the forms listed below.

(base + count chars)
Adjust the index forward by count characters, moving to later lines in the text if necessary. If there are fewer than count characters in the text after the current index, then set the index to the last character in the text.
(base - count chars)
Adjust the index backward by count characters, moving to earlier lines in the text if necessary. If there are fewer than count characters in the text before the current index, then set the index to the first character in the text.
(base + count lines)
Adjust the index forward by count lines, retaining the same character position within the line. If there are fewer than count lines after the line containing the current index, then set the index to refer to the same character position on the last line of the text. Then, if the line is not long enough to contain a character at the indicated character position, adjust the character position to refer to the last character of the line (the newline).
(base - count lines)
Adjust the index backward by count lines, retaining the same character position within the line. If there are fewer than count lines before the line containing the current index, then set the index to refer to the same character position on the first line of the text. Then, if the line is not long enough to contain a character at the indicated character position, adjust the character position to refer to the last character of the line (the newline).
(base linestart)
Adjust the index to refer to the first character on the line.
(base lineend)
Adjust the index to refer to the last character on the line (the newline).
(base wordstart)
Adjust the index to refer to the first character of the word containing the current index. A word consists of any number of adjacent characters that are letters, digits, or underscores, or a single character that is not one of these.
(base wordend)
Adjust the index to refer to the character just after the last one of the word containing the current index. If the current index refers to the last character of the text then it is not modified.

If more than one modifier is present then they are applied in left-to-right order. For example, the index (end - 1 chars) refers to the next-to-last character in the text and (insert wordstart - 1 chars) refers to the character just before the first one in the word containing the insertion cursor.


© Author | Home | Sitemap