Macro to select current paragraph

Help with writing and playing macros

Macro to select current paragraph

Postby Pedrober » Thu Aug 23, 2007 4:56 pm

I miss a general feature in UltraEdit: the possibility of automatically selecting a paragraph. I know it's a feature related to standard writing, not to code writing, but I am using the program for my needs and I would like to customize it as far as possible.
I have written a macro with this syntax but it's not perfect at all. Sometimes, the first character in the paragraph is not selected and sometimes the selection goes to the previous and the next carriage return. Any suggestion?
This is my poor macro:
InsertMode
ColumnModeOff
HexOff
UnixReOff
Find Up "^p"
Find RegExp "[a-z]"
EndSelect
StartSelect
Find Select "^p"
End of my macro. Thank you in advance.
User avatar
Pedrober
Basic User
Basic User
 
Posts: 23
Joined: Wed Aug 22, 2007 11:00 pm

Re: Macro to select current paragraph

Postby Mofi » Fri Aug 24, 2007 6:18 am

Are your paragraphs always single lines which means do you write long lines with soft word wrap enabled to be able to read it?
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Macro to select current paragraph

Postby Pedrober » Fri Aug 24, 2007 6:19 am

Yes, because I am using UltraEdit as a text editor.
User avatar
Pedrober
Basic User
Basic User
 
Posts: 23
Joined: Wed Aug 22, 2007 11:00 pm

Re: Macro to select current paragraph

Postby Mofi » Fri Aug 24, 2007 7:19 am

Here is the macro which needs macro property Continue if a Find with Replace not found or Continue if search string not found enabled.

ColumnModeOff
HexOff
Find Up "^p"
IfFound
Key HOME
IfColNumGt 1
Key HOME
EndIf
Else
Top
EndIf
Loop
IfEof
ExitLoop
EndIf
IfCharIs 13
Key DOWN ARROW
Else
IfCharIs 10
Key DOWN ARROW
Else
ExitLoop
EndIf
EndIf
EndLoop
StartSelect
Find Select "^p"
IfSel
Else
SelectToBottom
EndIf


And here is the macro again in UEM syntax with indentations and comments - see Macro examples and reference for beginners and experts.

Code: Select all
ColumnModeOff
HexOff
//  Search upwards for a DOS line termination.
Find Up "^p"
/*! If found, unselect it. The cursor is already on start of the next line.
    Key LEFT ARROW followed by Key RIGHT ARROW cannot be used to unselect
    the line termination because this could be an empty line and so the
    cursor could be moved with right arrow to next line, but not with left
    arrow back to previous line depending on the configuration settings.
    So a Key HOME is used. But when configuration setting >Home Key always
    Goto column 1< is not enabled, the cursor could be moved with first
    HOME to first non-white space character. So use HOME again when this
    happens. A simple unselect command would be fine. !*/
IfFound
    Key HOME
    IfColNumGt 1
        Key HOME
    EndIf
Else
//  No line termination found upwards - set cursor to top of the file.
    Top
EndIf
/*! Empty lines should be ignored. So when the character at start of the
    line is a carriage return (decimal code 13) or a line-feed (dec. 10)
    move the cursor in column 1 down until a different character is found
    or end of file is reached. At end of file nothing is selected. !*/
Loop
    IfEof
        ExitLoop
    EndIf
    IfCharIs 13
        Key DOWN ARROW
    Else
        IfCharIs 10
            Key DOWN ARROW
        Else
            ExitLoop
        EndIf
    EndIf
EndLoop
/*! Select now everything to next DOS line termination or to end of
    file if the cursor is on start of a string at the end of the file. !*/
StartSelect
Find Select "^p"
IfSel
Else
    SelectToBottom
EndIf
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Macro to select current paragraph

Postby Pedrober » Sat Aug 25, 2007 7:44 pm

Your macro works beautifully and it's perfect for my purpose. Thank you very much!
Best regards from Galiza (Spain)!
User avatar
Pedrober
Basic User
Basic User
 
Posts: 23
Joined: Wed Aug 22, 2007 11:00 pm


Return to Macros