- AuthorPosts
- February 25, 2011 at 9:00 pm #9285gningParticipant
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?
February 26, 2011 at 10:49 pm #9286webernMember
// 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
}
February 28, 2011 at 6:02 pm #9289shxParticipantwebern,
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
February 28, 2011 at 7:45 pm #9290webernMemberI just have removed two unnecessary lines form the code above. Recheck it now.
February 28, 2011 at 8:42 pm #9291gningParticipantThanks.
Maybe I’ll try to make a version that perceives a change of indent to be a paragraph boundary…
March 1, 2011 at 8:40 am #9293webernMemberI have added a line of code to perceive an indent as the paragraph boundary.
Also the code has been slightly optimized.
Recheck it.June 16, 2011 at 5:48 pm #9426gningParticipantThanks. 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.
- AuthorPosts
- You must be logged in to reply to this topic.