EmEditor (text editor) Forum Index
   Macro Samples
     Learning by doing: Loop through all lines
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
Stefan
Posted on: 11/2/2011 12:45 pm
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Re: Learning by doing: Loop through SELECTED lines
No useful script. Just an little lesion.
Loop virtually through only the selected lines in file.
The cursor will not move!
We access each line by its number only.

- - -

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



////Loop through Selection

////Object handling to save always typing of 'document.selection':
var d = document;
var s = d.selection;


////////Get the selected text to work on:
////////(Depends if already something is selected or not)
if (s.IsEmpty)
{
    ////If document.selection is empty:
    vWasAnSelection = false;

    ////Alternative one
    //alert("Nothing selected, script quits. Please select and start again.");
    //quit();

    ////Alternative two
    alert("Nothing selected, script will select whole text for you.");
    s.SelectAll();

}else{ 

    ////If there was an selection already:
    vWasAnSelection = true;
    alert("Selected text to work on: \n" +  s.text);
}



////////Get start and end line of the selection:
///Returns the line number of the top of the selection.
  FirstSelLine = s.GetTopPointY(eePosLogical);
///Returns the line number of the bottom of the selection.
  LastSelLine = s.GetBottomPointY(eePosLogical);



////For Each Line In SelectedLineS Do:
for( Line = FirstSelLine; Line <= LastSelLine; Line++)
{
    ////  <<< Your code here >>>
    //// Here an simple example:
    ret = Confirm(d.GetLine(Line));
    if (ret == false) {if (!vWasAnSelection){s.Collapse();} Quit();}
}

	
////If there was no selection do an UnSelectAll at the end:
if (!vWasAnSelection) s.Collapse();

Flat Previous Topic | Next Topic


Subject Poster Date
   Learning by doing: Loop through all lines Stefan 11/2/2011 3:54 am
   » Re: Learning by doing: Loop through SELECTED lines Stefan 11/2/2011 12:45 pm
       Re: Learning by doing: Loop through SELECTED lines Stefan 11/2/2011 1:12 pm

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