Author Topic: FindIn - Shortcuts for finding stuff in predefined sets of files  (Read 6920 times)

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Here is a macro that makes it easier to search common directories by choosing them from a table.  The table can be configured by editing the macro source.

Commands in this macro file:
- FindIn - Show the Find In dialog and initiate search.
- FindInFunction - Search in the current function.
- FindInThisFile - Search in the current buffer.
- FindInOpenBuffers - Search in the open buffers.
- FindInFileDirectory - Search in current file's directory.
- FindInProjectFiles - Search all project files.
- FindInWorkspaceFiles - Search all workspace files.
- OpenFileAtCursor - Opens the filename under the cursor.
- EditAssociatedFile - Opens file associated with current file (e.g. matching header file).

See screen shot to see an example of the Find In dialog.

suevian

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: FindIn - Shortcuts for finding stuff in predefined sets of files
« Reply #1 on: July 10, 2008, 12:34:12 pm »
Hi Crisant,

I can't get "Find in function", "Find in buffer" to work correctly. They don't appear in the tree.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: FindIn - Shortcuts for finding stuff in predefined sets of files
« Reply #2 on: July 10, 2008, 06:17:44 pm »
They aren't in the data structure that defines the tree (look at the source file), because personally I set them as key bindings instead:

Ctrl+' = FindInFunction
Ctrl+Shift+' = FindInThisFile
Alt+' = FindInOpenBuffers
Alt+Shift+' = FindInFileDirectory
Ctrl+Alt+' = FindInProjectFiles
Ctrl+Alt+Shift+' = FindInWorkspaceFiles

The idea behind the data structure is that you can customize it to your liking.  I suppose I could add all the possible "special" entries to the initial table, and then you can remove the ones you don't want.  Eventually I want to move the table into a separate file so the macro source can be updated without needing to merge your edited data structure back into the file.

suevian

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: FindIn - Shortcuts for finding stuff in predefined sets of files
« Reply #3 on: July 11, 2008, 08:38:18 am »
Yes, I understand now.

I modified events_FindIn.on_load() to add "Current Function", "Current Buffer", etc. to the main table. In that way I have to define only one shotcut for all search locations, and then choose from the table. The search locations are added to the tree in order of most frequently used - on top.

Thanks for the macro, it's very useful for me.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: FindIn - Shortcuts for finding stuff in predefined sets of files
« Reply #4 on: July 11, 2008, 05:21:10 pm »
That works, but you might be able to add them more easily by just modifying the table:

Code: [Select]
static FINDINRECORD s_arrayTreeData[] =
{
   { ". (current file's directory)", '"'MFFIND_BUFFER_DIR'"', '<sources>' },
   { "Other directory (prompt)", WHERE_PROMPT, '<sources>' },

For example add these lines:

Code: [Select]
   { "Current Function", '"<Current Function>"', '<sources>' },
   { "Current Buffer", '"'MFFIND_BUFFER'"', '<sources>' },

And so forth.
The s_arrayTreeData table should be the only thing you need to modify.
You should not need to modify any macro functions at all.