[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8. Searching and Replacing

GPS provides extensive search capabilities among its different elements. For instance, it is possible to search in the currently edited source file, or in all the source files belonging to the project, even those that are not currently open. It is also possible to search in the project explorer (on the left side of the main GPS window), or the help modules,...

All these search contexts are grouped into a single graphical window, that you can open either through the menu Navigate->Find/Replace..., or the shortcut Ctrl-F.

Selecting either of these two options will pop up a dialog on the screen, similar to the following:

search-hide

On this screen shot, you can see three entry fields:

Search for
This is the location where you type the string or pattern you are looking for. The search widget supports two modes, either fixed strings or regular expressions. You can commute between the two modes by either clicking on the Options button and selecting the appropriate check box, or by opening the combo box (click on the arrow on the right of the entry field).

In this combo box, a number of predefined patterns are provided. The top two ones are empty patterns, that automatically set up the appropriate fixed strings/regular expression mode. The other regular expressions are language-specific, and will match patterns like Ada type definition, C++ method declaration,...

Replace with
This field should contain the string that will replace the occurrences of the pattern defined above. The combo box provides a history of previously used replacement strings.

Look in
This field defines the context in which the search should occur. GPS will automatically select the most appropriate context when you open the search dialog, depending on which component currently has the focus. You can of course change the context to another one if needed.

Clicking on the arrow on the right will display the list of all possible contexts. This list includes:

Project Explorer
Search in the project explorer. An extra Scope box will be displayed where you can specify the scope of your search, which can be a set of: Projects, Directories, Files, Entities. The search in entities may take a long time, search each file is parsed during the search.

Open Files
Search in all the files that are currenly open in the source editor. The Scope entry is described in the Files... section below.

Files...
Search in a given set of files. An extra Files box will be displayed where you can specify the files by using standard shell (Unix or Windows) regular expression, e.g. *.ad? for all files ending with .ad and any trailing character. The directory specified where the search starts, and the Recursive search button whether sub directories will be searched as well.

The Scope entry is used to restrict the search to a set of language constructs, e.g. to avoid matching on comments when you are only interested in actual code, or to only search strings and comments, and ignore the code.

Files From Project
Search in all the files from the project, including files from project dependencies. The Scope entry is described in the Files... section above.

Current File
Search in the current source editor. The Scope entry is described in the Files... section above.

Project Browser
Search in the project browser (see section 7.9 The Project Browser).

Help
Search in the help window.

The second part of the window is a row of buttons, to start the search (or continue to the next occurrence), to stop the current search when it is taking too long, or to display the options.

search-options

There are four check boxes in this options box.

"Search All Occurrences"
The default mode for the search widget is interactive searching: its stops as soon as one occurrence of the pattern is found. You then have to press the Next button (or the equivalent shortcut Ctrl-N) to go to the next occurrence.

However, if you enable this check box, the search widget will start searching for all occurrences right away, and put the results in a new window called Locations (initially found in the bottom dock of the GPS window). You can interrupt the search at any time by pressing the Stop button: this will stop when the next occurrence is found.

This button is reset to its default value whenever you modify the searched pattern or the replacement text.

"Case Sensitive"
By default, patterns are case insensitive (upper-case letters and lower-case letters are considered as equivalent). You can change this behavior by clicking on this check box.

"Whole Word Only"
If activated, this check box will force the search engine to ignore substrings. "sensitive" will no longer match "insensitive".

"Regular Expression"
This button commutes between fixed string patterns and regular expressions. You can also commute between these two modes by selecting the arrow on the right of the Search for: field. The grammar followed by the regular expressions is similar to the Perl and Python regular expressions grammar, and is documented in the GNAT run time file `g-regpat.ads'. To open it from GPS, you can use the open from project dialog (File->Open From Project...) and type g-regpat.ads. See Open From Project for more information on this dialog.

As most GPS components, the search window is under control of the multiple document interface, and can thus be integrated into the main GPS window instead of being an external window.

To force this behavior, open the menu Window, select Search in the list at the bottom of the menu, and then select either Floating or Docked.

If you save the desktop (File->Save More->Desktop, GPS will automatically reopen the search dialog in its new place when it is started next time.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Mail Server on November, 9 2003 using texi2html