Author Topic: Trivial Question  (Read 1421 times)

lwb-ztexas

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Trivial Question
« on: May 04, 2023, 04:58:36 PM »
I have used SE for years and written lots of macros. However, I have not used SE for the last 3 years and you forget things...

I want a macro, tied to a key that grabs the word under the cursor and pulls up the Find Files dialog and pastes it in the search field.
I have code that almost works, but I can't get the field selected in the dialog to paste. I'm certain this is a 30 second answer for one of you guys...

Here is my current code:

#include "slick.sh"
#pragma option( strict, on )

_command void SearchWorkspaceForWord() name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   typeless old_pos, old_mark;
   save_pos( old_pos );
   save_selection( old_mark );
   _str ch = get_text( -1 );
   if ( _isSpaceChar( ch ) )
     left();
   select_whole_word();
   copy_to_clipboard();
   find_in_files();
   select_whole_word();
====> I think I'm missing something here
   paste();
}

Thanks!


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Trivial Question
« Reply #1 on: May 05, 2023, 10:15:04 AM »
For that one, there's a lot of code doing things with the search string combo box, and you can't pass the search string in through the form parameters, so I'd probably take a different approach to avoid possibly fighting it.  There's a var called old-search-string that find-in-files will put in the search string box as long as the options still have the default setting of using the search history.  So you could sneak in your current word like this:

Code: [Select]
#include "slick.sh"
#import "stdcmds.e"
#pragma option( strict, on )

_command void SearchWorkspaceForWord() name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)

{
   typeless old_pos, old_mark;
   save_pos( old_pos );
   save_selection( old_mark );
   _str ch = get_text( -1 );
   if ( _isSpaceChar( ch ) )
     left();
   word := cur_word(auto col);
   saved_search := old_search_string;
   old_search_string = word;
   find_in_files();
   old_search_string = saved_search;
}


lwb-ztexas

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Re: Trivial Question
« Reply #2 on: May 10, 2023, 04:53:02 PM »
Genius! Thanks!

lwb-ztexas

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Re: Trivial Question
« Reply #3 on: May 10, 2023, 05:44:55 PM »
Hmmm...

This won't compile...
    old_search_string = word;

Is it possible this is a function call? (makes sense to not use a global...)

Or, is there a list of all the globals used by the internals of the editor?

Thanks

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Trivial Question
« Reply #4 on: May 10, 2023, 08:23:46 PM »
That should be defined in the slick.sh you're including.  What version are you on, and what's the error it's giving you?

lwb-ztexas

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Re: Trivial Question
« Reply #5 on: May 12, 2023, 09:03:18 PM »
I should have known you were right!  ::)

I had to look at "cur_word()", it wanted a defined parameter for the reference.

This works like a charm!

Thanks!


#include "slick.sh"
#pragma option( strict, on )

_command void SearchWorkspaceForWord() name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   typeless old_pos, old_mark;
   save_pos( old_pos );
   save_selection( old_mark );
   _str ch = get_text( -1 );

   if ( _isSpaceChar( ch ) ) left();
   
   int start_col;
   old_search_string = cur_word(start_col);

   find_in_files();
}

lwb-ztexas

  • Junior Community Member
  • Posts: 5
  • Hero Points: 0
Re: Trivial Question
« Reply #6 on: February 06, 2024, 07:05:34 PM »
FYI... I found my old macro:

#include "slick.sh"
#pragma option( strict, on )

_command void SearchWorkspaceForWord() name_info(','VSARG2_EDITORCTL|VSARG2_READ_ONLY)
{
   typeless old_pos, old_mark;
   save_pos( old_pos );
   save_selection( old_mark );
   _str ch = get_text( -1 );

   if ( _isSpaceChar( ch ) ) left();
   
   int start_col;
   old_search_string = cur_word(start_col);

   find_in_files();
}