Author Topic: How to do a specific "find in files" bound to a key  (Read 6159 times)

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
How to do a specific "find in files" bound to a key
« on: September 19, 2016, 01:25:04 PM »
Hi:

I would like to bind to a key a search that performs the following:

1) The text to search for is whatever I have highlighted in the editor
2) Search all files in my project
3) Match case checked
4) Match whole word checked
5) Output into search results window as "auto increment"

Is there a command equivalent of the "Find in Files" dialog box where I can take currently highlighted word and do this?

Thanks,
Rob

Tim Kemp

  • Senior Community Member
  • Posts: 546
  • Hero Points: 92
Re: How to do a specific "find in files" bound to a key
« Reply #1 on: September 19, 2016, 01:48:02 PM »
You will need to write a macro. The function to call for searching is _mffind2().

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #2 on: September 19, 2016, 02:03:47 PM »
Thanks Tim.

I can't find _mffind2() documented in SE help. Is there somewhere else I can look for the documentation?

Also, how to get the highlighted text into a string that I can pass to _mffind2()?

Tim Kemp

  • Senior Community Member
  • Posts: 546
  • Hero Points: 92
Re: How to do a specific "find in files" bound to a key
« Reply #3 on: September 19, 2016, 02:53:22 PM »
To be honest, I got the _mffind2() by making a keyboard macro. I don't see any help for it either. I've always set up the options in the dialog and used the keyboard macro recorder to capture them.

I suggest you use HS2's macro, cur_word_sel(), to retrieve the current selection.

misc_tools_hs2.e


Graeme

  • Senior Community Member
  • Posts: 2821
  • Hero Points: 347
Re: How to do a specific "find in files" bound to a key
« Reply #4 on: September 20, 2016, 11:49:49 AM »
Have a look at this
https://community.slickedit.com/index.php/topic,11186.0.html

xsearch_workspace_cur_word_now and xsearch_cur_word.
For auto increment
      //return _mffind2(sw,'I','<Workspace>','*.*','','32',auto_increment_grep_buffer());

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #5 on: September 20, 2016, 12:39:40 PM »
Thanks Graeme! I will check it out.

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #6 on: December 22, 2016, 03:42:56 PM »
On a related question to this thread, is there a macro function that allows one to search the active buffer with the equivalent of "Look in: Current Procedure"? I would like to bind to another key to search for the highlighted string only in the current procedure.

The mffind2() macro doesn't seem to have an option for telling it to "Look in: Current Procedure". Is there another macro that does offer this?

I would also like to do "list all occurrences" and send the output of this search to a search/grep window.

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #7 on: December 22, 2016, 03:55:39 PM »
I think I found it by recording a macro and looking at the resulting source - mark_all_occurences()

Will be checking it out...

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2919
  • Hero Points: 153
Re: How to do a specific "find in files" bound to a key
« Reply #8 on: December 22, 2016, 05:18:34 PM »
On a related question to this thread, is there a macro function that allows one to search the active buffer with the equivalent of "Look in: Current Procedure"? I would like to bind to another key to search for the highlighted string only in the current procedure.

The mffind2() macro doesn't seem to have an option for telling it to "Look in: Current Procedure". Is there another macro that does offer this?

I would also like to do "list all occurrences" and send the output of this search to a search/grep window.

There isn't a built-in option for this.  If you look in tbfind.e, there is a function called _get_proc_mark().  It calls select_proc (which might be all you need), but it does some other stuff to allocate a new selection and tweak the selection type.

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #9 on: December 22, 2016, 07:02:36 PM »
Thanks for your reply Dan. I tried mark_all_occurences() and it seems to be doing exactly what I want.

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #10 on: December 22, 2016, 07:11:21 PM »
Question about the "search_options" argument to mark_all_occurrences() and mffind2().

When I did the macro record to find mark_all_occurences(), it gave me this:

mark_all_occurences("text_to_search","I?M",'2','0','4','0','1','0','1','0');

Here the "search_options" is "I?M". I think these options are documented in the documentation for mffind() in the "Help". It says what "I" is "Ignore case" and what "M" is "Limit search to marked area", but there is no documentation for what "?" means in search options.

So what does "?" mean here?

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2919
  • Hero Points: 153
Re: How to do a specific "find in files" bound to a key
« Reply #11 on: December 22, 2016, 08:00:18 PM »
Question about the "search_options" argument to mark_all_occurrences() and mffind2().

When I did the macro record to find mark_all_occurences(), it gave me this:

mark_all_occurences("text_to_search","I?M",'2','0','4','0','1','0','1','0');

Here the "search_options" is "I?M". I think these options are documented in the documentation for mffind() in the "Help". It says what "I" is "Ignore case" and what "M" is "Limit search to marked area", but there is no documentation for what "?" means in search options.

So what does "?" mean here?

Good question.  I had to dig a bit to find the answer myself.  The answer is that it turns on wrap (start searching again from the top when the bottom is reached), and prompt before wrapping.

If you would like to wrap without prompting, you can use the more documented 'P' option.  I will try to get this documented.

rowbearto

  • Senior Community Member
  • Posts: 2344
  • Hero Points: 132
Re: How to do a specific "find in files" bound to a key
« Reply #12 on: December 22, 2016, 08:05:48 PM »
Thanks Dan! I have another question.

Quote
If you would like to wrap without prompting, you can use the more documented 'P' option.

Where is the 'P' option documented? In _mffind() documentation in the Help, it only says that "P" is "ignored". Are you looking somewhere else in the documentation?

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2919
  • Hero Points: 153
Re: How to do a specific "find in files" bound to a key
« Reply #13 on: December 22, 2016, 08:11:17 PM »
Thanks Dan! I have another question.

Quote
If you would like to wrap without prompting, you can use the more documented 'P' option.


Where is the 'P' option documented? In _mffind() documentation in the Help, it only says that "P" is "ignored". Are you looking somewhere else in the documentation?

I looked at the help on the search built-in (in builtins.e), it is documented there, and also in on the help for the find command.  It would work for most gui-find features, but for _mffind() of course it doesn't make sense because definition you are searching the whole file.