SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: chrisant on July 03, 2008, 11:38:42 PM

Title: FindIn - Shortcuts for finding stuff in predefined sets of files
Post by: chrisant on July 03, 2008, 11:38:42 PM
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.
Title: Re: FindIn - Shortcuts for finding stuff in predefined sets of files
Post by: suevian 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.
Title: Re: FindIn - Shortcuts for finding stuff in predefined sets of files
Post by: chrisant 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.
Title: Re: FindIn - Shortcuts for finding stuff in predefined sets of files
Post by: suevian 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.
Title: Re: FindIn - Shortcuts for finding stuff in predefined sets of files
Post by: chrisant 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.