Author Topic: Regarding hs2_cur_word_sel macro  (Read 1713 times)

flethuseo

  • Senior Community Member
  • Posts: 173
  • Hero Points: 2
Regarding hs2_cur_word_sel macro
« on: May 15, 2015, 10:23:36 pm »
Hi all,
When I add the following code to the declaration of my command, I get a different
outcome on the text that is being obtained from a selection:
Code: [Select]
    name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_REQUIRES_PRO_EDITION)

When the macro is declared as follows, it only selects the first word in the selection. ( _str text = hs2_cur_word_sel(); )
Code: [Select]
    _command void PrintMacro2() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_REQUIRES_PRO_EDITION)
    {
    _str text = hs2_cur_word_sel();

    _begin_select();
    // Find end of statement. This handles multiple-line statements.
    search(";","@hXcs");

    insert_blankline_below();
    _insert_text('printf("' :+ text :+ '\n");');
    }

But if it is declared this way (omitting the VSARGS stuff), it will use the entire selection in the text variable:
Code: [Select]
    _command void PrintMacro2()

Why is that?

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Regarding hs2_cur_word_sel macro
« Reply #1 on: May 16, 2015, 06:49:22 am »
I think you missed 'VSARG2_MARK' referring to name_info of 'hs2_cur_word_sel'.
HS2

flethuseo

  • Senior Community Member
  • Posts: 173
  • Hero Points: 2
Re: Regarding hs2_cur_word_sel macro
« Reply #2 on: May 19, 2015, 01:27:01 pm »
In the following macro if I select from right to left, and when I select left to right. I get a different outcome for the search. I thought the _begin_select would have the search start from the same spot. How can I get the search to work from the beginning of the selection.

Code: [Select]
    _command void PrintMacro2() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_REQUIRES_PRO_EDITION)
    {
    _str text = hs2_cur_word_sel();

    _begin_select();
    // Find end of statement. This handles multiple-line statements.
    search(";","@hXcs");

    insert_blankline_below();
    _insert_text('printf("' :+ text :+ '\n");');
    }

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Regarding hs2_cur_word_sel macro
« Reply #3 on: May 19, 2015, 06:07:37 pm »
Sorry - I (still) don't really understand the macro :-\
AFAIK 'hs2_cur_word_sel' deselects an optionally existing selection.
Hence  I'm not sure about the purpose of '_begin_select'.
The text retrieved by 'hs2_cur_word_sel' is the same regardless of the select direction..
Hmm .. I should better ask or you should better tell the 'bigger problem you want to solve' ;)

HS2

flethuseo

  • Senior Community Member
  • Posts: 173
  • Hero Points: 2
Re: Regarding hs2_cur_word_sel macro
« Reply #4 on: May 21, 2015, 10:15:47 pm »
The problem I want to solve is to take a selection and then create a print statement with the selected text. I want do this with code I have selected. In order to do this, I have to determine where to put the print statement. If it's a statement that ends with a semicolon it should go directly below it.

The problem with my macro is that if I select a C++ statement from left to right, that is having the semicolon as the last character in the selection. Then the print statement will be below the next statement that ends with a ';'.
« Last Edit: May 21, 2015, 10:17:27 pm by flethuseo »

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Regarding hs2_cur_word_sel macro
« Reply #5 on: May 22, 2015, 06:13:25 am »
Ok - got it :)
What about just doing _begin_select before hs2_cur_word_sel i.e swapping those lines ?
Seems to be the easiest way.
HS2

flethuseo

  • Senior Community Member
  • Posts: 173
  • Hero Points: 2
Re: Regarding hs2_cur_word_sel macro
« Reply #6 on: May 22, 2015, 09:55:08 pm »
That worked!