Macro failed to playback in BLOCK EDIT MODE



  • 2018-05-15 notepad++ Macro failed to playback in BLOCK EDIT MODE

    my intention is to add a pair of bracket around every line of text, for instence,

    line 1
    line 2
    ...
    

    Should be changed into

    (line 1)
    (line 2)
    (...)
    

    To use/record macro, I have to use full key-based operation [alt+shift+left/right/home/end]. I recorded and test the macro several times. And I got the same result, the macro only works in the 1st line.

    My guess is that “Macro doesn’t support BLOCK EDIT MODE very well”.

    Anyone has a clue?

    Below is my macro in shortcuts.xml:

            <Macro name="nppMacro_eric" Ctrl="yes" Alt="yes" Shift="yes" Key="8">
                <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2309" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2317" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2428" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2431" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2177" wParam="0" lParam="0" sParam="" />
                <Action type="1" message="2170" wParam="0" lParam="0" sParam="(" />
                <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
                <Action type="0" message="2432" wParam="0" lParam="0" sParam="" />
                <Action type="1" message="2170" wParam="0" lParam="0" sParam=")" />
            </Macro>
    


  • @daidaiworm

    My guess is that “Macro doesn’t support BLOCK EDIT MODE very well”.

    You are probably right. However, you might be going about what you seem to want the hard way (unless it is not quite as simple as you state…for purposes of making an example to post…). But if it is that simple, consider a regular expression replacement recorded as a macro instead:

    Find what zone: (?-s)^.+
    Replace with zone: \($0\)
    Search mode: Regular expression



  • Hello @daidaiworm, and All,

    I could not post anything for a while, due to some “Guru meditation...” ! In the meantime, You’ve got, from @Scott-sumner, the right solution :-)) I exactly thought about the same regex S/R. Here is my initial post, which was ready… to be moved on line !


    I didn’t test the column mode feature, while building macros, but I would use, instead, a macro based on a search/replacement operation.

    So, if you replace your macro block, in the shortcuts.xml file, with the following block :

            <Macro name="nppMacro_eric" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s).+" />
                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                <Action type="3" message="1602" wParam="0" lParam="0" sParam="\($0\)" />
                <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
            </Macro>
    

    you should obtain a reliable macro and expected results :-))

    Notes :

    • The 1601 message initialize the search/replacement operation

    • The search regex (?-s).+ is inserted at the end of the 1601 message and search for the greatest range of standard characters so all line contents, without its line-break

    • The number 2, in message 1625, means that search is performed, in regular expression mode

    • The replacement regex \($0\) is inserted at the end of the 1602 message and rewrites a literal ( symbol, then all the search match ( $0 ) and, finally, the literal ) symbol

    • The flag number 768, in message 1702, represents the sum 512 ( Down direction) + 256 ( Wrap around )

    • The command number 1609, in message 1701, stands for a hit on the Replace All button

    Best Regards,

    guy038

    P.S. :

    • For a complete list of the search /replace encoding, in the shortcuts.xml file, refer to the link, below :

    http://docs.notepad-plus-plus.org/index.php/Editing_Configuration_Files#Search_.2F_Replace_encoding

    • Note that the flag value 512 means Search goes downwards ( and not upwards ! )

    • Be aware that when you use the command value 1614 ( Count ), the Find dialog must have been previously opened !


Log in to reply