Extended Search Plugin

Version 1.9 (October 16 2013)

Rudolf Widmann

Alan Ezust

Legal Notice

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no "Invariant Sections", "Front-Cover Texts" or "Back-Cover Texts", each as defined in the license. A copy of the license can be found in the file COPYING.DOC.txt included with jEdit.


Table of Contents

List of Examples

Chapter 1. Introduction

The Extended Search plugin offers enhanced search-and-replace dialogs based on those from the jEdit text editor. XSearch's dialogs are dockable or floatable, giving more flexible usability. They include all the standard search and replace functions described in jEdit user guide.

Sometimes, features are added and tested in XSearch and later added to jEdit. Think of XSearch as the experimental version of the SearchDialog.

For incremental search users, XSearch does not extend or change the behavior of the SearchBar, which is a View related feature. One interesting, (desirable?) side-effect of this is that changing the checkbox states or Search for: field of the incremental SearchBar has no effect on the state of the xsearch.SearchPanel checkboxes and textfields, or vice-versa. Another implication of this is that you now have two distinct pairs of find-next/previous actions in jedit - the plugin's xfind-next/xfind-previous uses the XSearch panel to decide what to search for, while the original find-next applies to the SearchBar and the original SearchReplace dialog.

As of XSearch 1.0.9.2, you have an option of overriding the built-in Find and Search in directory... actions with XSearch equivalents. The Find action, if there is a selection, will also serve as Replace in selection, but if there is no selection, will select the "current buffer" as the search scope.

Chapter 2. Extended Search Dialog

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

RE (regular expression support)

The regular expression support helps you to construct a regular expression. If you select from the popup menu, the according RE is inserted in the search field or in the replace field at the caret position. Any selected text is replaced.

The particular flavor of regular expressions supported in XSearch is gnu.regexp. This is not the same language or processor as Sun's java.util.regex. It's old, and has its own quirks, but some say it is more reliable for complex expressions which can cause Sun's engine to choke due to infinite recursion analyzing specific patterns against specific text.

Exceptions:

Brackets are inserted around the selection

The action "escape string" adds an escape to all RE relevant characters in the search string

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

synchronize search directory

When checked, the search directory is the directory of the current buffer

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

  • whole word: matches only complete words (according to regular expressions convention)

  • prefix: matches only words with the search string as prefix

  • suffix: matches only words with the search string as suffix

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

column search

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

  • expandTabs: if selected, tabs are expanded to the visible size. Otherwise, tabs are treated as 1 space

  • left col: left range, line begins with '1' (as displayed in status bar)

  • right col: right range, must be > left col + length(search string) (if no regexp). If right col is omitted, it is calculated automatically, to right col = left col + length(search string)

row search

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

  • upper row: upper range, first line begins with '1' (as displayed in status bar)

  • lower row: lower range, must be >= upper row

Hints:

  • If multiple lines are selected before invoking the search dialog, the upper / lower rows are predefined with the selected line range.

  • Row search allows "find all" and "replace&find" only inside the specified line range.

fold search

  • inside folds: matches only text inside of a fold

  • outside folds: matches only text outside of a fold

Restriction: not applicable for hypersearch

comment search

  • inside comments: matches only text inside of a comments

  • outside comments: matches only text outside of a comments

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

  • the hyper search feature (unchanged to the standard implementation)

  • the hyper replace feature, if allowed according to the global options

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, specified in the next lines, are used.

tentativ search

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

  • double typed char (toown instead of. town)

  • dash instead of underscore (Fast-Macro instead of Fast_Macro)

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

  • and nothing is selected, the first occurance of the search string will be replaced by the replace string

  • the search dialog is kept as long as 'keep dialog' is not switched off explicitely

Chapter 3. Extended Hypersearch Window

Note: The hyper search results are displayed in the dockable window "XHyperserarch". In the context menu, you have the options:

Expand Node

expand all subnodes of the selected node

Collapse Node

collapse all subnodes of the selected node

Expand Level 1

expand exactly 1 sublevel of the selected node

Expand Level 2

expand exactly 2 sublevel of the selected node

Expand all Nodes

expand all nodes

Collapse all Nodes

collapse all nodes

Write Node to buffer

writes the hypersearch result of the selected node to a new buffer

Write all Nodes to buffer

writes the hypersearch result of all nodes to a new buffer

Chapter 4. Extended Search 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. The search string is the current selection or, if nothing is selected, the previous search string.

