Author Topic: macro to select path from an unsaved buffer  (Read 277 times)

flethuseo

  • Senior Community Member
  • Posts: 168
  • Hero Points: 2
macro to select path from an unsaved buffer
« on: October 20, 2016, 09:38:21 pm »
I have tried recording a macro that will capture the path in a bunch of text that ends in *.xml. However when I try to execute, it only selects the quote and the C and not the full path:

Code: [Select]
#include "slick.sh"
_command last_recorded_macro() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
   _macro('R',1);
   if (find(".xml","+>NIp?")) stop();
   select_char();
   cursor_right();
   if (find('''C',"-NIp?")) stop();
}

sample text to execute macro on:
Code: [Select]
impl.data.query Tests
.9_Select_EpiZone_InvalidKey(tests.impl.data.query.SelectQueryTestCase)
junit.framework.AssertionFailedError: ERROR: Expected result file specified in TEST CASE 'C:\tvd\rtm\asdfy.xml' does not exist.
at junit.framework.Assert.fail(Assert.java:47)
at tests.impl.data.query.xml.TestCase.getExpectedResultFile(TestCase.java:650)
at tests.impl.data.query.TestComparator.compare(TestComparator.java:89)
at tests.impl.data.query.SelectQueryTestCase.runTest(SelectQueryTestCase.java:217)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 985
  • Hero Points: 83
Re: macro to select path from an unsaved buffer
« Reply #1 on: October 21, 2016, 06:22:08 pm »
The find() command will select the match if found (assuming that option is set in preferences).  It will override whatever previous selection operation.  You can you use the lower-level search() command instead, though do note it doesn't handle any wrapping at end or beginning of document.

flethuseo

  • Senior Community Member
  • Posts: 168
  • Hero Points: 2
Re: macro to select path from an unsaved buffer
« Reply #2 on: October 21, 2016, 10:33:02 pm »
Thanks, I got the desired behavior with this macro:
Code: [Select]
#include "slick.sh"
_command last_recorded_macro() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
   _str text = '.xml''';
   if (search(text, 'E>') != 0) {
      stop();
   }

   select_char();
   cursor_right();
   if (search('''C','-E')) stop();
}