macro to select HTML tag v2

macro to select HTML tag v2

44
Basic UserBasic User
44

    Apr 18, 2015#1

    Back in 2010, I wrote macro to select HTML tag, which I have been using ever since - but they weren't perfect.
    1. They didn't deal correctly with nested tag names that were similar, such as zip vs zipfileset (ant xml).
    2. It used main clipboard, which isn't nice.
    I have re-written them and present them here.

    Select previous tag: mapped to control+shift+,

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UltraEditReOn
    Clipboard 2
    IfSel
    Find RegExp Up Select "</++^c^{>^}^{[ ^p^r^n^t]+[~>]++>^}"
    Else
    Find Up "<"
    Find RegExp "[A-Za-z]"
    SelectWord
    Copy
    Find Up "<"
    Key LEFT ARROW
    Find RegExp Select "</++^c^{>^}^{[ ^p^r^n^t]+[~>]++>^}"
    EndIf
    Clipboard 0
    
    Select next tag: mapped to control+shift+.

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UltraEditReOn
    Clipboard 2
    IfSel
    Find RegExp Select "</++^c^{>^}^{[ ^p^r^n^t]+[~>]++>^}"
    Else
    Find "<"
    Find RegExp "[A-Za-z]"
    SelectWord
    Copy
    Find Up "<"
    Key LEFT ARROW
    Find RegExp Select "</++^c^{>^}^{[ ^p^r^n^t]+[~>]++>^}"
    EndIf
    Clipboard 0
    The idea is to make easy to run either macro once to select the next/previous tag, and to keep running either macro to select the next/previous open or close. Consider the below example where the | represents the cursor and can be either within the opening DIV tag or the content of the DIV tag.

    Code: Select all

    <div>
       <div style="color: red;"
             id="divWit|hId">Nested| <span>div</span>.
          <pre>
             monospaced
          </pre>
       </div>
    </div>
    
    Run the select previous macro and the opening DIV tag will be selected. Next, run the select next macro and the entire inner DIV will be selected. Run the select previous then select next again and the entire outer DIV will be selected.

    I have given this a proper write up on my blog here: UltraEdit macro to select HTML/XML tag.
    UltraEdit - licensed for life!

    http://robertmarkbramprogrammer.blogspot.com