Community
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Macro for html, xml, etc. any file with <markup></m

 
Post new topic   Reply to topic    Community Forum Index -> Tips
View previous topic :: View next topic  
Author Message
helios



Joined: 02 Mar 2003
Posts: 723
Location: Helios Software Solutions

PostPosted: Fri Jul 07, 2006 10:58 am    Post subject: Macro for html, xml, etc. any file with <markup></m Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
BenjaminB



Joined: 12 Sep 2006
Posts: 10

PostPosted: Tue Jan 02, 2007 1:53 pm    Post subject: Reply with quote

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>
Back to top
View user's profile Send private message
rsperberg



Joined: 29 Jul 2004
Posts: 35
Location: NJ

PostPosted: Wed Jan 03, 2007 12:20 am    Post subject: Slight change to account for nested elements Reply with quote

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


Last edited by rsperberg on Wed Jan 03, 2007 11:56 am; edited 1 time in total
Back to top
View user's profile Send private message
BenjaminB



Joined: 12 Sep 2006
Posts: 10

PostPosted: Wed Jan 03, 2007 8:39 am    Post subject: Re: Slight change to account for nested elements Reply with quote

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 Smile
Back to top
View user's profile Send private message
troels_kn



Joined: 28 Oct 2005
Posts: 32

PostPosted: Tue May 01, 2007 10:12 pm    Post subject: Reply with quote

If you don't use POSIX type regexp, you can instead use This for search and replace, respectively:
Code:
[ ]?>
>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Community Forum Index -> Tips All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB