search and replace macro...
Submitted by Thursday, 13 November, 2008 - 17:41
on
Hello,
I have a search and replace macro problem.
while searching, if the next text (e.g. WEB PAGES) is not in the display, a runtime exception occurs when searching for the next word. An example would be the text WEB PAGES being more than 50 lines down (I'm assuming 50 lines down is below the display of the screen) from the WEB PAGES text found.
giving the following macro
filename: test.bsh
--------------------------
// This is a recorded macro. First, check over the
// commands to make sure this is what you intended. Then,
// save this buffer, and the macro should appear in the
// Macros menu.
SearchAndReplace.setSearchString("WEB PAGE");
SearchAndReplace.setAutoWrapAround(false);
SearchAndReplace.setReverseSearch(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.find(view);
SearchAndReplace.setSearchString("WEB PAGE");
SearchAndReplace.setReplaceString("<<>>");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("WEB PAGE");
SearchAndReplace.setAutoWrapAround(false);
SearchAndReplace.setReverseSearch(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.find(view);
SearchAndReplace.setSearchString("WEB PAGE");
SearchAndReplace.setReplaceString("<<>>");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("WEB PAGE");
SearchAndReplace.setAutoWrapAround(false);
SearchAndReplace.setReverseSearch(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.find(view);
-------------------------------------------
and given the file to search and replace
filename: test.txt
------------------------------------------
WEB PAGE
...(about 60 lines down)...
WEB PAGE
------------------------------------------------
I get the following runtime error...
9:29:38 AM [error] SearchAndReplace: java.lang.RuntimeException: Invalid screen line count: 10
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.textarea.DisplayManager.getScreenLineCount(DisplayManager.java:192)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.textarea.FirstLine.physDown(FirstLine.java:174)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.textarea.DisplayManager.setFirstPhysicalLine(DisplayManager.java:632)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.textarea.TextArea.setFirstPhysicalLine(TextArea.java:754)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.textarea.TextArea.scrollTo(TextArea.java:981)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.textarea.TextArea.scrollTo(TextArea.java:887)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.search.SearchAndReplace.find(SearchAndReplace.java:661)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.search.SearchAndReplace.find(SearchAndReplace.java:519)
9:29:38 AM [error] SearchAndReplace: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
9:29:38 AM [error] SearchAndReplace: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
9:29:38 AM [error] SearchAndReplace: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
9:29:38 AM [error] SearchAndReplace: at java.lang.reflect.Method.invoke(Method.java:597)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.Reflect.invokeMethod(Reflect.java:134)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.Reflect.invokeStaticMethod(Reflect.java:98)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.Name.invokeMethod(Name.java:796)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.bsh.Interpreter.eval(Interpreter.java:644)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:336)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:281)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.BeanShell.runScript(BeanShell.java:207)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.Macros$BeanShellHandler.runMacro(Macros.java:1020)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.Macros$Macro.invoke(Macros.java:441)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.gui.InputHandler.invokeAction(InputHandler.java:383)
9:29:38 AM [error] SearchAndReplace: at org.gjt.sp.jedit.jEdit$3.invokeAction(jEdit.java:3000)
-----------------------------------------------------