text(n)

NAME
text, tk_mergeRange, tk_textCopy, tk_textCut, tk_textInsert, tk_textPaste, tk_textRebindMouseWheel, tk_textReplace - Create and manipulate 'text' hypertext editing widgets

SYNOPSIS
text pathName ?options?
tk_mergeRange varName range
tk_textCopy pathName
tk_textCut pathName
tk_textInsert pathName ?-hyphentags tagList? index chars ?tagList chars tagList ...?
tk_textPaste pathName
tk_textRebindMouseWheel pathName ?pathName ...?
tk_textReplace pathName ?-hyphentags tagList? index chars ?tagList chars tagList ...?
-background	-highlightthickness	-relief
-borderwidth	-insertbackground	-selectbackground
-cursor	-insertborderwidth	-selectborderwidth
-exportselection	-insertofftime	-selectforeground
-font	-insertontime	-setgrid
-foreground	-insertwidth	-takefocus
-highlightbackground	-padx	-xscrollcommand
-highlightcolor	-pady	-yscrollcommand

WIDGET-SPECIFIC OPTIONS
[-autoseparators autoSeparators AutoSeparators] Specifies a boolean that says whether separators are automatically inserted in the undo stack. Only meaningful when the -undo option is true. [-blockcursor blockCursor BlockCursor] Specifies a boolean that says whether the blinking insertion cursor should be drawn as a character-sized rectangular block. If false (the default) a thin vertical line is used for the insertion cursor. See section THE INSERTION CURSOR for more details. [-eolchar eolChar EolChar] Specifies the character to use when displaying the end of line symbol (see option -showendofline). An empty argument will force the use of the default symbol (U+00B6 = PILCROW SIGN). [-eolcolor eolColor EolColor] Specifies the foreground color to use when displaying the end of line symbol (see option -showendofline). An empty argument will force the use of the foreground color (set with -foreground; this is the default). [-eotchar eotChar EotChar] Specifies the character to use when displaying the end of text symbol (see option -showendoftext). An empty argument will force the use of the same symbol as used for showing the end of line symbol (see -eolchar). [-eotcolor eotColor EotColor] Specifies the foreground color to use when displaying the end of text symbol (see option -showendoftext). An empty argument will force the use of the same color as used for the end of line symbol (see -eolcolor). [-hyphencolor hyphenColor HyphenColor] Specifies the foreground color to use when displaying the soft hyphen character (U+00AD). An empty argument will force the use of the foreground color (set with -foreground; this is the default). [-endindex endIndex EndIndex] Specifies an index representing the end of the underlying textual data store that should be contained in the widget. This allows a text widget to reflect only a portion of a larger piece of text. Instead of an index, the empty string can be provided to this configuration option, which will configure the widget to the end index in the textual data store. Instead of an empty string the special index specifier end can be used. [-endline endLine EndLine] Note that this option is deprecated, option -endindex should be used instead. For compatibility reasons this option still will be supported, but may be removed in a future version.

    Specifies an integer line index representing the line of the underlying textual data store that should be just after the last line contained in the widget. This allows a text widget to reflect only a portion of a larger piece of text. Instead of an integer, the empty string can be provided to this configuration option, which will configure the widget to end at the very last line in the textual data store.
[-height height Height] Specifies the desired height for the window, in units of characters in the font given by the -font option. Must be at least one. [-inactiveselectbackground inactiveSelectBackground Foreground] Specifies the colour to use for the selection (the sel tag) when the window does not have the input focus. If empty, {}, then no selection is shown when the window does not have the focus. [-inactiveselectforeground inactiveSelectForeground Foreground] Specifies the foreground colour to use for the selection (the sel tag) when the window does not have the input focus. If empty, {}, then the colour specified with widget option -selectforeground will be used. [-hyphenrules hyphenRules HyphenRules] Specifies a list of spelling change rules for hyphenated words, given by the identifier of the rules. Only the rules given with this set will be used for spelling changes. Per default the set of rules is empty, this means that all rules are allowed. The rules are important when command tk_textInsert (or tk_textReplace) will be used with automatic spelling changes. An exception will be thrown if one of the given rules is not defined. See section for more details HYPHENATION RULES about the defined rules.

    If also option -lang is specified for a particular soft hyphen, then only the rules belonging to this language will be applied to this soft hyphen. This supports simpler hyphenators, not knowing spelling changes.

    This is the way how the hyphen rules will be applied ( denotes the soft hyphen character):

    ck  If the soft hyphen is the right neighbor of character and the right neighbor is character then the ck hyphenation rule will be applied to this hyphen. Example: the German word hyphenates into This rule belongs to language German (de).

    gemination
        If the soft hyphen is the left neighbor of a geminated letter 'l' (or 'L'), then the gemination hyphenation rule will be applied. Example: the Catalan word hyphenates into This rule belongs to the Catalan language (ca).

    doublevowel
        If the soft hyphen is the right neighbor of any vowel, and the right neighbor is the same vowel, then the doublevowel hyphenation rule will be applied to this hyphen. If this vowel is an then a conversion to e-acute will be done. Example: the Dutch word hyphenates into and becomes This rule belongs to the Dutch language (nl).

    doubledigraph
        In Polish language the following spelling change will be applied with this rule: becomes becomes becomes becomes becomes becomes and becomes

    repeathyphen
        In Polish the hyphen will be repeated after line break, this means for example that becomes

    trema
        If the soft hyphen is the right neighbor of any vowel, and the right neighbor of any vowel with trema (umlaut), then the trema hyphenation rule will be applied to this hyphen. Example: the Dutch word hyphenates into This rule belongs to the Dutch language (nl).

    tripleconsonant
        If the soft hyphen is the right neighbor of a double consonant, and the right neighbor is the same consonant, and this consonant is followed by a vowel (or by letter - Norwegian), then the tripleconsonant hyphenation rule will be applied when not hyphenating at this point. Examples: the German word hyphenates into but will be written when no hyphenation will be done. The Swedish word becomes and the Norwegian word becomes This rule belongs to languages German (de), Norwegian (no, nb, nn), and Swedish (sv).
[-hyphens hyphens Hyphens] Specifies a boolean indicating whether the hyphenation support will be activated. If activated, then in state normal or readonly the soft hyphen (Unicode point U+00AD) - also called SHY - will be invisible unless it is used at line end for displaying a hyphen character in case of dividing a word for line adjusting. If the widget is in state normal then the hyphen will be displayed like a normal character (with codepoint U+2010), it will not be used for hyphenation (but may be used for line wrapping, depending on the value of option -wrap). [-insertforeground insertForeground InsertForeground] Specifies the color to use as foreground for the characters in the area covered by the insertion cursor. This color will not be overridden with tagging options. Note that this color will not be used unless option -showinsertforeground is enabled. [-insertunfocussed insertUnfocussed InsertUnfocussed] Specifies how to display the insertion cursor when the widget does not have the focus. Must be none (the default) which means to not display the cursor, hollow which means to display a hollow box, or solid which means to display a solid box. Note that hollow and solid will appear very similar when the -blockcursor option is false. [-justify justify Justify] Setting the style how lines will be justified. This style will be used for the whole text, even for wrapped lines, but tags may override this style for individual lines.

    The following styles are possible:

    left
        The text is aligned along the left margin. This is the default.

    right
        The text is aligned along the right margin.

    full
        The text is aligned along the left margin, and word-spacing is adjusted so that the text flush with both margins.

    center
        The text is aligned to neither the left nor the right margin, there is an even gap on each side of each line.
[-lang lang Lang] Setting the language code of the text content. The language code will be used for line breaking (but only if option -useunibreak is also set), and it may be used to restrict the hyphenation rules (see -hyphenrules). An empty string is unsetting the language.

    The language code will be specified as ISO 639-1 code. The language code will not be verified, but it must be a string with two consecutive lowercase letters (for example ), or an empty string, otherwise an error will be thrown.
[-maxredo maxRedo MaxRedo] Specifies the maximum number of redo actions on the undo stack. A zero value will prevent any redo action, only undoes are possible. A negative value imply an unlimited number of redo actions (this is the default; note that the number of redo actions is always bound by the number of undo actions on the stack). Setting a lower positive value (including zero) than the previous (positive) number will reduce the redo stack immediately.

    This option is especially useful for setting an undo stack without redo capability; this means that in practice normally only the values -1 and 0 (zero) are useful (redo capability is on or off). When using a value greater than zero, mind that as soon as the redo stack size exceeds, all the redo items on the stack must expire (and will be deleted).
[-maxundo maxUndo MaxUndo] Specifies the maximum number of compound undo actions on the undo stack. A zero or a negative value imply an unlimited number of compound undo actions. Setting a lower value (greater than zero) than the previous (positive) number will reduce the stack immediately. [-maxundosize maxUndoSize MaxUndoSize] Specifies the maximal number of bytes stored on the undo stack, only characters will be counted (the byte size of the characters), and also embedded images and windows (each embedded item will be count with byte size one). A zero or a negative value imply an unlimited number of bytes. If a positive (non-zero) number of bytes is defined, option -maxundosize will have a higher priority than option -maxundo. Setting a number of bytes less than the number of bytes currently kept on the stack will not immediately reduce the stack. [-responsiveness responsiveness Responsiveness] Specifies the delay before the widget will repick (sending enter/leave/motion events when entering/leaving/hovering tagged regions) after scroll operations. The default value is 50 milliseconds. When setting the value to zero (or less than zero) the repick will be done immediately. The higher the responsiveness, the less the display will flicker while the widget is scrolling. [-showendofline showEndOfLine ShowEndOfLine] Specifies a boolean value determining whether manual line breaks ( ) will be emphasized with an end of line symbol (default is U+00B6 = PILCROW SIGN) at the end of the line, in this case that symbol does not belong to the text content and cannot be edited or selected. Per default the end of line symbol will not be shown. [-showendoftext showEndOfText ShowEndOfText] If this option is enabled the end of the text (after end of very last line) will be emphasized with an end of text symbol (per default this is the end of line symbol). This symbol does not belong to the text content and cannot be edited or selected. Per default the end of text symbol will not be shown. [-showinsertforeground showInsertForeground ShowInsertForeground] Use color option -insertforeground for the foreground of characters covered by the insert cursor if this option is enabled, otherwise the color of the characters will not change when coverd by the insertion cursor. Per default this option is disabled. [-spacemode spaceMode SpaceMode] Specifies the mode how spaces (U+0020) will be displayed. Default is none, this means that spaces will be displayed like any character, but when breaking lines at a space this space will be gobbled if option -wrap is set to word or codepoint (this is the common behavior of text editors). When setting to exact, no space character will be gobbled at all, even when breaking lines. Mode trim may be used for trimming consecutive space characters, but a single space will never be trimmed, instead it will be gobbled when a line break happens at this space (if option -wrap is set to word or codepoint). Normally mode trim will not be used in conjunction with state normal (see option -state). [-spacing1 spacing1 Spacing1] Requests additional space above each text line in the widget, using any of the standard forms for screen distances. If a line wraps, this option only applies to the first line on the display. This option may be overridden with -spacing1 options in tags. [-spacing2 spacing2 Spacing2] For lines that wrap (so that they cover more than one line on the display) this option specifies additional space to provide between the display lines that represent a single line of text. The value may have any of the standard forms for screen distances. This option may be overridden with -spacing2 options in tags. [-spacing3 spacing3 Spacing3] Requests additional space below each text line in the widget, using any of the standard forms for screen distances. If a line wraps, this option only applies to the last line on the display. This option may be overridden with -spacing3 options in tags. [-startindex startIndex StartIndex] Specifies an index representing the start of the underlying textual data store that should be contained in the widget. This allows a text widget to reflect only a portion of a larger piece of text. Instead of an index, the empty string can be provided to this configuration option, which will configure the widget to the start index in the textual data store. Instead of an empty string the special index specifier begin can be used. [-startline startLine StartLine] Note that this option is deprecated, option -startindex should be used instead. For compatibility reasons this option still will be supported, but may be removed in a future version.

    Specifies an integer line index representing the first line of the underlying textual data store that should be contained in the widget. This allows a text widget to reflect only a portion of a larger piece of text. Instead of an integer, the empty string can be provided to this configuration option, which will configure the widget to start at the very first line in the textual data store.
[-state state State] Specifies one of three states for the text: normal, disabled, or readonly. If the text is disabled then characters may not be inserted or deleted and no insertion cursor will be displayed, even if the input focus is in the widget. If the state is readonly then characters can be inserted and deleted, but the widget does not receive any modifications from GUI, the user cannot delete or insert, and no insertion cursor will be displayed.

    When hyphenation support is enabled (widget option -hyphens) switching the state to normal is re-displaying the text content without the use of soft hyphens for line break. Switching the state back to readonly, or disabled, is re-displaying the content regarding soft hyphens for possible line breaks.
[-steadymarks steadyMarks SteadyMarks] This option, if activated, will change the behavior of marks. Every mark now behaves simultaneously as an invisible character. One side effect is that the gravity will also apply to the insertion of marks. Another side effect is that every reference specified by a mark now will reference the pseudo-character position of that mark. (But it is important to mention that the real character position count will not be affected.)

    The change of this behavior will apply to all peers of this widget, it's not possible to have a different behavior in different peers.

    This option cannot be set if the widget is not overall clean (see command isclean -overall), an error will be thrown if this is not satisified. (It is not useful to switch this option, or setting this option, if the widget is not overall clean, this may cause errors in the order of the marks, therefore this is forbidden.)

    This option is facilitating programmed editor control, because the shuffle effect is eliminated, every mark now has a defined order relative to other marks, this order is not changing as long as the mark will not be moved with mark set. Note that the handling of marks, especially the change of the gravity, will be performed more efficiently when this option is activated.
[-synctime syncTime SyncTime] Specifies the timeout in milliseconds of the asynchronous line metrics calculation after any change which is affecting the geometry. Note that the calculation will be splitted into short line ranges (except if timeout is zero). The default value is 150 and will be changed only in seldom cases. For most applications this value offers a good responsiveness, and gives the impression of a better performance, compared to the behavior with a low timeout.

    When set to zero the line metrics update will be performed synchronous; this means the whole update will be performed immediately; with most applications this behavior would cause performance problems. When set to 1 the computation is already asynchronous, but the computation starts with each event loop cycle (this may also cause performance problems).
[-tabs tabs Tabs] Specifies a set of tab stops for the window. The option's value consists of a list of screen distances giving the positions of the tab stops, each of which is a distance relative to the left edge of the widget (excluding borders, padding, etc). Each position may optionally be followed in the next list element by one of the keywords left, right, center, or numeric, which specifies how to justify text relative to the tab stop. Left is the default; it causes the text following the tab character to be positioned with its left edge at the tab position. Right means that the right edge of the text following the tab character is positioned at the tab position, and center means that the text is centered at the tab position. Numeric means that the decimal point in the text is positioned at the tab position; if there is no decimal point then the least significant digit of the number is positioned just to the left of the tab position; if there is no number in the text then the text is right-justified at the tab position. For example, creates three tab stops at two-centimeter intervals; the first two use left justification and the third uses center justification.

    If the list of tab stops does not have enough elements to cover all of the tabs in a text line, then Tk extrapolates new tab stops using the spacing and alignment from the last tab stop in the list. Tab distances must be strictly positive, and must always increase from one tab stop to the next (if not, an error is thrown). The value of the -tabs option may be overridden by -tabs options in tags.

    If no -tabs option is specified, or if it is specified as an empty list, then Tk uses default tabs spaced every eight (average size) characters. To achieve a different standard spacing, for example every 4 characters, simply configure the widget with
