Author Topic: What is macro syntax for "while(not_end_of_file)"  (Read 1075 times)

JimmieC

  • Senior Community Member
  • Posts: 501
  • Hero Points: 17
What is macro syntax for "while(not_end_of_file)"
« on: May 03, 2022, 01:43:52 AM »
I want to iterate through an open file (buffer) in a macro and delete specific lines. I have searched the forum and SE Help for end of file, end of buffer, macro iterate, and more but I cannot find the answer.

I have this recorded macro. I just want to wrap it into while(!EOF).

_command DeleteDirLine() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);
   top_of_buffer();
   if (find_next('0')) stop();
   _deselect();
   begin_line_text_toggle();
   deselect();
   _select_char('','E');
   cursor_down();
   select_it("CHAR",'','E');
   delete_selection();
}

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2910
  • Hero Points: 153
Re: What is macro syntax for "while(not_end_of_file)"
« Reply #1 on: May 04, 2022, 01:52:22 PM »
I want to iterate through an open file (buffer) in a macro and delete specific lines. I have searched the forum and SE Help for end of file, end of buffer, macro iterate, and more but I cannot find the answer.

I have this recorded macro. I just want to wrap it into while(!EOF).

_command DeleteDirLine() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);
   top_of_buffer();
   if (find_next('0')) stop();
   _deselect();
   begin_line_text_toggle();
   deselect();
   _select_char('','E');
   cursor_down();
   select_it("CHAR",'','E');
   delete_selection();
}


You have a find_next without a find, so the find would have to go before the loop, after the top();up();.  But the basic pattern you're looking for is something like:

Code: [Select]
_command DeleteDirLine() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);
   top();up();
   while ( !down() ) {
      // down() is lower level than cursor down and returns non-zero when the bottom of the file is reached
      // If you still need to call cursor_down() in the loop, you should probably call down(), and if there is a status, break out of the loop

      // Repeated code goes here
   }
}

Also, you may want to use _begin_line(), or first_non_blank(), depending on which one you really want.  Macro recording is going to use what the key is bound to, but if you keep the macro, you may want to use more specific fucntions.

I hope this helps, if not let me know.