Author Topic: Assign selection to variable  (Read 1697 times)

tpb3470

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Assign selection to variable
« on: July 14, 2015, 06:42:16 pm »
Below is my macro I want to use to find dead/static code.  I get the selection correctly and can even copy to the clipboard (not that I need too), but I just can't get the selection to a variable for my multi-file find

_command tb() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);
   next_word();
   deselect();
   _select_char('','E');
   next_word();
   cursor_right();
   select_it('CHAR','','E');
   _str sel = "gForcePage";
   save_selection( sel ); "Does not do anything"
   copy_to_clipboard();
   _mffind2( sel,'','<Project>',
            '*.c;*.cc;*.cpp;*.cp;*.cxx;*.h;*.hh;*.hpp;*.hxx;*.inl;*.xpm','','96',
            '3');
}

Bamsen

  • Community Member
  • Posts: 45
  • Hero Points: 1
Re: Assign selection to variable
« Reply #1 on: July 15, 2015, 07:21:47 am »
The save_selection saves the actual selection, not the content of the selection.

This is a routine I lifted from somewhere, probably in this forum. :)
The OneLine flag determines if the returned variable will contain only one line
or multiple lines if the selection spans several lines.

static _str MST_Get_Selected_Text(boolean OneLine=false)
{
  _str text='',Result='';
  int i=0,Start=0,Stopp=0;
  i = _get_selinfo(Start,Stopp,0);
  if (i != TEXT_NOT_SELECTED_RC) {
    filter_init();
    while( filter_get_string(text) == 0 ) {
      if (OneLine) { return(text); }
      if (Result != "") { Result=Result :+ "\n"; }
      Result=Result :+ text;
    }
    filter_restore_pos();
    }
  return(Result);
}

Vikapolyak

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Assign selection to variable
« Reply #2 on: March 01, 2016, 05:28:27 am »
Does it matter in which order I assign the variables? For example if I assign a variable of the included template before I assign the variable which file I will include?

hs2

  • Senior Community Member
  • Posts: 2736
  • Hero Points: 285
Re: Assign selection to variable
« Reply #3 on: March 01, 2016, 06:23:38 am »
@Vikapolyak: You should be a bit more specific and provide some context.
Or .. I just don't get it ;)
HS2