xfind-next

Same as xfind-refind, but the search direction is forward. The search string is the current selection or, if nothing is selected, the previous search string.

xfind-prev

Same as xfind-refind, but the search direction is backward. The search string is the current selection or, if nothing is selected, the previous search string.

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:

  • the current selection, if a single selection exists

  • the word at the caret, if the caret is at a word. In this case, a "whole word search"is performed

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

Chapter 5. 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 subexpression>)
		
			

Example 5.1. get subexpressions

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 5.2. Delete all lines containing a string

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 5.3. Silent search

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))
	//do something with      xsearch.XSearchAndReplace.getLastMatchedSelection()
xsearch.SearchSettings.pop();
	

Chapter 6. Extended Search 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:

tabbed layout

If this option is selected, you see a tabbed layout that is better suited as a dockable. Otherwise, you see a classic dialog with buttons to toggle what you see, and a scrollbar as needed.

use XSearch instead of builtin actions

If this option is enabled, the built-in find actions "find" and "search in directory" are remapped to the equivalent XSearch actions.

The reasoning behind only mapping these, and not also not mapping "find next" and "find previous", is that these still apply to the incremental search bar. XSearch "xfind-next" and "xfind-previous" can be mapped to other shortcuts.

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, you can switch it off in the Extended Search 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 developing regular expressions.

Chapter 7. Feedback

You can write to:

Appendix A. Change log

Version 1.8 .  Requires JDK 1.6, jEdit 5.1pre1, GnuRegexpPlugin 1.0.1, and ProjectViewer 3.4.4

  • Updated for newer APIs in jEdit 5.1

Version 1.6 .  Requires JDK 1.5, jEdit 4.3pre17, GnuRegexpPlugin 1.0, and ProjectViewer 2.9.x

  • Updated for newer APIs in ProjectViewer and Core.

Version 1.5 (ae) .  Requires JDK 1.5, jEdit 4.3pre12, GnuRegexpPlugin 1.0, and ProjectViewer 2.1.x

  • Now uses new gnu.regexp plugin, recently removed from jEdit core.

Version 1.3.3 (ae) .  Requires JDK 1.5, jEdit 4.3pre12, ProjectViewer 2.1.x

  • Updated for jEdit 4.3pre12's relocated Beanshell package.

Version 1.3.2 (ae) .  Requires JDK 1.4, jEdit 4.3pre5, ProjectViewer 2.1.x

  • Bugfix in Project Search - now it waits for you to type something before it starts searching.

  • Fix bug # Bugs-1574049 - no more dialog popups during xfind-next and xfind-previous.

Version 1.3.1 .  Requires JDK 1.4, jEdit 4.3pre5, ProjectViewer 2.1.x

  • Option to show options in tabbed layout instead of everything in one panel.

  • Icons instead of text labels to save screen space.

  • Added default focus component, rewrote hiding/showing code. Escape hides xsearch, equally well as a dockable or as a floater.

  • New dir search options exposed from 4.3pre5: skip binary files and skip hidden directories.

  • Many bugfixes.

Version 1.1 .  Requires JDK 1.4, jEdit 4.3pre4, ProjectViewer 2.1.x.

  • New Feature: Project Search, search in all files of the current project of PV (rw)

  • Hyper search: navigation buttons added (rw)

  • Option to remap "find" and "search in directory" to XSearch actions (ae)

  • Changed the "synchronize" checkbox to a sync button, with a context menu for making it "autosync". (ae)

  • Small UI improvements

Version 1.0.9 (ae) . Requires JDK 1.4, jEdit 4.3pre3

  • Bugfix - search in selection was not working

  • removed action remapping (caused too much confusion)

Version 1.0.8 (ae) . Requires JDK 1.4, jEdit 4.3pre3

  • Uses Dockable windows instead of dialogs.

  • Remaps built-in actions for popping up Search dialogs.

  • Small bug fixes

Version 1.0.7. Requires JDK 1.4, jEdit 4.2

Version 1.0.6. Requires JDK 1.4, jEdit 4.2

Version 1.0.0. Requires JDK 1.4, jEdit 4.1

  • Final release for jEdit 4.1

Appendix B. Further ideas

Any ideas welcome

  • For multiple-file replacements, option to preview the replace-all before actually performing the replace.

  • Re-search of hypersearch results

  • Make the layout of widgets in dialog more flexible so that they use space more efficiently when docked.