edit - What's wrong with this SlickEdit macro? - Stack Overflow

admin2025-05-02  2

What's wrong with this macro. It only performs the operation on the first line.

#include "slick.sh"

_command format_HTML() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);

   top_of_buffer()
   while ( !down() ) {
        begin_line()
        last_event(name2event('<'));html_lt();
        keyin("p");
        last_event(name2event('>'));html_gt();
        last_event(name2event(' '));html_space();
        end_line();
        last_event(name2event(' '));html_space();
        last_event(name2event('<'));html_lt();
        keyin('/');
        keyin("p");
        last_event(name2event('>'));html_gt();
   }
}

This code is to format regular text into HTML paragraphs, however it only works on the first line.

What's wrong with this macro. It only performs the operation on the first line.

#include "slick.sh"

_command format_HTML() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);

   top_of_buffer()
   while ( !down() ) {
        begin_line()
        last_event(name2event('<'));html_lt();
        keyin("p");
        last_event(name2event('>'));html_gt();
        last_event(name2event(' '));html_space();
        end_line();
        last_event(name2event(' '));html_space();
        last_event(name2event('<'));html_lt();
        keyin('/');
        keyin("p");
        last_event(name2event('>'));html_gt();
   }
}

This code is to format regular text into HTML paragraphs, however it only works on the first line.

Share Improve this question edited Apr 10 at 15:27 Ley CM 176 bronze badges asked Dec 31, 2024 at 5:53 WaylandWayland 112 bronze badges 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Dec 31, 2024 at 15:47
Add a comment  | 

1 Answer 1

Reset to default 0

The issue with your macro is that the while (!down()) loop condition will exit after the first line because down() returns 0 when it successfully moves to the next line (and your loop continues while !down() is true, i.e., while moving down fails).

#include "slick.sh"

_command void format_HTML() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
    _macro('R',1);
    
    top_of_buffer();
    while (1) {
        begin_line();
        last_event(name2event('<')); html_lt();
        keyin("p");
        last_event(name2event('>')); html_gt();
        last_event(name2event(' ')); html_space();
        
        // Move to end of line
        end_line();
        
        last_event(name2event(' ')); html_space();
        last_event(name2event('<')); html_lt();
        keyin('/');
        keyin("p");
        last_event(name2event('>')); html_gt();
        
        // Try to move down
        if (down()) break;
    }
}
转载请注明原文地址:http://www.anycun.com/QandA/1746180205a92131.html