Page 1 of 1
Macro for html, xml, etc. any file with <markup></m
Posted: Fri Jul 07, 2006 10:58 am
by helios
Macro for html, xml, etc. any file with <markup></markup>
Purpose: Complete the opening <tag> with a closing </tag> without retyping the markup keyword.
Use Case:
The user types <body
The user types [Ctrl] > (Control + greater than key)
The macro completes <body></body> and position the cursor between the two tags.
Recording Procedure:
1) Type <
2) Type body
3) Start recording
4) Type the following:
>
[Ctrl][Shift]M
[Ctrol]+c
[Right]
[Right]
</
[Ctrl]+v
>
[Ctrl]M
[Left]
5) Stop recording.
6) Assign [Ctrl]. To the macro. (The dot "." is in the same key as the ">" -in my keyboard at least- )
7) Assign [Ctrl][Shift]. to the macro, also. In case somebody pressed [ctrl][shift] > just because the ">" is the "shift" key of the dot.
Now test the macro typing: <ThisIsATag and now [Ctrl]>
Contributed by Marcelo Finkielsztein.
Posted: Tue Jan 02, 2007 1:53 pm
by BenjaminB
It's pretty useful, but I think I may have an improvement for that, because it doesn't work so well if you have tags with attributes. (<a href="URI"> or <div id="header">, for example)
I altered it to make it work in all cases:
Type <a href="URI"
Start recording
Type:
>
[Ctrl]+[Shift]+[M]
[Left]
[Ctrl]+[Shift]+[Right]
[Ctrl]+[C]
[Ctrl]+[Shift]+[M]
[Right]
</
[Ctrl]+[V]
>
[Ctrl]+[Shift]+[M]
[Ctrl]+[Shift]+[M]
[F8] (or whatever key is assigned to find and replace)
Search for: ([^ ]*)[ ]?(>)
Replace with: \1\2
(Click "Find")
(Click "Replace")
(Close the Window)
[Right]
[Ctrl]+[Shift]+[M]
[Left]
[Left]
Stop Recording
(I assume you are using Posix Syntax and Regular Expressions is checked at the Search&Replace Dialogue. That deletes the possible space inside the closing tag.)
Now save your Makro and assign any shortcut you like. This should work with both simple tags and tags that have attributes:
<a href="
http://www.example.org"
+Macro becomes
<a href="http://www.example.org"></a>
<tag
+Macro becomes
<tag></tag>
Slight change to account for nested elements
Posted: Wed Jan 03, 2007 12:20 am
by rsperberg
I was very delighted to discover this first version of the automatic end-tag creation macro by Marcelo, and then I found situations where it didn't work as intended.
These weren't, however, elements with attributes. Instead, the problem I stumbled across was creating a new, second element nested inside the first:
<li><p></p></li>
So I've modified BenjaminB's improved version to anticipate there being text -- and specifically a set of paired angle brackets -- following the characters being entered in the macro. Otherwise the [Ctrl]+[Shift]+[M] won't always be selecting what was intended.
This works for the nested elements and elements with attributes, at least with the handful of tests I ran:
(Start recording):
>
[Left]
[Ctrl]+[Shift]+[M]
[Left]
[Ctrl]+[Shift]+[Right]
[Ctrl]+[C]
[Ctrl]+[Shift]+[M]
[Right]
</
[Ctrl]+[V]
>
[Left]
[Ctrl]+[Shift]+[M]
[Ctrl]+[Shift]+[M]
[F8] (or whatever key is assigned to find and replace)
Search for: ([^ ]*)[ ]?(>)
Replace with: \1\2
(Click "Find")
(Click "Replace")
(Close the Window)
[Left]
[Ctrl]+[Shift]+[M]
[Left]
(Stop recording)
I found it very convenient to assign [Ctrl]+> to this macro (that's [Ctrl]+[Shift]+.) as Marcelo suggests, because it helps me remember that I'm closing both the start-tag with a > and the whole element with an end-tag.
Thanks to Marcelo and BejjaminB for making this!
Roger Sperberg
Re: Slight change to account for nested elements
Posted: Wed Jan 03, 2007 8:39 am
by BenjaminB
rsperberg wrote:So I've modified BenjaminB's improved version to anticipate there being text -- and specifically a set of paired angle brackets -- following the characters being entered in the macro. Otherwise the [Ctrl]+[Shift]+[M] won't always be selecting what was intended.
I didn't think of that, thank you

Posted: Tue May 01, 2007 10:12 pm
by troels_kn
If you don't use POSIX type regexp, you can instead use This for search and replace, respectively: