EmEditor (text editor) Forum Index
   Macro Samples
     Learning by doing: Add closing HTML Tag
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
Stefan
Posted on: 11/1/2011 11:43 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 261
Learning by doing: Add closing HTML Tag


Best to learn is to do some lessons.
So i will show my steps creating an macro for others.

I am not saying that this is the best way to do it, it is just an start.

If you have an better way to do it, or other suggestions, just reply



Purpose:
Take the HTML tag on the left and put an closing tag on the right.

For example write <HtmL>| and execute the macro to get <HtmL>|</HtmL>


Handling:
Save this an EmEditor macro as *.jsee (JavaScript)
or add it as an macro snippet into the snippet plugin
and add an shortcut just as Ctrl+.



Code:

////HowTo: write an opening HTML tag (like: <html>) and execute this macro.
////Awaited: macro should write the closing tag for you. (e.g. </html>)

////////// Script:
////Pause update of the view till script is finished:
Redraw = false;


////Store current cursor position:
Line = document.selection.GetActivePointX( eePosView );
Colu = document.selection.GetActivePointY( eePosView );


////Use find to find the opening angle bracket "<" of the tag on the left:
document.selection.Find("<",eeFindPrevious);
////Erase the highlighting of found strings:
document.HighlightFind=false;


////Select the word on the right of the opening angle bracket:
document.selection.SelectWord();
////Store this selected word into an var called TAG:
TAG = document.selection.text;

////Jump back to start (behind open tag):
document.selection.SetActivePoint( eePosView, Line, Colu, false );
////Or to EOL if you prefer:
//document.selection.EndOfLine( );

////Add some text:
document.selection.text = " </" + TAG + ">";

////Jump back to start (between open and close tag):
document.selection.SetActivePoint( eePosView, Line, Colu, false );
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文