Home
Mail Mastodon RSS Feed

Next: Query Replace Term, Previous: Managing Dependencies, Up: Editing Prolog code   [Contents][Index]


7.22 Term Search ¶

You can search for Prolog terms matching a given search term with the command sweeprolog-term-search.

C-c C-s ¶

Search for Prolog terms matching a given search term in the current buffer (sweeprolog-term-search).

The command sweeprolog-term-search, bound by default to C-c C-s in Sweep Prolog mode buffers, prompts for a Prolog term to search for and finds terms in the current buffer that the search term subsumes. It highlights all matching terms in the buffer and moves the cursor to the end of the next match after point. For example, to find if-then-else constructs in the current buffer do C-c C-s _ -> _ ; _ RET.

This command highlights the current match with the sweeprolog-term-search-current face, and all other matches with the sweeprolog-term-search-match face. See (emacs)Face Customization for information about customizing faces.

While prompting for a search term in the minibuffer, this command populates the “future history” with the Prolog terms at point, with the most nested term at point on top. Typing M-n once in the minibuffer fills in the innermost term at point, typing M-n again cycles up the syntax tree at point filling the minibuffer with larger terms, up until the top-term at point. See (emacs)Minibuffer History, for more information about minibuffer history commands.

If you invoke sweeprolog-term-search with a prefix argument (C-u C-c C-s), you can further refine the search with an arbitrary Prolog goal. The given goal runs for each matching term, and if the goal fails sweeprolog-term-search disregards the corresponding match. You can use variables from the search term in the goal to refer to the corresponding subterms of the matching term—for example, you can find all places in your code where you have a call to sub_string/5 with either the first or the last argument being a literal atom by typing C-u C-c C-s sub_string(Str, _, _, _, Sub) RET atom(Str) ; atom(Sub) RET.

If you call this command with a double prefix argument (C-u C-u C-c C-s), it also prompts you to specify the class of term to search for. This can be one of the following symbols:

clause

Matches whole clauses.

head

Matches head terms.

goal

Matches goal terms.

data

Matches data terms.

_

Matches any term.

You can specify multiple classes in the minibuffer by delimiting them with ‘,’, in which case sweeprolog-term-search matches terms that match any of the these classes.

If you call sweeprolog-term-search with a negative prefix argument (C-- C-c C-s), it searches backward and moves to beginning of the first match that starts before point.

After invoking sweeprolog-term-search, use C-s to move to the next matching term and C-r to move backward to the previous match. To exit term search, type C-m (or RET). Similarly to Isearch, sweeprolog-term-search sets the mark to the original point so you can easily return to where you were before beginning the search. See (emacs)Basic Isearch.


Next: Query Replace Term, Previous: Managing Dependencies, Up: Editing Prolog code   [Contents][Index]


© 2025 Eshel Yaron