EmEditor (text editor) Forum Index
   Macro Samples
     Macro: Select whole paragraph
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
Stefan
Posted on: 7/10/2012 6:18 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: Macro: Select whole paragraph
//NEW, Di, 10.07.2012: error handling for BOF and EOF

I have seen an problem when the paragraph was
at the beginning of the file, with no empty
line above it. And the same at the end of file
if there was no empty line following.

So my improved macro detect this and handles accordingly:



// language = "JavaScript"
// Select whole paragraph macro.
// An paragraph is an block of text delimited 
//     by two empty lines. (Or BOF/EOF)
// How to:
// 1. Have the cursor inside an paragraph.
// 2. execute this macro.
//NEW, Di, 10.07.2012: error handling for BOF and EOF

o = document.selection;
nFound = o.Find("^\\s*$",eeFindPrevious | eeFindReplaceRegExp);
if(nFound==0){o.StartOfDocument(); o.StartOfLine();
	yPosBeg = o.GetActivePointY(eePosLogical);
}else{
	yPosBeg = o.GetActivePointY(eePosLogical) +1;
}
nFound = o.Find("^\\s*?$",eeFindNext | eeFindReplaceRegExp);
if(nFound==0){o.EndOfDocument(); o.EndOfLine();
	o.SetAnchorPoint(eePosLogical, 1, yPosBeg); 
}else{
	o.LineUp();o.EndOfLine(); //exclude trailing line break
	o.SetAnchorPoint(eePosLogical, 1, yPosBeg);
}
Flat Previous Topic | Next Topic


Subject Poster Date
   Macro: Select whole paragraph Stefan 5/2/2012 12:12 pm
     Re: Macro: Select whole paragraph Stefan 5/3/2012 12:57 pm
       Re: Macro: Select whole paragraph webern 5/3/2012 11:33 pm
         Re: Macro: Select whole paragraph Stefan 5/4/2012 6:16 am
           Re: Macro: Select whole paragraph webern 5/4/2012 1:33 pm
             Re: Macro: Select whole paragraph Stefan 5/7/2012 3:42 am
             » Re: Macro: Select whole paragraph Stefan 7/10/2012 6:18 am
                 Re: Macro: Select whole paragraph netsking 1/28/2013 11:30 am

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