Author Topic: open project file  (Read 5423 times)

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
open project file
« on: July 22, 2016, 04:38:11 PM »
I have a need for a macro that takes an argument of a file and line number and finds the file in the project and goes to the first column in at the line number in it. It needs to be able to be called from another macro or invoked from a command line (for integrating with another program that doesn't have complete paths). What am I doing wrong here?? I can't get this to launch correct from either. I'm not sure why there is both options for specifying arguments in name_info vs parameters either. Help!!

Code: [Select]
_command void open_project_file(_str file_name='',_str line_number='') name_info(VAR_ARG','VAR_ARG','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
    // Invoke SE with "vs.exe -p open_project_file file_name line_number"
    // Call from SE cli with "open_project_file file_name line_number"

    //parse arg(1) with file_name line_number;

    _str file_found = project_file_match(file_name, true);

    if (file_found != '') {

        push_bookmark();
        edit_file_in_project(file_found);
        goto_line(line_number);
        first_non_blank();
        message("Navigated to "file_name":"line_number". Bookmark pushed.");

    } else {

        message(file_name :+ " not found!!");
    }
}

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: open project file
« Reply #1 on: July 24, 2016, 09:39:16 AM »
Maybe this

Code: [Select]
_command void open_project_file(_str str='') name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
    // Invoke SE with 'vs.exe "-#open_project_file file_name line_number"'
    // Call from SE cli with "open_project_file file_name line_number"

    parse arg(1) with auto file_name auto line_number;


   say(file_name :+ ' zzz ' :+ line_number);

}

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
Re: open project file
« Reply #2 on: July 26, 2016, 05:29:43 PM »
Thanks, the following is working for command line invocation. I'm not sure how to determine if the function was called from invocation or macro call. The following will work correctly from SE cli or Invocation call but calling from another command as the parse_current_line_for_event command below does causes the parameters to be overwritten when the args are parsed. How do you tell if it was invoked from cli or called directly to determine if args needs to be parsed? arg() returns 2 for both instances but the function call version parses both parameters as a single argument.

Also, I'm trying to figure out how to search a line for tags using a regex. Anyone have experience or somewhere to point me to for somewhat simple examples?

Thanks in advance!
Code: [Select]
static boolean user_macro_debug_enabled = false;

_command void open_project_file(_str file_name='', _str line_number='') name_info(PROJECT_FILE_ARG','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   // Invoke SE with 'vs.exe "-#open_project_file file_name line_number"'
   // Call from SE cli with 'open_project_file file_name line_number'

   if ( user_macro_debug_enabled ) {

      say("Passed parameters - file_name: "file_name" - line_number: "line_number);
   }

   if (arg() > 0) {

      parse arg(1) with file_name line_number;

      if ( user_macro_debug_enabled ) {

         say("Parsed " :+ arg() :+ " arguments - file_name: "file_name" - line_number: "line_number);
      }
   }

   if (project_file_match(file_name, true) != '') {

      // Make SE the focus program.
      mdisetfocus();

      // Push a bookmark to easily go back.
      push_bookmark();

      edit_file_in_project(file_name);
      _str message_string = "Navigated to "file_name;

      // Validate a line number if supplied.
      if ((line_number != '') && isinteger(line_number)) {

         goto_line(line_number);
         first_non_blank();
         message_string :+= ":"line_number;
      }

      message(message_string". Bookmark pushed.");

   } else {

      message("Invalid project file or no project loaded");
   }
}

_command void parse_current_line_for_event() name_info(',')
{
   // Get 2 taged expression from current line using perl regex "(?i)^.*\|\s(\S*)\s*:(\d*).*$". First tagged is file_name second
   // taged is line number.

   /* Links to example code found so far...
   _str trace_line_str = '';
   get_line(trace_line_str);
   _str search_regex = "(?i)^.*\|\s(\S*)\s*:(\d*).*$";
   regex_search();
   //trace_line_str.regex_search()
   */

   //int returned_value = trace_line_str.search(search_regex,"IL",);
   //message("Found name: "trace_line_str"  Returned Value: "returned_value);

   open_project_file("test_file.h", 34);
}

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: open project file
« Reply #3 on: July 30, 2016, 09:27:32 AM »
Hi.  You could have a look at slickedit error parsing.  Click on "configure error parsing" in the Build menu, then press F1 for help.

Code: [Select]
_command void open_project_file(_str str='', ...) name_info(',')
{
    // Invoke SE with 'vs.exe "-#open_project_file file_name line_number"'
    // Call from SE cli with "open_project_file file_name line_number"

   //if (_executed_from_key_or_cmdline(name_name(last_index('','C'))))
   if (_executed_from_key_or_cmdline("open_project_file"))
      // if executed from command line, key press, menu, or toolbar button
      say("not macro");
   else
      say("from macro");

   parse arg(1) with auto file_name auto line_number;

   say(file_name :+ ' zzz ' :+ line_number :+ " " :+ arg());
}