Two levels of search functions exist: high level functions that provide user interfacing and multiple file searching, and built-in functions that are used without affecting the high level search commands such as the find_next command. The built-in functions are not affected by the global editor search options.
The table below shows a list of commonly used search functions. For a complete list, see Help → Macro Functions by Category → Search Functions.
|
Function |
Description |
|---|---|
|
gui_find |
Displays Find and Replace view open to the Find tab, and performs search using the find or _mffind functions. |
|
gui_replace |
Displays Find and Replace view open to the Replace tab, and performs search using gui_replace2 or _mfreplace functions. |
|
gui_replace2 |
Performs a search and replace based on arguments given. This function is very similar to the replace function, except that this function uses a dialog box to prompt the user where to replace. |
|
find_next |
Searches for next occurrence of search string used by any of these high-level search functions. This function is not affected by previous searches done with low-level built-in functions. |
|
find |
Performs search based on arguments given. |
|
replace |
Performs a replace based on arguments given. The user is prompted where to replace through the message line. |
|
_mffind |
Performs a multiple file and buffer search based on the arguments given. |
|
_mfreplace |
Performs a multiple file and buffer search based on the arguments given. |
|
search |
Performs a search, or search and replace, based on arguments given. Does not support wrapping to top or bottom of file. When performing a replace, the user is not prompted at all. |
|
repeat_search |
Searches for the next occurrence of search string used by last call to the search built-in. |
The following example searches for lines that contain a particular search string and places the lines in another window and buffer:
defmain()
{
orig_wid=p_window_id;
// The +w option forces a new window to be created. The +t options
// force a new buffer to be created.
status=edit("+w +t");
if (status) {
_message_box("Unable to create temp window and buffer\n\n":+
get_message(status));
}
delete_line(); // Delete the blank line.
output_wid=p_window_id;
p_window_id=orig_wid;
top(); // Place the cursor at the top in column 1.
status=search("if","w@"); // Case-insensitive word search for if @ specifies
// no string not found message.
for (;;)
{
if (status) {
break;
}
get_line(line); // Place the cursor at the end of the line so no
// more occurrences can be found on this line.
_end_line();
output_wid.insert_line(line);
status=repeat_search();
}
// Make the output window active so we can see the results.
p_window_id=output_wid;
}The next example is very similar to the example above except that the output data is placed in a view and buffer. The only advantage in using a view and buffer is that the output can be displayed in a list box without the user having to see a new window created.
#include "slick.sh"
defmain()
{
// Create a temporary view and buffer within the current window.
// Each window can store multiple cursor positions (views) to any buffer.
orig_view_id=_create_temp_view(temp_view_id);
if (orig_view_id=="") {
return("");
}
activate_view(orig_view_id);
top(); // Place the cursor at the top in column 1.
status=search("if","w"); // Case sensitive word search for if.
for (;;) {
if (status) {
// Clear the pending message caused by built-in search failing.
clear_message();
break;
}
get_line(line);
// Place the cursor at the end of the line so no more occurrences
// can be found on this line.
_end_line();
activate_view(temp_view_id);
insert_line(' 'line); // Insert a space at the beginning of the line
// because this will be inserted into a listbox.
activate_view(orig_view_id);
status=repeat_search();
}
// Display the buffer in a list box.
// The _sellist_form dialog box will delete the temp view and buffer.
// The original view must be activated before showing the _sellist_form or
// the dialog box will operate strangely.
activate_view(orig_view_id);
result=show("_sellist_form -mdi -modal",
"Sample Selection List",
// Indicate next argument is view_id.
SL_VIEWID|SL_SELECTCLINE,
temp_view_id,
"OK",
"", // Help item.
"", // Use default font.
"" // Call back function.
);
if (result) {
message("Selection list cancelled");
} else {
message("Item selected is "result);
}
}