java.lang.Object
org.gjt.sp.jedit.search.SearchAndReplace
Class that implements regular expression and literal search within
jEdit buffers.
There are two main groups of methods in this class:
- Property accessors - for changing search and replace settings.
- Actions - for performing search and replace.
jEdit.setBooleanProperty("search.hypersearch.toggle",true); jEdit.setBooleanProperty("search.keepDialog.toggle",true);If you are not using the dialog to undertake a search or replace, you may call any of the search and replace methods (including
hyperSearch(View)
) without concern for the value of these
properties.- Version:
- $Id: SearchAndReplace.java 24989 2020-03-10 07:55:36Z kpouer $
- Author:
- Slava Pestov, John Gellene (API documentation)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
escapeRegexp
(String str, boolean multiline) Escapes characters with special meaning in a regexp.static boolean
Finds the next occurrence of the search string.static boolean
Finds the next instance of the search string in the specified buffer.static boolean
Finds the next instance of the search string in the specified buffer.static boolean
Returns the state of the auto wrap around flag.static boolean
Returns the state of the BeanShell replace flag.static boolean
Returns the state of the ignore case flag.static boolean
Returns the state of the regular expression flag.static String
Returns the current replacement string.static boolean
Returns the state of the reverse search flag.static SearchFileSet
Returns the current search file set.static SearchMatcher
Returns the current search string matcher.static String
Returns the current search string.static boolean
Returns if the replacement string will assume the same case as each specific occurrence of the search string.static boolean
Returns the state of the whole word flag.static boolean
hyperSearch
(View view) Performs a HyperSearch.static boolean
hyperSearch
(View view, boolean selection) Performs a HyperSearch.static void
load()
Loads search and replace state from the properties.static boolean
Replaces the current selection with the replacement string.static boolean
Replaces text in the specified range with the replacement string.static boolean
replaceAll
(View view) Replaces all occurrences of the search string with the replacement string.static boolean
replaceAll
(View view, boolean dontOpenChangedFiles) Replaces all occurrences of the search string with the replacement string.static void
save()
Saves search and replace state to the properties.static void
setAutoWrapAround
(boolean wrap) Sets the state of the auto wrap around flag.static void
setBeanShellReplace
(boolean beanshell) Sets the state of the BeanShell replace flag.static void
setIgnoreCase
(boolean ignoreCase) Sets the ignore case flag.static void
setRegexp
(boolean regexp) Sets the state of the regular expression flag.static void
setReplaceString
(String replace) Sets the current replacement string.static void
setReverseSearch
(boolean reverse) Determines whether a reverse search will conducted from the current position to the beginning of a buffer.static void
setSearchFileSet
(SearchFileSet fileset) Sets the current search file set.static void
setSearchMatcher
(SearchMatcher matcher) Sets a custom search string matcher.static void
setSearchString
(String search) Sets the current search string.static void
setWholeWord
(boolean wholeWord) Sets the whole word flag.
-
Constructor Details
-
SearchAndReplace
public SearchAndReplace()
-
-
Method Details
-
setSearchString
Sets the current search string.- Parameters:
search
- The new search string
-
getSearchString
Returns the current search string. -
setReplaceString
Sets the current replacement string.- Parameters:
replace
- The new replacement string
-
getReplaceString
Returns the current replacement string. -
setWholeWord
public static void setWholeWord(boolean wholeWord) Sets the whole word flag.- Parameters:
wholeWord
- True if only whole words should be searched, false otherwise- Since:
- 4.5pre1
-
setIgnoreCase
public static void setIgnoreCase(boolean ignoreCase) Sets the ignore case flag.- Parameters:
ignoreCase
- True if searches should be case insensitive, false otherwise
-
getWholeWord
public static boolean getWholeWord()Returns the state of the whole word flag.- Returns:
- True if only whole words should be searched, false otherwise
- Since:
- 4.5pre1
-
getIgnoreCase
public static boolean getIgnoreCase()Returns the state of the ignore case flag.- Returns:
- True if searches should be case insensitive, false otherwise
-
setRegexp
public static void setRegexp(boolean regexp) Sets the state of the regular expression flag.- Parameters:
regexp
- True if regular expression searches should be performed
-
getRegexp
public static boolean getRegexp()Returns the state of the regular expression flag.- Returns:
- True if regular expression searches should be performed
-
setReverseSearch
public static void setReverseSearch(boolean reverse) Determines whether a reverse search will conducted from the current position to the beginning of a buffer. Note that reverse search and regular expression search is mutually exclusive; enabling one will disable the other.- Parameters:
reverse
- True if searches should go backwards, false otherwise
-
getReverseSearch
public static boolean getReverseSearch()Returns the state of the reverse search flag.- Returns:
- True if searches should go backwards, false otherwise
-
setBeanShellReplace
public static void setBeanShellReplace(boolean beanshell) Sets the state of the BeanShell replace flag.- Parameters:
beanshell
- True if the replace string is a BeanShell expression- Since:
- jEdit 3.2pre2
-
getBeanShellReplace
public static boolean getBeanShellReplace()Returns the state of the BeanShell replace flag.- Returns:
- True if the replace string is a BeanShell expression
- Since:
- jEdit 3.2pre2
-
setAutoWrapAround
public static void setAutoWrapAround(boolean wrap) Sets the state of the auto wrap around flag.- Parameters:
wrap
- If true, the 'continue search from start' dialog will not be displayed- Since:
- jEdit 3.2pre2
-
getAutoWrapAround
public static boolean getAutoWrapAround()Returns the state of the auto wrap around flag.- Since:
- jEdit 3.2pre2
-
setSearchMatcher
Sets a custom search string matcher. Note that callingsetSearchString(String)
,setWholeWord(boolean)
,setIgnoreCase(boolean)
, orsetRegexp(boolean)
will reset the matcher to the default. -
getSearchMatcher
Returns the current search string matcher.- Returns:
- a SearchMatcher or null if there is no search or if the matcher can match empty String
- Throws:
IllegalArgumentException
- if regular expression search is enabled, the search string or replacement string is invalidException
- Since:
- jEdit 4.1pre7
-
setSearchFileSet
Sets the current search file set.- Parameters:
fileset
- The file set to perform searches in- See Also:
-
getSearchFileSet
Returns the current search file set. -
getSmartCaseReplace
public static boolean getSmartCaseReplace()Returns if the replacement string will assume the same case as each specific occurrence of the search string.- Since:
- jEdit 4.2pre10
-
hyperSearch
Performs a HyperSearch.- Parameters:
view
- The view- Since:
- jEdit 2.7pre3
-
hyperSearch
Performs a HyperSearch.- Parameters:
view
- The viewselection
- If true, will only search in the current selection. Note that the file set must be the current buffer file set for this to work.- Since:
- jEdit 4.0pre1
-
find
Finds the next occurrence of the search string.- Parameters:
view
- The view- Returns:
- True if the operation was successful, false otherwise
-
find
Finds the next instance of the search string in the specified buffer.- Parameters:
view
- The viewbuffer
- The bufferstart
- Location where to start the search- Throws:
Exception
-
find
public static boolean find(View view, Buffer buffer, int start, boolean firstTime, boolean reverse) throws Exception Finds the next instance of the search string in the specified buffer.- Parameters:
view
- The viewbuffer
- The bufferstart
- Location where to start the searchfirstTime
- SeeSearchMatcher.nextMatch(CharSequence,boolean,boolean,boolean,boolean)
.- Throws:
Exception
- Since:
- jEdit 4.1pre7
-
replace
Replaces the current selection with the replacement string.- Parameters:
view
- The view- Returns:
- True if the operation was successful, false otherwise
-
replace
Replaces text in the specified range with the replacement string.- Parameters:
view
- The viewbuffer
- The bufferstart
- The start offsetend
- The end offset- Returns:
- True if the operation was successful, false otherwise
-
replaceAll
Replaces all occurrences of the search string with the replacement string.- Parameters:
view
- The view- Returns:
- the number of modified files
-
replaceAll
Replaces all occurrences of the search string with the replacement string.- Parameters:
view
- The viewdontOpenChangedFiles
- Whether to open changed files or to autosave them quietly- Returns:
- the number of modified files
-
escapeRegexp
Escapes characters with special meaning in a regexp.- Parameters:
str
- the string to escapemultiline
- Should \n be escaped?- Returns:
- the string with escaped characters
- Since:
- jEdit 4.3pre1
-
load
public static void load()Loads search and replace state from the properties. -
save
public static void save()Saves search and replace state to the properties.
-