The Find and Replace Window

The Find and Replace window provides a means to perform pattern-matching searches to locate expressions. The search is performed against all expressions in the current document and all expressions in the libraries listed in the Document Explorer. All expressions are included, including expressions in object definitions like the type definition, the properties, and the clauses. Unit test expressions are also included in the search results.

The search can either return results where the expression matches exactly or it can do a pattern based search. Which search is performed depends on whether the Pattern or Exact radio button is selected.

When the Pattern radio button is selected, the search process uses is the same pattern matching that is used in clauses. For example, if the search expression is a + b where a and b are set to the Variables namespace, the Find command will find all Add expressions that have two terms, including expressions such as ab + c, x + y, and x + 32. On the other hand, if a and b are in any other namespace, then a search for ‘a + b’ will only find expressions that exactly match a + b. If the Exact radio button is selected with this same expression, then only expressions the expression a + b where a and b are set to the Variables namespace will match. The Exact radio button allows searches for expressions that contain variables. If the find expression doesn't have terms in the Variables namespace, the results returned for the Pattern and Exact settings are the same.

Any pattern that can be used in a match expression in Sym code can be used in the search functionality, including the list variable objects. Pattern matching works for any expression, for example if you type x^-1 into the Find: expression, (where x is a variable) the search results will contain any Power expression that has the value "-1" in the exponent. Similarly, if you typed x^y into the Find: expression where both x and y are variables, the search would find every expression that has an instance of the Power object in it. For more information, see Pattern Matching - Overview.

By default, when you edit the Find expression, new terms are placed in the Variables namespace. To change to a different namespace, right-click the term in the expression that you want to change and select Set namespace… (Alt + N) from the context menu.

Starting a search from a document module

There are several ways to start a search:

  • Highlight an expression in any module and press Ctrl + F. The Find and Replace window will open and the Find expression will be populated with the highlighted expression. Press Enter or select the search button to start the search.
  • Highlight an object definition in an Object Module and press Ctrl + F. In this case, a find expression will be generated for the selected object. In the find expression, each of the parameters will be filled with a variable, so the search will find all instances of the selected object.
  • Select Edit > Find from the main menu to open the Find and Replace window, then create the Find expression in the same way that you would create any other expression in a document. All of the expression editing tools are available including the autocomplete popup and the Properties viewer.

Working with search results

The search results are organized in a tree with the document or library as the top level item and the module underneath. The expressions containing terms that match the search pattern are listed under each module. In the search results, the entire expression is shown, not just the term that matches the pattern.

Context menus

The Find expression uses the same context menu as expressions in Document Modules.

The Result expressions in the search results have a context menu item named Go to expression. When selected, the Document Module, Object Module, or Unit Test Module containing the expression is opened with the selected expression highlighted.

Replacing expressions

Expressions can be modified using the Replace option in the Find and Replace window. To begin, we can start by pressing Ctrl + H or selecting Replace... in the Edit menu.

In this case, both Find: and Replace with: are shown in the top window. Variables are used here in the same way that the variables are used when just doing a search. For example, if we put the expression

where "a" is in the Variables namespace as the Find: expression and put the expression

in the Replace with: expression, then the search will return all results that pattern match to the find expression and will offer to replace each expression with the expression generated by replacing "a" with the expression bound to "a" by each pattern match. If "x + 1" appears in the document, it will be replaced by "x - 1" and so on.

When Replace is selected, each item shown in the results list has a checkbox in front of it which allows selecting which expressions in the document you want to replace. In addition, each item shows the whole expression after the replacement has been applied.