EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     anybody got a macro or other tool that can do Select Paragraph?
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
gning
Posted on: 6/16/2011 9:48 am
Just popping in
Joined: 9/10/2008
From:
Posts: 17
Re: 2 gning
Thanks. The macro basically works. But when I said "perceive a change of indent as a paragraph boundary", what I meant was that if one set of lines is indented to a different depth from other lines that are adjacent to it, that the macro would see these as being two distinct paragraphs.

Maybe that's not necessary. In fact, I probably don't need it. So I'll probably just use your macro as it is, but without the last line.

Sorry I asked the question and then forgot for so long to check back for the answers...

Anyway, the object I had in mind was to combine that with a macro of my own for reflowing text in a selection. Put them together, and you get something to reflow the paragraph the cursor is in.

Here is my reflow-selection macro:

// Save current wrap setting:
var stateNoWrap = editor.QueryStatusByID(4208);		// No Wrap
var stateWindowWrap = editor.QueryStatusByID(4210);	// Wrap by Window
var statePageWrap = editor.QueryStatusByID(4318);	// Wrap by Page
// Temporarily set Wrap by Characters mode:
editor.ExecuteCommandByID(4209);
// Reflow:
document.selection.Format(eeFormatJoinLines);
document.selection.Format(eeFormatSplitLines);
// Restore previous wrap setting:
if (stateNoWrap >= eeStatusLatched)
	editor.ExecuteCommandByID(4208);
else if (stateWindowWrap >= eeStatusLatched)
	editor.ExecuteCommandByID(4210);
else if (statePageWrap >= eeStatusLatched)
	editor.ExecuteCommandByID(4318);


The neat thing about this macro as it stands now is that if you select multiple paragraphs, it preserves the spaces between then and reflows each one individually.
webern
Posted on: 2/28/2011 11:40 pm
Not too shy to talk
Joined: 11/23/2006
From: Moscow, Russia
Posts: 38
Re: 2 gning
I have added a line of code to perceive an indent as the paragraph boundary.
Also the code has been slightly optimized.
Recheck it.
gning
Posted on: 2/28/2011 11:42 am
Just popping in
Joined: 9/10/2008
From:
Posts: 17
Re: 2 shx
Thanks.

Maybe I'll try to make a version that perceives a change of indent to be a paragraph boundary...
webern
Posted on: 2/28/2011 10:45 am
Not too shy to talk
Joined: 11/23/2006
From: Moscow, Russia
Posts: 38
2 shx
I just have removed two unnecessary lines form the code above. Recheck it now.
shx
Posted on: 2/28/2011 9:02 am
Just can't stay away
Joined: 2/18/2009
From:
Posts: 77
Re: anybody got a macro or other tool that can do Select Paragraph?
webern,

Thanks for posting the code. It will help me in developing my macro in which the next/prev phrase surrounded by quotes should be selected.

Steven


----------------
Steven

webern
Posted on: 2/26/2011 1:49 pm
Not too shy to talk
Joined: 11/23/2006
From: Moscow, Russia
Posts: 38
Re: anybody got a macro or other tool that can do Select Paragraph?
[CODE]
// File: Select_Paragraph.jsee
// Autor: Dmitry Pirozhkov
// Date: 23.Nov.2006
// Info: Macro to select the entire paragraph.
// Requires: EmEditor Professional v.7.00 or later
// Usage: Place the cursor anywhere within a paragraph you wish to select. Run this macro.

var blankLine = "^$"; //the paragraph delimiter
var y1;

with (document.selection) {

if (document.GetLine(GetActivePointY(eePosLogical), eeGetLineWithNewLines).length<=2) {
alert ("Please, place the cursor on the non-blank line.");
Quit();
}

if (!Find(blankLine, eeFindPrevious | eeFindReplaceQuiet | eeFindReplaceRegExp)) {
y1 = 1;
} else y1 = GetActivePointY(eePosLogical)+1;

if (!Find(blankLine, eeFindNext | eeFindReplaceQuiet | eeFindReplaceRegExp)) {
EndOfDocument();
}

SetActivePoint(eePosLogical, 1, y1, true);
StartOfLine(true,eeLineHomeText);
//to perceive an indent as the paragraph boundary
}

[/CODE]
gning
Posted on: 2/25/2011 12:00 pm
Just popping in
Joined: 9/10/2008
From:
Posts: 17
anybody got a macro or other tool that can do Select Paragraph?
I'm hoping to make a key which, when pressed anywhere in the paragraph, does a reflow of the text in it. Since there's no paragraph selection primitive, has anybody worked on a macro that can tell what a paragraph is?
Threaded | Oldest First Previous Topic | Next Topic | Top


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