Automatically close tags

Help with writing and playing macros

Automatically close tags

Postby Daniel_T » Wed May 23, 2007 8:03 am

Hello

Can i configure the UltraEdit 13.00, so that when i type the ">" of <html>, the close-tag "</html>" will automatically be added?

I searched in the forums and at some searchengines, but i havent found help.

Thanks for help!
Daniel
User avatar
Daniel_T
Newbie
 
Posts: 3
Joined: Tue May 22, 2007 11:00 pm

Re: Automatically close tags

Postby Bego » Wed May 23, 2007 10:58 am

You can write a simple small macro, that you can assign e.g. to "ctrl-shift->".
Automatically would be strange. What happens if you really want to write <html> ?

Macro looks like this:
Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOn
Key Ctrl+LEFT ARROW
"/"
Key Ctrl+RIGHT ARROW
">"


rds Bego
User avatar
Bego
Master
Master
 
Posts: 358
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Automatically close tags

Postby Daniel_T » Wed May 23, 2007 11:25 am

First thanks for your help, but...

Bego wrote:Automatically would be strange. What happens if you really want to write <html> ?

When I write <html>, it would be nice when UE add </html> and but the cursor between <html> and </html>, so that I dont have to write the closing-tag.

I write <html> and get <html></html>.

Maybe you have not understood what I mean. My English is not that good.
Daniel
User avatar
Daniel_T
Newbie
 
Posts: 3
Joined: Tue May 22, 2007 11:00 pm

Re: Automatically close tags

Postby Bego » Wed May 23, 2007 12:35 pm

your description really was strange. but now I got you.
Take this one:
Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOn
Clipboard 9
StartSelect
Key Ctrl+LEFT ARROW
Copy
EndSelect
Key Ctrl+RIGHT ARROW
"></"
Paste
">"
Key Ctrl+LEFT ARROW
Key Ctrl+LEFT ARROW
Key Ctrl+LEFT ARROW
Key RIGHT ARROW
Clipboard 0


EDIT: at my example, write "<html" without the > and then let it run.

You can do similar with tags... somehow....

rds Bego
User avatar
Bego
Master
Master
 
Posts: 358
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Automatically close tags

Postby Daniel_T » Wed May 23, 2007 1:46 pm

Thank alot Bego, that works nice!

Daniel
User avatar
Daniel_T
Newbie
 
Posts: 3
Joined: Tue May 22, 2007 11:00 pm

Re: Automatically close tags

Postby elishnevsky » Wed Nov 21, 2007 9:52 pm

Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOn
">"
Find Up "<"
IfFound
Clipboard 9
Key RIGHT ARROW
SelectWord
Copy
Find ">"
Key LEFT ARROW
Key RIGHT ARROW
"</"
Paste
">"
Find Up "<"
Key LEFT ARROW
Clipboard 0
EndIf

Hey, I wrote this macro. It also works fine even if you have attributes in your tag. Try it.
User avatar
elishnevsky
Newbie
 
Posts: 2
Joined: Sun Jul 25, 2004 11:00 pm

Re: Automatically close tags

Postby Bego » Fri Nov 23, 2007 8:09 pm

Yes, even better :-)
User avatar
Bego
Master
Master
 
Posts: 358
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Automatically close tags

Postby mbrowne » Thu Jun 05, 2008 10:07 am

The last macro mentioned did not work so well for me (maybe because of changes in the newer version of UltraEdit), but it was close. Here's my version:

Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOn
">"
Find Up "<"
IfFound
Clipboard 9
Key RIGHT ARROW
SelectWord
Copy
Find ">"
Find ">"
Key LEFT ARROW
"</"
Paste
Find Up "<"
Key LEFT ARROW
Clipboard 0
Find ">"
Key RIGHT ARROW
EndIf
mbrowne
Newbie
 
Posts: 1
Joined: Thu Jun 05, 2008 10:06 am

Re: Automatically close tags

Postby vastek » Wed May 18, 2011 6:42 am

Hi,
Actually the recently opened tag gets closed but it is not closing the previous tag on the next execution of the Macro.
Kindly, update the coding asap

For EX:-
If we open <p> tag and <b> tag as below
<p> sample <b> document for reference

And when we apply the macro we get the output as
<p> sample <b> document for reference </b></b>

Here we need to close both the <p> and <b> Tags.
vastek
Newbie
 
Posts: 2
Joined: Wed May 18, 2011 6:26 am

Re: Automatically close tags

Postby Mofi » Tue May 31, 2011 12:31 am

vastek, the macros posted here are designed for closing just the last tag. For a task like you posted a script would be necessary because with a macro that is impossible to realize. Even a script solution is hard to code because lots of other tags can be between the opening tag which should be closed and the current position of the cursor. Some of these embedded tags can be empty elements like <br> or <img src="...">, others can be block elements with closing tag optional in HTML, but required in XHTML like <li>, <p>, <td>, ... So the script would need to read in worst case entire structure of the entire HTML or XHTML file, interpret it depending on type of file, handle error conditions like missing closing tags or wrong order of closing tags (<b><i>...</b></i> is allowed in HTML, but not in XHTML) to finally find out if a closing tag is missing and which one.

BTW: UEStudio has this feature built-in. It's available in the HTML toolbar and has the name HTML Close Tag and which works also for XHTML and XML files. So if you need that often, you should think about upgrading from UltraEdit to UEStudio.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Automatically close tags

Postby vastek » Tue Jul 05, 2011 2:02 am

Dear Mofi,

Thanks for your reply and yes it is used only for closing last tag.

I got the required info. Thanks for your effort.
vastek
Newbie
 
Posts: 2
Joined: Wed May 18, 2011 6:26 am


Return to Macros