How to execute command Cursor To Next Paragraph from within a macro?

Help with writing and playing macros

How to execute command Cursor To Next Paragraph from within a macro?

Postby ironmike » Tue Apr 02, 2013 1:09 pm

Why does the cursor movement command ALT+RIGHT ARROW not appear in the list of keyboard combinations supported by the 'KEY' macro command? ALT+RIGHT ARROW moves the cursor to the first non-blank character in the next paragraph. If I can't do this with the KEY command in a macro, how can I do it in a macro?
ironmike
Newbie
 
Posts: 5
Joined: Mon Mar 25, 2013 12:57 pm

Re: How to execute command Cursor To Next Paragraph from within a macro?

Postby Mofi » Wed Apr 03, 2013 12:36 am

Yes, Alt+RIGHT ARROW by default assigned to command CursorToNextParagraph is not available as macro command. An alternate method to set the caret to first non whitespace character in next paragraph is:

Code: Select all
PerlReOn
Find MatchCase RegExp "(?:\r\n[ \t]*){2,}"
IfFound
Key RIGHT ARROW
Key LEFT ARROW
EndIf

The Perl regular expression Find searches for two or more DOS line terminators with zero or more spaces/tabs at beginning of every line. In other words it finds the whitespaces between last character of current paragraph and first non whitespace character of next paragraph. If such a whitespace block is found, moving the caret once right and left cancels the selection of the find and let the caret blink left of first non whitespace character at beginning of next paragraph.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to execute command Cursor To Next Paragraph from within a macro?

Postby ironmike » Sun Apr 07, 2013 11:56 am

Thanks Mofi.
ironmike
Newbie
 
Posts: 5
Joined: Mon Mar 25, 2013 12:57 pm

Re: How to execute command Cursor To Next Paragraph from within a macro?

Postby ironmike » Sun Apr 07, 2013 12:50 pm

Well, I thought I understood this but now I guess I admit I don't.

I just took the macro code you supplied in your example:

Code: Select all
    PerlReOn
    Find MatchCase RegExp "(?:\r\n[ \t]*){2,}"
    IfFound
    Key RIGHT ARROW
    Key LEFT ARROW
    EndIf


And I added

Code: Select all
    PerlReOn
    Find MatchCase RegExp "(?:\r\n[ \t]*){2,}"
    IfFound
    Key RIGHT ARROW
    Key LEFT ARROW
    Key CTRL+T   
    EndIf


I expected the macro to position the cursor on the first non whitespace character in the next paragraph, then reformat that paragraph within the current column bounds (CTRL+T does that).

It does not work; no paragraph reformat occurs. If I type CTRL+T manually, outside a macro, it does reformat the paragraph.

Why?
ironmike
Newbie
 
Posts: 5
Joined: Mon Mar 25, 2013 12:57 pm

Re: How to execute command Cursor To Next Paragraph from within a macro?

Postby Mofi » Mon Apr 08, 2013 8:25 am

In UltraEdit macros you can use only the commands which are listed in the editor and described in help of UltraEdit. Click on button help or press key F1 in the Edit/Create Macro dialog to open the help page with all available commands. The command Reformat Paragraph which you have assigned to key Ctrl+T is not available as macro command. You need to emulate this command with other macro commands like regular expression replaces.

The macro command Key does not emulate a user keyboard hit and therefore does not execute internal commands you have assigned to hotkeys. That cannot work as the macro interpreter would need to wait until the executed command is finished before continues with next command in the macro. When you execute Reformat Paragraph, you wait automatically before executing the next command.

Internal commands which require usually user interaction or user configuration are not available as macro commands as the result of the macro would be unpredictable because of depending on user interaction / configuration. Good written macros are independent on user settings.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to execute command Cursor To Next Paragraph from within a macro?

Postby Mofi » Fri Apr 12, 2013 11:54 am

BTW: Do you know that you can reformat all paragraphs in a file by simply selecting everything with Ctrl+A and executing Format - Reformat Paragraph?
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros