Author Topic: passing selected text as search string?  (Read 1529 times)

flethuseo

  • Senior Community Member
  • Posts: 176
  • Hero Points: 2
passing selected text as search string?
« on: February 05, 2013, 05:14:36 pm »
How do I change this macro to use the selected string, rather than a predefined string. That is, I want the string "WellDataInfo_Test_" to be changed to be whatever the user is selecting at that moment.
Code: [Select]
#include "slick.sh"

_command my_renumber() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
  int not_found = 0; /* boolean to terminate loop */
  int iLoop = 0;     /* Counter to renumber items */

  /* Use search initially; if that call doen't find an item, we're done. */
  if (search('WellDataInfo_Test_:i', 'R') != 0)
  {
    not_found = 1;
  }

  while (!not_found)
  {
    if (search_replace('WellDataInfo_Test_' :+ iLoop/2, 'R') == STRING_NOT_FOUND_RC)
    {
      not_found = 1;
    }
    iLoop++;
  }
}

hs2

  • Senior Community Member
  • Posts: 2732
  • Hero Points: 284
Re: passing selected text as search string?
« Reply #1 on: February 06, 2013, 10:03:45 am »
This macro returns the current word or selected text if any. Hope it helps.
HS2

flethuseo

  • Senior Community Member
  • Posts: 176
  • Hero Points: 2
Re: passing selected text as search string?
« Reply #2 on: February 06, 2013, 10:04:42 pm »
Cool, it works nicely:

Code: [Select]
_command my_renumber() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
   int not_found = 0; /* boolean to terminate loop */
   int iLoop = 0;     /* Counter to renumber items */

   /* Use search initially; if that call doen't find an item, we're done. */
   _str text = hs2_cur_word_sel()
   if (search(text :+ ':i', 'R') != 0) {
      not_found = 1;
   }

   while (!not_found) {
      if (search_replace(text :+ iLoop/2, 'R') == STRING_NOT_FOUND_RC) {
         not_found = 1;
      }
      iLoop++;
   }
}

How do I go about debugging it step by step, could anyone tell me the steps to do that or where I can find that in the help

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: passing selected text as search string?
« Reply #3 on: February 06, 2013, 10:12:31 pm »
The Help system has a topic on "Slick-C Debugger" which describes how to use the Slick-C Debugger to debug macros.

hs2

  • Senior Community Member
  • Posts: 2732
  • Hero Points: 284
Re: passing selected text as search string?
« Reply #4 on: February 06, 2013, 10:13:46 pm »
See 'Help>Index: Slick-C debugger'. Good luck, HS2