[-tabstyle tabStyle TabStyle] Specifies how to interpret the relationship between tab stops on a line and tabs in the text of that line. The value must be tabular (the default) or wordprocessor. Note that tabs are interpreted as they are encountered in the text. If the tab style is tabular then the n'th tab character in the line's text will be associated with the n'th tab stop defined for that line. If the tab character's x coordinate falls to the right of the n'th tab stop, then a gap of a single space will be inserted as a fallback. If the tab style is wordprocessor then any tab character being laid out will use (and be defined by) the first tab stop to the right of the preceding characters already laid out on that line. The value of the -tabstyle option may be overridden by -tabstyle options in tags. [-tagging tagging Tagging] Setting the mode how characters will be tagged when inserting text without explicit tagging information.

    The following modes are defined:

    within
        The new text will receive any tags that are present on both before and after the insertion point, regardless whether it's a character (including the invisible newline), a soft hyphen, an embedded window, or an embedded image; if a tag is present on only one of these characters (windows, or images) then it will not be applied to the new text. This is the default tagging mode (and the way how the older versions of the text widget worked).

    gravity
        The new text will receive any tags that are present at one side of the insertion point: if the insert cursor has right gravity then the text will receive the tags of the character after the insertion point (including the invisible newline), otherwise, if the insertion cursor has left gravity, it will receive the tags of the character before the insertion point (Arabian mode), but only if a preceding character exists in this line. This mode is commonly used in some text editors.

    none
        The new text will not receive any tags from surrounded text.
[-undo undo Undo] Specifies a boolean that says whether the undo mechanism is active or not. [-undotagging undoTagging UndoTagging] This boolean value specifies the setup value for -undo option when creating tags. Per default the setup value is true. Note that this value will not be used for the special tag sel. See description of tag option -undo for more information. [-width width Width] Specifies the desired width for the window in units of characters in the font given by the -font option. If the font does not have a uniform width then the width of the character is used in translating from character units to screen units. [-useunibreak useUniBreak UseUniBreak] If this option is enabled then wrap mode codepoint (see option -wrap) will use the external library libunibreak (from Wu Yongwei) for the computation of line breaks, but only if this library is available (currently only UNIX). This library even supports language dependent line breaking. Otherwise, if this option is not enabled, or if libunibreak is not available, a simpler algorithm (also based on the recommendations of the Unicode consortium, but restricted to Latin-1 and most non-language dependent characters, without regarding combined marks, and without language support) will be used for the computation of the breaks. Per default this option is not enabled.

    For a simple test whether the unibreak libary is available see command brks.
[-wrap wrap Wrap] Specifies how to handle lines in the text that are too long to be displayed in a single line of the text's window. The value must be none, char, word, or codepoint. A wrap mode of none means that each line of text appears as exactly one line on the screen; extra characters that do not fit on the screen are not displayed. In the other modes each line of text will be broken up into several screen lines if necessary to keep all the characters visible. In char mode a screen line break may occur after any character; in word mode a line break will only be made at word boundaries. The elaborated mode codepoint is based on Unicode code points, and conforms exactly (with libunibreak) or mostly (with internal algorithm) to the recommendations of the Unicode consortium. If option -useunibreak is set, then the unibreak library (from Wu Yongwei) will be used for the line break computation. This library even supports language dependent line breaking (see option -lang for language support). Otherwise, if -useunibreak is not set, or if the unibreak library is not available, a simpler algorithm - also based on the recommendations of the Unicode consortium, but restricted to Latin-1 and most non-language dependent characters, without regarding combined marks, and without language support - will be used for the computation of the breaks.

DESCRIPTION

The text command creates a new window (given by the pathName argument) and makes it into a text widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the text such as its default background color and relief. The text command returns the path name of the new window.

A text widget displays one or more lines of text and allows that text to be edited. Text widgets support four different kinds of annotations on the text, called tags, marks, embedded windows or embedded images. Tags allow different portions of the text to be displayed with different fonts and colors. In addition, Tcl commands can be associated with tags so that scripts are invoked when particular actions such as keystrokes and mouse button presses occur in particular ranges of the text. See TAGS below for more details.

The second form of annotation consists of floating markers in the text called Marks are used to keep track of various interesting positions in the text as it is edited. See MARKS below for more details.

The third form of annotation allows arbitrary windows to be embedded in a text widget. See EMBEDDED WINDOWS below for more details.

The fourth form of annotation allows Tk images to be embedded in a text widget. See EMBEDDED IMAGES below for more details.

The text widget also has a built-in undo/redo mechanism. See THE UNDO MECHANISM below for more details.

The text widget allows for the creation of peer widgets. These are other text widgets which share the same underlying data (text, marks, tags, images, etc). See PEER WIDGETS below for more details.

INDICES

Many of the widget commands for texts take one or more indices as arguments. An index is a string 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. Most modifiers (as documented below) allow an optional submodifier. Valid submodifiers are any and display. If the submodifier is abbreviated, then it must be followed by whitespace, but otherwise there need be no space between the submodifier and the following modifier. Typically the display submodifier adjusts the meaning of the following modifier to make it refer to visual or non-elided units rather than logical units, but this is explained for each relevant case below. Lastly, where count is used as part of a modifier, it can be positive or negative, so is perfectly valid (and equivalent to

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, and if char is begin then it refers the first character at start of 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.

begin
    Indicates the start of the text (the character just at the start of the first line).

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 (see MARKS for details).

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.

tag.current.first
    Indicates the first character in the region (a connected span of text sharing the same tag) nearby the current mark (it is left from, right from, or inside the tagged region) that has been tagged with tag. This form generates an error if no character is currently tagged with tag nearby the current mark.

tag.current.last
    Indicates the character just after the last one in the region (a connected span of text sharing the same tag) nearby the current mark (it is left from, right from, or inside the tagged region) that has been tagged with tag. This form generates an error if no character is currently tagged with tag nearby the current mark.

pathName
    Indicates the position of the embedded window whose name is pathName. This form generates an error if there is no embedded window by the given name.

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 have one of the forms listed below. Keywords such as chars and wordend may be abbreviated as long as the abbreviation is unambiguous.

+ count ?submodifier? 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 index in the text. Spaces on either side of count are optional. If the display submodifier is given, elided characters are skipped over without being counted. If any is given, then all characters are counted.

- count ?submodifier? 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 index in the text (1.0). Spaces on either side of count are optional. If the display submodifier is given, elided characters are skipped over without being counted. If any is given, then all characters are counted.

+ count ?submodifier? indices
    Adjust the index forward by count index positions, moving to later lines in the text if necessary. If there are fewer than count index positions in the text after the current index, then set the index to the last index position in the text. Spaces on either side of count are optional. Note that an index position is either a single character or a single embedded image or embedded window. If the display submodifier is given, elided indices are skipped over without being counted. If any is given, then all indices are counted; this is also the default behavior if no modifier is given.

- count ?submodifier? indices
    Adjust the index backward by count index positions, moving to earlier lines in the text if necessary. If there are fewer than count index positions in the text before the current index, then set the index to the first index position (1.0) in the text. Spaces on either side of count are optional. If the display submodifier is given, elided indices are skipped over without being counted. If any is given, then all indices are counted; this is also the default behavior if no modifier is given.

+ count ?submodifier? lines
    Adjust the index forward by count lines, retaining the same 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 position on the last line of the text. Then, if the line is not long enough to contain a character at the indicated position, adjust the character position to refer to the last character of the line (the newline). Spaces on either side of count are optional.

    If the display submodifier is given, then each visual display line is counted separately, and in this case the position is determined by the current pixel position.

    Otherwise, if any (or no modifier) is given, then each logical line (no matter how many times it is visually wrapped) counts just once, and the position is determined by the character position.

- count ?submodifier? lines
    Adjust the index backward by count logical lines, retaining the same 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 position on the first line of the text. Then, if the line is not long enough to contain a character at the indicated position, adjust the character position to refer to the last character of the line (the newline). Spaces on either side of count are optional.

    If the display submodifier is given, then each visual display line is counted separately, and in this case the character position is determined by the current pixel position.

    Otherwise, if any (or no modifier) is given, then each logical line (no matter how many times it is visually wrapped) counts just once, and the character position is determined by the index position.

?submodifier? linestart
    Adjust the index to refer to the first index on the line. If the display submodifier is given, this is the first index on the display line, otherwise on the logical line.

?submodifier? lineend
    Adjust the index to refer to the last index on the line (the newline). If the display submodifier is given, this is the last index on the display line, otherwise on the logical line.

?submodifier? 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. If the display submodifier is given, this only examines non-elided characters, otherwise all characters (elided or not) are examined.

?submodifier? 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 the display submodifier is given, this only examines non-elided characters, otherwise all characters (elided or not) are examined.

If more than one modifier is present then they are applied in left-to-right order. For example, the index refers to the next-to-last character in the text and refers to the character just before the first one in the word containing the insertion cursor. Modifiers are applied one by one in this left to right order, and after each step the resulting index is constrained to be a valid index in the text widget. So, for example, the index refers to the index

Where modifiers result in index changes by display lines, display chars or display indices, and the base refers to an index inside an elided tag, that base index is considered to be equivalent to the first following non-elided index.

TAGS

The first form of annotation in text widgets is a tag. A tag is a textual string that is associated with some of the characters in a text. Tags may contain arbitrary characters, but it is probably best to avoid using the characters (space), or these characters have special meaning in indices, so tags containing them cannot be used as indices. There may be any number of tags associated with characters in a text. Each tag may refer to a single character, a range of characters, or several ranges of characters. An individual character may have any number of tags associated with it.

A priority order is defined among tags, and this order is used in implementing some of the tag-related functions described below. When a tag is defined (by associating it with characters or setting its display options or binding commands to it), it is given a priority higher than any existing tag. The priority order of tags may be redefined using the and widget commands.

Tags serve three purposes in text widgets. First, they control the way information is displayed on the screen. By default, characters are displayed as determined by the -background, -font, and -foreground options for the text widget. However, display options may be associated with individual tags using the widget command. If a character has been tagged, then the display options associated with the tag override the default display style. The following options are currently supported for tags:

-background color
    Color specifies the background color to use for characters associated with the tag. It may have any of the forms accepted by Tk_GetColor.

-bgstipple bitmap
    Bitmap specifies a bitmap that is used as a stipple pattern for the background. It may have any of the forms accepted by Tk_GetBitmap. If bitmap has not been specified, or if it is specified as an empty string, then a solid fill will be used for the background.

-borderwidth pixels
    Pixels specifies the width of a border to draw around the tag using any of the forms accepted by Tk_GetPixels. This option should be used in conjunction with the -relief option to provide the desired border.

-elide boolean
    Elide specifies whether the data should be elided. Elided data (characters, soft hyphens, images, embedded windows, etc) is not displayed and takes no space on screen, but further on behaves just as normal data. An empty string (instead of a boolean value) is clearing the elide option of this tag. It is not allowed to set this option with the special selection tag sel.

-eolcolor color
    Specifies the foreground color to use when displaying the end of line symbol inside the tagged region. An empty argument will force the use of the foreground color (set with -foreground; this is the default).

-fgstipple bitmap
    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 accepted by Tk_GetBitmap. If bitmap has not been specified, or if it is specified as an empty string, then a solid fill will be used.

-font fontName
    FontName is the name of a font to use for drawing characters. It may have any of the forms accepted by Tk_GetFont.

-foreground color
    Color specifies the color to use when drawing text and other foreground information such as underlines. It may have any of the forms accepted by Tk_GetColor.

-hyphencolor color
    Specifies the foreground color to use when displaying the soft hyphen character (U+00AD) inside the tagged region. An empty argument will force the use of the foreground color (set with -foreground; this is the default).

-hyphenrules rules
    Specifies a list of spelling change rules for hyphenated words, specified by the identifier of the rules. Only the rules given with this set will be used for spelling changes. The rules will be applied in the given order of this list. Per default the set of rules is empty. An exception will be thrown if one of the given rules is not defined.

    This tag option overrules the global option -hyphenrules, this means that the global rules will be applied only to hyphens without tagged rules.

    For the definition of hyphenation rules see widget option -hyphenrules.

-inactivebackground color
    Color specifies the background color to use for characters associated with the tag, when the window does not have the focus. It may have any of the forms accepted by Tk_GetColor. If specified then it will overrule the -background option of the sel tag, provided that the actual tag has a higher priority.

-inactiveforeground color
    Color specifies the color to use when drawing text and other foreground information such as underlines, when the window does not have the focus. It may have any of the forms accepted by Tk_GetColor. If specified then it will overrule the -foreground option of the sel tag, provided that the actual tag has a higher priority.

-inactiveselectbackground color
    Color specifies the background color to use when displaying selected items, when the window does not have the focus. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color specified by the -selectbackground tag option is used. If specified then it will overrule the -inactivebackground option of the sel tag, provided that the actual tag has a higher priority.

-inactiveselectforeground color
    Color specifies the foreground color to use when displaying selected items, when the window does not have the focus. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color specified by the -selectforeground tag option is used. If specified then it will overrule the -inactiveforeground option of the sel tag, provided that the actual tag has a higher priority.

-indentbackground boolean
    If true then the background, set with -background tag option, will be indented according to the -lmargin1, and -lmargin2 tag options. This has the (intended) side effect that hovering the margin (left from indented text) will not trigger events.

-justify justify
    If the first non-elided 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, full, or center. If a line wraps, then the justification for each line on the display is determined by the first non-elided character of that display line.

-lang code
    Setting the language code of the text content inside the tagged region. If this tag option is specified, it overrides the -lang option for the text widget. For a detailed description of this option see widget option -lang.

-lmargin1 pixels
    If the first non-elided 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.

-lmargin2 pixels
    If the first non-elided 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.

-lmargincolor color
    Color specifies the background color to use in regions that do not contain characters because they are indented by -lmargin1 or -lmargin2. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color used is specified by the -background tag option (or, if this is also unspecified, by the -background widget option).

-offset pixels
    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.

-overstrike boolean
    Specifies whether or not to draw a horizontal rule through the middle of characters. Boolean may have any of the forms accepted by Tcl_GetBoolean.

-overstrikecolor color
    Color specifies the color to use when displaying the overstrike. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color specified by the -foreground tag option is used.

-overstrikefg color
    Note that this option is deprecated, option -overstrikecolor should be used instead. For compatibility reasons this option still will be supported, but may be removed in a future version. See equivalent tag option -overstrikecolor for a description.

-relief relief
    Relief specifies the relief style to use for drawing the border, in any of the forms accepted by Tk_GetRelief. This option is used in conjunction with the -borderwidth option to enable to the desired border appearance.

-rmargin pixels
    If the first non-elided 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 non-elided character of that display line.

-rmargincolor color
    Color specifies the background color to use in regions that do not contain characters because they are indented by -rmargin. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color used is specified by the -background tag option (or, if this is also unspecified, by the -background widget option).

-selectbackground color
    Color specifies the background color to use when displaying selected items. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color specified by the -background tag option is used.

-selectforeground color
    Color specifies the foreground color to use when displaying selected items. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color specified by the -foreground tag option is used.

-spacing1 pixels
    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.

-spacing2 pixels
    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.

-spacing3 pixels
    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.

-tabs tabList
    TabList specifies a set of tab stops in the same form as for the -tabs option for the text widget. This option only applies to a display line if it applies to the first non-elided 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 -tabs widget option.

-tabstyle style
    Style specifies either the tabular or wordprocessor style of tabbing to use for the text widget. This option only applies to a display line if it applies to the first non-elided 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).

-underline boolean
    Boolean specifies whether or not to draw an underline underneath characters. It may have any of the forms accepted by Tcl_GetBoolean.

-underlinecolor color
    Color specifies the color to use when displaying the underline. It may have any of the forms accepted by Tk_GetColor. If color has not been specified, or if it is specified as an empty string, then the color specified by the -foreground tag option is used.

-underlinefg color
    Note that this option is deprecated, option -underlinecolor should be used instead. For compatibility reasons this option still will be supported, but may be removed in a future version. See equivalent tag option -underlinecolor for a description.

-undo boolean
    Specifies whether adding/removing this tag to/from text will be undone with undo operation. If this flag is false, then changes of tag associations will not be undone for this tag. The default is given with text option -undotagging (normally true), except for the special selection flag sel, the default for this tag is always false.

-wrap mode
    Mode specifies how to handle lines that are wider than the text's window. This option only applies to a display line if it applies to the first non-elided character on that display line. It has the same legal values as the -wrap option for the text widget: none, char, word, or codepoint. If this tag option is specified, it overrides the -wrap option for the text widget.

If a character has several tags associated with it, and if their display options conflict, then the options of the highest priority tag are used. If a particular display option has not been specified for a particular tag, or if it is specified as an empty string, then that option will never be used; the next-highest-priority tag's option will used instead. If no tag specifies a particular display option, then the default style for the widget will be used.

The second purpose for tags is event bindings. You can associate bindings with a tag in much the same way you can associate bindings with a widget class: whenever particular X events occur on characters with the given tag, a given Tcl command will be executed. Tag bindings can be used to give behaviors to ranges of characters; among other things, this allows hypertext-like features to be implemented. For details, see the description of the widget command below. Tag bindings are shared between all peer widgets (including any bindings for the special sel tag).

The third use for tags is in managing the selection. See THE SELECTION below. With the exception of the special sel tag, all tags are shared between peer text widgets, and may be manipulated on an equal basis from any such widget. The sel tag exists separately and independently in each peer text widget (but any tag bindings to sel are shared).

MARKS

The second form of annotation in text widgets is a mark. The name of a mark may contain arbitrary characters, but it is probably best to avoid using the characters (space), or these characters have special meaning in indices. Marks are used for remembering particular places in a text. They are something like tags, in that they have names and they refer to places in the file, but a mark is not associated with particular characters. Instead, a mark is associated with the gap between two characters. Only a single position may be associated with a mark at any given time. If the characters around a mark are deleted the mark will still remain; it will just have new neighbor characters. In contrast, if the characters containing a tag are deleted then the tag will no longer have an association with characters in the file. Marks may be manipulated with the widget command, and their current locations may be determined by using the mark name as an index in widget commands.

Each mark also has a which is either left or right. The gravity for a mark specifies what happens to the mark when text is inserted at the point of the mark. If a mark has left gravity, then the mark is treated as if it were attached to the character on its left, so the mark will remain to the left of any text inserted at the mark position. If the mark has right gravity, new text inserted at the mark position will appear to the left of the mark (so that the mark remains rightmost). The gravity for a mark defaults to right.

The name space for marks is different from that for tags: the same name may be used for both a mark and a tag, but they will refer to different things.

Two marks have special significance. First, the mark insert is associated with the insertion cursor, as described under THE INSERTION CURSOR below. Second, the mark current is associated with the character closest to the mouse and is adjusted automatically to track the mouse position and any changes to the text in the widget (one exception: current is not updated in response to mouse motions if a mouse button is down; the update will be deferred until all mouse buttons have been released). Neither of these special marks may be deleted. With the exception of these two special marks, all marks are shared between peer text widgets, and may be manipulated on an equal basis from any peer.

Generated marks (created with command mark generate) have a special meaning. They will be discarded by the undo mechanism (relevant only if widget option -steadymarks is enabled). Furthermore these marks are only command dump is showing generated marks, the commands mark names, mark next, and mark previous, cannot generated marks.

EMBEDDED WINDOWS

The third form of annotation in text widgets is an embedded window. Each embedded window annotation causes a window to be displayed at a particular point in the text. There may be any number of embedded windows in a text widget, and any widget may be used as an embedded window (subject to the usual rules for geometry management, which require the text window to be the parent of the embedded window or a descendant of its parent).

The embedded window's position on the screen will be updated as the text is modified or scrolled, and it will be mapped and unmapped as it moves into and out of the visible area of the text widget. Each embedded window occupies one unit's worth of index space in the text widget, and it may be referred to either by the name of its embedded window or by its position in the widget's index space. If the range of text containing the embedded window is deleted, and this range is not saved on undo stack, then the window is destroyed. Similarly if the text widget as a whole is deleted, then the window is destroyed. If this automatic destroy behavior is not wanted then option -owner should be set accordingly.

Eliding an embedded window immediately after scheduling it for creation via pathName window create index -create will prevent it from being effectively created. Uneliding an elided embedded window scheduled for creation via pathName window create index -create will automatically trigger the associated creation script. After destroying an elided embedded window, the latter won't get automatically recreated.

When an embedded window is added to a text widget with the pathName window create widget command, several configuration options may be associated with it. These options may be modified later with the pathName window configure widget command. The following options are currently supported:

-align where
    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).

-create script
    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. Two substitutions will be performed in script before evaluation. %W will be substituted by the name of the parent text widget, and %% will be substituted by a single %. If the annotation's window should ever be deleted, script will be evaluated again the next time the annotation is displayed.

-owner boolean
    If true then the text widget is the owner of the embedded window. Only if it is the owner the window will be destroyed if the range of text containing the embedded window is deleted, and the deleted text is not saved on undo stack. Per default this option is true. Setting this option to false should be done with care, because in this case the text widget is not responsible for the lifetime of the embedded window.

-padx pixels
    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.

-pady pixels
    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.

-stretch boolean
    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.

-tags tagList
    Specifies a set of tags to apply to the embedded window. TagList consists of a list of tag names, which replace any existing tags for the embedded window. TagList may be an empty list. Note that it is not possible to add or remove the special selection tag sel, it will be left untouched with this option.

-window pathName
    Specifies the name of a window to display in the annotation. Note that if a pathName has been set, then later configuring a window to the empty string will not delete the widget corresponding to the old pathName. Rather it will remove the association between the old pathName and the text widget. If multiple peer widgets are in use, it is usually simpler to use the -create option if embedded windows are desired in each peer.

EMBEDDED IMAGES

The final form of annotation in text widgets is an embedded image. Each embedded image annotation causes an image to be displayed at a particular point in the text. There may be any number of embedded images in a text widget, and a particular image may be embedded in multiple places in the same text widget.

The embedded image's position on the screen will be updated as the text is modified or scrolled. Each embedded image occupies one unit's worth of index space in the text widget, and it may be referred to either by its position in the widget's index space, or the name it is assigned when the image is inserted into the text widget with pathName image create. If the range of text containing the embedded image is deleted then that copy of the image is removed from the screen.

Eliding an embedded image immediately after scheduling it for creation via pathName image create index -create will prevent it from being effectively created. Uneliding an elided embedded image scheduled for creation via pathName image create index -create will automatically trigger the associated creation script. After destroying an elided embedded image, the latter won't get automatically recreated.

When an embedded image is added to a text widget with the pathName 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 text 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 pathName image configure.

When an embedded image is added to a text widget with the pathName image create widget command, several configuration options may be associated with it. These options may be modified later with the pathName image configure widget command. The following options are currently supported:

-align where
    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).

-image image
    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.

-name ImageName
    Specifies the name by which this image instance may be referenced in the text 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.

-padx pixels
    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.

-pady pixels
    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.

-tags tagList
    Specifies a set of tags to apply to the embedded image. TagList consists of a list of tag names, which replace any existing tags for the embedded image. TagList may be an empty list. Note that it is not possible to add or remove the special selection tag sel, it will be left untouched with this option.

EXTRA FUNCTIONS

  MERGE RANGE

NAME
    tk_mergeRange - insert/merge a given range into a sorted list of ranges.

SYNOPSYS
    tk_mergeRange varName range

DESCRIPTION
    This procedure is inserting range into a sorted list of ranges, given with varName. If given range is adjacent to, or intersecting a range in given list, then it will be amalgamated. This means that the result is a sorted list of disjoint ranges. This procedure return the new content of varName.

  INSERT TEXT

NAME
    tk_textInsert - insert characters into a text widget regarding soft hyphen pattern.

SYNOPSYS
    tk_textInsert pathName ?-hyphentags tagList? index chars ?tagList chars tagList ...?

DESCRIPTION
    This procedure is especially supporting the predefined spelling changes (see section HYPHENATION RULES).

    The procedure tk_textInsert inserts all of the chars arguments just before the character at index in the specified text widget, see command insert of the text widget for a detailed description. This procedure will pre-parse the chars arguments before it calls command insert of pathName for the execution of the insertion. The parser is recognizing the following escape sequences:

    •   The sequence will be replaced by the soft hyphen character. Example: will hyphenate into

    •   The sequence will be replaced by the soft hyphen character, and, provided that no tagged list of rules is given (in tagList), a special tag with all known hyphen rules (regarding option -lang) will be attached to this hyphen (this means that all known hyphenation rules will be applied to this hyphen - probably restricted by option -lang).

    •   The sequence - RULE is the identifier for a defined hyphenation rule (see section HYPHENATION RULES) - will be replaced with a soft hyphen, and applies a tag with the specified hyphenation rule RULE to this soft hyphen character. An error will be thrown if the specified rule is not defined, or if the trailing colon is missing.

    •   Any other escaped character (not nor nor ) will be replaced by this character; this means that the former escape character will be removed.

    The latter case is required to allow the escape character inside a string - it has to be doubled - otherwise an unambiguous identification is not possible. Example: the character string will be interpreted as (a string), but the character string will be interpreted as soft hyphen character. (Please note that all the statements about the escape character are related to the list notation, inside the string notation every escape character has to be doubled.)

    It is allowed to abbreviate all rules with a two-letter code:

    •   :ck: is already an abbreviation

    •   :dd: is :doubledigraph:

    •   :dv: is :doublevowel:

    •   :ge: is :gemination:

    •   :tc: is :tripleconsonant:

    •   :tr: is :trema:

    •   :rh: is :repeathyphen:

    If option -hyphentags is specified then the associated tagList will additionally be associated with all soft hyphens in new text; combined with the inherited tags, or the specified tags. This is especially useful for hiding/showing soft hyphens (see tag option -elide).

  REBIND MOUSE WHEEL EVENT

NAME
    tk_textRebindMouseWheel - rebind the mouse wheel event.

SYNOPSYS
    tk_textRebindMouseWheel pathName ?pathName ...?

DESCRIPTION
    This procedure provides a portable way to rebind the mouse wheel events of embedded windows, so that the text widget will receive the events, as if the embedded windows are transparent for mouse wheel events. Without rebinding only the embedded window may receive the mouse wheel events, this might break the expected scroll behavior of the text widget.

    The first pathName is the receiver of the mouse wheel events, i.e. the text widget which contains the embedded windows. If no further argument is specified, then all currently embedded windows will be rebound. Otherwise only the specified embedded windows, starting with the second provided argument, will be rebound.

  REPLACE TEXT

NAME
    tk_textReplace - replace a range of characters inside a text widget regarding soft hyphen pattern.

SYNOPSYS
    tk_textReplace pathName ?-hyphentags tagList? index chars ?tagList chars tagList ...?

DESCRIPTION
    This procedure is especially supporting the predefined spelling changes (see section HYPHENATION RULES).

    The procedure tk_textReplace replaces the range of characters between index1 and index2, see command replace for a detailed description. This procedure will pre-parse the chars arguments before it calls command replace of pathName for the execution of the replacement. The parser is recognizing the escape sequences and see procedure tk_textInsert which works in a similar way.

    If option -hyphentags is specified then the associated tagList will additionally be associated with all soft hyphens in new text; combined with the inherited tags, or the specified tags. This is especially useful for hiding/showing soft hyphens (see tag option -elide).

HYPHENATION RULES

The rules are:

[1] In natural (pre-reform) German orthography, a before the hyphenation point can change into a hyphenates into This spelling change will be called ck rule.

[2] In modern Dutch, an e-diaeresis after the hyphenation point can change into a simple : hyphenates into This also applies for i-diaeresis, o-diaeresis, and u-diaeresis. This spelling change will be called trema rule.

[3] In German, Norwegian, and Swedish, a triple consonant can change into a double consonant: Swedish becomes when not hyphenated, Norwegian becomes and German becomes (in pre-reform orthography). This spelling change will be called tripleconsonant rule. (Note that is a reverse rule, applied when a word will not be hyphenated at this point).

[4] In Dutch, a letter can disappear inside a doubled vowel: hyphenates into In case of an double it will change to the corresponding vowel with accute, for example becomes This spelling change will be called doublevowel rule.

[5] Hungarian has an unusual hyphenation case which involves reinsertion of a root-letter, as in the following example: becomes These special cases, occurring when the characters are in the middle of a word are: becomes becomes becomes becomes becomes becomes becomes This rule is named doubledigraph.

[6] In Catalan, a geminated consonant can be split: the word hyphenates into The name for this rule is gemination.

[7] In Polish the hyphen will be repeated after line break, this means for example that becomes The name of this rule is repeathyphen.

Applying hyphenation rule RULE (which may result into spelling changes) will be done automatically in the following cases:

[1] The hyphen is tagged with hyphenation rule RULE (tag option -hyphenrules includes RULE).

[2] The widget option -hyphenrules contains rule RULE, and no tag (attached to this hyphen) is overruling.

INSERTING TEXT WITH SOFT HYPHENS

When spelling changes are involved it might be convenient to use the helper functions tk_textInsert and tk_textReplace. These functions are providing a simple way to insert hyphenated text regarding the spelling changes based on rules. Example:

tk_textInsert end .t "Nach dem Ein\\-le\\-gen des Pa\\-piers soll\\-ten\
    die Druc\\+ker\\-ein\\-stel\\-lun\\-gen über\\-prüft wer\\-den."

This text in German may be hyphenated and displayed in the following way:

Nach dem Einlegen des Papiers sollten die Druk- kereinstellungen überprüft werden.

Second example:

tk_textInsert end .t "Nach dem Ein\\-le\\-gen des Pa\\-piers soll\\-ten\
    die Druc\\:ck:ker\\-ein\\-stel\\-lun\\-gen über\\-prüft wer\\-den."

This gives the same result, but here the ck rule is explictly specified.

tk_textInsert end .t "Nach dem Ein\\+le\\+gen des Pa\\+piers soll\\+ten\
    die Druc\\+ker\\+ein\\+stel\\+lun\\+gen über\\+prüft wer\\+den."

This will also give the same result, because only the ck rule will be detected for spelling changes.

tk_textInsert end .t "Nach dem Ein\\-le\\-gen des Pa\\-piers soll\\-ten\
    die Druc\\-ker\\-ein\\-stel\\-lun\\-gen über\\-prüft wer\\-den." ck .t tag configure ck -hyphenrules {ck}

The same result as before, because the ck rule is applied explictly (to all soft hyphens).

tk_textInsert end .t {Nach dem Ein\-le\-gen des Pa\-piers soll\-ten\
    die Druc\-ker\-ein\-stel\-lun\-gen über\-prüft wer\-den.} trema .t tag configure trema -hyphenrules {trema}

In this case only the trema rule will be applied to the text - the ck rule is missing - thus we cannot get here the correct result, this text may be (wrongly) hyphenated in the following way:

Nach dem Einlegen des Papiers sollten die Druc- kereinstellungen überprüft werden.

The explicit specification of the hyphenation rule is the preferred method (second example), however it depends on the quality of the hyphenator which method will be used. For instance, the TeX hyphenator does not know about spelling changes, and here the method with the use of (for any hyphenation point like in the third example) may give fairly good results. Of course, the use of is (currently) only useful for the languages Catalan, Dutch, German, Hungarian, Norwegian, Polish, and Swedish.

THE SELECTION

Selection support is implemented via tags. If the -exportselection option for the text widget is true then the sel tag will be associated with the selection:

[1] Whenever characters are tagged with sel the text widget will claim ownership of the selection.

[2] Attempts to retrieve the selection will be serviced by the text widget, returning all the characters with the sel tag.

