This is not necessarily the current version of this TIP.
| TIP: | 113 |
| Title: | Multi-Line Searches in the Text Widget |
| Version: | $Revision: 1.4 $ |
| Author: | Vince Darley <vincentdarley at users dot sourceforge dot net> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Friday, 11 October 2002 |
This TIP proposes enhancing the implementation of the $textwidget search subcommand to allow matching of both exact strings and regexp patterns which span multiple lines, and to allow reporting on all matches.
If the string/pattern given to the search subcommand contains sub-strings/patterns which match newlines, then it will be possible for that command to return a match which spans multiple lines. Where a match could occur both within a single line and across multiple lines, the first such match will be found, and the length of the match will follow the usual regexp rules, as documented in the regexp man page.
This should be able to be implemented reasonably efficiently, given the TCL_REG_CANMATCH flag supported by the regexp library, with no impact at all on the speed of matching single lines.
In addition, if a new -all option is given to the search subcommand, then all matches within the given range will be reported. This means the return result of the command will be a list of indices, and, if a -count var option was given, var will be set to a list of match-index-lengths.
The text widget man page will need updating to reflect the new ''-all' option, and to remove the "single line" caveat.
This is available from:
http://sourceforge.net/tracker/?func=detail&aid=621901&group_id=12997&atid=312997
(However, this patch has to workaround a bug in Tcl's unicode string manipulation, so search performance is impacted)
It isn't yet clear to me whether it would be useful to add equivalents to some or all of the -line, -lineanchor, -linestop regexp options. These may be helpful when matching across multiple lines, but at first glance I don't think they are quite as useful when searching in text widgets as for the standard regexp command (but, if only for consistency, it may be sensible to add them so as not to have an unnatural distinction between searching a string and searching in a widget).
On the implementation side, it might be interesting to abstract the search interface away from the text widget, so that it could in principle be applied to any line-based textual source.
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.