{The jstools Find Panel

Introduction
The jstools package provides a Find Panel, shared by several applications, which lets you search for a string of text, and optionally replace it with another string of text.  The full functionality of the Find Panel is available if you're searching in a text window you can edit (as in the editor, jedit); a subset of the features is available if you're searching in a text window you can't edit (as in jdoc or jmore).

The Find Panel is implemented by the jfindpanel.tcl library; if you're a Tk programmer, you can use it in your own applications.

This document describes the Find Panel provided by version 4.0/4.0b of the jstools libraries.

Usage
The Find Panel has two fields for you to type the search string (or pattern) and the replacement string into, and four buttons: `Search', `Replace', `Replace All', and `Cancel'.  There are also some checkbuttons which control the Find Panel's behaviour, which are described under Find Panel Options below.  (Not all these features will be available if the window you're searching in isn't editable; see Searching in Non­Editable Windows for details.)

If all you want to do is find the next occurrence of a string, you can just type the string you want to search for in the `Search for:' field, and click `Search' (or just press Return).  The Find Panel will find the next occurrence of the string in the text after the insertion point (the blinking vertical bar) and select it.  (If the string you typed didn't appear in the text after the insertion point, an alert panel will tell you so.)

If you want to search repeatedly through the text for a particular string, you can keep clicking on the `Search' button (or pressing Return).

To replace a string, type the search string in the `Search for:' field, and type the replacement string in the `Replace with:' field.  Then click on Search to find and select the next ocurrence of the search string, and click on `Replace' to replace it and continue the search.  Clicking `Replace' replaces whatever the current selection is (it doesn't necessarily have to be the result of a search) with the text in the `Replace with:' field.

You can click on `Replace All' to replace the search string (the contents of the `Search for:' field) with the replacement string (the contents of the `Replace with:' field) everywhere in the text.  This should be done with some caution, of course.

(If you need to search for or substitute a newline or a tab, you can type them in the search and replace fields as Control-J and Control-I, respectively.  No, it's not intuitive, but it works.)

The `Cancel' button makes the find panel go away and returns you to editing your text.

Searching in Non­Editable Windows
If the text window you're searching in is not editable (as in the jmore application), then the Find Panel features that allow you to replace text are not available.  The `Replace with:' field, the `Replace' button, and the `Replace All' button will not be displayed in this case.

Using the Find Panel with a non­editable window is a little tricky, because the Find Panel searches from the insertion point in a text window.  In an editable window, the insertion point is displayed as a blinking vertical bar, but in a non­editable window it's invisible.  So it may be hard to tell where the search is starting from.  If you can't find a string you're fairly sure is in the text, you can try scrolling the text window up to the top and clicking in the upper­left corner to set the insertion point at the beginning of the text.

Find Panel Options
If the `Backwards' checkbutton is selected, the search will be backwards in the text from the current insertion point; otherwise it will be forwards.

If the `Case­sensitive' checkbutton is selected, then the Find Panel will only search for an exact match, so that if you search for `because', you won't find `Because'.  Normally, case is ignored when searching, so `because' and `Because' (and `BECAUSE' and `becausE') will match.

In any case, if you search for `because of' with one space, you won't find `because  of' with two spaces.

If the `Regex' checkbutton is selected, then searching and replacement will be done using regular expressions rather than fixed strings.  Regular expressions allow you to express more complicated patterns than just specific sequences of characters; for instance, you could search for all words that are in all capitals, or all occurrences of a number in parentheses.  You can also use fragments of the matched text in the replacement text.  For the details of regular expressions, see the Tcl regexp(n) and regsub(n) manual pages.  (Another place to look for information is the REGULAR EXPRESSIONS section of the ed(1) manual page, although the regular expressions in ed(1) differ slightly from those used by Tcl.)

Currently, you can only search forward for regular expressions; if you have both `Regex' and `Backwards' selected, you'll get a notice telling you so when you click `Search'.

Evolution
Feel free to report bugs (and feature requests) to me, <js@calumet.org>, and I will try to deal with them.  Also, feel free to fix bugs or add features on your own and let me know how you did it.

Bugs and Limitations
* The Find Panel makes copies of the text in the text window to search in, so it may be wasteful of memory and slow with windows containing lots of text.

* You can't search backwards for a regular expression.

Future Directions
* There should be a way to highlight all occurrences of a string, rather than just jumping to each one in succession.
} {{{sel {42.56 42.70}} {jdoc:xref:link {4.0 4.19 4.298 4.303 4.403 4.407 4.411 4.416 6.37 6.51 8.71 8.92 11.280 11.298 11.403 11.436 26.66 26.71}} {jdoc:xref:manpage {37.493 37.499 37.507 37.513 37.613 37.615 37.668 37.670}} {jdoc:anchor:anchorname {3.0 4.0 10.0 11.0 25.0 26.0 30.0 31.0 41.0 42.0}} {richtext:font:roman {2.0 3.0 4.0 4.4 4.11 4.298 4.303 4.403 4.407 4.411 4.416 6.37 6.51 8.75 8.82 10.0 11.0 11.280 11.298 11.403 11.436 13.177 13.183 15.133 15.139 21.115 21.124 21.129 21.138 25.0 26.0 26.66 26.71 30.0 31.0 37.90 37.109 37.493 37.499 37.507 37.513 37.613 37.615 37.668 37.670 41.0 42.0 42.55 42.71 44.0 45.0 49.0 50.0 51.0}} {richtext:font:italic {37.90 37.109}} {richtext:font:bold {4.4 4.11 6.37 6.51 8.75 8.82 13.177 13.183 15.133 15.139 21.115 21.124 21.129 21.138}} {richtext:font:bolditalic {11.280 11.298 11.403 11.436}} {richtext:font:typewriter {4.298 4.303 4.403 4.407 4.411 4.416 26.66 26.71 37.493 37.499 37.507 37.513 37.613 37.615 37.668 37.670 42.55 42.71}} {richtext:font:heading0 {1.0 2.0}} {richtext:font:heading1 {3.0 4.0 10.0 11.0 25.0 26.0 30.0 31.0 41.0 42.0}} {richtext:font:heading2 {44.0 45.0 49.0 50.0}} {jdoc:link:jedit.jdoc {4.298 4.303}} {jdoc:link:jdoc.jdoc {4.403 4.407}} {jdoc:link:jmore.jdoc {4.411 4.416 26.66 26.71}} {jdoc:link:jfindpanel.tcl.jdoc {6.37 6.51}} {jdoc:manpage:ed {37.613 37.615 37.668 37.670}} {jdoc:manpage:regexp {37.493 37.499}} {jdoc:manpage:regsub {37.507 37.513}} {jdoc:link:#Find_Panel_Options {11.280 11.298}} {jdoc:anchorname:Find_Panel_Options {30.0 31.0}} {jdoc:link:#Searching_in_Non­Editable_Windows {11.403 11.436}} {jdoc:anchorname:Searching_in_Non­Editable_Windows {25.0 26.0}} {jdoc:anchorname:Introduction {3.0 4.0}} {jdoc:anchorname:Usage {10.0 11.0}} {jdoc:link:jslibraries.jdoc {8.71 8.92}} {jdoc:anchorname:Evolution {41.0 42.0}} {jdoc:link:jstools.jdoc {4.0 4.19}}} {{abbrevstart 50.2} {abbrevend 50.2} {insert 42.70} {anchor 50.37} {current 35.85}}}