[3] If the selection is claimed away by another application or by another window within this application, then the sel tag will be removed from all characters in the text.

[4] Whenever the sel tag range changes a virtual event <<Selection>> is generated. It might also be generated when selection is affected but not actually changed. Further, multiple selection changes could happen before events can be processed leading to multiple events with the same visible selection.

The sel tag is automatically defined when a text widget is created, and it may not be deleted with the widget command. Furthermore, the -selectbackground, -selectborderwidth, -selectforeground, -inactiveselectbackground, -inactiveselectforeground, and -selectborderwidth options for the text widget are tied to the -background, -borderwidth, -foreground, -inactiveselectbackground, -inactiveselectforeground, and -borderwidth options for the sel tag: changes in either will automatically be reflected in the other. This allows programmatic control over the visualization of the sel tag for foreground and background windows, or to have sel not shown at all for background windows. Each peer text widget has its own sel tag which can be separately configured and set.

The sel tag is overruling all other tags, except if a tag with higher priority has explicitly defined the selection attributes (-selectbackground and -selectforeground if the window is active; -inactiveselectbackground and -inactiveselectforeground if the window is inactive).

Note the specific behavior if -inactiveselectbackground is not defined (empty): if the window does not have the focus, then the selection attributes of the text widget and all the attributes of the sel tag will not be regarded; this means that in general no selection will be shown, this is the default behavior on Windows.

Note the specific behavior on Mac: if the window does not have the focus, and does not have state normal (see widget option -state), then the selection attributes of the text widget and all the attributes of the sel tag will not be regarded; this means that per default no selection will be shown.

THE INSERTION CURSOR

The mark named insert has special significance in text widgets. It is defined automatically when a text widget is created and it may not be unset with the widget command. The insert mark represents the position of the insertion cursor, and the insertion cursor will automatically be drawn at this point whenever the text widget has the input focus.

The cursor shape (vertical line or rectangular block) can be specified with option -blockcursor. But note that in general the block cursor is useful only if also the options -showendofline and -showendoftext are enabled (otherwise the cursor handling is unsatisfying). With a block cursor the optimal width (option -insertwidth) is 2, and with a bar cursor (vertical line) the optimal width is 2 as well, or even 1 if the cursor is blinking. When disabling the blinking, or when setting a block cursor shape, it is recommended to specify the cursor width (option -insertwidth) explicitly. Of course, in most cases the default settings for the cursor will be preferred.

THE MODIFIED FLAG

The text widget can keep track of changes to the textual content of the widget by means of the modified flag. Inserting or deleting text will set this flag. The flag can be queried, set and cleared programmatically as well. Whenever the flag changes state a <<Modified>> virtual event is generated. See the pathName edit modified widget command for more details.

THE ALTERED FLAG

It's possible to keep track of any change which has an affect on text content, even if only the representation is affected. Also any change in tag associations will be seen as a change in the representation. If option -steadymarks is enabled, also the mark operations may have effects on the text content (although indirectly). Whenever the flag changes state a <<Altered>> virtual event is generated. See the pathName edit altered widget command for more details.

THE IRREVERSIBLE FLAG

As a supplement to the flag also the flag is provided. This flag informs whether the original content (before any modification/operation has been performed) can be restored. Whenever the state of this flag is changing, the virtual event <<Irreversible>> is fired. For more details see the pathName edit irreversible widget command.

THE UNDO MECHANISM

The text widget has an unlimited undo and redo mechanism (when the -undo widget option is true) which records every insert and delete action on a stack, including the insertion and deletion of embedded windows and embedded images. Furthermore any change of tag associations will be recorded. If option -steadymarks is enabled even operations on marks will push an undo operation on the stack.

Boundaries (called are inserted between edit actions. The purpose of these separators is to group inserts, deletes and replaces into one compound edit action. When undoing a change everything between two separators will be undone. The undone changes are then moved to the redo stack, so that an undone edit can be redone again. The redo stack is cleared whenever new edit actions are recorded on the undo stack. The undo and redo stacks can be cleared to keep their depth under control.

Separators are inserted automatically when the -autoseparators widget option is true. You can insert separators programmatically as well. If a separator is already present at the top of the undo stack no other will be inserted. That means that two separators on the undo stack are always separated by at least one undoable action.

The <<UndoStack>> virtual event is generated every time the undo stack or the redo stack is changing.

The undo mechanism is also linked to the and flag. This means that undoing or redoing changes can take a modified/altered text widget back to the unmodified/unaltered state or vice versa. The modified/altered flag will be set automatically to the appropriate state. The automatic coupling of the flag does not work when the flag has been set by the user, until the flag has been reset again.

See below for the pathName edit widget command that controls the undo mechanism.

PEER WIDGETS

The text widget has a separate store of all its data concerning each line's textual contents, marks, tags, images and windows, and the undo stack.

While this data store cannot be accessed directly (i.e. without a text widget as an intermediary), multiple text widgets can be created, each of which present different views on the same underlying data. Such text widgets are known as peer text widgets.

As text is added, deleted, edited and coloured in any one widget, and as images, marks, tags are adjusted, all such changes will be reflected in all peers.

All data and markup is shared, except for a few small details. First, the sel tag may be set and configured (in its display style) differently for each peer. Second, each peer has its own insert and current mark positions (but all other marks are shared). Third, embedded windows, which are arbitrary other widgets, cannot be shared between peers. This means the -window option of embedded windows is independently set for each peer (it is advisable to use the -create script capabilities to allow each peer to create its own embedded windows as needed). Fourth, all of the configuration options of each peer (e.g. -font, etc) can be set independently, with the exception of -undo, -maxundo, -maxundosize, -maxredo, -autoseparators (i.e. all undo, redo and modified state issues are shared). Also option -steadymarks cannot be set independently.

Finally any single peer need not contain the whole content from the underlying data store. When creating a peer, a contiguous range (e.g. only range through ) may be specified. This allows a peer to contain just a small portion of the overall text. The range will expand and contract as text is inserted or deleted. If the peer's contents contracts to nothing (i.e. the start of the content is after last newline, as a result of a deletion from another widget), then it is impossible for new content to be inserted. The peer will simply become an empty shell (dead peer) on which the background can be configured, but which will never show any content (without manual reconfiguration of the start and end range). Note that a peer which does not contain all of the underlying data store still has indices numbered from to It is simply that those indices reflect a subset of the total data, and data outside the contained range is not accessible to the peer. This means that the command peerName index end may return quite different values in different peers. Similarly, commands like peerName tag ranges will not return index ranges outside that which is meaningful to the peer. The configuration options -startindex and -endindex may be used to control how much of the underlying data is contained in any given text widget.

Note that peers are really peers. Deleting the text widget will not cause any other peers to be deleted, or otherwise affected.

See below for the pathName peer widget command that controls the creation of peer widgets.

ASYNCHRONOUS UPDATE OF LINE HEIGHTS

In order to maintain a responsive user-experience, the text widget calculates lines metrics (line heights in pixels) asynchronously. Because of this, some commands of the text widget may return wrong results if the asynchronous calculations are not finished at the time of calling. This applies to pathName count -ypixels and pathName yview.

Again for performance reasons, it would not be appropriate to let these commands always wait for the end of the update calculation each time they are called. In most use cases of these commands a more or less inaccurate result does not really matter compared to execution speed.

In case accurate result is needed (and if the text widget is managed by a geometry manager), one can resort to pathName sync and pathName pendingsync to control the synchronization of the view of text widgets. Alternatively, in very special cases (in general this would cause performance problem), setting widget option -synctime to zero provides accurate results at any time.

The <<WidgetViewSync>> virtual event fires when the line heights of the text widget become obsolete (due to some editing command or configuration change), and again when the internal data of the text widget are back in sync with the widget view. The detail field (%d substitution) is either true (when the widget is in sync) or false (when it is not).

pathName sync, pathName pendingsync and <<WidgetViewSync>> apply to each text widget independently of its peers.

  EXAMPLES OF USE

This immediately completes line metrics at any cost; the GUI unresponsive while this is occurring:

$w sync $w yview moveto $fraction

This synchronously waits for up-to-date line metrics (but with the GUI responsive) before executing the scheduled command, but does not block execution flow:

$w sync -command [list $w yview moveto $fraction]

This synchronously waits for up-to-date line metrics while keeping the GUI responsive:

# init set yud($w) 0 proc updateaction w {
    set ::yud($w) 1
    # any other update action here... } # runtime $w sync -command [list updateaction $w] vwait yud($w) $w yview moveto $fraction

This is an extension of the previous example with a list of actions to perform once the synchronization is completed.

# init set todo($w) {} proc updateaction w {
    foreach cmd $::todo($w) {uplevel #0 $cmd}
    set todo($w) {} } # runtime lappend todo($w) [list $w yview moveto $fraction] $w sync -command [list updateaction $w]

This detects whether a synchronization is pending, and if so just postpones the code until that synchronization is done, detecting that happening with a virtual event.

# init set todo($w) {} bind $w <<WidgetViewSync>> {
    if {%d} {
        foreach cmd $todo(%W) {eval $cmd}
        set todo(%W) {}
    } } # runtime if {![$w pendingsync]} {
    $w yview moveto $fraction } else {
    lappend todo($w) [list $w yview moveto $fraction] }

IMPROVING THE PERFORMANCE WITH TAGS

The use of thousands of different tags when inserting text is a bit slow. Often such a large number of different tags can be avoided. Example:

