Author Topic: Macro to make a clickable list of files from a shell command  (Read 3496 times)

preiter

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Macro to make a clickable list of files from a shell command
« on: April 25, 2012, 12:36:04 am »
I'm new to macro programming, but this one macro would help me a lot.

I would like to take the current selection and pass it to a shell command. The command will generate a list of files, which I would like to go to the build window. Then I would like to be able to click on the list and edit the selected file.

I have looked at the examples on this board, but they seem don't seem to be working for me. Here's what I have so far:
#include "slick.sh"
_command code_search() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _str text = 'Some text I would like to be my selection';
   activate_build ();
   _str cmdline="my_shell_command " :+ text;
   concur_command (cmdline, false, true, false, false);
}

Thanks for the help

hs2

  • Senior Community Member
  • Posts: 2754
  • Hero Points: 291
Re: Macro to make a clickable list of files from a shell command
« Reply #1 on: April 25, 2012, 07:54:03 am »
You could use this macro to retrieve the current word or selection.
Good luck, HS2

preiter

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: Macro to make a clickable list of files from a shell command
« Reply #2 on: April 25, 2012, 04:50:25 pm »
Great! That worked to get the current selection.
Now I have a list of files in my build window. What is the easiest way to select one and edit it?
I am hoping for some functionality similar to when you build the project, and there are errors. You can click on the errors and it takes you directly to the file containing the error.
Is it possible to get similar behavior from a macro?

hs2

  • Senior Community Member
  • Posts: 2754
  • Hero Points: 291
Re: Macro to make a clickable list of files from a shell command
« Reply #3 on: April 25, 2012, 08:14:02 pm »
This is possible.
1) use 'Build>Configure Error Parsing' to create and activate a custom parser for your macro output (see Help for details)
2) you could use the following macros (as starting point) to manually invoke the SE error parser
Note that concur_command runs asynchronously. Hence and as far as I know there is no way to 'trigger' on the completion of your macro.
The cerr macro is there for completeness reasons.

Edit: Call clear_pbuffer first in your macro to get just 1 list in the build window.

Code: [Select]
_command void serr () name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
{
   cursor_data();
   push_bookmark();

   activate_build();
   // invoke error parser
   set_error_markers();
   refresh('A');
   // goto 1st error (if any) or at the end of build buffer
   if ( next_error() )
   {
      // undo unnamed bookmark
      pop_bookmark();
      bottom_of_build();
      _beep();
   }
   // activate edit win.
   cursor_data();
}

_command void bottom_of_build() name_info(',')
{
   int formwid = activate_toolbar("_tbshell_form", "_shellEditor");
   if (!formwid) return;

   _nocheck _control _shellEditor;
   int wid = formwid._shellEditor;
   activate_window( wid );
   bottom();
}

_command void cerr () name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
{
   clear_all_error_markers();
}

Good luck, HS2
« Last Edit: April 25, 2012, 10:25:41 pm by hs2 »