XSearch

by Rudi Widmann <rudi.widmann@web.de>

The XSearch plugin provides extensions of the search and replace function of the jedit text editor.

It doesn't extend the search bar, which is a view related feature

It is 100 % compatible to the standart search and replace functions described in jEdit user guide.

XSearch Dialog

The XSearch Dialog is an extension of the core search-and-replace dialog

find All

Search for all occurances of the search string in the current buffer, according to the current settings.
All matches are selected, and a match counter is displayed.

Restriction: only applicable for the current buffer

resetSettings

Resets search settings to default values

find from top

Start searching from top of buffer.
Note: "refind" will search for the next occurance, as long as no search settings are changed

backward search

"backward search" is available for regular expressions, too.

word part search

Restriction: combination with option "regular expression" is not supported

column search

Search for all occurances of the search string in the given column range

row search

Search for all occurances of the search string in the given row range

Hints:

fold search

Restriction: not applicable for hypersearch

comment search

Note: "comment search" in the current buffer uses identifies comments according to the definition in the according edit mode. For hypersearch, this is not possible. Therefore, the comment indicators are defined in XSearch.props.

hyper search

This checkbox toggles

hyper range

This feature is an extention to the hyper search facility. If hyper search is invoked, the matching lines are displayed in the hyper search window, and additionally the surrounding lines before (up) and after (down) the match.

Tip: extremly useful if you search where a method is called and which parameters are used.

tentativ search

Tentativ search uses a search algorithm which tolerates following type mismatching.

combination with option "regular expression" is not supported

Example: You search "My_Bsh_Macro" but you enter the search string Myy_Bsh-mmacro

Tentativ search performs a search with the regexp "My+_Bsh[-_]m+acro"

Search Settings History

If enabled, all search settings which apply to a certain search string are memorized.

If you recall a search string of the History Text Field , its last settings (inclusiv search directory) are active in the xsearch and replace dialog.

Show Options: search | replace | extended

Hide or show the search | replace | extended options.

If a non-default option is selected but not visible, it is displayed in a line below "show options"

Replace and Find

If Replace and Find is invoked

XSearch menu

xfind replace

Displays the xsearch-and-replace dialog box

If text was selected in the text area and the selection does not span a line break, the selected text becomes the default search string (standard behaviour).

xfind-refind

Performes a search with the previously used search string, taking in account the current search options, without displaying the xsearch-and-replace dialog.

xfind-first

Same as xfind-refind, but the search starts from the top of the document.

xfind-next

Same as xfind-refind, but the search direction is forward

xfind-prev

Same as xfind-refind, but the search direction is backward

Note: If the option regexp is activ, no search is performed.The message "invalid search settings" is displayed

xreplace-in-selection

Performes the last replace action for all occurances of the search string in the current selection.

xreplace-and-find-next

Repeats the last replace action

xreplace-all

Performes the last replace action for all occurances of the search string in the current document.

xsearch-directory...

Displays the xsearch-and-replace dialog box.

The options "hypersearch" and "search in directory" are already selected (standard behaviour).

quick-xfind-standard-options

Performes a search without displaying the xsearch-and-replace dialog, ignoring the current search settings.

The search string is:

If no valid search string is found, the xsearch-and-replace dialog is displayed with standart settings.

quick-hypersearch-standard-options

Same as quick-xfind-standard-options, but a hypersearch in the current buffer is performed.

quick-allbuffersearch-standard-options

Same as quick-xfind-standard-options, but a hypersearch in all open buffers is performed.

quick-xfind-current-options

Same as quick-xfind-standard-options, but the current options are used.

quick-hypersearch-current-options

Same as quick-hypersearch-standard-options, but the current options are used.

Note: When using quick-search, the user is often not aware of the current search settings. Therefore, only quick search with standard options is recommended

Bean shell support

getMatchedSubexpressions

After a search with regular expressions, you can obtain the subexpressions
Method: String[] xsearch.XSearchAndReplace.getMatchedSubexpressions(String <matched String>)
or String xsearch.XSearchAndReplace.getMatchedSubexpressions(String <matched String>, int <number of required subexpression)

Example:

xsearch.XSearchAndReplace.setSearchString("(^\\* SYNTAX - ERRORS : *)([1-9]+)");
if (xsearch.XSearchAndReplace.find(view))
String[] subExp = xsearch.XSearchAndReplace.getMatchedSubexpressions(textArea.getSelectedText());

resetSettings

Resets search settings to default values
Execution: xsearch.SearchSettings.resetSettings()

push Settings

Saves the current search settings on a stack. Useful if you don't want to overwrite the settings during macro run
Execution: xsearch.SearchSettings.push();

pop Settings

Restores the last pushed search settings.
Execution: xsearch.SearchSettings.pop();

find all

To manipulate all matches inside the current buffer, "findAll" selects all matches. With the method "textArea.getSelectedLines()", they can be manipulated.

Example: The following bsh macro deletes all lines which contain the string "jEdit ist doof"

xsearch.SearchSettings.push();
xsearch.SearchSettings.resetSettings();
xsearch.XSearchAndReplace.setSearchString("jEdit ist doof");
xsearch.XSearchAndReplace.setSearchFileSet(new CurrentBufferSet());
xsearch.XSearchAndReplace.setFindAll(true);
xsearch.XSearchAndReplace.find(view);
int[] lines = textArea.getSelectedLines();
for (int i=lines.length-1;i>=0;i--) {
textArea.moveCaretPosition(buffer.getLineStartOffset(lines[i]));
textArea.deleteLine(); }
xsearch.SearchSettings.pop();

silent search

When you write macros or plugins which invoke search very often, updating the textarea is time consuming. For better performance, highlighting of the search match can be disabled (flag "silent"=xsearch.XSearchAndReplace.FIND_OPTION_SILENT (true) when calling "find")

find(View view, Buffer buffer, int start, int end, boolean firstTime, boolean reverse, boolean silent)

The result of the last search is obtained from method "getLastMatchedSelection"

Example:

xsearch.SearchSettings.push();
xsearch.SearchSettings.resetSettings();
xsearch.XSearchAndReplace.setSearchString("target");
if (xsearch.XSearchAndReplace.find(view, buffer, 0, buffer.getLength(), false, false, xsearch.XSearchAndReplace.FIND_OPTION_SILENT))
Log.log(Log.DEBUG, BeanShell.class,"+++ Temporary_Macro.9 "+xsearch.XSearchAndReplace.getLastMatchedSelection());
xsearch.SearchSettings.pop();

XSearch global options

It is possible to tailor the layout of the xsearch-and-replace dialog box. Disable features you will "never" use. They won't consume any space on the xsearch-and-replace dialog.

Further options:

Hyper replace ("hyper search enables hyper replace, too")

If this option is selected, the checkbox "hyper search" toggles the feature "hyper replace", too.

"Hyper replace" is activated when invoking "replace all".

It displays all changed lines in the hyper search window.

Replace case sensitiv

The default replace implementation in jEdit is case sensitiv, that means that if the search is case-insensitive, jEdit attempts to modify the case of the replacement string to match that of the particular instance of the search string being replaced (see jEidt user guide: "Replacing text").

If this behavious is not required, it is possible to swich it off in the XSearch global options

Use textArea Font in search and replace field

Toggles the font used for the search and replace textareas. The textArea font is usually fixed width, therefore better readable.

This is especially useful when developping regular expressions.