set n 0 foreach i $items {
    $w insert insert $i [incr n] " "
    $w tag bind $n <Enter> [list Hilite $w $n yellow]
    $w tag bind $n <Leave> [list Hilite $w $n {}]
    $w tag bind $n <1> [list Action $w $n] } proc Hilite {w n bg} {
    $w tag configure $n -background $bg } proc Action {w n} {
    # do any action based on number $n }

This piece of code assigns an unique tag to each item, used for highlighting and identifying the item. But this can be solved in a different way, with only two tags:

set n 0 foreach i $items {
    $w mark set [incr n] insert left
    $w insert end $i item " " } $w tag configure hilite -background yellow $w tag bind item <Enter> {Enter %W} $w tag bind item <Leave> {Leave %W} $w tag bind item <1> {Action %W} proc Enter {w} {
    $w tag add hilite item.current.first item.current.last } proc Leave {w} {
    $w tag remove hilite begin end } proc Action {w} {
    set n [$w mark previous item.current.last {[0-9]*}]
    # do any action based on number $n }

The latter method may improve the performance of text insertion significantly, because marks are very efficient, even if thousands of marks are in usage. Also the number of bindings will be reduced, so the overall consumption of resources is reduced.

WIDGET COMMAND

The text command creates a new Tcl command whose name is the same as the path name of the text's window. This command may be used to invoke various operations on the widget. It has the following general form: pathName option ?arg ...? PathName is the name of the command, which is the same as the text widget's path name. Option and the args determine the exact behavior of the command. The following commands are possible for text widgets:

pathName bbox ?-extents? index
    Returns a list of four elements describing the screen area of the character given by index. The first two elements of the list give the x and y coordinates of the upper-left corner of the area occupied by the character, and the last two elements give the width and height of the area. If the character is only partially visible on the screen, then the return value reflects just the visible part. If the character is not visible on the screen then the return value is an empty list.

    If space mode trim is set (see option -spacemode) then the trimmed spaces will be measured with a width of zero.

    If option -extents is specified then a list of four elements describing the invisible extents of the bounding box will returned. If x/y (first/second value) is not zero, then the first x/y pixels are not visible on screen. If width/height (third/fourth value) is not zero, then the last width/height pixels are not visible on screen. If the line which contains this character is not visible on the screen, then the return value is an empty list.

pathName brks string ?lang?
    This command expects a string of characters, and the result is a list of integers. This list has exactly the character length of the given string, and integer value 1 in this list denotes a potential line break point at this character position, value 2 denotes a mandatory line break point, and value 0 (zero) denotes no line break at this character position. If the optional language code is specified (see widget option -lang for language codes), then the external library libunibreak (from Wu Yongwei) will be used for the line break computation; an error will be thrown if this library is not available. If no language code is specified, then the internal wrap algorithm will be used: also based on the recommendations of the Unicode consortium, but restricted to Latin-1 and most non-language dependent characters, without regarding combined marks, and without language support.

    This command has three purposes:

    [1] It provides a simple check whether libunibreak is available or not (even an empty string, and any language code, e.g. works for this check). An error will be thrown if libunibreak is not available, but a language code has been specified (-lang).

    [2] For a proof of the line break algorithm, especially for testing the internal algorithm.

    [3] It is also conceivable to use this function for the computation of line breaks inside other widgets.

pathName cget option
    Returns the current value of the configuration option given by option. Option may have any of the values accepted by the text command.

pathName checksum
    Computes a checksum over the whole widget content. The result is platform independent.

    One or more of the following switches (or abbreviations thereof) may be specified to control the extraction:

    -all
        Computes the checksum over all these elements: chars (characters and soft hyphens), tags, images, and windows. This is the default, and includes the following switches: -chars, -image, -tag, -window.

    -chars
        The computation considers all characters and soft hyphens.

    -displaychars
        If this option is given, then only those characters and soft hyphens which are not elided will be considered in the computation of the checksum.

    -displaytext
        If this option is given, then only those characters which are not elided will be considered in the computation of the checksum. Note that soft hyphens (Unicode point U+00AD) do not belong to this result.

    -image
        The computation considers all embedded images. In case of an image the name of the image will be used for the checksum computation.

    -mark
        The computation considers all marks. In case of a mark the name of the mark and his gravity will be used for the checksum computation. Note that the computation discards generated marks, and it discards the special marks current, and insert.

    -tag
        Consider tag information in the checksum computation. The name of the tags associated to this data (characters, soft hyphen, image, or window) will be used for the checksum computation. But this computation also considers the priority of the tags.

    -text
        The computation considers all characters. Note that soft hyphens (Unicode point U+00AD) do not belong to this result.

    -window
        The computation considers all embedded windows. In case of a window the pathname of the window will be used for the checksum computation.

pathName clear
    This command is clearing the overall widget, this affects all the characters, soft hyphens, embedded images, embedded windows, tag information, and marks. This is not bounded by restrictions, given with option -startindex/-endindex. Also the undo stack will be cleared. It's like a reset to the initial state, without resetting the options of the widget, and without clearing widget bindings. Also the states edit modified, edit altered, and edit irreversible will be resetted to false. The widget now will be overall clean (see command isclean -overall). Note that this operation cannot be undone.

pathName compare index1 op index2
    Compares the indices given by index1 and index2 according to the relational operator given by op, and returns 1 if the relationship is satisfied and 0 if it is not. Op must be one of the operators <, <=, ==, >=, >, or !=. If op is == then 1 is returned if the two indices refer to the same character, if op is < then 1 is returned if index1 refers to an earlier character in the text than index2, and so on.

pathName configure ?option? ?value option value ...?
    Query or modify the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). 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 widget option(s) to have the given value(s); in this case the command returns an empty string. Option may have any of the values accepted by the text command.

pathName count ?options? index1 index2
    Counts the number of relevant things between the two indices. If index1 is after index2, the result will be a negative number (and this holds for each of the possible options). The actual items which are counted depend on the options given. The result is a list of integers, one for the result of each counting option given. Valid counting options are -chars, -displaychars, -displayhyphens, -displayindices, -displaylines, -displaytext, -hyphens, -indices, -lines, -text, -xpixels and -ypixels. The default value, if no option is specified, is -indices. There is an additional possible option -update which is a modifier. If given (and if the text widget is managed by a geometry manager), then all subsequent options ensure that any possible out of date information is recalculated. This currently only has any effect for the -ypixels count (which, if -update is not given, will use the text widget's current cached value for each line). The count options are interpreted as follows:

    -chars
        count all characters, whether elided or not, this also includes soft hyphens. Do not count embedded windows or images.

    -displaychars
        count all non-elided characters (see -chars).

    -displayhyphens
        count all non-elided soft hyphens.

    -displayindices
        count all non-elided characters, soft hyphens, windows and images (see -indices).

    -displaylines
        count all display lines (i.e. counting one for each time a line wraps) from the line of the first index up to, but not including the display line of the second index. Therefore if they are both on the same display line, zero will be returned. By definition displaylines are visible and therefore this only counts portions of actual visible lines.

    -displaytext
        count all non-elided characters, but discard soft hyphens (see -text).

    -hyphens
        count all soft hyphens, whether elided or not.

    -indices
        count all characters, soft hyphens, and embedded windows or images (i.e. everything which counts in text-widget index space), whether they are elided or not.

    -lines
        count all logical lines (irrespective of wrapping) from the line of the first index up to, but not including the line of the second index. Therefore if they are both on the same line, zero will be returned. Logical lines are counted whether they are currently visible (non-elided) or not.

    -text
        count all characters, whether elided or not, but discard soft hyphens.

    -xpixels
        count the number of horizontal pixels from the first pixel of the first index to (but not including) the first pixel of the second index. To count the total desired width of the text widget (assuming wrapping is not enabled, and the used font is ideally monospaced), first find the longest line and then use

    -ypixels
        count the number of vertical pixels from the first pixel of the first index to (but not including) the first pixel of the second index. If both indices are on the same display line, zero will be returned. To count the total number of vertical pixels in the text widget, use and to ensure this is up to date, use

pathName debug ?boolean?
    If boolean is specified, then it must have one of the true or false values accepted by Tcl_GetBoolean. If the value is a true one then internal consistency checks will be turned on in the B-tree code associated with text widgets. If boolean has a false value then the debugging checks will be turned off. In either case the command returns an empty string. If boolean is not specified then the command returns on or off to indicate whether or not debugging is turned on. There is a single debugging switch shared by all text widgets: turning debugging on or off in any widget turns it on or off for all widgets. For widgets with large amounts of text, the consistency checks may cause a noticeable slow-down.

    When debugging is turned on, the drawing routines of the text widget set the global variables tk_textRedraw and tk_textRelayout to the lists of indices that are redrawn. The values of these variables are tested by Tk's test suite.

pathName delete ?options? index1 ?index2 ...?
    Delete a range of characters from the text. If both index1 and index2 are specified, then delete all the characters starting with the one given by index1 and stopping just before index2 (i.e. the character at index2 is not deleted). If index2 does not specify a position later in the text than index1 then no characters are deleted. If index2 is not specified then the single character at index1 is deleted. Attempts to delete characters in a way that would leave the text without a newline as the last character will be tweaked by the text widget to avoid this. In particular, deletion of text up to the end of the text (inclusively the last newline) will not delete the last newline, but the tag associations of this newline will be cleared. The command returns an empty string. If more indices are given, multiple ranges of text will be deleted. All indices are first checked for validity before any deletions are made. They are sorted and the text is removed from the last range to the first range so deleted text does not cause an undesired index shifting side-effects. If multiple ranges with the same start index are given, then the longest range is used. If overlapping ranges are given, then they will be merged into spans that do not cause deletion of text outside the given ranges due to text shifted during deletion.

    This command allows the following options:

    -marks
        Additionally all the marks belonging to the specified range will be deleted. Here the indices will be interpreted differenty (but it's important to note that this re-interpretation is not affecting the range of character deletion). If index1 is specified in a numerical form the deletion of the marks starts with the first mark at this position, otherwise it starts with the next mark after that mark; provided that a mark at this position exists, otherwise the deletion starts at first character position. If index2 is specified in a numerical form the deletion ends with the first mark at this position (not including this mark), otherwise it ends immediately before that mark; provided that a mark at this position exists, otherwise the deletion ends just before last character position (specified with index2). If index2 is unspecified then index2 will be assumed as equal to "$index1+1c". This option is especially intended for programmed editor control, if option -steadymarks is activated. Note that the special marks and and also generated marks (see mark generate), will not be deleted.

    -inclusive
        This option is useful only if combined with option -marks. It causes that also the marks referred to by index1 and index2 will be deleted (provided that the concerned mark is neither a special mark - insert or current, - nor a generated mark).

pathName dlineinfo ?-extents? index
    Returns a list with five elements describing the area occupied by the display line containing index. The first two elements of the list give the x and y coordinates of the upper-left corner of the area occupied by the line, the third and fourth elements give the width and height of the area, and the fifth element gives the position of the baseline for the line, measured down from the top of the area. All of this information is measured in pixels. If the current wrap mode is none and the line extends beyond the boundaries of the window, the area returned reflects the entire area of the line, including the portions that are out of the window. If the line is shorter than the full width of the window then the area returned reflects just the portion of the line that is occupied by characters and embedded windows. If the current wrap mode is different from none, the area returned reflects the area occupied by all characters displayed on this line, which can be smaller than the widget width. If the display line containing index is not visible on the screen then the return value is an empty list.

    If option -extents is specified then a list of four elements describing the invisible extents of the bounding box will returned, plus a fifth value for the baseline position. If x/y (first/second value) is not zero, then the first x/y pixels are not visible on screen. If width/height (third/fourth value) is not zero, then the last width/height pixels are not visible on screen. If the display line containing index is not visible on the screen then the return value is an empty list.

pathName dump ?switches? index1 ?index2?
    Return the contents of the text widget from index1 up to, but not including index2, including the text and information about marks, tags, and embedded windows, and images. If index2 is not specified, then it defaults to one character past index1. The information is returned in the following format:

    key1 value1 index1 key2 value2 index2 ...

    The possible key values are text, hyphen, mark, tagon, tagoff, image, window and node. The corresponding value is the text, mark name, tag name, image name, window name or node identifier, the hyphen has no value (this means the value is empty). The index information is the index of the start of the text, hyphen, mark, tag transition, image, window or node. One or more of the following switches (or abbreviations thereof) may be specified to control the dump:

    -all
        Return information about all elements: text, hyphens, marks, tags, images and windows (but not nodes). This is the default.

    -chars
        Include information about text (characters and soft hyphens) in the dump results. The value is the text up to the next element or the end of range indicated by index2. A text element does not span newlines. A multi-line block of text that contains no marks or tag transitions will still be dumped as a set of text segments that each end with a newline. The newline is part of the value.

    -command command
        Instead of returning the information as the result of the dump operation, invoke the command on each element of the text widget within the range. The command has three arguments appended to it before it is evaluated: the key, value, and index.

    -image
        Include information about images in the dump results.

    -mark
        Include information about marks in the dump results.

    -node
        This information is for debugging only. It informs that the following content will belong to this B-Tree node.

    -tag
        Include information about tag transitions in the dump results. Tag information is returned as tagon and tagoff elements that indicate the begin and end of each range of each tag, respectively.

    -text
        Include information about text (characters) in the dump results. The value is the text up to the next element or the end of range indicated by index2. A text element does not span newlines. A multi-line block of text that contains no marks or tag transitions will still be dumped as a set of text segments that each end with a newline. The newline is part of the value. Note that soft hyphens (Unicode point U+00AD) do not belong to this result.

    -tags tagList
        Specifies a set of tags to apply to the embedded window. TagList consists of a list of tag names, which replace any existing tags for the embedded window. TagList may be an empty list. Note that it is not possible to add or remove the special selection tag sel, it will be left untouched with this option.

    -window
        Include information about embedded windows in the dump results. The value of a window is its Tk pathname, unless the window has not been created yet. (It must have a create script.) In this case an empty string is returned, and you must query the window by its index position to get more information.

    --  This switch has no effect except to terminate the list of switches: the next argument will be treated as pattern even if it starts with -.

pathName edit option ?arg ...?
    This command controls the undo mechanism and the modified flag. The exact behavior of the command depends on the option argument that follows the edit argument. The following forms of the command are currently supported:

    pathName edit altered
        Returns whether changes have been done (eventual) affecting the text content, or the representation of the text content. Any of the following commands can set this flag to true:

        [1] pathName delete

        [2] pathName edit redo

        [3] pathName insert

        [4] pathName mark gravity|set|unset (but only if -steadymarks is enabled)

        [5] pathName tag add|clear|lower|raise|remove (but not if -undo of affected tag is false)

        [6] pathName insert

        This flag will be false before any of these operations have been done. It can never be false if edit irreversible reports true. It will be true after clear and load, and it will be true again if all changes have been undone (with edit undo or edit recover). Also enabling the undo stack (via widget option -undo) will reset this state to false.

        Any change of this state, if caused by an operation with (eventual) effects on the (representation of the) text content, will trigger the virtual event <<Altered>>.

    pathName edit canredo
        Note that this command is deprecated, command pathName edit info should be used instead. For compatibility reasons this command still will be supported, but may be removed in a future version.

        Returns a boolean true if redo is possible, i.e. when the redo stack is not empty. Otherwise returns false.

    pathName edit canundo
        Note that this command is deprecated, command pathName edit info should be used instead. For compatibility reasons this command still will be supported, but may be removed in a future version.

        Returns a boolean true if undo is possible, i.e. when the undo stack is not empty. Otherwise returns false.

    pathName edit info ??--? array? | ?-option?
        Returns information about edit states.

        pathName edit info ?--? ?array?
            Stores an array of some edit information in given variable array, if array is not given then an unnamed variable will be used. The name of the array must not start with a hyphen (-), unless it will be preceeded with --, otherwise it will be treated as an option (see chapter below).

            This command returns the array name array, or an empty string (unnamed variable) if array is not specified.

            This is the available information related to this widget:

                bytesize
                Current byte size, only characters have been counted (a character may have more than one byte).

                lines
                Current number of lines.

                visibleimages
                Number of visible embedded images.

                visiblewindows
                Number of visible embedded windows.

            This is the available information related to whole content:

                totalbytesize
                Current byte size, only characters have been counted (a character may have more than one byte).

                undodepth
                The depth (number of undoable actions) of the undo stack.

                redodepth
                The depth (number of redoable actions) of the redo stack.

                undostacksize
                Current number of items on undo stack.

                redostacksize
                Current number of items on redo stack.

                undobytesize
                Current number of bytes on the undo stack, only characters have been counted (a character may have more than one byte).

                redobytesize
                Current number of bytes on the redo stack, only characters have been counted (a character may have more than one byte).

                undocommands
                If the current undo stack action does not contain an undo atom, then this information is empty. Otherwise it contains the list of commands that have been pushed for undoing onto the stack since last inserted separator. A command is one of: delete, image, insert, mark, tag, or window. Note that mark can only occur when option -steadymarks is enabled. Also note that the replace command is pushing either delete and insert. Further note that this list contains all edit operations of the current undo atom, this means that some commands can occur repeatedly.

                redocommands
                If the current undo stack action does not contain an redo atom, then this information is empty. Otherwise it contains the list of commands that have been undone with current undo command, see undocommands for more details.

                totallines
                Current number of lines.

                images
                Number of embedded images.

                windows
                Number of embedded windows.

                tags
                Number of currently defined tags.

                usedtags
                Number of tags currently used.

                marks
                Number of currently defined marks, this does not include the special marks insert and current, nor the generated marks (see mark generate).

                generatedmarks
                Number of generated marks currently defined (see mark generate).

            This information is unrelated to the content:

                linespernode
                Minimal number of lines per node in B-Tree, this information is only useful for testing.

            In the future the information might be extended. Note that embedded windows and images will each be count with byte size one.

        pathName edit info -option
            This version will return only the specified value. Option is one of bytesize, generatedmarks, images, lines, linespernode, marks, redobytesize, redocommands, redodepth, redostacksize, tags, totalbytesize, totallines, undobytesize, undocommands, undodepth, undostacksize, usedtags, visibleimages, visiblewindows, or windows. See chapter above about the meaning.

    pathName edit inspect ?stack?
        Returns information about all undo, or redo, atoms. If stack is specified (must be either undo or redo), then only the information of this stack will be returned, otherwise the result contains two lists, firstly all undo atoms, and secondly all redo atoms. Any atom information contains at least one sub-atom. Each sub-atom is a list where the first element of the list (at least) describes the nature of the sub-atom.

        This is an informal description about the sub-atom content:

        {clear}
            Redo clearing tag associations (tag clear).

        {clear tag-list skip length ...}
            Undo clearing tag associations (tag clear).

        {delete}
            Redo the deletion either of characters, hyphen, embedded image, or embedded window (delete).

        {delete character string tag-list}
            Undo the deletion of characters (delete), does not contain soft hyphens.

        {delete hyphen tag-list}
            Undo the deletion of a soft hyphen (delete).

        {delete image tag-list image-options}
            Undo the deletion of an embedded image (delete).

        {delete window tag-list window-options}
            Undo the deletion of an embedded window (delete).

        {insert}
            Undo an insert operation; either characters, hyphen, embedded image, or embedded window.

        {insert character string tag-list}
            Redo an insert operation of characters.

        {insert hyphen tag-list}
            Redo an insert operation of a soft hyphen.

        {insert image tag-list image-options}
            Redo an insert operation of an embedded image.

        {insert window tag-list window-options}
            Redo an insert operation of an embedded window.

        {mark gravity name}
            Undo/redo toggling the gravity of a mark; either from left to right, or from right to left (tag gravity).

        {mark set name left}
            Undo/redo setting a mark with left gravity (mark set).

        {mark set name right}
            Undo/redo setting a mark with right gravity (mark set).

        {mark unset name}
            Undo/redo unsetting a mark (mark unset).

        {tag add tag}
            Undo/redo adding an association with tags (tag add).

        {tag remove tag}
            Undo/redo removing an association with tags (tag delete).

    pathName edit irreversible
        Returns a flag whether the content of the text widget is irreversible. The content is irreversible if the undo stack is not enabled when performing undoable edit operations, or the undo stack is enabled, but incomplete due to the limitation of stack depth and/or stack byte size. Also disabling widget option -undo will become an irreversible state if the undo stack was not empty at this time. A change of this state, if caused by an operation with (eventual) effects on the (representation of the) text content (see edit altered for details), will trigger the virtual event <<Irreversible>>. The state will be resetted to false if one of the following commands will be performed: clear, load, edit reset, or edit reset undo (but not edit reset redo). The state will also be resetted to false when widget option -undo will be enabled.

    pathName edit modified ?boolean?
        If boolean is not specified, returns the modified flag of the widget. The insert, delete, edit undo, edit redo and edit recover commands or the user can set or clear the modified flag. If boolean is specified, sets the modified flag of the widget to boolean.

    pathName edit recover
        Applies all undo items, without adding redo items. The initial text (before any modification has been done since the undo stack is enabled) will be recovered. The undo stack is empty afterwards.

        Note: If edit irreversible returns true (before calling this function), then it's not possible to recover the initial text, in this case it will be recovered as much as possible. If edit irreversible returns false (before calling this function), then the state edit altered will change to false.

    pathName edit redo
        When the -undo option is true, reapplies the last undone edits provided no other edits were done since then. Generates an error when the redo stack is empty. Does nothing when the -undo option is false.

    pathName edit reset ?stack?
        If stack is not specified, then clear the undo and redo stacks. Otherwise only clear the specified stack. The specified stack must be either undo or redo, otherwise an error will be thrown.

    pathName edit separator ?-immediately?
        Inserts a separator (boundary) on the undo stack. Does nothing when the -undo option is false. Per default the insertion of the separator will be postponed until the next insert/delete/replace/edit undo/edit redo/edit recover command will be performed. If option -immediately is specified then the separator will be pushed immediately; this is required if mark or tag operations should be separated.

    pathName edit undo
        Undoes the last edit action when the -undo option is true. An edit action is defined as all the commands modifying any text, or tag associations (but not the changes of tag options) that are recorded on the undo stack in between two separators, furthermore this includes the (dis-)embedding of images and windows, but not changes of the content or options of images and windows. Generates an error when the undo stack is empty. Does nothing when the -undo option is false, or when -maxredo is set to zero.

        The marks are not influencing the display, thus operations on marks will not be recorded, except if option -steadymarks is enabled: this is the appropriate mode for programmed editor control, and here the recovery of the marks (position and gravity) is essential. But operations on the special marks insert and current, as well as operations on generated marks, will never be recorded, these marks should in general not be used if undoing the operation on a mark is essential.

pathName get ?switch? ?--? index1 ?index2 ...?
    Return a range of characters from the text. The return value will be all the characters in the text starting with the one whose index is index1 and ending just before the one whose index is index2 (the character at index2 will not be returned). If index2 is omitted then the single character at index1 is returned. 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 an empty string is returned. If the specified range contains embedded windows, no information about them is included in the returned string. If multiple index pairs are given, multiple ranges of text will be returned in a list. Invalid ranges will not be represented with empty strings in the list. The ranges are returned in the order passed to pathName get. The switch will be interpreted as follows:

    -chars
        all characters within the ranges will be returned, whether elided or not, this also includes soft hyphens. This is the default, if no switch is given.

    -text
        all characters, which are not soft hyphens, within the ranges will be returned, whether elided or not.

    -displaychars
        only those characters which are not elided will be returned, this also includes soft hyphens. This may have the effect that some of the returned ranges are empty strings.

    -displaytext
        only those characters, which are neither soft hyhens, nor elided, will be returned. This may have the effect that some of the returned ranges are empty strings.

pathName image option ?arg ...?
    This command is used to manipulate embedded images. The behavior of the command depends on the option argument that follows the image argument. The following forms of the command are currently supported:

    pathName image cget index option
        Returns the value of a configuration option for an embedded image. Index identifies the embedded image, and option specifies a particular configuration option, which must be one of the ones listed in the section EMBEDDED IMAGES.

    pathName image configure index ?option value ...?
        Query or modify the configuration options for an embedded image. If no option is specified, returns a list describing all of the available options for the embedded image at index (see Tk_ConfigureInfo for information on the format of this list). 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 EMBEDDED IMAGES for information on the options that are supported.

    pathName image create index ?option value ...?
        This command creates a new image annotation, which will appear in the text at the position given by index. Any number of option-value pairs may be specified to configure the annotation. Returns a unique identifier that may be used as an index to refer to this image. See EMBEDDED IMAGES for information on the options that are supported, and a description of the identifier returned.

    pathName image names
        Returns a list whose elements are the names of all image instances currently embedded in window.

pathName index index
    Returns the position corresponding to index in the form line.char where line is the line number and char is the character number. Index may have any of the forms described under INDICES above.

pathName insert index chars ?tagList chars tagList ...?
    Inserts all of the chars arguments just before the character at index. If index refers to the end of the text (the character after the last newline) then the new text is inserted just before the last newline instead. If there is a single chars argument and no tagList, then the new text will receive any tags depending on the tagging mode (see option -tagging). If tagList is specified then it consists of a list of tag names; the new characters will receive all of the tags in this list and no others, regardless of the tagging mode. If multiple chars-tagList argument pairs are present, they produce the same effect as if a separate pathName insert widget command had been issued for each pair, in order. The last tagList argument may be omitted.

pathName inspect ?switches?
    Return the content of the text widget, including the text and optionally information about tags, embedded windows, and embedded images. The information is returned in the following format (notated in EBNF; BEG denotes the start of a list, end END denotes the end of the list; white spaces will not be taken into consideration):

        Inspect = BEG, Setup?, Configure?, Segment+, END; Setup = BEG, "setup", PathName, TextOptions, END; Configure = BEG, "configure", TagName, (BEG, TagOptions, END)?, END; Bindings = BEG, "bind", TagName, (BEG, Script, END), END; Segment = BEG, ((Content, TagInfo) | Mark | Elide | Binding), END; Content = Text | Hyphen | Break | EmbImage | EmbWindow; Text = "text", BEG, Character+, END; Hyphen = "hyphen"; EmbImage = "image", ImageOptions; EmbWindow = "window", WindowOptions; Mark = Gravity, MarkName; Gravity = "left" | "right"; Elide = "elide", ("on" | "off"); TagInfo = (Tags, Tags?)?; Tags = BEG, TagName*, END; Character = ?Any character except newline?; Newline = ?The newline character?; TextOptions = ?See STANDARD OPTIONS and WIDGET-SPECIFIC OPTIONS?; TagOptions = ?See TAGS?; ImageOptions = ?See EMBEDDED IMAGES?; WindowOptions = ?See EMBEDDED WINDOWS?; PathName = ?Any valid widget pathname?; TagName = ?Any tag name?; MarkName = ?Any mark name?;

    We will also provide an informal description of the items; note that the optional tagList will be provided only if option -nested is specified:

    {setup pathName configurationList}
        Provides the overall information about the inspected widget, notably its pathName and configuration options.

    {configure tagName ?configurationList?}
        Describes the configuration of a particular tag.

    {bind tagName event script}
        Describes a binding applied to a tag

    {text content ?tagList ?tagList??}
        Describes a character sequence, optionally including what tags were applied to it.

    {break tagList ?tagList?}
        Describes a newline character, including what tags were applied to it.

    {hyphen tagList ?tagList?}
        Describes a soft hyphen, including what tags were applied to it.

    {image imageOptions ?tagList ?tagList??}
        Describes an image that was embedded, optionally including what tags were applied to it.

    {window windowOptions ?tagList ?tagList??}
        Describes a window that was embedded, optionally including what tags were applied to it.

    {left markName}
        Describes a mark with left gravity.

    {right markName}
        Describes a mark with right gravity.

    {elide on|off}
        Describes whether elision is turned on or off at the current handling point.

    One or more of the following switches (or abbreviations thereof) may be specified to control the extraction:

        -all
            Return information about all elements: text (characters and soft hyphens), marks, tags, images, and windows. This is the default, and includes the following switches: -chars, -mark -tag, -image, and -window.

        -complete
            Return complete information, this includes the following switches: -all, -bindings, -configurations, -elide, -includedbconfig, -includedefaultconfig, -includeselection, -includesyscolors, -includesysconfig, -insertmark, and -setup.

        -bindings
            Include all tag bindings into the result.

        -chars
            Include information about characters and soft hyphens in the dump results. The content of this segment is the text up to the next segment. The segmentation of text depends on the tagging information, any change in tagging is starting a new segment.

        -configurations
            Include all the tag configurations.

        -displaychars
            If this option is given, then only those characters and soft hyphens which are not elided will be included into the result of the text element.

        -displaytext
            If this option is given, then only those characters which are not elided will be included into the result of the text element. Note that soft hyphens (Unicode point U+00AD) do not belong to this result.

        -dontresolvecolors
            Do not resolve system color names (this is affecting the content of -setup, and -configurations). Resolving system color names is required for portability, but in case of system dependent use (if all system color names will be resolvable) it is not required. Per default system color names will be resolved.

        -dontresolvefonts
            Do not resolve font names (this is affecting the content of -setup, and -configurations). Resolving font names is required for portability, but in case of private use (if all font names will be resolvable) it is not required. Per default font names will be resolved.

        -elide
            The result will also include information about elided regions. It is for information only - better visibility of elided text. The load command will ignore these elements.

        -image
            Include information about images in the result. The content of the image is a list containing the image options.

        -includedbconfig
            This option makes sense only if also option -setup (or -all) is specified. With this option a configuration option will be included into the list of configuration even if the value of this option is equal to the value from option database (per default database values are excluded).

        -includedefaultconfig
            This option makes sense only if also option -setup (or -all) is specified. With this option a configuration option will be included into the list of configuration even if the value of this option is equal to the default value (per default the default values are excluded). Note that the options -includedbconfig and -includesysconfig have higher priority.

        -includeselection
            This option makes sense only if also option -tag (or -all) is specified. With this option the selection tag sel will be included into the result. Per default the selection will be discarded when inspecting the content.

        -includesyscolors
            When inspecting widget or tag option values normally system colors (like or will be discarded, except if option -includesyscolors is specified.

        -includesysconfig
            This option makes sense only if also option -setup (or -all) is specified. With this option a configuration option will be included into the list of configuration even if the value of this option is equal to the system value (per default the system values are excluded). Note that option -includedbconfig has a higher priority.

        -insertmark
            Include information about the mark in the dump results. Without this option, this mark will not be printed.

        -mark
            Include information about marks in the dump results. Depending on the gravity the type of this segment is either left or right. The segment content is the name of the mark. The special marks insert and current will be discarded (but see option -insertmark), and generated marks will also be discarded.

        -nested
            This option will only be regarded in conjunction with switch -tag, see description of switch -tag below.

        -setup
            Include the pathname of the widget, and a list of configuration options. Per default a configuration option will be included only if the value is neither equal to the default value, nor equal to the system value, nor equal to the value from option database. This can be modified with options -includedefaultconfig, -includesysconfig, and -includedbconfig.

        -tag
            Include information about tags in the result. If additionally option -nested is specified, then two tag sets will be provided: firstly all the tags starting with this content, and secondly all the tags ending after this content (similar to the tagon and tagoff ranges in the dump format). Without the -nested option (this is the default) only one list will be provided, namely all the tags associated to this segment content. The tag list will be sorted in order from lowest priority to highest priority.

        -text
            Include information about text (characters) in the dump result. The content of this segment is the text up to the next segment. The segmentation of text depends on the tagging information, any change in tagging is starting a new segment. Note that soft hyphens (Unicode point U+00AD) do not belong to this result.

        -window
            Include information about embedded windows in the result. The content of a window is a list containing the window options.

    The result of this command can be used for loading a widget with a snapshot (see command load).

pathName isclean ?-overall? ?-discardselection?
    Returns whether this widget does not contain any character, soft hyphen, embedded window, or embedded image, except an untagged sole newline. Furthermore a clean widget does not contain any marks, except the special marks current and insert, and generated marks. If option -overall is specified, then this test will discard any restrictions given with widget options -startindex and -endindex. If option -discardselection is given, the special selection tag sel will be discarded when testing whether the sole newline is tagged.

pathName isdead
    A text widget is dead if it does not contain any line (in this case no insertion is possible anymore). This only happens if one of the widget options -startindex/-endindex is specified.

pathName isempty ?-overall?
    Returns whether this widget does not contain any character, soft hyphen, embedded window, or embedded image, except a sole newline. If the -overall option is specified, then this test will discard restrictions given with widget options -startindex and -endindex.

pathName lineno index
    Returns the line number corresponding to index. Index may have any of the forms described under INDICES above.

    If the widget is dead (i.e., does not contain lines, which is possible only if option -startline/-endline is involved), then 0 (zero) will be returned.

pathName load ?-validconfig? serialContent
    Load the text widget with given content serialContent. The widget will be cleared before the load will be done, this includes all marks, but not the tag definitions. The format of serialContent is described in the inspect subcommand, which produces it. Normally invalid configuaration options will be skipped, except if option -validconfig is specified, in this case an error will be thrown if an invalid option value will be encountered. Normally the latter only may happen if the given content is produced under a different system.

    For a complete recovery of the text widget content the following is required:

    •   The content contains the complete information (see flag -all of command inspect).

    •   All embedded images have to exist.

    •   Either the embedded windows have to exist, or the window item contains an executable create option.

    The states edit modified, edit altered, and edit irreversible will be resetted to false. Note that this operation cannot be undone.

pathName mark option ?arg ...?
    This command is used to manipulate marks. The exact behavior of the command depends on the option argument that follows the mark argument. The following forms of the command are currently supported:

    pathName mark compare markName1 op markName2
        Compares the marks given by markName1 and markName2 according to the relational operator given by op, and returns 1 if the relationship is satisfied and 0 if it is not. Op must be one of the operators <, <=, ==, >=, >, or !=. If op is == then 1 is returned if the two marks are the same, if op is < then 1 is returned if markName1 refers to an earlier mark in the text than markName2, and so on. If one of the given operands is not an exisiting mark, then an error will be thrown. This command is especially useful when option -steadymarks is enabled.

    pathName mark exists markName
        Returns whether the specified mark is already existing at any position.

    pathName mark generate
        Creates a mark, either for temporary use, or for static use. This mark has the following properties:

        [1] Operations on this mark will not be stacked onto the undo stack (relevant only if option -steadymarks is enabled).

        [2] It is not visible, this means that the commands mark names, mark next, and mark previous will not return generated marks, and command inspect will not print this mark (but command dump will print it, it has the form

        [3] This mark cannot be deleted except with command mark unset (this means that delete -marks will not delete this kind of marks).

        [4] Commands clear and load will not delete this mark, but the relative order to other (generated) marks may change after clearing the text content (command load is also clearing before loading).

        [5] After deletion of a generated mark (with mark unset) this mark will expire, which means that a subsequent call of mark set with this mark will throw an error.

        The initial position of this mark is at start of text. This command returns the generated name of the mark.

    pathName mark gravity markName ?direction?
        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.

    pathName mark names ?-discardspecial? ?pattern?
        Returns a list whose elements are the names of all the marks that are currently set. If an optional pattern is specified, then only the names matching this pattern will be included in the result; see string match about the rules of pattern matching. If option -discardspecial is specified, then exclude the special marks insert and current from result, even when matching the given pattern.

    pathName mark next ?-discardspecial? index ?pattern?
        Returns the name of the next mark at or after index. If index is specified in numerical form, then the search for the next mark begins at that index. If index 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 a text widget in the same order as the mark information returned by the pathName dump operation. If a mark has been set to the special end index, then it appears to be after end with respect to the pathName mark next operation. An empty string is returned if there are no marks after index.

        If an optional pattern is specified, then skip all the marks not matching this pattern during the search; see string match about the rules of pattern matching.

        If option -discardspecial is specified, then skip the special marks insert and current during the search.

    pathName mark previous ?-discardspecial? index ?pattern?
        Returns the name of the mark at or before index. If index is specified in numerical form, then the search for the previous mark begins with the character just before that index. If index 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 pathName 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 pathName dump operation. An empty string is returned if there are no marks before index.

        If an optional pattern is specified, then skip all the marks not matching this pattern during the search; see string match about the rules of pattern matching.

        If option -discardspecial is specified, then skip the special marks insert and current during the search.

    pathName mark set markName index ?direction?
        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 does not exist, a new mark is created. If the third parameter direction is specified - it must be left or right - the gravity of markName is set to the given value (the gravity for a mark defaults to right). This command returns an empty string.

        If widget option -steadymarks is enabled, and index is the name of an existing mark, then markName will be set left or right from index (but at the same numerical position), according to the gravity of index.

    pathName 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 and When removing a generated mark (see mark generate) a future call of mark set with this mark will throw an error (even after clearing the widget). This command returns an empty string.

pathName peer option args
    This command is used to create and query widget peers. It has two forms, depending on option:

    pathName peer create newPathName ?options?
        Creates a peer text widget with the given newPathName, and any optional standard configuration options (as for the text command). By default the peer will have the same start and end line as the parent widget, but these can be overridden with the standard configuration options.

    pathName peer names
        Returns a list of peers of this widget (this does not include the widget itself). The order within this list is undefined.

pathName pendingsync
    Returns 1 if the line heights calculations are not up-to-date, 0 otherwise.

pathName replace index1 index2 chars ?tagList chars tagList ...?
    Replaces the range of characters between index1 and index2 with the given characters and tags. See the section on pathName insert for an explanation of the handling of the tagList... arguments, and the section on pathName delete for an explanation of the handling of the indices. If index2 corresponds to an index earlier in the text than index1, an error will be generated.

    The deletion and insertion are arranged so that no unnecessary scrolling of the window or movement of insertion cursor occurs. In addition the undo/redo stack are correctly modified, if undo operations are active in the text widget. The command returns an empty string.

pathName scan option args
    This command is used to implement scanning on texts. It has two forms, depending on option:

    pathName scan mark x y
        Records x and y and the current view in the text window, for use in conjunction with later pathName scan dragto commands. Typically this command is associated with a mouse button press in the widget. It returns an empty string.

    pathName scan dragto x y
        This command computes the difference between its x and y arguments and the x and y arguments to the last pathName scan mark command for the widget. It then adjusts the view by 10 times the difference in coordinates. This command is typically associated with mouse motion events in the widget, to produce the effect of dragging the text at high speed through the window. The return value is an empty string.

pathName search ?switches? pattern index ?stopIndex?
    Searches the text in pathName starting at index for a range of characters that matches pattern. If a match is found, the index of the first character in the match is returned as result; otherwise an empty string is returned. One or more of the following switches (or abbreviations thereof) may be specified to control the search:

    -forwards
        The search will proceed forward through the text, finding the first matching range starting at or after the position given by index. This is the default.

    -backwards
        The search will proceed backward through the text, finding the matching range closest to index whose first character is before index (it is not allowed to be at index). Note that, for a variety of reasons, backwards searches can be substantially slower than forwards searches (particularly when using -regexp), so it is recommended that performance-critical code use forward searches.

    -exact
        Use exact matching: the characters in the matching range must be identical to those in pattern. This is the default.

    -regexp
        Treat pattern as a regular expression and match it against the text using the rules for regular expressions (see the regexp command and the re_syntax page for details). The default matching automatically passes both the -lineanchor and -linestop options to the regexp engine (unless -nolinestop is used), so that ^$ match beginning and end of line, and ., [^ sequences will never match the newline character \n.

    -nolinestop
        This allows . and [^ sequences to match the newline character \n, which they will otherwise not do (see the regexp command for details). This option is only meaningful if -regexp is also given, and an error will be thrown otherwise. For example, to match the entire text, use

    -nocase
        Ignore case differences between the pattern and the text.

    -count varName
        The argument following -count gives the name of a variable; if a match is found, the number of index positions between beginning and end of the matching range will be stored in the variable. If there are no embedded images or windows in the matching range (and there are no elided characters if -elide is not given), this is equivalent to the number of characters matched. In either case, the range matchIdx to matchIdx + $count chars will return the entire matched text.

    -all
        Find all matches in the given range and return a list of the indices of the first character of each match. If a -count varName switch is given, then varName is also set to a list containing one element for each successful match. Note that, even for exact searches, the elements of this list may be different, if there are embedded images, windows or hidden text. Searches with -all behave very similarly to the Tcl command regexp -all, in that overlapping matches are not normally returned. For example, applying an -all search of the pattern against will just match twice, once for each word, and matching against will just match once.

    -overlap
        When performing -all searches, the normal behavior is that matches which overlap an already-found match will not be returned. This switch changes that behavior so that all matches which are not totally enclosed within another match are returned. For example, applying an -overlap search of the pattern against will just match twice (i.e. no different to just -all), but matching against will now match twice. An error will be thrown if this switch is used without -all.

    -strictlimits
        When performing any search, the normal behavior is that the start and stop limits are checked with respect to the start of the matching text. With the -strictlimits flag, the entire matching range must lie inside the start and stop limits specified for the match to be valid.

    -elide
        Find elided (hidden) text as well. By default only displayed text is searched.

    -discardhyphens
        Do not match with soft hyphens, this means that soft hyphens inside widget content will be discarded while performing the search operation. If the text contains soft hyphen this option is often a must.

    --  This switch has no effect except to terminate the list of switches: the next argument will be treated as pattern even if it starts with -.

    The matching range may be within a single line of text, or run across multiple lines (if parts of the pattern can match a new-line). For regular expression matching one can use the various newline-matching features such as $ to match the end of a line, ^ to match the beginning of a line, and to control whether . is allowed to match a new-line. If stopIndex is specified, the search stops at that index: for forward searches, no match at or after stopIndex will be considered; for backward searches, no match earlier in the text than stopIndex will be considered. If stopIndex is omitted, the entire text will be searched: when the beginning or end of the text is reached, the search continues at the other end until the starting location is reached again; if stopIndex is specified, no wrap-around will occur. This means that, for example, if the search is -forwards but stopIndex is earlier in the text than startIndex, nothing will ever be found. See KNOWN BUGS below for a number of minor limitations of the pathName search command.

pathName see index
    Adjusts the view in the window so that the character given by index is completely visible. If index is already visible then the command does nothing. If index is a short distance out of view, the command adjusts the view just enough to make index visible at the edge of the window. If index is far out of view, then the command centers index in the window.

pathName sync ?-command ?command??
    Controls the synchronization of the view of the text widget.

    pathName sync
        Immediately brings the line metrics up-to-date by forcing computation of any outdated line heights. The command returns immediately if there is no such outdated line heights, otherwise it returns only at the end of the computation. It is guaranteed that the <<WidgetViewSync>> virtual event fires after executing this command, even if no line was outdated. The command returns an empty string.

    pathName sync -command
        Returns the command which will be scheduled as soon an the line metric calculation is up-to-date, or an empty string if no command is available.

    pathName sync -command command
        Schedules command to be executed (by the event loop) exactly once as soon as all line heights are up-to-date. A new script will replace any existing script, but if the first character is then the new script augments an existing script. If there is no pending line metrics computation, the scheduling is immediate (as if the line metrics computation will finish now). bgerror is called on command failure. This command returns an empty string.

    If a command is given (with -command command) then it is ensured that command will be called only when all line height values currently are up-to-date. When waiting for event <<WidgetViewSync>> it is possible that some race conditions will affect the received state.

pathName tag option ?arg ...?
    This command is used to manipulate tags. The exact behavior of the command depends on the option argument that follows the tag argument. The following forms of the command are currently supported:

    pathName tag add tagName index1 ?index2 index1 index2 ...?
        Associate the tag tagName with all of the characters starting with index1 and ending just before index2 (the character at index2 is not 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.

    pathName tag bind tagName ?sequence? ?script?
        This command associates script with the tag given by tagName. Whenever the event sequence given by sequence occurs for a character that has been tagged with tagName, the script will be invoked. This widget command is similar to the bind command except that it operates on characters in a text 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 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, Button, Motion, and Key) or virtual events. Mouse and keyboard event bindings for a text widget respectively use the current and insert marks described under MARKS 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 events are directed to the current character, while keyboard events are directed to the insert character. If a virtual event is used in a binding, that binding can trigger only if the virtual event is defined by an underlying mouse-related or keyboard-related event.

        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.

    pathName tag cget tagName option
        This 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 pathName tag configure widget command.

    pathName tag clear ?-discardselection? index1 ?index2 index1 index2 ...?
        Remove all tags from all of the characters starting at index1 and ending just before index2 (the character at index2 is not affected). A single command may contain any number of index1-index2 pairs. If the last index2 is omitted then all tags will be 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. This command returns a list of all removed tags, sorted in order from lowest priority to highest priority. If option -discardselection is given then the special selection tag sel will not be removed.

    pathName tag configure tagName ?option? ?value? ?option value ...?
        This command is similar to the pathName configure widget command except that it modifies options associated with the tag given by tagName instead of modifying options for the overall text widget. If no option is specified, the command returns a list describing all of the available options for tagName (see Tk_ConfigureInfo for information on the format of this list). 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 TAGS above for details on the options available for tags.

    pathName tag delete tagName ?tagName ...?
        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.

    pathName tag findnext ?-discardselection? index
        Finds the first tagged character either at specified position index, or right from specified position index, and returns the index of the detected character. The value of the result will be empty if no character can be found. If option -discardselection is given then the special selection tag sel will be discarded.

    pathName tag findprev ?-discardselection? index
        Finds the first tagged character either at specified position index, or left from specified position index, and returns the index of the detected character. The value of the result will be empty if no character can be found. If option -discardselection is given then the special selection tag sel will be discarded.

    pathName tag getrange tagName index
        Returns the range of text that have been tagged with tagName, and which includes the character at the specified position index (inclusive start of range, but exclusive end of range). If the character at specified position index is not tagged with tagName, then the returned value will be empty.

    pathName tag lower tagName ?belowThis?
        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.

    pathName tag names ?switches? ?index?
        Returns a list whose elements are the names of all the tags that are active at the character position given by index. If index is omitted, then the return value will describe all of the tags that exist for the text. The list will be sorted in order from lowest priority to highest priority.

        One or more of the following switches (or abbreviations thereof) may be specified to control the result:

        -all
            Return all tags that exist for the text (this includes all tags that have been named in a widget command but have not been deleted by a widget command, even if no characters/soft hyphens/embedded images/embedded windows are currently marked with the tag). This is the default.

        -discardselection
            Discard the special selection tag sel. (This option is identical to option -noselection, and only provided to be conform with other tag sub-commands.)

        -display
            Include all tags (eventually) influencing the display of text.

        -nodisplay
            Discard all tags (eventually) influencing the display of text.

        -elide
            Include all tags where option -elide is enabled.

        -noelide
            Discard all tags where option -elide is enabled.

        -geometry
            Include all tags (eventually) influencing the display geometry.

        -nogeometry
            Discard all tags (eventually) influencing the display geometry.

        -lineheight
            Include all tags (eventually) influencing the line height.

        -nolineheight
            Discard all tags (eventually) influencing the line height.

        -selection
            Include all tags affecting selected text. Currently this is only the sel tag.

        -noselection
            Discard all tags affecting selected text. Currently this is discarding only the sel tag. (This option is identical to option -discardselection).

        -undo
            Include all tags where option -undo is enabled.

        -noundo
            Discard all tags where option -undo is enabled.

        -used
            Include all tags which are currently used for associations with any character, soft hyphen, embedded image, or embedded window.

        -noused
            Discard all tags which are currently used for associations with any character, soft hyphen, embedded image, or embedded window.

        -unused
            This option is identical to option -noused, and only provided for convenience.

    pathName tag nextrange tagName index1 ?index2?
        This command 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.

    pathName tag prevrange tagName index1 ?index2?
        This command searches the text 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.

    pathName tag priority tagName
        Returns the priority (a positive integer value, or zero) of the specified tag. This allows to compare the priority of tags.

    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.

    pathName tag ranges tagName
        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 tag then an empty string is returned.

    pathName tag remove tagName index1 ?index2 index1 index2 ...?
        Remove the tag tagName from all of the characters starting at index1 and ending just before index2 (the character at index2 is not 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. This command returns an empty string.

pathName watch ?-always? ?commandPrefix?
    Monitors widget modifications, it causes a Tcl command to be executed whenever certain widget modifications are done. In general only user (GUI) modifications will be watched. But if option -always is specified then all modifications will be watched. In fact the triggering depends on the way how a certain modification will be executed:

    •   If option -always is not specified then the delete command triggers only if the argument index1 (the starting point of the deletion) is specified with (the insertion cursor).

    •   If option -always is not specified then the insert command triggers only if the argument index (the starting point of the insertion) is specified with (the insertion cursor).

    •   If option -always is not specified then the mark set command triggers only if the argument markName (the name of the mark) is specified with (the insertion cursor).

    •   If option -always is not specified then the replace command triggers only if the argument index1 (the starting point of the replacement) is specified with (the insertion cursor).

    •   edit undo|redo|recover will trigger the corresponding undo|redo event.

    •   A resize or content change of a displayed image will trigger event image.

    •   Any change of a displayed window (resize, map, or unmap) will trigger event window.

    Additionally any of the following commands may trigger because the view may change:

    •   pathName clear|load

    •   pathName configure

    •   pathName edit recover|redo|undo

    •   pathName image configure|create

    •   pathName mark gravity|set|unset

    •   pathName see

    •   pathName tag add|delete|lower|raise|remove

    •   pathName window configure|create

    •   pathName xview arg...

    •   pathName yview arg...

    Also destroying an embedded window may trigger due to a changed view.

    Note that the delete, and the insert operation will be handled in the same way as the replace operation, this means that firstly the deletion part triggers, and secondly the insertion part will be triggered. In case of delete the insertion part is empty (zero characters), and in case of insert the deletion range is empty.

    CommandPrefix will be resolved using the usual namespace resolution rules used by commands. If the command does not exist, an error will be thrown (except the command argument is empty). When a certain widget modification triggers, a number of arguments are appended to commandPrefix so that the actual command is as follows:

    commandPrefix... pathName op index1 index2 info userFlag

    UserFlag informs whether this is a user (GUI) modification. Note that this flag is meaningful only if op is delete, or insert.

    Op indicates which operation has been performed:

    insert
        Zero or more characters have been inserted, this event will be triggered after the insertion has been realized. Index1 and index2 are specifying the range of the new characters after insertion, this range can be empty. Info will contain five items:

        [1] The inserted characters.

        [2] A list of tags applied to the character just before the inserted characters.

        [3] A list of tags applied to the character just after the inserted characters.

        [4] A list of tags applied to the newly inserted characters.

        [5] A boolean flag indicating whether this is the final part of a multi-insert/replace.

        It should be avoided to call commands inside this event which will insert or delete as long as final is false, the result can be unexpected. Such commands should be postponed, either with the after command, or until final state is true.

        This event will also be triggered for delete, and replace operations, in these cases zero characters may be inserted, and index1 refers to the start position of the deletion.

    delete
        Zero or more characters will be deleted, this event will be triggered before the deletion has been realized. Index1 and index2 are specifying the range of the characters to be deleted, this range can be empty. Info will contain six items:

        [1] The deleted characters.

        [2] A list of tags applied to the character just before the deleted characters.

        [3] A list of tags applied to the character just after the deleted characters.

        [4] A list of tage applied to the first deleted character.

        [5] A list of tage applied to the last deleted character.

        [6] A boolean flag indicating whether this is the final part of a multi-delete/replace.

        This event will also be triggered for insert, and replace operations, in these cases the deletion range may be empty, and index1 refers to the start position of the insertion.

        It should be avoided to call commands inside this event which will insert or delete, the result can be unexpected. Such commands should be postponed, either with the after command, or until the corresponding insert event will be triggered.

    cursor
        The position of the insertion cursor has been moved. Index1 is the old character position, and can be empty, index2 is the new character position of the cursor. Here info contains a list of tags which would be applied if the user (GUI) is inserting a character at the new cursor position.

    view
        The view of the widget has changed (scrolling the widget, moving the cursor, the see command has been executed, or any other modifying command has been performed - see the list of modifiying commands above). Here index1 specifies the pixel position of the upper left corner in the form @x,y, and index2 specifies the pixel position of the lower right corner. Info does not have a meaning here and will be empty.

    undo
        An undo action has been performed. Info contains two elements. The first is the performed undo command, one of: delete, image, insert, mark, tag, or window. The second is a boolean flag indicating whether this is the final part of a multi-undo action.

        It is not allowed to perform any textual modification, nor is it allowed to reset the undo/redo stack, an error will be thrown.

    redo
        A redo action has been performed. Info contains two elements. The first is the performed redo command, one of: delete, image, insert, mark, tag, or window. The second is a boolean flag indicating whether this is the final part of a multi-redo action.

        It is not allowed to perform any textual modification, nor is it allowed to reset the undo/redo stack, an error will be thrown.

    image
        An image has been resized, or the content has changed. Info contains the name of the affected image as first element. In case of a change in size the width and height of the image before resizing will be the second and third element of info.

    window
        Either a window has changed the display state (mapped or unmapped), or the size of the window has changed. Info contains the name of the affected window as first element. And if the size of the window has changed, then info will provide the old width and height with a second and third element.

    PathName is the name of the widget where the modification has been done. In case of insert/delete also the modifications in a different peer will be triggered for this widget, provided that the range of the modification is inside the displayed range. It is guaranteed that the widget, where the insert/delete has been done, will be triggered at first, but the order of triggering other peers is unspecified.

    If commandPrefix is not specified, then the watch of modifications will be terminated. Otherwise it will replace any existing script, but if the first character is then the new script augments an existing script.

    This command returns the command prefix which has been set before this call, this can be empty if a command prefix was not set.

pathName window option ?arg ...?
    This command is used to manipulate embedded windows. The behavior of the command depends on the option argument that follows the window argument. The following forms of the command are currently supported:

    pathName window cget index option
        Returns the value of a configuration option for an embedded window. Index identifies the embedded window, and option specifies a particular configuration option, which must be one of the ones listed in the section EMBEDDED WINDOWS.

    pathName window configure index ?option value ...?
        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 (see Tk_ConfigureInfo for information on the format of this list). 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 EMBEDDED WINDOWS for information on the options that are supported.

    pathName window create index ?option value ...?
        This command creates a new window annotation, which will appear in the text at the position given by index. Any number of option-value pairs may be specified to configure the annotation. See EMBEDDED WINDOWS for information on the options that are supported. Returns an empty string.

    pathName window names
        Returns a list whose elements are the names of all windows currently embedded in window.

pathName xview option args
    This command is used to query and change the horizontal position of the text in the widget's window. It can take any of the following forms:

    pathName xview
        Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the portion of the document's horizontal span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the text is off-screen to the left, the middle 40% is visible in the window, and 40% of the text is off-screen to the right. The fractions refer only to the lines that are actually visible in the window: if the lines in the window are all very short, so that they are entirely visible, the returned fractions will be 0 and 1, even if there are other lines in the text that are much wider than the window. These are the same values passed to scrollbars via the -xscrollcommand option.

    pathName xview moveto fraction
        Adjusts the view in the window so that fraction of the horizontal span of the text is off-screen to the left. Fraction is a fraction between 0 and 1.

    pathName xview scroll number what
        This command shifts the view in the window left or right according to number and what. What must be pages, pixels, or units. If what is pages or units then number must be an integer, otherwise number may be specified in any of the forms acceptable to Tk_GetPixels, such as or (the result is rounded to the nearest integer value. If no units are given, pixels are assumed). If what is pages then the view adjusts by number screenfuls; if it is pixels then the view adjusts by number pixels; if it is units, the view adjusts left or right by number average-width characters on the display. If number is negative then characters farther to the left become visible; if it is positive then characters farther to the right become visible.

pathName yview ?args?
    This command is used to query and change the vertical position of the text in the widget's window. It can take any of the following forms:

    pathName yview
        Returns a list containing two elements, both of which are real fractions between 0 and 1. The first element gives the position of the first visible pixel of the first character (or image, etc) in the top line in the window, relative to the text as a whole (0.5 means it is halfway through the text, for example). The second element gives the position of the first pixel just after the last visible one in the bottom line of the window, relative to the text as a whole. These are the same values passed to scrollbars via the -yscrollcommand option.

    pathName yview moveto fraction
        Adjusts the view in the window so that the pixel given by fraction appears at the top of the top line of the window. Fraction is a fraction between 0 and 1; 0 indicates the first pixel of the first character in the text, 0.33 indicates the pixel that is one-third the way through the text; and so on. Values close to 1 will indicate values close to the last pixel in the text (1 actually refers to one pixel beyond the last pixel), but in such cases the widget will never scroll beyond the last pixel, and so a value of 1 will effectively be rounded back to whatever fraction ensures the last pixel is at the bottom of the window, and some other pixel is at the top.

    pathName yview scroll number what
        This command adjust the view in the window up or down according to number and what. What must be pages, pixels, or units. If what is units or pages then number must be an integer, otherwise number may be specified in any of the forms acceptable to Tk_GetPixels, such as or (the result is rounded to the nearest integer value. If no units are given, pixels are assumed). If what is units, the view adjusts up or down by number lines on the display; if it is pages then the view adjusts by number screenfuls; if it is pixels then the view adjusts by number pixels. If number is negative then earlier positions in the text become visible; if it is positive then later positions in the text become visible.

    pathName yview ?-pickplace? index
        Changes the view in the widget's window to make index visible. If the -pickplace option is not specified then index will appear at the top of the window. If -pickplace is specified then the widget chooses where index appears in the window:

        [1] If index is already visible somewhere in the window then the command does nothing.

        [2] If index is only a few lines off-screen above the window then it will be positioned at the top of the window.

        [3] If index is only a few lines off-screen below the window then it will be positioned at the bottom of the window.

        [4] Otherwise, index will be centered in the window.

        The -pickplace option has been obsoleted by the pathName see widget command (pathName see handles both x- and y-motion to make a location visible, whereas the -pickplace mode only handles motion in y).

    pathName yview number
        This command makes the first character on the line after the one given by number visible at the top of the window. Number must be an integer. This command used to be used for scrolling, but now it is obsolete.

BINDINGS

Tk automatically creates class bindings for texts that give them the following default behavior. In the descriptions below, is dependent on the value of the tcl_wordchars variable. See tclvars(n).

[1] Clicking mouse button 1 positions the insertion cursor at the closest edge of the character underneath the mouse cursor, sets the input focus to this widget, and clears any selection in the widget. Dragging with mouse button 1 strokes out a selection between the insertion cursor and the character under the mouse.

[2] Double-clicking with mouse button 1 selects the word under the mouse and positions the insertion cursor at the start of the word. Dragging after a double click will stroke out a selection consisting of whole words.

[3] Triple-clicking with mouse button 1 selects the line under the mouse and positions the insertion cursor at the start of the line. Dragging after a triple click will stroke out a selection consisting of whole lines.

[4] The ends of the selection can be adjusted by dragging with mouse button 1 while the Shift key is down; this will adjust the end of the selection that was nearest to the mouse cursor when button 1 was pressed. If the button is double-clicked before dragging then the selection will be adjusted in units of whole words; if it is triple-clicked then the selection will be adjusted in units of whole lines.

[5] Clicking mouse button 1 with the Control key down will reposition the insertion cursor without affecting the selection.

[6] If any normal printing characters are typed, they are inserted at the point of the insertion cursor.

[7] The view in the widget can be adjusted by dragging with the middle mouse button (button 2, or button 3 in TkAqua). If the middle mouse button is clicked without moving the mouse, the selection is copied into the text at the position of the mouse cursor. The Insert key also inserts the selection, but at the position of the insertion cursor.

[8] If the mouse is dragged out of the widget while button 1 is pressed, the entry will automatically scroll to make more text visible (if there is more text off-screen on the side where the mouse left the window).

[9] The Left and Right keys move the insertion cursor one character to the left or right; they also clear any selection in the text. If Left or Right is typed with the Shift key down, then the insertion cursor moves and the selection is extended to include the new character. Control-Left and Control-Right move the insertion cursor by words, and Control-Shift-Left and Control-Shift-Right move the insertion cursor by words and also extend the selection. Control-b and Control-f behave the same as Left and Right, respectively. Meta-b and Meta-f behave the same as Control-Left and Control-Right, respectively.

[10]
    The Up and Down keys move the insertion cursor one line up or down and clear any selection in the text. If Up or Right is typed with the Shift key down, then the insertion cursor moves and the selection is extended to include the new character. Control-Up and Control-Down move the insertion cursor by paragraphs (groups of lines separated by blank lines), and Control-Shift-Up and Control-Shift-Down move the insertion cursor by paragraphs and also extend the selection. Control-p and Control-n behave the same as Up and Down, respectively.

[11]
    The Next and Prior keys move the insertion cursor forward or backwards by one screenful and clear any selection in the text. If the Shift key is held down while Next or Prior is typed, then the selection is extended to include the new character.

[12]
    Control-Next and Control-Prior scroll the view right or left by one page without moving the insertion cursor or affecting the selection.

[13]
    Home and Control-a move the insertion cursor to the beginning of its display line and clear any selection in the widget. Shift-Home moves the insertion cursor to the beginning of the display line and also extends the selection to that point.

[14]
    End and Control-e move the insertion cursor to the end of the display line and clear any selection in the widget. Shift-End moves the cursor to the end of the display line and extends the selection to that point.

[15]
    Control-Home and Meta-< move the insertion cursor to the beginning of the text and clear any selection in the widget. Control-Shift-Home moves the insertion cursor to the beginning of the text and also extends the selection to that point.

[16]
    Control-End and Meta-> move the insertion cursor to the end of the text and clear any selection in the widget. Control-Shift-End moves the cursor to the end of the text and extends the selection to that point.

[17]
    The Select key and Control-Space set the selection anchor to the position of the insertion cursor. They do not affect the current selection. Shift-Select and Control-Shift-Space adjust the selection to the current position of the insertion cursor, selecting from the anchor to the insertion cursor if there was not any selection previously.

[18]
    Control-/ selects the entire contents of the widget.

[19]
    Control-\ clears any selection in the widget.

[20]
    The F16 key (labelled Copy on many Sun workstations) or Meta-w copies the selection in the widget to the clipboard, if there is a selection. This action is carried out by the command tk_textCopy.

[21]
    The F20 key (labelled Cut on many Sun workstations) or Control-w copies the selection in the widget to the clipboard and deletes the selection. This action is carried out by the command tk_textCut. If there is no selection in the widget then these keys have no effect.

[22]
    The F18 key (labelled Paste on many Sun workstations) or Control-y inserts the contents of the clipboard at the position of the insertion cursor. This action is carried out by the command tk_textPaste.

[23]
    The Delete key deletes the selection, if there is one in the widget. If there is no selection, it deletes the character to the right of the insertion cursor.

[24]
    Backspace and Control-h delete the selection, if there is one in the widget. If there is no selection, they delete the character to the left of the insertion cursor.

[25]
    Control-d deletes the character to the right of the insertion cursor.

[26]
    Meta-d deletes the word to the right of the insertion cursor.

[27]
    Control-k deletes from the insertion cursor to the end of its line; if the insertion cursor is already at the end of a line, then Control-k deletes the newline character.

[28]
    Control-o opens a new line by inserting a newline character in front of the insertion cursor without moving the insertion cursor.

[29]
    Meta-backspace and Meta-Delete delete the word to the left of the insertion cursor.

[30]
    Control-t reverses the order of the two characters to the right of the insertion cursor.

[31]
    Control-x deletes whatever is selected in the text widget after copying it to the clipboard.

[32]
    Control-z undoes the last edit action if the -undo option is true. Does nothing otherwise.

[33]
    Control-Z (or Control-y on Windows) reapplies the last undone edit action if the -undo option is true. Does nothing otherwise.

If the widget is disabled using the -state option, then its view can still be adjusted and text can still be selected, but no insertion cursor will be displayed and no text modifications will take place.

The behavior of texts can be changed by defining new bindings for individual widgets or by redefining the class bindings.

DEPRECIATION WARNINGS

Some functions/options now are marked as deprecated and will be removed in a later version. Here is an overview about all possible depreciation warnings, with possible solutions:

•   tk::text: Option "-startline" is deprecated, please use option "-startindex".

Replace all occurrences of with

•   tk::text: Option "-endline" is deprecated, please use option "-endindex".

Replace all occurrences of with

•   tk::text: Attempt to modify a disabled widget is deprecated.

Remove this useless expression, a disabled widget cannot be modified.

•   tk::text: Attempt to modify a dead widget is deprecated.

Remove this useless expression, a dead widget (does not contain lines and does not show an insertion cursor) cannot be modified.

•   tk::text: Command "edit canredo" is deprecated, please use "edit info".

Replace all occurrences with

•   tk::text: Command "edit canundo" is deprecated, please use "edit info".

Replace all occurrences with

•   tk::text: "begin" is a reserved index identifier and shouldn't be used for mark names anymore.

Replace this mark name with a different mark name, but do this at all places where begin is used as a name for a mark.

•   tk::text: Tag option "-overstrikefg" is deprecated, please use option "-overstrikecolor".

Replace all occurrences with

•   tk::text: Tag option "-underlinefg" is deprecated, please use option "-underlinecolor".

Replace all occurrences with

KNOWN ISSUES

  ISSUES CONCERNING INDICES

Currently the special index specifier begin has the lowest precedence, although it should have the same precedence as the special index special end (see section INDICES). In a future release this will be corrected. The current behavior is a workaround, avoiding that existing applications will break with the introduction of begin.

  ISSUES CONCERNING WIDGET STATE

Older versions of text widgets are ignoring textual changes (insert/replace/delete) if the state of the widget is set to disabled (see widget option -state). But it allows to insert/delete embedded windows and images. Because of compatibility reasons this behavior has not been changed. But in future versions also inserting/deleting embedded windows and images should not be allowed. Furthermore in a future version an error message should be thrown when attempting to make textual changes (including embedded windows and images), because silently ignoring changes (current behavior) can be quite confusing.

  ISSUES CONCERNING DEAD PEERS

See isdead about dead peers. Because of compatibility reasons textual changes within a dead peer are still allowed, although it has no effect, but in future versions of text widgets an error message should be thrown when attempting to make changes within a dead peer.

  PERFORMANCE ISSUES

Text widgets should run efficiently under a variety of conditions. The text widget uses about 2-3 bytes of main memory for each byte of text, so texts containing a megabyte or more should be practical on most workstations. Text is represented internally with a modified B-tree structure that makes operations relatively efficient even with large texts. Tags are included in the B-tree structure in a way that allows tags to span large ranges or have many disjoint smaller ranges without loss of efficiency. Marks are also implemented in a way that allows large numbers of marks. In most cases it is fine to have large numbers of unique tags, or a tag that has many distinct ranges.

One performance problem can arise if you have hundreds or thousands of different tags that all have the following characteristics: the first and last ranges of each tag are near the beginning and end of the text, respectively, or a single tag range covers most of the text widget. The cost of adding and deleting tags like this is proportional to the number of other tags with the same properties. In contrast, there is no problem with having thousands of distinct tags if their overall ranges are localized and spread uniformly throughout the text.

The display line with the insert cursor is redrawn each time the cursor blinks, which causes a steady stream of graphics traffic. Set the -insertofftime attribute to zero for avoiding this.

  KNOWN BUGS

The pathName search -regexp sub-command attempts to perform sophisticated regexp matching across multiple lines in an efficient fashion (since Tk 8.5), examining each line individually, and then in small groups of lines, whether searching forwards or backwards. Under certain conditions the search result might differ from that obtained by applying the same regexp to the entire text from the widget in one go. For example, when searching with a greedy regexp, the widget will continue to attempt to add extra lines to the match as long as one of two conditions are true: either Tcl's regexp library returns a code to indicate a longer match is possible (but there are known bugs in Tcl which mean this code is not always correctly returned); or if each extra line added results in at least a partial match with the pattern. This means in the case where the first extra line added results in no match and Tcl's regexp system returns the incorrect code and adding a second extra line would actually match, the text widget will return the wrong result. In practice this is a rare problem, but it can occur, for example:

pack [text .t] .t insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n" .t search -regexp -- {(a+|b+\nc+\nb+)+\na+} 1.0

will not find a match when one exists of 19 characters starting from the first

Whenever one possible match is fully enclosed in another, the search command will attempt to ensure only the larger match is returned. When performing backwards regexp searches it is possible that Tcl will not always achieve this, in the case where a match is preceded by one or more short, non-overlapping matches, all of which are preceded by a large match which actually encompasses all of them. The search algorithm used by the widget does not look back arbitrarily far for a possible match which might cover large portions of the widget. For example:

pack [text .t] .t insert 1.0 "aaaa\nbbbb\nbbbb\nbbbb\nbbbb\n" .t search -regexp -backward -- {b+\n|a+\n(b+\n)+} end

matches at when a true greedy match would match at Similarly if we add -all to this case, it matches at all of and when really it should only match at since that match encloses all the others.

SEE ALSO
entry(n), scrollbar(n)

KEYWORDS
text, widget, tkvars