OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tk8.6.12 / doc / text.n
1 '\"
2 '\" Copyright (c) 1992 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH text n 8.5 Tk "Tk Built-In Commands"
9 .so man.macros
10 .BS
11 '\" Note: do not modify the .SH NAME line immediately below!
12 .SH NAME
13 text, tk_textCopy, tk_textCut, tk_textPaste \- Create and manipulate 'text' hypertext editing widgets
14 .SH SYNOPSIS
15 .nf
16 \fBtext\fR \fIpathName \fR?\fIoptions\fR?
17 \fBtk_textCopy\fR \fIpathName\fR
18 \fBtk_textCut\fR \fIpathName\fR
19 \fBtk_textPaste\fR \fIpathName\fR
20 .SO
21 \-background    \-highlightthickness    \-relief
22 \-borderwidth   \-insertbackground      \-selectbackground
23 \-cursor        \-insertborderwidth     \-selectborderwidth
24 \-exportselection       \-insertofftime \-selectforeground
25 \-font  \-insertontime  \-setgrid
26 \-foreground    \-insertwidth   \-takefocus
27 \-highlightbackground   \-padx  \-xscrollcommand
28 \-highlightcolor        \-pady  \-yscrollcommand
29 .SE
30 .SH "WIDGET-SPECIFIC OPTIONS"
31 .OP \-autoseparators autoSeparators AutoSeparators
32 Specifies a boolean that says whether separators are automatically inserted in
33 the undo stack. Only meaningful when the \fB\-undo\fR option is true.
34 .OP \-blockcursor blockCursor BlockCursor
35 Specifies a boolean that says whether the blinking insertion cursor should be
36 drawn as a character-sized rectangular block. If false (the default) a thin
37 vertical line is used for the insertion cursor.
38 .OP \-endline endLine EndLine
39 Specifies an integer line index representing the line of the underlying
40 textual data store that should be just after the last line contained in
41 the widget. This allows a text widget to reflect only a portion of a
42 larger piece of text. Instead of an integer, the empty string can be
43 provided to this configuration option, which will configure the widget
44 to end at the very last line in the textual data store.
45 .OP \-height height Height
46 Specifies the desired height for the window, in units of characters in the
47 font given by the \fB\-font\fR option. Must be at least one.
48 .OP \-inactiveselectbackground inactiveSelectBackground Foreground
49 Specifies the colour to use for the selection (the \fBsel\fR tag) when the
50 window does not have the input focus. If empty, \fB{}\fR, then no selection is
51 shown when the window does not have the focus.
52 .OP \-insertunfocussed insertUnfocussed InsertUnfocussed
53 .VS 8.6
54 Specifies how to display the insertion cursor when the widget does not have
55 the focus. Must be \fBnone\fR (the default) which means to not display the
56 cursor, \fBhollow\fR which means to display a hollow box, or \fBsolid\fR which
57 means to display a solid box. Note that \fBhollow\fR and \fBsolid\fR will
58 appear very similar when the \fB\-blockcursor\fR option is false.
59 .VE 8.6
60 .OP \-maxundo maxUndo MaxUndo
61 Specifies the maximum number of compound undo actions on the undo stack. A
62 zero or a negative value imply an unlimited undo stack.
63 .OP \-spacing1 spacing1 Spacing1
64 Requests additional space above each text line in the widget, using any of the
65 standard forms for screen distances. If a line wraps, this option only applies
66 to the first line on the display. This option may be overridden with
67 \fB\-spacing1\fR options in tags.
68 .OP \-spacing2 spacing2 Spacing2
69 For lines that wrap (so that they cover more than one line on the display)
70 this option specifies additional space to provide between the display lines
71 that represent a single line of text. The value may have any of the standard
72 forms for screen distances. This option may be overridden with
73 \fB\-spacing2\fR options in tags.
74 .OP \-spacing3 spacing3 Spacing3
75 Requests additional space below each text line in the widget, using any of the
76 standard forms for screen distances. If a line wraps, this option only applies
77 to the last line on the display. This option may be overridden with
78 \fB\-spacing3\fR options in tags.
79 .OP \-startline startLine StartLine
80 Specifies an integer line index representing the first line of the underlying
81 textual data store that should be contained in the widget. This allows a text
82 widget to reflect only a portion of a larger piece of text. Instead of an
83 integer, the empty string can be provided to this configuration option, which
84 will configure the widget to start at the very first line in the textual data
85 store.
86 .OP \-state state State
87 Specifies one of two states for the text: \fBnormal\fR or \fBdisabled\fR. If
88 the text is disabled then characters may not be inserted or deleted and no
89 insertion cursor will be displayed, even if the input focus is in the widget.
90 .OP \-tabs tabs Tabs
91 Specifies a set of tab stops for the window. The option's value consists of a
92 list of screen distances giving the positions of the tab stops, each of which
93 is a distance relative to the left edge of the widget (excluding borders,
94 padding, etc). Each position may optionally be followed in the next list
95 element by one of the keywords \fBleft\fR, \fBright\fR, \fBcenter\fR, or
96 \fBnumeric\fR, which specifies how to justify text relative to the tab stop.
97 \fBLeft\fR is the default; it causes the text following the tab character to
98 be positioned with its left edge at the tab position. \fBRight\fR means that
99 the right edge of the text following the tab character is positioned at the
100 tab position, and \fBcenter\fR means that the text is centered at the tab
101 position. \fBNumeric\fR means that the decimal point in the text is positioned
102 at the tab position; if there is no decimal point then the least significant
103 digit of the number is positioned just to the left of the tab position; if
104 there is no number in the text then the text is right-justified at the tab
105 position. For example,
106 .QW "\fB\-tabs {2c left 4c 6c center}\fR"
107 creates three tab stops at two-centimeter intervals; the first two use left
108 justification and the third uses center justification.
109 .RS
110 .PP
111 If the list of tab stops does not have enough elements to cover all of the
112 tabs in a text line, then Tk extrapolates new tab stops using the spacing and
113 alignment from the last tab stop in the list. Tab distances must be strictly
114 positive, and must always increase from one tab stop to the next (if not, an
115 error is thrown). The value of the \fB\-tabs\fR option may be overridden by
116 \fB\-tabs\fR options in tags.
117 .PP
118 If no \fB\-tabs\fR option is specified, or if it is specified as an empty
119 list, then Tk uses default tabs spaced every eight (average size) characters.
120 To achieve a different standard spacing, for example every 4 characters,
121 simply configure the widget with
122 .QW "\fB\-tabs \N'34'[expr {4 * [font measure $font 0]}] left\N'34' \-tabstyle wordprocessor\fR" .
123 .RE
124 .OP \-tabstyle tabStyle TabStyle
125 Specifies how to interpret the relationship between tab stops on a line and
126 tabs in the text of that line. The value must be \fBtabular\fR (the default)
127 or \fBwordprocessor\fR. Note that tabs are interpreted as they are encountered
128 in the text. If the tab style is \fBtabular\fR then the \fIn\fR'th tab
129 character in the line's text will be associated with the \fIn\fR'th tab stop
130 defined for that line. If the tab character's x coordinate falls to the right
131 of the \fIn\fR'th tab stop, then a gap of a single space will be inserted as a
132 fallback. If the tab style is \fBwordprocessor\fR then any tab character being
133 laid out will use (and be defined by) the first tab stop to the right of the
134 preceding characters already laid out on that line. The value of the
135 \fB\-tabstyle\fR option may be overridden by \fB\-tabstyle\fR options in tags.
136 .OP \-undo undo Undo
137 Specifies a boolean that says whether the undo mechanism is active or not.
138 .OP \-width width Width
139 Specifies the desired width for the window in units of characters in the font
140 given by the \fB\-font\fR option. If the font does not have a uniform width
141 then the width of the character
142 .QW 0
143 is used in translating from character units to screen units.
144 .OP \-wrap wrap Wrap
145 Specifies how to handle lines in the text that are too long to be displayed in
146 a single line of the text's window. The value must be \fBnone\fR or \fBchar\fR
147 or \fBword\fR. A wrap mode of \fBnone\fR means that each line of text appears
148 as exactly one line on the screen; extra characters that do not fit on the
149 screen are not displayed. In the other modes each line of text will be broken
150 up into several screen lines if necessary to keep all the characters visible.
151 In \fBchar\fR mode a screen line break may occur after any character; in
152 \fBword\fR mode a line break will only be made at word boundaries.
153 .BE
154 .SH DESCRIPTION
155 .PP
156 The \fBtext\fR command creates a new window (given by the \fIpathName\fR
157 argument) and makes it into a text widget. Additional options, described
158 above, may be specified on the command line or in the option database to
159 configure aspects of the text such as its default background color and relief.
160 The \fBtext\fR command returns the path name of the new window.
161 .PP
162 A text widget displays one or more lines of text and allows that text to be
163 edited. Text widgets support four different kinds of annotations on the text,
164 called tags, marks, embedded windows or embedded images. Tags allow different
165 portions of the text to be displayed with different fonts and colors. In
166 addition, Tcl commands can be associated with tags so that scripts are invoked
167 when particular actions such as keystrokes and mouse button presses occur in
168 particular ranges of the text. See \fBTAGS\fR below for more details.
169 .PP
170 The second form of annotation consists of floating markers in the text called
171 .QW marks .
172 Marks are used to keep track of various interesting positions in the text as
173 it is edited. See \fBMARKS\fR below for more details.
174 .PP
175 The third form of annotation allows arbitrary windows to be embedded in a text
176 widget. See \fBEMBEDDED WINDOWS\fR below for more details.
177 .PP
178 The fourth form of annotation allows Tk images to be embedded in a text
179 widget. See \fBEMBEDDED IMAGES\fR below for more details.
180 .PP
181 The text widget also has a built-in undo/redo mechanism. See
182 \fBTHE UNDO MECHANISM\fR below for more details.
183 .PP
184 The text widget allows for the creation of peer widgets. These are other text
185 widgets which share the same underlying data (text, marks, tags, images, etc).
186 See \fBPEER WIDGETS\fR below for more details.
187 .SH INDICES
188 .PP
189 Many of the widget commands for texts take one or more indices as arguments.
190 An index is a string used to indicate a particular place within a text, such
191 as a place to insert characters or one endpoint of a range of characters to
192 delete. Indices have the syntax
193 .CS
194 \fIbase modifier modifier modifier ...\fR
195 .CE
196 Where \fIbase\fR gives a starting point and the \fImodifier\fRs adjust the
197 index from the starting point (e.g. move forward or backward one character).
198 Every index must contain a \fIbase\fR, but the \fImodifier\fRs are optional.
199 Most modifiers (as documented below) allow an optional submodifier. Valid
200 submodifiers are \fBany\fR and \fBdisplay\fR. If the submodifier is
201 abbreviated, then it must be followed by whitespace, but otherwise there need
202 be no space between the submodifier and the following \fImodifier\fR.
203 Typically the \fBdisplay\fR submodifier adjusts the meaning of the following
204 \fImodifier\fR to make it refer to visual or non-elided units rather than
205 logical units, but this is explained for each relevant case below. Lastly,
206 where \fIcount\fR is used as part of a modifier, it can be positive or
207 negative, so
208 .QW "\fIbase\fR \- \-3 lines"
209 is perfectly valid (and equivalent to
210 .QW "\fIbase\fR +3lines" ).
211 .PP
212 The \fIbase\fR for an index must have one of the following forms:
213 .TP 12
214 \fIline\fB.\fIchar\fR
215 .
216 Indicates \fIchar\fR'th character on line \fIline\fR. Lines are numbered from
217 1 for consistency with other UNIX programs that use this numbering scheme.
218 Within a line, characters are numbered from 0. If \fIchar\fR is \fBend\fR then
219 it refers to the newline character that ends the line.
220 .TP 12
221 \fB@\fIx\fB,\fIy\fR
222 .
223 Indicates the character that covers the pixel whose x and y coordinates within
224 the text's window are \fIx\fR and \fIy\fR.
225 .TP 12
226 \fBend\fR
227 .
228 Indicates the end of the text (the character just after the last newline).
229 .TP 12
230 \fImark\fR
231 .
232 Indicates the character just after the mark whose name is \fImark\fR.
233 .TP 12
234 \fItag\fB.first\fR
235 .
236 Indicates the first character in the text that has been tagged with \fItag\fR.
237 This form generates an error if no characters are currently tagged with
238 \fItag\fR.
239 .TP 12
240 \fItag\fB.last\fR
241 .
242 Indicates the character just after the last one in the text that has been
243 tagged with \fItag\fR. This form generates an error if no characters are
244 currently tagged with \fItag\fR.
245 .TP 12
246 \fIpathName\fR
247 .
248 Indicates the position of the embedded window whose name is \fIpathName\fR.
249 This form generates an error if there is no embedded window by the given name.
250 .TP 12
251 \fIimageName\fR
252 .
253 Indicates the position of the embedded image whose name is \fIimageName\fR.
254 This form generates an error if there is no embedded image by the given name.
255 .PP
256 If the \fIbase\fR could match more than one of the above forms, such as a
257 \fImark\fR and \fIimageName\fR both having the same value, then the form
258 earlier in the above list takes precedence. If modifiers follow the base
259 index, each one of them must have one of the forms listed below. Keywords such
260 as \fBchars\fR and \fBwordend\fR may be abbreviated as long as the
261 abbreviation is unambiguous.
262 .TP
263 \fB+ \fIcount\fR ?\fIsubmodifier\fR? \fBchars\fR
264 .
265 Adjust the index forward by \fIcount\fR characters, moving to later lines in
266 the text if necessary. If there are fewer than \fIcount\fR characters in the
267 text after the current index, then set the index to the last index in the
268 text. Spaces on either side of \fIcount\fR are optional. If the \fBdisplay\fR
269 submodifier is given, elided characters are skipped over without being
270 counted. If \fBany\fR is given, then all characters are counted. For
271 historical reasons, if neither modifier is given then the count actually takes
272 place in units of index positions (see \fBINDICES\fR for details). This
273 behaviour may be changed in a future major release, so if you need an index
274 count, you are encouraged to use \fBindices\fR instead wherever possible.
275 .TP
276 \fB\- \fIcount\fR ?\fIsubmodifier\fR? \fBchars\fR
277 .
278 Adjust the index backward by \fIcount\fR characters, moving to earlier lines
279 in the text if necessary. If there are fewer than \fIcount\fR characters in
280 the text before the current index, then set the index to the first index in
281 the text (1.0). Spaces on either side of \fIcount\fR are optional. If the
282 \fBdisplay\fR submodifier is given, elided characters are skipped over without
283 being counted. If \fBany\fR is given, then all characters are counted. For
284 historical reasons, if neither modifier is given then the count actually takes
285 place in units of index positions (see \fBINDICES\fR for details). This
286 behavior may be changed in a future major release, so if you need an index
287 count, you are encouraged to use \fBindices\fR instead wherever possible.
288 .TP
289 \fB+ \fIcount\fR ?\fIsubmodifier\fR? \fBindices\fR
290 .
291 Adjust the index forward by \fIcount\fR index positions, moving to later lines
292 in the text if necessary. If there are fewer than \fIcount\fR index positions
293 in the text after the current index, then set the index to the last index
294 position in the text. Spaces on either side of \fIcount\fR are optional. Note
295 that an index position is either a single character or a single embedded image
296 or embedded window. If the \fBdisplay\fR submodifier is given, elided indices
297 are skipped over without being counted. If \fBany\fR is given, then all
298 indices are counted; this is also the default behaviour if no modifier is
299 given.
300 .TP
301 \fB\- \fIcount\fR ?\fIsubmodifier\fR? \fBindices\fR
302 .
303 Adjust the index backward by \fIcount\fR index positions, moving to earlier
304 lines in the text if necessary. If there are fewer than \fIcount\fR index
305 positions in the text before the current index, then set the index to the
306 first index position (1.0) in the text. Spaces on either side of \fIcount\fR
307 are optional. If the \fBdisplay\fR submodifier is given, elided indices are
308 skipped over without being counted. If \fBany\fR is given, then all indices
309 are counted; this is also the default behaviour if no modifier is given.
310 .TP
311 \fB+ \fIcount\fR ?\fIsubmodifier\fR? \fBlines\fR
312 .
313 Adjust the index forward by \fIcount\fR lines, retaining the same character
314 position within the line. If there are fewer than \fIcount\fR lines after the
315 line containing the current index, then set the index to refer to the same
316 character position on the last line of the text. Then, if the line is not long
317 enough to contain a character at the indicated character position, adjust the
318 character position to refer to the last character of the line (the newline).
319 Spaces on either side of \fIcount\fR are optional. If the \fBdisplay\fR
320 submodifier is given, then each visual display line is counted separately.
321 Otherwise, if \fBany\fR (or no modifier) is given, then each logical line (no
322 matter how many times it is visually wrapped) counts just once. If the
323 relevant lines are not wrapped, then these two methods of counting are
324 equivalent.
325 .TP
326 \fB\- \fIcount\fR ?\fIsubmodifier\fR? \fBlines\fR
327 .
328 Adjust the index backward by \fIcount\fR logical lines, retaining the same
329 character position within the line. If there are fewer than \fIcount\fR lines
330 before the line containing the current index, then set the index to refer to
331 the same character position on the first line of the text. Then, if the line
332 is not long enough to contain a character at the indicated character position,
333 adjust the character position to refer to the last character of the line (the
334 newline). Spaces on either side of \fIcount\fR are optional. If the
335 \fBdisplay\fR submodifier is given, then each visual display line is counted
336 separately. Otherwise, if \fBany\fR (or no modifier) is given, then each
337 logical line (no matter how many times it is visually wrapped) counts just
338 once. If the relevant lines are not wrapped, then these two methods of
339 counting are equivalent.
340 .TP
341 ?\fIsubmodifier\fR? \fBlinestart\fR
342 .
343 Adjust the index to refer to the first index on the line. If the \fBdisplay\fR
344 submodifier is given, this is the first index on the display line, otherwise
345 on the logical line.
346 .TP
347 ?\fIsubmodifier\fR? \fBlineend\fR
348 .
349 Adjust the index to refer to the last index on the line (the newline). If the
350 \fBdisplay\fR submodifier is given, this is the last index on the display
351 line, otherwise on the logical line.
352 .TP
353 ?\fIsubmodifier\fR? \fBwordstart\fR
354 .
355 Adjust the index to refer to the first character of the word containing the
356 current index. A word consists of any number of adjacent characters that are
357 letters, digits, or underscores, or a single character that is not one of
358 these. If the \fBdisplay\fR submodifier is given, this only examines
359 non-elided characters, otherwise all characters (elided or not) are examined.
360 .TP
361 ?\fIsubmodifier\fR? \fBwordend\fR
362 .
363 Adjust the index to refer to the character just after the last one of the word
364 containing the current index. If the current index refers to the last
365 character of the text then it is not modified. If the \fBdisplay\fR
366 submodifier is given, this only examines non-elided characters, otherwise all
367 characters (elided or not) are examined.
368 .PP
369 If more than one modifier is present then they are applied in left-to-right
370 order. For example, the index
371 .QW "\fBend \- 1 chars\fR"
372 refers to the next-to-last character in the text and
373 .QW "\fBinsert wordstart \- 1 c\fR"
374 refers to the character just before the first one in the word containing the
375 insertion cursor. Modifiers are applied one by one in this left to right
376 order, and after each step the resulting index is constrained to be a valid
377 index in the text widget. So, for example, the index
378 .QW "\fB1.0 \-1c +1c\fR"
379 refers to the index
380 .QW \fB2.0\fR .
381 .PP
382 Where modifiers result in index changes by display lines, display chars or
383 display indices, and the \fIbase\fR refers to an index inside an elided tag,
384 that base index is considered to be equivalent to the first following
385 non-elided index.
386 .SH TAGS
387 .PP
388 The first form of annotation in text widgets is a tag. A tag is a textual
389 string that is associated with some of the characters in a text. Tags may
390 contain arbitrary characters, but it is probably best to avoid using the
391 characters
392 .QW " "
393 (space), \fB+\fR, or \fB\-\fR: these characters have special meaning in
394 indices, so tags containing them cannot be used as indices. There may be any
395 number of tags associated with characters in a text. Each tag may refer to a
396 single character, a range of characters, or several ranges of characters. An
397 individual character may have any number of tags associated with it.
398 .PP
399 A priority order is defined among tags, and this order is used in implementing
400 some of the tag-related functions described below. When a tag is defined (by
401 associating it with characters or setting its display options or binding
402 commands to it), it is given a priority higher than any existing tag. The
403 priority order of tags may be redefined using the
404 .QW "\fIpathName \fBtag raise\fR"
405 and
406 .QW "\fIpathName \fBtag lower\fR"
407 widget commands.
408 .PP
409 Tags serve three purposes in text widgets. First, they control the way
410 information is displayed on the screen. By default, characters are displayed
411 as determined by the \fB\-background\fR, \fB\-font\fR, and \fB\-foreground\fR
412 options for the text widget. However, display options may be associated with
413 individual tags using the
414 .QW "\fIpathName \fBtag configure\fR"
415 widget command. If a character has been tagged, then the display options
416 associated with the tag override the default display style. The following
417 options are currently supported for tags:
418 .TP
419 \fB\-background \fIcolor\fR
420 .
421 \fIColor\fR specifies the background color to use for characters associated
422 with the tag. It may have any of the forms accepted by \fBTk_GetColor\fR.
423 .TP
424 \fB\-bgstipple \fIbitmap\fR
425 .
426 \fIBitmap\fR specifies a bitmap that is used as a stipple pattern for the
427 background. It may have any of the forms accepted by \fBTk_GetBitmap\fR. If
428 \fIbitmap\fR has not been specified, or if it is specified as an empty string,
429 then a solid fill will be used for the background.
430 .TP
431 \fB\-borderwidth \fIpixels\fR
432 .
433 \fIPixels\fR specifies the width of a border to draw around the tag using any
434 of the forms accepted by \fBTk_GetPixels\fR. This option should be used in
435 conjunction with the \fB\-relief\fR option to provide the desired border.
436 .TP
437 \fB\-elide \fIboolean\fR
438 .
439 \fIElide\fR specifies whether the data should be elided. Elided data
440 (characters, images, embedded windows, etc.) is not displayed and takes no
441 space on screen, but further on behaves just as normal data.
442 .TP
443 \fB\-fgstipple \fIbitmap\fR
444 .
445 \fIBitmap\fR specifies a bitmap that is used as a stipple pattern when drawing
446 text and other foreground information such as underlines. It may have any of
447 the forms accepted by \fBTk_GetBitmap\fR. If \fIbitmap\fR has not been
448 specified, or if it is specified as an empty string, then a solid fill will be
449 used.
450 .TP
451 \fB\-font \fIfontName\fR
452 .
453 \fIFontName\fR is the name of a font to use for drawing characters. It may
454 have any of the forms accepted by \fBTk_GetFont\fR.
455 .TP
456 \fB\-foreground \fIcolor\fR
457 .
458 \fIColor\fR specifies the color to use when drawing text and other foreground
459 information such as underlines. It may have any of the forms accepted by
460 \fBTk_GetColor\fR.
461 .TP
462 \fB\-justify \fIjustify\fR
463 .
464 If the first non-elided character of a display line has a tag for which this
465 option has been specified, then \fIjustify\fR determines how to justify the
466 line. It must be one of \fBleft\fR, \fBright\fR, or \fBcenter\fR. If a line
467 wraps, then the justification for each line on the display is determined by
468 the first non-elided character of that display line.
469 .TP
470 \fB\-lmargin1 \fIpixels\fR
471 .
472 If the first non-elided character of a text line has a tag for which this
473 option has been specified, then \fIpixels\fR specifies how much the line
474 should be indented from the left edge of the window. \fIPixels\fR may have any
475 of the standard forms for screen distances. If a line of text wraps, this
476 option only applies to the first line on the display; the \fB\-lmargin2\fR
477 option controls the indentation for subsequent lines.
478 .TP
479 \fB\-lmargin2 \fIpixels\fR
480 .
481 If the first non-elided character of a display line has a tag for which this
482 option has been specified, and if the display line is not the first for its
483 text line (i.e., the text line has wrapped), then \fIpixels\fR specifies how
484 much the line should be indented from the left edge of the window.
485 \fIPixels\fR may have any of the standard forms for screen distances. This
486 option is only used when wrapping is enabled, and it only applies to the
487 second and later display lines for a text line.
488 .TP
489 \fB\-lmargincolor \fIcolor\fR
490 .
491 \fIColor\fR specifies the background color to use in regions that do not
492 contain characters because they are indented by \fB\-lmargin1\fR or
493 \fB\-lmargin2\fR. It may have any of the forms accepted by
494 \fBTk_GetColor\fR. If \fIcolor\fR has not been specified, or if it is
495 specified as an empty string, then the color used is specified by the
496 \fB-background\fR tag option (or, if this is also unspecified, by the
497 \fB-background\fR widget option).
498 .TP
499 \fB\-offset \fIpixels\fR
500 .
501 \fIPixels\fR specifies an amount by which the text's baseline should be offset
502 vertically from the baseline of the overall line, in pixels. For example, a
503 positive offset can be used for superscripts and a negative offset can be used
504 for subscripts. \fIPixels\fR may have any of the standard forms for screen
505 distances.
506 .TP
507 \fB\-overstrike \fIboolean\fR
508 .
509 Specifies whether or not to draw a horizontal rule through the middle of
510 characters. \fIBoolean\fR may have any of the forms accepted by
511 \fBTcl_GetBoolean\fR.
512 .TP
513 \fB\-overstrikefg \fIcolor\fR
514 .
515 \fIColor\fR specifies the color to use when displaying the overstrike. It may
516 have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not
517 been specified, or if it is specified as an empty string, then the color
518 specified by the \fB\-foreground\fR tag option is used.
519 .TP
520 \fB\-relief \fIrelief\fR
521 .
522 \fIRelief\fR specifies the relief style to use for drawing the border, in any
523 of the forms accepted by \fBTk_GetRelief\fR. This option is used in
524 conjunction with the \fB\-borderwidth\fR option to enable to the desired
525 border appearance.
526 .TP
527 \fB\-rmargin \fIpixels\fR
528 .
529 If the first non-elided character of a display line has a tag for which this
530 option has been specified, then \fIpixels\fR specifies how wide a margin to
531 leave between the end of the line and the right edge of the window.
532 \fIPixels\fR may have any of the standard forms for screen distances. This
533 option is only used when wrapping is enabled. If a text line wraps, the right
534 margin for each line on the display is determined by the first non-elided
535 character of that display line.
536 .TP
537 \fB\-rmargincolor \fIcolor\fR
538 .
539 \fIColor\fR specifies the background color to use in regions that do not
540 contain characters because they are indented by \fB\-rmargin\fR. It may
541 have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not
542 been specified, or if it is specified as an empty string, then the color
543 used is specified by the \fB-background\fR tag option (or, if this is also
544 unspecified, by the \fB-background\fR widget option).
545 .TP
546 \fB\-selectbackground \fIcolor\fR
547 \fIColor\fR specifies the background color to use when displaying selected
548 items. It may have any of the forms accepted by \fBTk_GetColor\fR. If
549 \fIcolor\fR has not been specified, or if it is specified as an empty
550 string, then the color specified by the \fB\-background\fR tag option is
551 used.
552 .TP
553 \fB\-selectforeground \fIcolor\fR
554 \fIColor\fR specifies the foreground color to use when displaying selected
555 items. It may have any of the forms accepted by \fBTk_GetColor\fR. If
556 \fIcolor\fR has not been specified, or if it is specified as an empty
557 string, then the color specified by the \fB\-foreground\fR tag option is
558 used.
559 .TP
560 \fB\-spacing1 \fIpixels\fR
561 .
562 \fIPixels\fR specifies how much additional space should be left above each
563 text line, using any of the standard forms for screen distances. If a line
564 wraps, this option only applies to the first line on the display.
565 .TP
566 \fB\-spacing2 \fIpixels\fR
567 .
568 For lines that wrap, this option specifies how much additional space to leave
569 between the display lines for a single text line. \fIPixels\fR may have any of
570 the standard forms for screen distances.
571 .TP
572 \fB\-spacing3 \fIpixels\fR
573 .
574 \fIPixels\fR specifies how much additional space should be left below each
575 text line, using any of the standard forms for screen distances. If a line
576 wraps, this option only applies to the last line on the display.
577 .TP
578 \fB\-tabs \fItabList\fR
579 .
580 \fITabList\fR specifies a set of tab stops in the same form as for the
581 \fB\-tabs\fR option for the text widget. This option only applies to a display
582 line if it applies to the first non-elided character on that display line. If
583 this option is specified as an empty string, it cancels the option, leaving it
584 unspecified for the tag (the default). If the option is specified as a
585 non-empty string that is an empty list, such as \fB\-tags\0{\0}\fR, then it
586 requests default 8-character tabs as described for the \fB\-tags\fR widget
587 option.
588 .TP
589 \fB\-tabstyle \fIstyle\fR
590 .
591 \fIStyle\fR specifies either the \fItabular\fR or \fIwordprocessor\fR style of
592 tabbing to use for the text widget. This option only applies to a display line
593 if it applies to the first non-elided character on that display line. If this
594 option is specified as an empty string, it cancels the option, leaving it
595 unspecified for the tag (the default).
596 .TP
597 \fB\-underline \fIboolean\fR
598 .
599 \fIBoolean\fR specifies whether or not to draw an underline underneath
600 characters. It may have any of the forms accepted by \fBTcl_GetBoolean\fR.
601 .TP
602 \fB\-underlinefg \fIcolor\fR
603 .
604 \fIColor\fR specifies the color to use when displaying the underline. It may
605 have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not
606 been specified, or if it is specified as an empty string, then the color
607 specified by the \fB\-foreground\fR tag option is used.
608 .TP
609 \fB\-wrap \fImode\fR
610 .
611 \fIMode\fR specifies how to handle lines that are wider than the text's
612 window. This option only applies to a display line if it applies to the
613 first non-elided character on that display line. It has the same legal
614 values as the \fB\-wrap\fR option for the text widget: \fBnone\fR,
615 \fBchar\fR, or \fBword\fR. If this tag option is specified, it
616 overrides the \fB\-wrap\fR option for the text widget.
617 .PP
618 If a character has several tags associated with it, and if their display
619 options conflict, then the options of the highest priority tag are used. If a
620 particular display option has not been specified for a particular tag, or if
621 it is specified as an empty string, then that option will never be used; the
622 next-highest-priority tag's option will used instead. If no tag specifies a
623 particular display option, then the default style for the widget will be used.
624 .PP
625 The second purpose for tags is event bindings. You can associate bindings with
626 a tag in much the same way you can associate bindings with a widget class:
627 whenever particular X events occur on characters with the given tag, a given
628 Tcl command will be executed. Tag bindings can be used to give behaviors to
629 ranges of characters; among other things, this allows hypertext-like features
630 to be implemented. For details, see the description of the
631 .QW "\fIpathName \fBtag bind\fR"
632 widget command below. Tag bindings are shared between all peer widgets
633 (including any bindings for the special \fBsel\fR tag).
634 .PP
635 The third use for tags is in managing the selection. See \fBTHE SELECTION\fR
636 below. With the exception of the special \fBsel\fR tag, all tags are shared
637 between peer text widgets, and may be manipulated on an equal basis from any
638 such widget. The \fBsel\fR tag exists separately and independently in each
639 peer text widget (but any tag bindings to \fBsel\fR are shared).
640 .SH MARKS
641 .PP
642 The second form of annotation in text widgets is a mark. Marks are used for
643 remembering particular places in a text. They are something like tags, in that
644 they have names and they refer to places in the file, but a mark is not
645 associated with particular characters. Instead, a mark is associated with the
646 gap between two characters. Only a single position may be associated with a
647 mark at any given time. If the characters around a mark are deleted the mark
648 will still remain; it will just have new neighbor characters. In contrast, if
649 the characters containing a tag are deleted then the tag will no longer have
650 an association with characters in the file. Marks may be manipulated with the
651 .QW "\fIpathName \fBmark\fR"
652 widget command, and their current locations may be determined by using the
653 mark name as an index in widget commands.
654 .PP
655 Each mark also has a
656 .QW gravity ,
657 which is either \fBleft\fR or \fBright\fR. The gravity for a mark specifies
658 what happens to the mark when text is inserted at the point of the mark. If a
659 mark has left gravity, then the mark is treated as if it were attached to the
660 character on its left, so the mark will remain to the left of any text
661 inserted at the mark position. If the mark has right gravity, new text
662 inserted at the mark position will appear to the left of the mark (so that the
663 mark remains rightmost). The gravity for a mark defaults to \fBright\fR.
664 .PP
665 The name space for marks is different from that for tags: the same name may be
666 used for both a mark and a tag, but they will refer to different things.
667 .PP
668 Two marks have special significance. First, the mark \fBinsert\fR is
669 associated with the insertion cursor, as described under
670 \fBTHE INSERTION CURSOR\fR
671 below. Second, the mark \fBcurrent\fR is associated with the
672 character closest to the mouse and is adjusted automatically to track the
673 mouse position and any changes to the text in the widget (one exception:
674 \fBcurrent\fR is not updated in response to mouse motions if a mouse button is
675 down; the update will be deferred until all mouse buttons have been released).
676 Neither of these special marks may be deleted. With the exception of these two
677 special marks, all marks are shared between peer text widgets, and may be
678 manipulated on an equal basis from any peer.
679 .SH "EMBEDDED WINDOWS"
680 .PP
681 The third form of annotation in text widgets is an embedded window. Each
682 embedded window annotation causes a window to be displayed at a particular
683 point in the text. There may be any number of embedded windows in a text
684 widget, and any widget may be used as an embedded window (subject to the usual
685 rules for geometry management, which require the text window to be the parent
686 of the embedded window or a descendant of its parent).
687 .PP
688 The embedded window's position on the screen will be updated as the text is
689 modified or scrolled, and it will be mapped and unmapped as it moves into and
690 out of the visible area of the text widget. Each embedded window occupies one
691 unit's worth of index space in the text widget, and it may be referred to
692 either by the name of its embedded window or by its position in the widget's
693 index space. If the range of text containing the embedded window is deleted
694 then the window is destroyed. Similarly if the text widget as a whole is
695 deleted, then the window is destroyed.
696 .PP
697 Eliding an embedded window immediately after scheduling it for creation via
698 \fIpathName \fBwindow create \fIindex \fB-create\fR will prevent it from being
699 effectively created. Uneliding an elided embedded window scheduled for creation
700 via \fIpathName \fBwindow create \fIindex \fB-create\fR will automatically
701 trigger the associated creation script. After destroying an elided embedded
702 window, the latter won't get automatically recreated.
703 .PP
704 When an embedded window is added to a text widget with the \fIpathName
705 \fBwindow create\fR widget command, several configuration options may be
706 associated with it. These options may be modified later with the \fIpathName
707 \fBwindow configure\fR widget command. The following options are currently
708 supported:
709 .TP
710 \fB\-align \fIwhere\fR
711 .
712 If the window is not as tall as the line in which it is displayed, this option
713 determines where the window is displayed in the line. \fIWhere\fR must have
714 one of the values \fBtop\fR (align the top of the window with the top of the
715 line), \fBcenter\fR (center the window within the range of the line),
716 \fBbottom\fR (align the bottom of the window with the bottom of the line's
717 area), or \fBbaseline\fR (align the bottom of the window with the baseline of
718 the line).
719 .TP
720 \fB\-create \fIscript\fR
721 .
722 Specifies a Tcl script that may be evaluated to create the window for the
723 annotation. If no \fB\-window\fR option has been specified for the annotation
724 this script will be evaluated when the annotation is about to be displayed on
725 the screen. \fIScript\fR must create a window for the annotation and return
726 the name of that window as its result. Two substitutions will be performed in
727 \fIscript\fR before evaluation. \fI%W\fR will be substituted by the name of
728 the parent text widget, and \fI%%\fR will be substituted by a single \fI%\fR.
729 If the annotation's window should ever be deleted, \fIscript\fR will be
730 evaluated again the next time the annotation is displayed.
731 .TP
732 \fB\-padx \fIpixels\fR
733 .
734 \fIPixels\fR specifies the amount of extra space to leave on each side of the
735 embedded window. It may have any of the usual forms defined for a screen
736 distance.
737 .TP
738 \fB\-pady \fIpixels\fR
739 .
740 \fIPixels\fR specifies the amount of extra space to leave on the top and on
741 the bottom of the embedded window. It may have any of the usual forms defined
742 for a screen distance.
743 .TP
744 \fB\-stretch \fIboolean\fR
745 .
746 If the requested height of the embedded window is less than the height of the
747 line in which it is displayed, this option can be used to specify whether the
748 window should be stretched vertically to fill its line. If the \fB\-pady\fR
749 option has been specified as well, then the requested padding will be retained
750 even if the window is stretched.
751 .TP
752 \fB\-window \fIpathName\fR
753 .
754 Specifies the name of a window to display in the annotation. Note that if a
755 \fIpathName\fR has been set, then later configuring a window to the empty
756 string will not delete the widget corresponding to the old \fIpathName\fR.
757 Rather it will remove the association between the old \fIpathName\fR and the
758 text widget. If multiple peer widgets are in use, it is usually simpler to use
759 the \fB\-create\fR option if embedded windows are desired in each peer.
760 .SH "EMBEDDED IMAGES"
761 .PP
762 The final form of annotation in text widgets is an embedded image. Each
763 embedded image annotation causes an image to be displayed at a particular
764 point in the text. There may be any number of embedded images in a text
765 widget, and a particular image may be embedded in multiple places in the same
766 text widget.
767 .PP
768 The embedded image's position on the screen will be updated as the text is
769 modified or scrolled. Each embedded image occupies one unit's worth of index
770 space in the text widget, and it may be referred to either by its position in
771 the widget's index space, or the name it is assigned when the image is inserted
772 into the text widget with \fIpathName \fBimage create\fR. If the range of text
773 containing the embedded image is deleted then that copy of the image is removed
774 from the screen.
775 .PP
776 Eliding an embedded image immediately after scheduling it for creation via
777 \fIpathName \fBimage create \fIindex \fB-create\fR will prevent it from being
778 effectively created. Uneliding an elided embedded image scheduled for creation
779 via \fIpathName \fBimage create \fIindex \fB-create\fR will automatically
780 trigger the associated creation script. After destroying an elided embedded
781 image, the latter won't get automatically recreated.
782 .PP
783 When an embedded image is added to a text widget with the \fIpathName \fBimage
784 create\fR widget command, a name unique to this instance of the image is
785 returned. This name may then be used to refer to this image instance. The name
786 is taken to be the value of the \fB\-name\fR option (described below). If the
787 \fB\-name\fR option is not provided, the \fB\-image\fR name is used instead.
788 If the \fIimageName\fR is already in use in the text widget, then \fB#\fInn\fR
789 is added to the end of the \fIimageName\fR, where \fInn\fR is an arbitrary
790 integer. This insures the \fIimageName\fR is unique. Once this name is
791 assigned to this instance of the image, it does not change, even though the
792 \fB\-image\fR or \fB\-name\fR values can be changed with \fIpathName \fBimage
793 configure\fR.
794 .PP
795 When an embedded image is added to a text widget with the \fIpathName \fBimage
796 create\fR widget command, several configuration options may be associated with
797 it. These options may be modified later with the \fIpathName \fBimage
798 configure\fR widget command. The following options are currently supported:
799 .TP
800 \fB\-align \fIwhere\fR
801 .
802 If the image is not as tall as the line in which it is displayed, this option
803 determines where the image is displayed in the line. \fIWhere\fR must have one
804 of the values \fBtop\fR (align the top of the image with the top of the line),
805 \fBcenter\fR (center the image within the range of the line), \fBbottom\fR
806 (align the bottom of the image with the bottom of the line's area), or
807 \fBbaseline\fR (align the bottom of the image with the baseline of the line).
808 .TP
809 \fB\-image \fIimage\fR
810 .
811 Specifies the name of the Tk image to display in the annotation. If
812 \fIimage\fR is not a valid Tk image, then an error is returned.
813 .TP
814 \fB\-name \fIImageName\fR
815 .
816 Specifies the name by which this image instance may be referenced in the text
817 widget. If \fIImageName\fR is not supplied, then the name of the Tk image is
818 used instead. If the \fIimageName\fR is already in use, \fI#nn\fR is appended
819 to the end of the name as described above.
820 .TP
821 \fB\-padx \fIpixels\fR
822 .
823 \fIPixels\fR specifies the amount of extra space to leave on each side of the
824 embedded image. It may have any of the usual forms defined for a screen
825 distance.
826 .TP
827 \fB\-pady \fIpixels\fR
828 .
829 \fIPixels\fR specifies the amount of extra space to leave on the top and on
830 the bottom of the embedded image. It may have any of the usual forms defined
831 for a screen distance.
832 .SH "THE SELECTION"
833 .PP
834 Selection support is implemented via tags. If the \fB\-exportselection\fR option
835 for the text widget is true then the \fBsel\fR tag will be associated with the
836 selection:
837 .IP [1]
838 Whenever characters are tagged with \fBsel\fR the text widget will claim
839 ownership of the selection.
840 .IP [2]
841 Attempts to retrieve the selection will be serviced by the text widget,
842 returning all the characters with the \fBsel\fR tag.
843 .IP [3]
844 If the selection is claimed away by another application or by another window
845 within this application, then the \fBsel\fR tag will be removed from all
846 characters in the text.
847 .IP [4]
848 Whenever the \fBsel\fR tag range changes a virtual event \fB<<Selection>>\fR
849 is generated.
850 .PP
851 The \fBsel\fR tag is automatically defined when a text widget is created, and
852 it may not be deleted with the
853 .QW "\fIpathName \fBtag delete\fR"
854 widget command. Furthermore, the \fB\-selectbackground\fR,
855 \fB\-selectborderwidth\fR, and \fB\-selectforeground\fR options for the text
856 widget are tied to the \fB\-background\fR, \fB\-borderwidth\fR, and
857 \fB\-foreground\fR options for the \fBsel\fR tag: changes in either will
858 automatically be reflected in the other. Also the
859 \fB\-inactiveselectbackground\fR option for the text widget is used instead of
860 \fB\-selectbackground\fR when the text widget does not have the focus. This
861 allows programmatic control over the visualization of the \fBsel\fR tag for
862 foreground and background windows, or to have \fBsel\fR not shown at all (when
863 \fB\-inactiveselectbackground\fR is empty) for background windows. Each peer
864 text widget has its own \fBsel\fR tag which can be separately configured and
865 set.
866 .SH "THE INSERTION CURSOR"
867 .PP
868 The mark named \fBinsert\fR has special significance in text widgets. It is
869 defined automatically when a text widget is created and it may not be unset
870 with the
871 .QW "\fIpathName \fBmark unset\fR"
872 widget command. The \fBinsert\fR mark represents the position of the insertion
873 cursor, and the insertion cursor will automatically be drawn at this point
874 whenever the text widget has the input focus.
875 .SH "THE MODIFIED FLAG"
876 .PP
877 The text widget can keep track of changes to the content of the widget by
878 means of the modified flag. Inserting or deleting text will set this flag. The
879 flag can be queried, set and cleared programmatically as well. Whenever the
880 flag changes state a \fB<<Modified>>\fR virtual event is generated. See the
881 \fIpathName \fBedit modified\fR widget command for more details.
882 .SH "THE UNDO MECHANISM"
883 .PP
884 The text widget has an unlimited undo and redo mechanism (when the
885 \fB\-undo\fR widget option is true) which records every insert and delete
886 action on a stack.
887 .PP
888 Boundaries (called
889 .QW separators )
890 are inserted between edit actions. The purpose of these separators is to group
891 inserts, deletes and replaces into one compound edit action. When undoing a
892 change everything between two separators will be undone. The undone changes
893 are then moved to the redo stack, so that an undone edit can be redone again.
894 The redo stack is cleared whenever new edit actions are recorded on the undo
895 stack. The undo and redo stacks can be cleared to keep their depth under
896 control.
897 .PP
898 Separators are inserted automatically when the \fB\-autoseparators\fR widget
899 option is true. You can insert separators programmatically as well. If a
900 separator is already present at the top of the undo stack no other will be
901 inserted. That means that two separators on the undo stack are always
902 separated by at least one insert or delete action.
903 .PP
904 The \fB<<UndoStack>>\fR virtual event is generated every time the undo stack
905 or the redo stack becomes empty or unempty.
906 .PP
907 The undo mechanism is also linked to the modified flag. This means that
908 undoing or redoing changes can take a modified text widget back to the
909 unmodified state or vice versa. The modified flag will be set automatically to
910 the appropriate state. This automatic coupling does not work when the modified
911 flag has been set by the user, until the flag has been reset again.
912 .PP
913 See below for the \fIpathName \fBedit\fR widget command that controls the undo
914 mechanism.
915 .SH "PEER WIDGETS"
916 .PP
917 The text widget has a separate store of all its data concerning each line's
918 textual contents, marks, tags, images and windows, and the undo stack.
919 .PP
920 While this data store cannot be accessed directly (i.e. without a text widget
921 as an intermediary), multiple text widgets can be created, each of which
922 present different views on the same underlying data. Such text widgets are
923 known as peer text widgets.
924 .PP
925 As text is added, deleted, edited and coloured in any one widget, and as
926 images, marks, tags are adjusted, all such changes will be reflected in all
927 peers.
928 .PP
929 All data and markup is shared, except for a few small details. First, the
930 \fBsel\fR tag may be set and configured (in its display style) differently for
931 each peer. Second, each peer has its own \fBinsert\fR and \fBcurrent\fR mark
932 positions (but all other marks are shared). Third, embedded windows, which are
933 arbitrary other widgets, cannot be shared between peers. This means the
934 \fB\-window\fR option of embedded windows is independently set for each peer
935 (it is advisable to use the \fB\-create\fR script capabilities to allow each
936 peer to create its own embedded windows as needed). Fourth, all of the
937 configuration options of each peer (e.g. \fB\-font\fR, etc) can be set
938 independently, with the exception of \fB\-undo\fR, \fB\-maxundo\fR,
939 \fB\-autoseparators\fR (i.e. all undo, redo and modified state issues are
940 shared).
941 .PP
942 Finally any single peer need not contain all lines from the underlying data
943 store. When creating a peer, a contiguous range of lines (e.g. only lines 52
944 through 125) may be specified. This allows a peer to contain just a small
945 portion of the overall text. The range of lines will expand and contract as
946 text is inserted or deleted. The peer will only ever display complete lines of
947 text (one cannot share just part of a line). If the peer's contents contracts
948 to nothing (i.e. all complete lines in the peer widget have been deleted from
949 another widget), then it is impossible for new lines to be inserted. The peer
950 will simply become an empty shell on which the background can be configured,
951 but which will never show any content (without manual reconfiguration of the
952 start and end lines). Note that a peer which does not contain all of the
953 underlying data store still has indices numbered from
954 .QW 1.0
955 to
956 .QW end .
957 It is simply that those indices reflect a subset of the total data, and data
958 outside the contained range is not accessible to the peer. This means that the
959 command \fIpeerName \fBindex end\fR may return quite different values in
960 different peers. Similarly, commands like \fIpeerName \fBtag ranges\fR will
961 not return index ranges outside that which is meaningful to the peer. The
962 configuration options \fB\-startline\fR and \fB\-endline\fR may be used to
963 control how much of the underlying data is contained in any given text widget.
964 .PP
965 Note that peers are really peers. Deleting the
966 .QW original
967 text widget will not cause any other peers to be deleted, or otherwise
968 affected.
969 .PP
970 See below for the \fIpathName \fBpeer\fR widget command that controls the
971 creation of peer widgets.
972 .SH "ASYNCHRONOUS UPDATE OF LINE HEIGHTS"
973 .PP
974 In order to maintain a responsive user-experience, the text widget calculates
975 lines metrics (line heights in pixels) asynchronously. Because of this, some
976 commands of the text widget may return wrong results if the asynchronous
977 calculations are not finished at the time of calling. This applies to
978 \fIpathName \fBcount -ypixels\fR and \fIpathName \fByview\fR.
979 .PP
980 Again for performance reasons, it would not be appropriate to let these
981 commands always wait for the end of the update calculation each time they are
982 called. In most use cases of these commands a more or less inaccurate result
983 does not really matter compared to execution speed.
984 .PP
985 In case accurate result is needed (and if the text widget is managed by a
986 geometry manager), one can resort to \fIpathName \fBsync\fR and \fIpathName
987 \fBpendingsync\fR to control the synchronization of the view of text widgets.
988 .PP
989 The \fB<<WidgetViewSync>>\fR virtual event fires when the line heights of the
990 text widget become obsolete (due to some editing command or configuration
991 change), and again when the internal data of the text widget are back in sync
992 with the widget view. The detail field (%d substitution) is either true (when
993 the widget is in sync) or false (when it is not).
994 .PP
995 \fIpathName \fBsync\fR, \fIpathName \fBpendingsync\fR and
996 \fB<<WidgetViewSync>>\fR apply to each text widget independently of its peers.
997 .PP
998 Examples of use:
999 .CS
1000 ## Example 1:
1001 # immediately complete line metrics at any cost (GUI unresponsive)
1002 $w sync
1003 $w yview moveto $fraction
1004
1005 ## Example 2:
1006 # synchronously wait for up-to-date line metrics (GUI responsive)
1007 # before executing the scheduled command, but don't block execution flow
1008 $w sync -command [list $w yview moveto $fraction]
1009
1010 ## Example 3:
1011 # init
1012 set yud($w) 0
1013 proc updateaction w {
1014 \&set ::yud($w) 1
1015 \&# any other update action here...
1016 }
1017 # runtime, synchronously wait for up-to-date line metrics (GUI responsive)
1018 $w sync -command [list updateaction $w]
1019 vwait yud($w)
1020 $w yview moveto $fraction
1021
1022 ## Example 4:
1023 # init
1024 set todo($w) {}
1025 proc updateaction w {
1026 \&foreach cmd $::todo($w) {uplevel #0 $cmd}
1027 \&set todo($w) {}
1028 }
1029 # runtime
1030 lappend todo($w) [list $w yview moveto $fraction]
1031 $w sync -command [list updateaction $w]
1032
1033 ## Example 5:
1034 # init
1035 set todo($w) {}
1036 bind $w <<WidgetViewSync>> {
1037 \&if {%d} {
1038 \&\&foreach cmd $todo(%W) {eval $cmd}
1039 \&\&set todo(%W) {}
1040 \&}
1041 }
1042 # runtime
1043 if {![$w pendingsync]} {
1044 \&$w yview moveto $fraction
1045 } else {
1046 \&lappend todo($w) [list $w yview moveto $fraction]
1047 }
1048 .CE
1049 .SH "WIDGET COMMAND"
1050 .PP
1051 The \fBtext\fR command creates a new Tcl command whose name is the same as the
1052 path name of the text's window. This command may be used to invoke various
1053 operations on the widget. It has the following general form:
1054 .CS
1055 \fIpathName option \fR?\fIarg arg ...\fR?
1056 .CE
1057 \fIPathName\fR is the name of the command, which is the same as the text
1058 widget's path name. \fIOption\fR and the \fIarg\fRs determine the exact
1059 behavior of the command. The following commands are possible for text widgets:
1060 .TP
1061 \fIpathName \fBbbox \fIindex\fR
1062 .
1063 Returns a list of four elements describing the screen area of the character
1064 given by \fIindex\fR. The first two elements of the list give the x and y
1065 coordinates of the upper-left corner of the area occupied by the character,
1066 and the last two elements give the width and height of the area. If the
1067 character is only partially visible on the screen, then the return value
1068 reflects just the visible part. If the character is not visible on the screen
1069 then the return value is an empty list.
1070 .TP
1071 \fIpathName \fBcget\fR \fIoption\fR
1072 .
1073 Returns the current value of the configuration option given by \fIoption\fR.
1074 \fIOption\fR may have any of the values accepted by the \fBtext\fR command.
1075 .TP
1076 \fIpathName \fBcompare\fR \fIindex1 op index2\fR
1077 .
1078 Compares the indices given by \fIindex1\fR and \fIindex2\fR according to the
1079 relational operator given by \fIop\fR, and returns 1 if the relationship is
1080 satisfied and 0 if it is not. \fIOp\fR must be one of the operators <, <=, ==,
1081 >=, >, or !=. If \fIop\fR is == then 1 is returned if the two indices refer to
1082 the same character, if \fIop\fR is < then 1 is returned if \fIindex1\fR refers
1083 to an earlier character in the text than \fIindex2\fR, and so on.
1084 .TP
1085 \fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
1086 .
1087 Query or modify the configuration options of the widget. If no \fIoption\fR is
1088 specified, returns a list describing all of the available options for
1089 \fIpathName\fR (see \fBTk_ConfigureInfo\fR for information on the format of
1090 this list). If \fIoption\fR is specified with no \fIvalue\fR, then the command
1091 returns a list describing the one named option (this list will be identical to
1092 the corresponding sublist of the value returned if no \fIoption\fR is
1093 specified). If one or more \fIoption\-value\fR pairs are specified, then the
1094 command modifies the given widget option(s) to have the given value(s); in
1095 this case the command returns an empty string. \fIOption\fR may have any of
1096 the values accepted by the \fBtext\fR command.
1097 .TP
1098 \fIpathName \fBcount\fR ?\fIoptions\fR? \fIindex1 index2\fR
1099 .
1100 Counts the number of relevant things between the two indices. If \fIindex1\fR
1101 is after \fIindex2\fR, the result will be a negative number (and this holds
1102 for each of the possible options). The actual items which are counted depend
1103 on the options given. The result is a list of integers, one for the result of
1104 each counting option given. Valid counting options are \fB\-chars\fR,
1105 \fB\-displaychars\fR, \fB\-displayindices\fR, \fB\-displaylines\fR,
1106 \fB\-indices\fR, \fB\-lines\fR, \fB\-xpixels\fR and \fB\-ypixels\fR. The
1107 default value, if no option is specified, is \fB\-indices\fR. There is an
1108 additional possible option \fB\-update\fR which is a modifier. If given (and
1109 if the text widget is managed by a geometry manager), then all subsequent
1110 options ensure that any possible out of date information is recalculated.
1111 This currently only has any effect for the \fB\-ypixels\fR count (which, if
1112 \fB\-update\fR is not given, will use the text widget's current cached value
1113 for each line). This \fB\-update\fR option is obsoleted by \fIpathName
1114 \fBsync\fR, \fIpathName \fBpendingsync\fR and \fB<<WidgetViewSync>>\fR.  The
1115 count options are interpreted as follows:
1116 .RS
1117 .IP \fB\-chars\fR
1118 count all characters, whether elided or not. Do not count embedded windows or
1119 images.
1120 .IP \fB\-displaychars\fR
1121 count all non-elided characters.
1122 .IP \fB\-displayindices\fR
1123 count all non-elided characters, windows and images.
1124 .IP \fB\-displaylines\fR
1125 count all display lines (i.e. counting one for each time a line wraps) from
1126 the line of the first index up to, but not including the display line of the
1127 second index. Therefore if they are both on the same display line, zero will
1128 be returned. By definition displaylines are visible and therefore this only
1129 counts portions of actual visible lines.
1130 .IP \fB\-indices\fR
1131 count all characters and embedded windows or images (i.e. everything which
1132 counts in text-widget index space), whether they are elided or not.
1133 .IP \fB\-lines\fR
1134 count all logical lines (irrespective of wrapping) from the line of the first
1135 index up to, but not including the line of the second index. Therefore if they
1136 are both on the same line, zero will be returned. Logical lines are counted
1137 whether they are currently visible (non-elided) or not.
1138 .IP \fB\-xpixels\fR
1139 count the number of horizontal pixels from the first pixel of the first index
1140 to (but not including) the first pixel of the second index. To count the total
1141 desired width of the text widget (assuming wrapping is not enabled), first
1142 find the longest line and then use
1143 .QW ".text count \-xpixels \N'34'${line}.0\N'34' \N'34'${line}.0 lineend\N'34'" .
1144 .IP \fB\-ypixels\fR
1145 count the number of vertical pixels from the first pixel of the first index to
1146 (but not including) the first pixel of the second index. If both indices are
1147 on the same display line, zero will be returned. To count the total number of
1148 vertical pixels in the text widget, use
1149 .QW ".text count \-ypixels 1.0 end" ,
1150 and to ensure this is up to date, use
1151 .QW ".text count \-update \-ypixels 1.0 end" .
1152 .PP
1153 The command returns a positive or negative integer corresponding to the number
1154 of items counted between the two indices. One such integer is returned for
1155 each counting option given, so a list is returned if more than one option was
1156 supplied. For example
1157 .QW ".text count \-xpixels \-ypixels 1.3 4.5"
1158 is perfectly valid and will return a list of two elements.
1159 .RE
1160 .TP
1161 \fIpathName \fBdebug \fR?\fIboolean\fR?
1162 .
1163 If \fIboolean\fR is specified, then it must have one of the true or false
1164 values accepted by Tcl_GetBoolean. If the value is a true one then internal
1165 consistency checks will be turned on in the B-tree code associated with text
1166 widgets. If \fIboolean\fR has a false value then the debugging checks will be
1167 turned off. In either case the command returns an empty string. If
1168 \fIboolean\fR is not specified then the command returns \fBon\fR or \fBoff\fR
1169 to indicate whether or not debugging is turned on. There is a single debugging
1170 switch shared by all text widgets: turning debugging on or off in any widget
1171 turns it on or off for all widgets. For widgets with large amounts of text,
1172 the consistency checks may cause a noticeable slow-down.
1173 .RS
1174 .PP
1175 When debugging is turned on, the drawing routines of the text widget set the
1176 global variables \fBtk_textRedraw\fR and \fBtk_textRelayout\fR to the lists of
1177 indices that are redrawn. The values of these variables are tested by Tk's
1178 test suite.
1179 .RE
1180 .TP
1181 \fIpathName \fBdelete \fIindex1 \fR?\fIindex2 ...\fR?
1182 .
1183 Delete a range of characters from the text.
1184 If both \fIindex1\fR and \fIindex2\fR are specified, then delete
1185 all the characters starting with the one given by \fIindex1\fR
1186 and stopping just before \fIindex2\fR (i.e. the character at
1187 \fIindex2\fR is not deleted).
1188 If \fIindex2\fR does not specify a position later in the text
1189 than \fIindex1\fR then no characters are deleted.
1190 If \fIindex2\fR is not specified then the single character at
1191 \fIindex1\fR is deleted.
1192 Attempts to delete characters in a way that would leave
1193 the text without a newline as the last character will be tweaked by the
1194 text widget to avoid this. In particular, deletion of complete lines of
1195 text up to the end of the text will also delete the newline character just
1196 before the deleted block so that it is replaced by the new final newline
1197 of the text widget.
1198 The command returns an empty string.
1199 If more indices are given, multiple ranges of text will be deleted.
1200 All indices are first checked for validity before any deletions are made.
1201 They are sorted and the text is removed from the last range to the
1202 first range so deleted text does not cause an undesired index shifting
1203 side-effects.  If multiple ranges with the same start index are given,
1204 then the longest range is used.  If overlapping ranges are given, then
1205 they will be merged into spans that do not cause deletion of text
1206 outside the given ranges due to text shifted during deletion.
1207 .TP
1208 \fIpathName \fBdlineinfo \fIindex\fR
1209 .
1210 Returns a list with five elements describing the area occupied by the display
1211 line containing \fIindex\fR. The first two elements of the list give the x and
1212 y coordinates of the upper-left corner of the area occupied by the line, the
1213 third and fourth elements give the width and height of the area, and the fifth
1214 element gives the position of the baseline for the line, measured down from
1215 the top of the area. All of this information is measured in pixels. If the
1216 current wrap mode is \fBnone\fR and the line extends beyond the boundaries of
1217 the window, the area returned reflects the entire area of the line, including
1218 the portions that are out of the window. If the line is shorter than the full
1219 width of the window then the area returned reflects just the portion of the
1220 line that is occupied by characters and embedded windows. If the display line
1221 containing \fIindex\fR is not visible on the screen then the return value is
1222 an empty list.
1223 .TP
1224 \fIpathName \fBdump \fR?\fIswitches\fR? \fIindex1 \fR?\fIindex2\fR?
1225 .
1226 Return the contents of the text widget from \fIindex1\fR up to, but not
1227 including \fIindex2\fR, including the text and information about marks, tags,
1228 and embedded windows. If \fIindex2\fR is not specified, then it defaults to
1229 one character past \fIindex1\fR. The information is returned in the following
1230 format:
1231 .RS
1232 .LP
1233 \fIkey1 value1 index1 key2 value2 index2\fR ...
1234 .LP
1235 The possible \fIkey\fR values are \fBtext\fR, \fBmark\fR, \fBtagon\fR,
1236 \fBtagoff\fR, \fBimage\fR, and \fBwindow\fR. The corresponding \fIvalue\fR is
1237 the text, mark name, tag name, image name, or window name. The \fIindex\fR
1238 information is the index of the start of the text, mark, tag transition, image
1239 or window. One or more of the following switches (or abbreviations thereof)
1240 may be specified to control the dump:
1241 .TP
1242 \fB\-all\fR
1243 .
1244 Return information about all elements: text, marks, tags, images and windows.
1245 This is the default.
1246 .TP
1247 \fB\-command \fIcommand\fR
1248 .
1249 Instead of returning the information as the result of the dump operation,
1250 invoke the \fIcommand\fR on each element of the text widget within the range.
1251 The command has three arguments appended to it before it is evaluated: the
1252 \fIkey\fR, \fIvalue\fR, and \fIindex\fR.
1253 .TP
1254 \fB\-image\fR
1255 .
1256 Include information about images in the dump results.
1257 .TP
1258 \fB\-mark\fR
1259 .
1260 Include information about marks in the dump results.
1261 .TP
1262 \fB\-tag\fR
1263 .
1264 Include information about tag transitions in the dump results. Tag information
1265 is returned as \fBtagon\fR and \fBtagoff\fR elements that indicate the begin
1266 and end of each range of each tag, respectively.
1267 .TP
1268 \fB\-text\fR
1269 .
1270 Include information about text in the dump results. The value is the text up
1271 to the next element or the end of range indicated by \fIindex2\fR. A text
1272 element does not span newlines. A multi-line block of text that contains no
1273 marks or tag transitions will still be dumped as a set of text segments that
1274 each end with a newline. The newline is part of the value.
1275 .TP
1276 \fB\-window\fR
1277 .
1278 Include information about embedded windows in the dump results. The value of a
1279 window is its Tk pathname, unless the window has not been created yet. (It
1280 must have a create script.) In this case an empty string is returned, and you
1281 must query the window by its index position to get more information.
1282 .RE
1283 .TP
1284 \fIpathName \fBedit \fIoption \fR?\fIarg arg ...\fR?
1285 .
1286 This command controls the undo mechanism and the modified flag. The exact
1287 behavior of the command depends on the \fIoption\fR argument that follows the
1288 \fBedit\fR argument. The following forms of the command are currently
1289 supported:
1290 .RS
1291 .TP
1292 \fIpathName \fBedit canredo\fR
1293 .
1294 Returns a boolean true if redo is possible, i.e. when the redo stack is not
1295 empty. Otherwise returns false.
1296 .TP
1297 \fIpathName \fBedit canundo\fR
1298 .
1299 Returns a boolean true if undo is possible, i.e. when the undo stack is not
1300 empty. Otherwise returns false.
1301 .TP
1302 \fIpathName \fBedit modified \fR?\fIboolean\fR?
1303 .
1304 If \fIboolean\fR is not specified, returns the modified flag of the widget.
1305 The insert, delete, edit undo and edit redo commands or the user can set or
1306 clear the modified flag. If \fIboolean\fR is specified, sets the modified flag
1307 of the widget to \fIboolean\fR.
1308 .TP
1309 \fIpathName \fBedit redo\fR
1310 .
1311 When the \fB\-undo\fR option is true, reapplies the last undone edits provided
1312 no other edits were done since then. Generates an error when the redo stack is
1313 empty. Does nothing when the \fB\-undo\fR option is false.
1314 .TP
1315 \fIpathName \fBedit reset\fR
1316 .
1317 Clears the undo and redo stacks.
1318 .TP
1319 \fIpathName \fBedit separator\fR
1320 .
1321 Inserts a separator (boundary) on the undo stack. Does nothing when the
1322 \fB\-undo\fR option is false.
1323 .TP
1324 \fIpathName \fBedit undo\fR
1325 .
1326 Undoes the last edit action when the \fB\-undo\fR option is true. An edit
1327 action is defined as all the insert and delete commands that are recorded on
1328 the undo stack in between two separators. Generates an error when the undo
1329 stack is empty. Does nothing when the \fB\-undo\fR option is false.
1330 .RE
1331 .TP
1332 \fIpathName \fBget\fR ?\fB\-displaychars\fR? ?\fB\-\-\fR? \fIindex1\fR ?\fIindex2 ...\fR?
1333 .
1334 Return a range of characters from the text. The return value will be all the
1335 characters in the text starting with the one whose index is \fIindex1\fR and
1336 ending just before the one whose index is \fIindex2\fR (the character at
1337 \fIindex2\fR will not be returned). If \fIindex2\fR is omitted then the single
1338 character at \fIindex1\fR is returned. If there are no characters in the
1339 specified range (e.g. \fIindex1\fR is past the end of the file or \fIindex2\fR
1340 is less than or equal to \fIindex1\fR) then an empty string is returned. If
1341 the specified range contains embedded windows, no information about them is
1342 included in the returned string. If multiple index pairs are given, multiple
1343 ranges of text will be returned in a list. Invalid ranges will not be
1344 represented with empty strings in the list. The ranges are returned in the
1345 order passed to \fIpathName \fBget\fR. If the \fB\-displaychars\fR option is
1346 given, then, within each range, only those characters which are not elided
1347 will be returned. This may have the effect that some of the returned ranges
1348 are empty strings.
1349 .TP
1350 \fIpathName \fBimage \fIoption \fR?\fIarg arg ...\fR?
1351 .
1352 This command is used to manipulate embedded images. The behavior of the
1353 command depends on the \fIoption\fR argument that follows the \fBimage\fR
1354 argument. The following forms of the command are currently supported:
1355 .RS
1356 .TP
1357 \fIpathName \fBimage cget \fIindex option\fR
1358 .
1359 Returns the value of a configuration option for an embedded image. \fIIndex\fR
1360 identifies the embedded image, and \fIoption\fR specifies a particular
1361 configuration option, which must be one of the ones listed in the section
1362 \fBEMBEDDED IMAGES\fR.
1363 .TP
1364 \fIpathName \fBimage configure \fIindex\fR ?\fIoption value ...\fR?
1365 .
1366 Query or modify the configuration options for an embedded image. If no
1367 \fIoption\fR is specified, returns a list describing all of the available
1368 options for the embedded image at \fIindex\fR (see \fBTk_ConfigureInfo\fR for
1369 information on the format of this list). If \fIoption\fR is specified with no
1370 \fIvalue\fR, then the command returns a list describing the one named option
1371 (this list will be identical to the corresponding sublist of the value
1372 returned if no \fIoption\fR is specified). If one or more \fIoption\-value\fR
1373 pairs are specified, then the command modifies the given option(s) to have the
1374 given value(s); in this case the command returns an empty string. See
1375 \fBEMBEDDED IMAGES\fR for information on the options that are supported.
1376 .TP
1377 \fIpathName \fBimage create \fIindex\fR ?\fIoption value ...\fR?
1378 .
1379 This command creates a new image annotation, which will appear in the text at
1380 the position given by \fIindex\fR. Any number of \fIoption\-value\fR pairs may
1381 be specified to configure the annotation. Returns a unique identifier that may
1382 be used as an index to refer to this image. See \fBEMBEDDED IMAGES\fR for
1383 information on the options that are supported, and a description of the
1384 identifier returned.
1385 .TP
1386 \fIpathName \fBimage names\fR
1387 .
1388 Returns a list whose elements are the names of all image instances currently
1389 embedded in \fIwindow\fR.
1390 .RE
1391 .TP
1392 \fIpathName \fBindex \fIindex\fR
1393 .
1394 Returns the position corresponding to \fIindex\fR in the form \fIline.char\fR
1395 where \fIline\fR is the line number and \fIchar\fR is the character number.
1396 \fIIndex\fR may have any of the forms described under \fBINDICES\fR above.
1397 .TP
1398 \fIpathName \fBinsert \fIindex chars \fR?\fItagList chars tagList ...\fR?
1399 .
1400 Inserts all of the \fIchars\fR arguments just before the character at
1401 \fIindex\fR. If \fIindex\fR refers to the end of the text (the character after
1402 the last newline) then the new text is inserted just before the last newline
1403 instead. If there is a single \fIchars\fR argument and no \fItagList\fR, then
1404 the new text will receive any tags that are present on both the character
1405 before and the character after the insertion point; if a tag is present on
1406 only one of these characters then it will not be applied to the new text. If
1407 \fItagList\fR is specified then it consists of a list of tag names; the new
1408 characters will receive all of the tags in this list and no others, regardless
1409 of the tags present around the insertion point. If multiple
1410 \fIchars\fR\-\fItagList\fR argument pairs are present, they produce the same
1411 effect as if a separate \fIpathName \fBinsert\fR widget command had been
1412 issued for each pair, in order. The last \fItagList\fR argument may be
1413 omitted.
1414 .TP
1415 \fIpathName \fBmark \fIoption \fR?\fIarg arg ...\fR?
1416 .
1417 This command is used to manipulate marks. The exact behavior of the command
1418 depends on the \fIoption\fR argument that follows the \fBmark\fR argument. The
1419 following forms of the command are currently supported:
1420 .RS
1421 .TP
1422 \fIpathName \fBmark gravity \fImarkName\fR ?\fIdirection\fR?
1423 .
1424 If \fIdirection\fR is not specified, returns \fBleft\fR or \fBright\fR to
1425 indicate which of its adjacent characters \fImarkName\fR is attached to. If
1426 \fIdirection\fR is specified, it must be \fBleft\fR or \fBright\fR; the
1427 gravity of \fImarkName\fR is set to the given value.
1428 .TP
1429 \fIpathName \fBmark names\fR
1430 .
1431 Returns a list whose elements are the names of all the marks that are
1432 currently set.
1433 .TP
1434 \fIpathName \fBmark next \fIindex\fR
1435 .
1436 Returns the name of the next mark at or after \fIindex\fR. If \fIindex\fR is
1437 specified in numerical form, then the search for the next mark begins at that
1438 index. If \fIindex\fR is the name of a mark, then the search for the next mark
1439 begins immediately after that mark. This can still return a mark at the same
1440 position if there are multiple marks at the same index. These semantics mean
1441 that the \fBmark next\fR operation can be used to step through all the marks
1442 in a text widget in the same order as the mark information returned by the
1443 \fIpathName \fBdump\fR operation. If a mark has been set to the special
1444 \fBend\fR index, then it appears to be \fIafter\fR \fBend\fR with respect to
1445 the \fIpathName \fBmark next\fR operation. An empty string is returned if
1446 there are no marks after \fIindex\fR.
1447 .TP
1448 \fIpathName \fBmark previous \fIindex\fR
1449 .
1450 Returns the name of the mark at or before \fIindex\fR. If \fIindex\fR is
1451 specified in numerical form, then the search for the previous mark begins with
1452 the character just before that index. If \fIindex\fR is the name of a mark,
1453 then the search for the next mark begins immediately before that mark. This
1454 can still return a mark at the same position if there are multiple marks at
1455 the same index. These semantics mean that the \fIpathName \fBmark previous\fR
1456 operation can be used to step through all the marks in a text widget in the
1457 reverse order as the mark information returned by the \fIpathName \fBdump\fR
1458 operation. An empty string is returned if there are no marks before
1459 \fIindex\fR.
1460 .TP
1461 \fIpathName \fBmark set \fImarkName index\fR
1462 .
1463 Sets the mark named \fImarkName\fR to a position just before the character at
1464 \fIindex\fR. If \fImarkName\fR already exists, it is moved from its old
1465 position; if it does not exist, a new mark is created. This command returns an
1466 empty string.
1467 .TP
1468 \fIpathName \fBmark unset \fImarkName \fR?\fImarkName markName ...\fR?
1469 .
1470 Remove the mark corresponding to each of the \fImarkName\fR arguments. The
1471 removed marks will not be usable in indices and will not be returned by future
1472 calls to
1473 .QW "\fIpathName \fBmark names\fR" .
1474 This command returns an empty string.
1475 .RE
1476 .TP
1477 \fIpathName \fBpeer \fIoption args\fR
1478 .
1479 This command is used to create and query widget peers. It has two forms,
1480 depending on \fIoption\fR:
1481 .RS
1482 .TP
1483 \fIpathName \fBpeer create \fInewPathName\fR ?\fIoptions\fR?
1484 .
1485 Creates a peer text widget with the given \fInewPathName\fR, and any optional
1486 standard configuration options (as for the \fItext\fR command). By default the
1487 peer will have the same start and end line as the parent widget, but these can
1488 be overridden with the standard configuration options.
1489 .TP
1490 \fIpathName \fBpeer names\fR
1491 .
1492 Returns a list of peers of this widget (this does not include the widget
1493 itself). The order within this list is undefined.
1494 .RE
1495 .TP
1496 \fIpathName \fBpendingsync\fR
1497 Returns 1 if the line heights calculations are not up-to-date, 0 otherwise.
1498 .TP
1499 \fIpathName \fBreplace\fR \fIindex1 index2 chars\fR ?\fItagList chars tagList ...\fR?
1500 Replaces the range of characters between \fIindex1\fR and \fIindex2\fR
1501 with the given characters and tags.  See the section on \fIpathName
1502 \fBinsert\fR for an explanation of the handling of the \fItagList...\fR
1503 arguments, and the section on \fIpathName
1504 \fBdelete\fR for an explanation of the handling of the indices.  If
1505 \fIindex2\fR corresponds to an index earlier in the text than
1506 \fIindex1\fR, an error will be generated.
1507 .RS
1508 .PP
1509 The deletion and insertion are arranged so that no unnecessary scrolling of
1510 the window or movement of insertion cursor occurs. In addition the undo/redo
1511 stack are correctly modified, if undo operations are active in the text
1512 widget. The command returns an empty string.
1513 .RE
1514 .TP
1515 \fIpathName \fBscan \fIoption args\fR
1516 .
1517 This command is used to implement scanning on texts. It has two forms,
1518 depending on \fIoption\fR:
1519 .RS
1520 .TP
1521 \fIpathName \fBscan mark \fIx y\fR
1522 .
1523 Records \fIx\fR and \fIy\fR and the current view in the text window, for use
1524 in conjunction with later \fIpathName \fBscan dragto\fR commands. Typically
1525 this command is associated with a mouse button press in the widget. It returns
1526 an empty string.
1527 .TP
1528 \fIpathName \fBscan dragto \fIx y\fR
1529 .
1530 This command computes the difference between its \fIx\fR and \fIy\fR arguments
1531 and the \fIx\fR and \fIy\fR arguments to the last \fIpathName \fBscan mark\fR
1532 command for the widget. It then adjusts the view by 10 times the difference in
1533 coordinates. This command is typically associated with mouse motion events in
1534 the widget, to produce the effect of dragging the text at high speed through
1535 the window. The return value is an empty string.
1536 .RE
1537 .TP
1538 \fIpathName \fBsearch \fR?\fIswitches\fR? \fIpattern index \fR?\fIstopIndex\fR?
1539 .
1540 Searches the text in \fIpathName\fR starting at \fIindex\fR for a range of
1541 characters that matches \fIpattern\fR. If a match is found, the index of the
1542 first character in the match is returned as result; otherwise an empty string
1543 is returned. One or more of the following switches (or abbreviations thereof)
1544 may be specified to control the search:
1545 .RS
1546 .TP
1547 \fB\-forwards\fR
1548 .
1549 The search will proceed forward through the text, finding the first matching
1550 range starting at or after the position given by \fIindex\fR. This is the
1551 default.
1552 .TP
1553 \fB\-backwards\fR
1554 .
1555 The search will proceed backward through the text, finding the matching range
1556 closest to \fIindex\fR whose first character is before \fIindex\fR (it is not
1557 allowed to be at \fIindex\fR). Note that, for a variety of reasons, backwards
1558 searches can be substantially slower than forwards searches (particularly when
1559 using \fB\-regexp\fR), so it is recommended that performance-critical code use
1560 forward searches.
1561 .TP
1562 \fB\-exact\fR
1563 .
1564 Use exact matching: the characters in the matching range must be identical to
1565 those in \fIpattern\fR. This is the default.
1566 .TP
1567 \fB\-regexp\fR
1568 .
1569 Treat \fIpattern\fR as a regular expression and match it against the text
1570 using the rules for regular expressions (see the \fBregexp\fR command
1571 and the \fBre_syntax\fR page for
1572 details). The default matching automatically passes both the
1573 \fB\-lineanchor\fR and \fB\-linestop\fR options to the regexp engine (unless
1574 \fB\-nolinestop\fR is used), so that \fI^$\fR match beginning and end of line,
1575 and \fI.\fR, \fI[^\fR sequences will never match the newline character
1576 \fI\en\fR.
1577 .TP
1578 \fB\-nolinestop\fR
1579 .
1580 This allows \fI.\fR and \fI[^\fR sequences to match the newline character
1581 \fI\en\fR, which they will otherwise not do (see the \fBregexp\fR command for
1582 details). This option is only meaningful if \fB\-regexp\fR is also given, and
1583 an error will be thrown otherwise. For example, to match the entire text, use
1584 .QW "\fIpathName \fBsearch \-nolinestop \-regexp\fR \N'34'.*\N'34' 1.0" .
1585 .TP
1586 \fB\-nocase\fR
1587 .
1588 Ignore case differences between the pattern and the text.
1589 .TP
1590 \fB\-count\fI varName\fR
1591 .
1592 The argument following \fB\-count\fR gives the name of a variable; if a match
1593 is found, the number of index positions between beginning and end of the
1594 matching range will be stored in the variable. If there are no embedded images
1595 or windows in the matching range (and there are no elided characters if
1596 \fB\-elide\fR is not given), this is equivalent to the number of characters
1597 matched. In either case, the range \fImatchIdx\fR to \fImatchIdx + $count
1598 chars\fR will return the entire matched text.
1599 .TP
1600 \fB\-all\fR
1601 .
1602 Find all matches in the given range and return a list of the indices of the
1603 first character of each match. If a \fB\-count\fI varName\fR switch is given,
1604 then \fIvarName\fR is also set to a list containing one element for each
1605 successful match. Note that, even for exact searches, the elements of this
1606 list may be different, if there are embedded images, windows or hidden text.
1607 Searches with \fB\-all\fR behave very similarly to the Tcl command \fBregexp
1608 \-all\fR, in that overlapping matches are not normally returned. For example,
1609 applying an \fB\-all\fR search of the pattern
1610 .QW \ew+
1611 against
1612 .QW "hello there"
1613 will just match twice, once for each word, and matching
1614 .QW "Z[a\-z]+Z"
1615 against
1616 .QW ZooZooZoo
1617 will just match once.
1618 .TP
1619 \fB\-overlap\fR
1620 .
1621 When performing \fB\-all\fR searches, the normal behaviour is that matches
1622 which overlap an already-found match will not be returned. This switch changes
1623 that behaviour so that all matches which are not totally enclosed within
1624 another match are returned. For example, applying an \fB\-overlap\fR search of
1625 the pattern
1626 .QW \ew+
1627 against
1628 .QW "hello there"
1629 will just match twice (i.e. no different to just \fB\-all\fR), but matching
1630 .QW Z[a\-z]+Z
1631 against
1632 .QW ZooZooZoo
1633 will now match twice. An error will be thrown if this switch is used without
1634 \fB\-all\fR.
1635 .TP
1636 \fB\-strictlimits\fR
1637 .
1638 When performing any search, the normal behaviour is that the start and stop
1639 limits are checked with respect to the start of the matching text. With the
1640 \fB\-strictlimits\fR flag, the entire matching range must lie inside the start
1641 and stop limits specified for the match to be valid.
1642 .TP
1643 \fB\-elide\fR
1644 .
1645 Find elided (hidden) text as well. By default only displayed text is searched.
1646 .TP
1647 \fB\-\|\-\fR
1648 .
1649 This switch has no effect except to terminate the list of switches: the next
1650 argument will be treated as \fIpattern\fR even if it starts with \fB\-\fR.
1651 .PP
1652 The matching range may be within a single line of text, or run across multiple
1653 lines (if parts of the pattern can match a new-line). For regular expression
1654 matching one can use the various newline-matching features such as \fB$\fR to
1655 match the end of a line, \fB^\fR to match the beginning of a line, and to
1656 control whether \fB.\fR is allowed to match a new-line. If \fIstopIndex\fR is
1657 specified, the search stops at that index: for forward searches, no match at
1658 or after \fIstopIndex\fR will be considered; for backward searches, no match
1659 earlier in the text than \fIstopIndex\fR will be considered. If
1660 \fIstopIndex\fR is omitted, the entire text will be searched: when the
1661 beginning or end of the text is reached, the search continues at the other end
1662 until the starting location is reached again; if \fIstopIndex\fR is specified,
1663 no wrap-around will occur. This means that, for example, if the search is
1664 \fB\-forwards\fR but \fIstopIndex\fR is earlier in the text than
1665 \fIstartIndex\fR, nothing will ever be found. See \fBKNOWN BUGS\fR below for a
1666 number of minor limitations of the \fIpathName \fBsearch\fR command.
1667 .RE
1668 .TP
1669 \fIpathName \fBsee \fIindex\fR
1670 .
1671 Adjusts the view in the window so that the character given by \fIindex\fR is
1672 completely visible. If \fIindex\fR is already visible then the command does
1673 nothing. If \fIindex\fR is a short distance out of view, the command adjusts
1674 the view just enough to make \fIindex\fR visible at the edge of the window.
1675 If \fIindex\fR is far out of view, then the command centers \fIindex\fR in the
1676 window.
1677 .TP
1678 \fIpathName \fBsync\fR ?\fB-command \fIcommand\fR?
1679 Controls the synchronization of the view of the text widget.
1680 .RS
1681 .TP
1682 \fIpathName \fBsync\fR
1683 Immediately brings the line metrics up-to-date by forcing computation of any
1684 outdated line heights. The command returns immediately if there is no such
1685 outdated line heights, otherwise it returns only at the end of the computation.
1686 The command returns an empty string.
1687 .TP
1688 \fIpathName \fBsync -command \fIcommand\fR
1689 Schedules \fIcommand\fR to be executed (by the event loop) exactly once as soon
1690 as all line heights are up-to-date. If there are no pending line metrics
1691 calculations, the scheduling is immediate. The command returns the empty
1692 string. \fBbgerror\fR is called on \fIcommand\fR failure.
1693 .RE
1694 .TP
1695 \fIpathName \fBtag \fIoption \fR?\fIarg arg ...\fR?
1696 .
1697 This command is used to manipulate tags. The exact behavior of the command
1698 depends on the \fIoption\fR argument that follows the \fBtag\fR argument. The
1699 following forms of the command are currently supported:
1700 .RS
1701 .TP
1702 \fIpathName \fBtag add \fItagName index1 \fR?\fIindex2 index1 index2 ...\fR?
1703 .
1704 Associate the tag \fItagName\fR with all of the characters starting with
1705 \fIindex1\fR and ending just before \fIindex2\fR (the character at
1706 \fIindex2\fR is not tagged). A single command may contain any number of
1707 \fIindex1\fR\-\fIindex2\fR pairs. If the last \fIindex2\fR is omitted then the
1708 single character at \fIindex1\fR is tagged. If there are no characters in the
1709 specified range (e.g. \fIindex1\fR is past the end of the file or \fIindex2\fR
1710 is less than or equal to \fIindex1\fR) then the command has no effect.
1711 .TP
1712 \fIpathName \fBtag bind \fItagName\fR ?\fIsequence\fR? ?\fIscript\fR?
1713 .
1714 This command associates \fIscript\fR with the tag given by \fItagName\fR.
1715 Whenever the event sequence given by \fIsequence\fR occurs for a character
1716 that has been tagged with \fItagName\fR, the script will be invoked. This
1717 widget command is similar to the \fBbind\fR command except that it operates on
1718 characters in a text rather than entire widgets. See the \fBbind\fR manual
1719 entry for complete details on the syntax of \fIsequence\fR and the
1720 substitutions performed on \fIscript\fR before invoking it. If all arguments
1721 are specified then a new binding is created, replacing any existing binding
1722 for the same \fIsequence\fR and \fItagName\fR (if the first character of
1723 \fIscript\fR is
1724 .QW +
1725 then \fIscript\fR augments an existing binding rather than replacing it). In
1726 this case the return value is an empty string. If \fIscript\fR is omitted then
1727 the command returns the \fIscript\fR associated with \fItagName\fR and
1728 \fIsequence\fR (an error occurs if there is no such binding). If both
1729 \fIscript\fR and \fIsequence\fR are omitted then the command returns a list of
1730 all the sequences for which bindings have been defined for \fItagName\fR.
1731 .RS
1732 .PP
1733 The only events for which bindings may be specified are those related to the
1734 mouse and keyboard (such as \fBEnter\fR, \fBLeave\fR, \fBButtonPress\fR,
1735 \fBMotion\fR, and \fBKeyPress\fR) or virtual events. Event bindings for a text
1736 widget use the \fBcurrent\fR mark described under \fBMARKS\fR above. An
1737 \fBEnter\fR event triggers for a tag when the tag first becomes present on the
1738 current character, and a \fBLeave\fR event triggers for a tag when it ceases
1739 to be present on the current character. \fBEnter\fR and \fBLeave\fR events can
1740 happen either because the \fBcurrent\fR mark moved or because the character at
1741 that position changed. Note that these events are different than \fBEnter\fR
1742 and \fBLeave\fR events for windows. Mouse and keyboard events are directed to
1743 the current character. If a virtual event is used in a binding, that binding
1744 can trigger only if the virtual event is defined by an underlying
1745 mouse-related or keyboard-related event.
1746 .PP
1747 It is possible for the current character to have multiple tags, and for each
1748 of them to have a binding for a particular event sequence. When this occurs,
1749 one binding is invoked for each tag, in order from lowest-priority to highest
1750 priority. If there are multiple matching bindings for a single tag, then the
1751 most specific binding is chosen (see the manual entry for the \fBbind\fR
1752 command for details). \fBcontinue\fR and \fBbreak\fR commands within binding
1753 scripts are processed in the same way as for bindings created with the
1754 \fBbind\fR command.
1755 .PP
1756 If bindings are created for the widget as a whole using the \fBbind\fR
1757 command, then those bindings will supplement the tag bindings. The tag
1758 bindings will be invoked first, followed by bindings for the window as a
1759 whole.
1760 .RE
1761 .TP
1762 \fIpathName \fBtag cget \fItagName option\fR
1763 .
1764 This command returns the current value of the option named \fIoption\fR
1765 associated with the tag given by \fItagName\fR. \fIOption\fR may have any of
1766 the values accepted by the \fIpathName \fBtag configure\fR widget command.
1767 .TP
1768 \fIpathName \fBtag configure \fItagName\fR ?\fIoption\fR? ?\fIvalue\fR? ?\fIoption value ...\fR?
1769 .
1770 This command is similar to the \fIpathName \fBconfigure\fR widget command
1771 except that it modifies options associated with the tag given by \fItagName\fR
1772 instead of modifying options for the overall text widget. If no \fIoption\fR
1773 is specified, the command returns a list describing all of the available
1774 options for \fItagName\fR (see \fBTk_ConfigureInfo\fR for information on the
1775 format of this list). If \fIoption\fR is specified with no \fIvalue\fR, then
1776 the command returns a list describing the one named option (this list will be
1777 identical to the corresponding sublist of the value returned if no
1778 \fIoption\fR is specified). If one or more \fIoption\-value\fR pairs are
1779 specified, then the command modifies the given option(s) to have the given
1780 value(s) in \fItagName\fR; in this case the command returns an empty string.
1781 See \fBTAGS\fR above for details on the options available for tags.
1782 .TP
1783 \fIpathName \fBtag delete \fItagName \fR?\fItagName ...\fR?
1784 .
1785 Deletes all tag information for each of the \fItagName\fR arguments. The
1786 command removes the tags from all characters in the file and also deletes any
1787 other information associated with the tags, such as bindings and display
1788 information. The command returns an empty string.
1789 .TP
1790 \fIpathName\fB tag lower \fItagName \fR?\fIbelowThis\fR?
1791 .
1792 Changes the priority of tag \fItagName\fR so that it is just lower in priority
1793 than the tag whose name is \fIbelowThis\fR. If \fIbelowThis\fR is omitted,
1794 then \fItagName\fR's priority is changed to make it lowest priority of all
1795 tags.
1796 .TP
1797 \fIpathName \fBtag names \fR?\fIindex\fR?
1798 .
1799 Returns a list whose elements are the names of all the tags that are active at
1800 the character position given by \fIindex\fR. If \fIindex\fR is omitted, then
1801 the return value will describe all of the tags that exist for the text (this
1802 includes all tags that have been named in a
1803 .QW "\fIpathName \fBtag\fR"
1804 widget command but have not been deleted by a
1805 .QW "\fIpathName \fBtag delete\fR"
1806 widget command, even if no characters are currently marked with the tag). The
1807 list will be sorted in order from lowest priority to highest priority.
1808 .TP
1809 \fIpathName \fBtag nextrange \fItagName index1 \fR?\fIindex2\fR?
1810 .
1811 This command searches the text for a range of characters tagged with
1812 \fItagName\fR where the first character of the range is no earlier than the
1813 character at \fIindex1\fR and no later than the character just before
1814 \fIindex2\fR (a range starting at \fIindex2\fR will not be considered). If
1815 several matching ranges exist, the first one is chosen. The command's return
1816 value is a list containing two elements, which are the index of the first
1817 character of the range and the index of the character just after the last one
1818 in the range. If no matching range is found then the return value is an empty
1819 string. If \fIindex2\fR is not given then it defaults to the end of the text.
1820 .TP
1821 \fIpathName \fBtag prevrange \fItagName index1 \fR?\fIindex2\fR?
1822 .
1823 This command searches the text for a range of characters tagged with
1824 \fItagName\fR where the first character of the range is before the character
1825 at \fIindex1\fR and no earlier than the character at \fIindex2\fR (a range
1826 starting at \fIindex2\fR will be considered). If several matching ranges
1827 exist, the one closest to \fIindex1\fR is chosen. The command's return value
1828 is a list containing two elements, which are the index of the first character
1829 of the range and the index of the character just after the last one in the
1830 range. If no matching range is found then the return value is an empty string.
1831 If \fIindex2\fR is not given then it defaults to the beginning of the text.
1832 .TP
1833 \fIpathName\fB tag raise \fItagName \fR?\fIaboveThis\fR?
1834 .
1835 Changes the priority of tag \fItagName\fR so that it is just higher in
1836 priority than the tag whose name is \fIaboveThis\fR. If \fIaboveThis\fR is
1837 omitted, then \fItagName\fR's priority is changed to make it highest priority
1838 of all tags.
1839 .TP
1840 \fIpathName \fBtag ranges \fItagName\fR
1841 .
1842 Returns a list describing all of the ranges of text that have been tagged with
1843 \fItagName\fR. The first two elements of the list describe the first tagged
1844 range in the text, the next two elements describe the second range, and so on.
1845 The first element of each pair contains the index of the first character of
1846 the range, and the second element of the pair contains the index of the
1847 character just after the last one in the range. If there are no characters
1848 tagged with \fItag\fR then an empty string is returned.
1849 .TP
1850 \fIpathName \fBtag remove \fItagName index1 \fR?\fIindex2 index1 index2 ...\fR?
1851 .
1852 Remove the tag \fItagName\fR from all of the characters starting at
1853 \fIindex1\fR and ending just before \fIindex2\fR (the character at
1854 \fIindex2\fR is not affected). A single command may contain any number of
1855 \fIindex1\fR\-\fIindex2\fR pairs. If the last \fIindex2\fR is omitted then the
1856 tag is removed from the single character at \fIindex1\fR. If there are no
1857 characters in the specified range (e.g. \fIindex1\fR is past the end of the
1858 file or \fIindex2\fR is less than or equal to \fIindex1\fR) then the command
1859 has no effect. This command returns an empty string.
1860 .RE
1861 .TP
1862 \fIpathName \fBwindow \fIoption \fR?\fIarg arg ...\fR?
1863 .
1864 This command is used to manipulate embedded windows. The behavior of the
1865 command depends on the \fIoption\fR argument that follows the \fBwindow\fR
1866 argument. The following forms of the command are currently supported:
1867 .RS
1868 .TP
1869 \fIpathName \fBwindow cget \fIindex option\fR
1870 .
1871 Returns the value of a configuration option for an embedded window.
1872 \fIIndex\fR identifies the embedded window, and \fIoption\fR specifies a
1873 particular configuration option, which must be one of the ones listed in the
1874 section \fBEMBEDDED WINDOWS\fR.
1875 .TP
1876 \fIpathName \fBwindow configure \fIindex\fR ?\fIoption value ...\fR?
1877 .
1878 Query or modify the configuration options for an embedded window. If no
1879 \fIoption\fR is specified, returns a list describing all of the available
1880 options for the embedded window at \fIindex\fR (see \fBTk_ConfigureInfo\fR for
1881 information on the format of this list). If \fIoption\fR is specified with no
1882 \fIvalue\fR, then the command returns a list describing the one named option
1883 (this list will be identical to the corresponding sublist of the value
1884 returned if no \fIoption\fR is specified). If one or more \fIoption\-value\fR
1885 pairs are specified, then the command modifies the given option(s) to have the
1886 given value(s); in this case the command returns an empty string. See
1887 \fBEMBEDDED WINDOWS\fR for information on the options that are supported.
1888 .TP
1889 \fIpathName \fBwindow create \fIindex\fR ?\fIoption value ...\fR?
1890 .
1891 This command creates a new window annotation, which will appear in the text at
1892 the position given by \fIindex\fR. Any number of \fIoption\-value\fR pairs may
1893 be specified to configure the annotation. See \fBEMBEDDED WINDOWS\fR for
1894 information on the options that are supported. Returns an empty string.
1895 .TP
1896 \fIpathName \fBwindow names\fR
1897 .
1898 Returns a list whose elements are the names of all windows currently embedded
1899 in \fIwindow\fR.
1900 .RE
1901 .TP
1902 \fIpathName \fBxview \fIoption args\fR
1903 .
1904 This command is used to query and change the horizontal position of the text
1905 in the widget's window. It can take any of the following forms:
1906 .RS
1907 .TP
1908 \fIpathName \fBxview\fR
1909 .
1910 Returns a list containing two elements. Each element is a real fraction
1911 between 0 and 1; together they describe the portion of the document's
1912 horizontal span that is visible in the window. For example, if the first
1913 element is .2 and the second element is .6, 20% of the text is off-screen to
1914 the left, the middle 40% is visible in the window, and 40% of the text is
1915 off-screen to the right. The fractions refer only to the lines that are
1916 actually visible in the window: if the lines in the window are all very short,
1917 so that they are entirely visible, the returned fractions will be 0 and 1,
1918 even if there are other lines in the text that are much wider than the window.
1919 These are the same values passed to scrollbars via the \fB\-xscrollcommand\fR
1920 option.
1921 .TP
1922 \fIpathName \fBxview moveto\fI fraction\fR
1923 .
1924 Adjusts the view in the window so that \fIfraction\fR of the horizontal span
1925 of the text is off-screen to the left. \fIFraction\fR is a fraction between 0
1926 and 1.
1927 .TP
1928 \fIpathName \fBxview scroll \fInumber what\fR
1929 .
1930 This command shifts the view in the window left or right according to
1931 \fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBunits\fR, \fBpages\fR or
1932 \fBpixels\fR. If \fIwhat\fR is \fBunits\fR or \fBpages\fR then \fInumber\fR
1933 must be an integer, otherwise number may be specified in any of the forms
1934 acceptable to \fBTk_GetPixels\fR, such as
1935 .QW 2.0c
1936 or
1937 .QW 1i
1938 (the result is rounded to the nearest integer value. If no units are given,
1939 pixels are assumed). If \fIwhat\fR is \fBunits\fR, the view adjusts left or
1940 right by \fInumber\fR average-width characters on the display; if it is
1941 \fBpages\fR then the view adjusts by \fInumber\fR screenfuls; if it is
1942 \fBpixels\fR then the view adjusts by \fInumber\fR pixels. If \fInumber\fR is
1943 negative then characters farther to the left become visible; if it is positive
1944 then characters farther to the right become visible.
1945 .RE
1946 .TP
1947 \fIpathName \fByview \fR?\fIargs\fR?
1948 .
1949 This command is used to query and change the vertical position of the text in
1950 the widget's window. It can take any of the following forms:
1951 .RS
1952 .TP
1953 \fIpathName \fByview\fR
1954 .
1955 Returns a list containing two elements, both of which are real fractions
1956 between 0 and 1. The first element gives the position of the first visible
1957 pixel of the first character (or image, etc) in the top line in the window,
1958 relative to the text as a whole (0.5 means it is halfway through the text, for
1959 example). The second element gives the position of the first pixel just after
1960 the last visible one in the bottom line of the window, relative to the text as
1961 a whole. These are the same values passed to scrollbars via the
1962 \fB\-yscrollcommand\fR option.
1963 .TP
1964 \fIpathName \fByview moveto\fI fraction\fR
1965 .
1966 Adjusts the view in the window so that the pixel given by \fIfraction\fR
1967 appears at the top of the top line of the window. \fIFraction\fR is a fraction
1968 between 0 and 1; 0 indicates the first pixel of the first character in the
1969 text, 0.33 indicates the pixel that is one-third the way through the text; and
1970 so on. Values close to 1 will indicate values close to the last pixel in the
1971 text (1 actually refers to one pixel beyond the last pixel), but in such cases
1972 the widget will never scroll beyond the last pixel, and so a value of 1 will
1973 effectively be rounded back to whatever fraction ensures the last pixel is at
1974 the bottom of the window, and some other pixel is at the top.
1975 .TP
1976 \fIpathName \fByview scroll \fInumber what\fR
1977 .
1978 This command adjust the view in the window up or down according to
1979 \fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBunits\fR, \fBpages\fR or
1980 \fBpixels\fR. If \fIwhat\fR is \fBunits\fR or \fBpages\fR then \fInumber\fR
1981 must be an integer, otherwise number may be specified in any of the forms
1982 acceptable to \fBTk_GetPixels\fR, such as
1983 .QW 2.0c
1984 or
1985 .QW 1i
1986 (the result is rounded to the nearest integer value. If no units are given,
1987 pixels are assumed). If \fIwhat\fR is \fBunits\fR, the view adjusts up or down
1988 by \fInumber\fR lines on the display; if it is \fBpages\fR then the view
1989 adjusts by \fInumber\fR screenfuls; if it is \fBpixels\fR then the view
1990 adjusts by \fInumber\fR pixels. If \fInumber\fR is negative then earlier
1991 positions in the text become visible; if it is positive then later positions
1992 in the text become visible.
1993 .TP
1994 \fIpathName \fByview \fR?\fB\-pickplace\fR? \fIindex\fR
1995 .
1996 Changes the view in the widget's window to make \fIindex\fR visible. If the
1997 \fB\-pickplace\fR option is not specified then \fIindex\fR will appear at the
1998 top of the window. If \fB\-pickplace\fR is specified then the widget chooses
1999 where \fIindex\fR appears in the window:
2000 .RS
2001 .IP [1]
2002 If \fIindex\fR is already visible somewhere in the window then the command
2003 does nothing.
2004 .IP [2]
2005 If \fIindex\fR is only a few lines off-screen above the window then it will be
2006 positioned at the top of the window.
2007 .IP [3]
2008 If \fIindex\fR is only a few lines off-screen below the window then it will be
2009 positioned at the bottom of the window.
2010 .IP [4]
2011 Otherwise, \fIindex\fR will be centered in the window.
2012 .PP
2013 The \fB\-pickplace\fR option has been obsoleted by the \fIpathName \fBsee\fR
2014 widget command (\fIpathName \fBsee\fR handles both x- and y-motion to make a
2015 location visible, whereas the \fB\-pickplace\fR mode only handles motion in
2016 y).
2017 .RE
2018 .TP
2019 \fIpathName \fByview \fInumber\fR
2020 .
2021 This command makes the first character on the line after the one given by
2022 \fInumber\fR visible at the top of the window. \fINumber\fR must be an
2023 integer. This command used to be used for scrolling, but now it is obsolete.
2024 .RE
2025 .SH BINDINGS
2026 .PP
2027 Tk automatically creates class bindings for texts that give them the following
2028 default behavior.
2029 In the descriptions below,
2030 .QW word
2031 is dependent on the value of
2032 the \fBtcl_wordchars\fR variable.  See \fBtclvars\fR(n).
2033 .IP [1]
2034 Clicking mouse button 1 positions the insertion cursor at the closest edge of the
2035 character underneath the mouse cursor, sets the input focus to this widget,
2036 and clears any selection in the widget. Dragging with mouse button 1 strokes
2037 out a selection between the insertion cursor and the character under the
2038 mouse.
2039 .IP [2]
2040 Double-clicking with mouse button 1 selects the word under the mouse and
2041 positions the insertion cursor at the start of the word. Dragging after a
2042 double click will stroke out a selection consisting of whole words.
2043 .IP [3]
2044 Triple-clicking with mouse button 1 selects the line under the mouse and
2045 positions the insertion cursor at the start of the line. Dragging after a
2046 triple click will stroke out a selection consisting of whole lines.
2047 .IP [4]
2048 The ends of the selection can be adjusted by dragging with mouse button 1
2049 while the Shift key is down; this will adjust the end of the selection that
2050 was nearest to the mouse cursor when button 1 was pressed. If the button is
2051 double-clicked before dragging then the selection will be adjusted in units of
2052 whole words; if it is triple-clicked then the selection will be adjusted in
2053 units of whole lines.
2054 .IP [5]
2055 Clicking mouse button 1 with the Control key down will reposition the
2056 insertion cursor without affecting the selection.
2057 .IP [6]
2058 If any normal printing characters are typed, they are inserted at the point of
2059 the insertion cursor.
2060 .IP [7]
2061 The view in the widget can be adjusted by dragging with the middle mouse
2062 button (button 2, or button 3 in TkAqua). If the middle mouse button is
2063 clicked without moving the mouse, the selection is copied into the text at the
2064 position of the mouse cursor. The Insert key also inserts the selection,
2065 but at the position of the insertion cursor.
2066 .IP [8]
2067 If the mouse is dragged out of the widget while button 1 is pressed, the entry
2068 will automatically scroll to make more text visible (if there is more text
2069 off-screen on the side where the mouse left the window).
2070 .IP [9]
2071 The Left and Right keys move the insertion cursor one character to the left or
2072 right; they also clear any selection in the text. If Left or Right is typed
2073 with the Shift key down, then the insertion cursor moves and the selection is
2074 extended to include the new character. Control-Left and Control-Right move the
2075 insertion cursor by words, and Control-Shift-Left and Control-Shift-Right move
2076 the insertion cursor by words and also extend the selection. Control-b and
2077 Control-f behave the same as Left and Right, respectively. Meta-b and Meta-f
2078 behave the same as Control-Left and Control-Right, respectively.
2079 .IP [10]
2080 The Up and Down keys move the insertion cursor one line up or down and clear
2081 any selection in the text. If Up or Right is typed with the Shift key down,
2082 then the insertion cursor moves and the selection is extended to include the
2083 new character. Control-Up and Control-Down move the insertion cursor by
2084 paragraphs (groups of lines separated by blank lines), and Control-Shift-Up
2085 and Control-Shift-Down move the insertion cursor by paragraphs and also extend
2086 the selection. Control-p and Control-n behave the same as Up and Down,
2087 respectively.
2088 .IP [11]
2089 The Next and Prior keys move the insertion cursor forward or backwards by one
2090 screenful and clear any selection in the text. If the Shift key is held down
2091 while Next or Prior is typed, then the selection is extended to include the
2092 new character.
2093 .IP [12]
2094 Control-Next and Control-Prior scroll the view right or left by one page
2095 without moving the insertion cursor or affecting the selection.
2096 .IP [13]
2097 Home and Control-a move the insertion cursor to the beginning of its display
2098 line and clear any selection in the widget. Shift-Home moves the insertion
2099 cursor to the beginning of the display line and also extends the selection to
2100 that point.
2101 .IP [14]
2102 End and Control-e move the insertion cursor to the end of the display line and
2103 clear any selection in the widget. Shift-End moves the cursor to the end of
2104 the display line and extends the selection to that point.
2105 .IP [15]
2106 Control-Home and Meta-< move the insertion cursor to the beginning of the text
2107 and clear any selection in the widget. Control-Shift-Home moves the insertion
2108 cursor to the beginning of the text and also extends the selection to that
2109 point.
2110 .IP [16]
2111 Control-End and Meta-> move the insertion cursor to the end of the text and
2112 clear any selection in the widget. Control-Shift-End moves the cursor to the
2113 end of the text and extends the selection to that point.
2114 .IP [17]
2115 The Select key and Control-Space set the selection anchor to the position of
2116 the insertion cursor. They do not affect the current selection. Shift-Select
2117 and Control-Shift-Space adjust the selection to the current position of the
2118 insertion cursor, selecting from the anchor to the insertion cursor if there
2119 was not any selection previously.
2120 .IP [18]
2121 Control-/ selects the entire contents of the widget.
2122 .IP [19]
2123 Control-\e clears any selection in the widget.
2124 .IP [20]
2125 The F16 key (labelled Copy on many Sun workstations) or Meta-w copies the
2126 selection in the widget to the clipboard, if there is a selection. This
2127 action is carried out by the command \fBtk_textCopy\fR.
2128 .IP [21]
2129 The F20 key (labelled Cut on many Sun workstations) or Control-w copies the
2130 selection in the widget to the clipboard and deletes the selection. This
2131 action is carried out by the command \fBtk_textCut\fR. If there is no
2132 selection in the widget then these keys have no effect.
2133 .IP [22]
2134 The F18 key (labelled Paste on many Sun workstations) or Control-y inserts the
2135 contents of the clipboard at the position of the insertion cursor. This action
2136 is carried out by the command \fBtk_textPaste\fR.
2137 .IP [23]
2138 The Delete key deletes the selection, if there is one in the widget. If there
2139 is no selection, it deletes the character to the right of the insertion
2140 cursor.
2141 .IP [24]
2142 Backspace and Control-h delete the selection, if there is one in the widget.
2143 If there is no selection, they delete the character to the left of the
2144 insertion cursor.
2145 .IP [25]
2146 Control-d deletes the character to the right of the insertion cursor.
2147 .IP [26]
2148 Meta-d deletes the word to the right of the insertion cursor.
2149 .IP [27]
2150 Control-k deletes from the insertion cursor to the end of its line; if the
2151 insertion cursor is already at the end of a line, then Control-k deletes the
2152 newline character.
2153 .IP [28]
2154 Control-o opens a new line by inserting a newline character in front of the
2155 insertion cursor without moving the insertion cursor.
2156 .IP [29]
2157 Meta-backspace and Meta-Delete delete the word to the left of the insertion
2158 cursor.
2159 .IP [30]
2160 Control-x deletes whatever is selected in the text widget after copying it to
2161 the clipboard.
2162 .IP [31]
2163 Control-t reverses the order of the two characters to the right of the
2164 insertion cursor.
2165 .IP [32]
2166 Control-z undoes the last edit action if the \fB\-undo\fR option is true.
2167 Does nothing otherwise.
2168 .IP [33]
2169 Control-Z (or Control-y on Windows) reapplies the last undone edit action if
2170 the \fB\-undo\fR option is true. Does nothing otherwise.
2171 .PP
2172 If the widget is disabled using the \fB\-state\fR option, then its view can
2173 still be adjusted and text can still be selected, but no insertion cursor will
2174 be displayed and no text modifications will take place.
2175 .PP
2176 The behavior of texts can be changed by defining new bindings for individual
2177 widgets or by redefining the class bindings.
2178 .SH "KNOWN ISSUES"
2179 .SS "ISSUES CONCERNING CHARS AND INDICES"
2180 .PP
2181 Before Tk 8.5, the widget used the string
2182 .QW chars
2183 to refer to index positions (which included characters, embedded windows and
2184 embedded images). As of Tk 8.5 the text widget deals separately and correctly
2185 with
2186 .QW chars
2187 and
2188 .QW indices .
2189 For backwards compatibility, however, the index modifiers
2190 .QW "+N chars"
2191 and
2192 .QW "\-N chars"
2193 continue to refer to indices. One must use any of the full forms
2194 .QW "+N any chars"
2195 or
2196 .QW "\-N any chars"
2197 etc. to refer to actual character indices. This confusion may be fixed in a
2198 future release by making the widget correctly interpret
2199 .QW "+N chars"
2200 as a synonym for
2201 .QW "+N any chars" .
2202 .SS "PERFORMANCE ISSUES"
2203 .PP
2204 Text widgets should run efficiently under a variety of conditions. The text
2205 widget uses about 2-3 bytes of main memory for each byte of text, so texts
2206 containing a megabyte or more should be practical on most workstations. Text
2207 is represented internally with a modified B-tree structure that makes
2208 operations relatively efficient even with large texts. Tags are included in
2209 the B-tree structure in a way that allows tags to span large ranges or have
2210 many disjoint smaller ranges without loss of efficiency. Marks are also
2211 implemented in a way that allows large numbers of marks. In most cases it is
2212 fine to have large numbers of unique tags, or a tag that has many distinct
2213 ranges.
2214 .PP
2215 One performance problem can arise if you have hundreds or thousands of
2216 different tags that all have the following characteristics: the first and last
2217 ranges of each tag are near the beginning and end of the text, respectively,
2218 or a single tag range covers most of the text widget. The cost of adding and
2219 deleting tags like this is proportional to the number of other tags with the
2220 same properties. In contrast, there is no problem with having thousands of
2221 distinct tags if their overall ranges are localized and spread uniformly
2222 throughout the text.
2223 .PP
2224 Very long text lines can be expensive, especially if they have many marks and
2225 tags within them.
2226 .PP
2227 The display line with the insert cursor is redrawn each time the cursor
2228 blinks, which causes a steady stream of graphics traffic. Set the
2229 \fB\-insertofftime\fR attribute to 0 avoid this.
2230 .SS "KNOWN BUGS"
2231 .PP
2232 The \fIpathName \fBsearch \-regexp\fR sub-command attempts to perform
2233 sophisticated regexp matching across multiple lines in an efficient fashion
2234 (since Tk 8.5), examining each line individually, and then in small groups of
2235 lines, whether searching forwards or backwards. Under certain conditions the
2236 search result might differ from that obtained by applying the same regexp to
2237 the entire text from the widget in one go. For example, when searching with a
2238 greedy regexp, the widget will continue to attempt to add extra lines to the
2239 match as long as one of two conditions are true: either Tcl's regexp library
2240 returns a code to indicate a longer match is possible (but there are known
2241 bugs in Tcl which mean this code is not always correctly returned); or if each
2242 extra line added results in at least a partial match with the pattern. This
2243 means in the case where the first extra line added results in no match and
2244 Tcl's regexp system returns the incorrect code and adding a second extra line
2245 would actually match, the text widget will return the wrong result. In
2246 practice this is a rare problem, but it can occur, for example:
2247 .CS
2248 pack [\fBtext\fR .t]
2249 \&.t insert 1.0 "aaaa\enbbbb\encccc\enbbbb\enaaaa\en"
2250 \&.t search \-regexp \-\- {(a+|b+\enc+\enb+)+\ena+} 1.0
2251 .CE
2252 will not find a match when one exists of 19 characters starting from the first
2253 .QW b .
2254 .PP
2255 Whenever one possible match is fully enclosed in another, the search command
2256 will attempt to ensure only the larger match is returned. When performing
2257 backwards regexp searches it is possible that Tcl will not always achieve
2258 this, in the case where a match is preceded by one or more short,
2259 non-overlapping matches, all of which are preceded by a large match which
2260 actually encompasses all of them. The search algorithm used by the widget does
2261 not look back arbitrarily far for a possible match which might cover large
2262 portions of the widget. For example:
2263 .CS
2264 pack [\fBtext\fR .t]
2265 \&.t insert 1.0 "aaaa\enbbbb\enbbbb\enbbbb\enbbbb\\n"
2266 \&.t search \-regexp \-backward \-\- {b+\en|a+\en(b+\en)+} end
2267 .CE
2268 matches at
2269 .QW 5.0
2270 when a true greedy match would match at
2271 .QW 1.0 .
2272 Similarly if we add \fB\-all\fR to this case, it matches at all of
2273 .QW 5.0 ,
2274 .QW 4.0 ,
2275 .QW 3.0
2276 and
2277 .QW 1.0 ,
2278 when really it should only match at
2279 .QW 1.0
2280 since that match encloses all the others.
2281 .SH "SEE ALSO"
2282 entry(n), scrollbar(n)
2283 .SH KEYWORDS
2284 text, widget, tkvars
2285 '\" Local Variables:
2286 '\" mode: nroff
2287 '\" End: