Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9285

    gning
    Participant

    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?

    #9286

    webern
    Member

    // 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
    }

    #9289

    shx
    Participant

    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

    #9290

    webern
    Member

    I just have removed two unnecessary lines form the code above. Recheck it now.

    #9291

    gning
    Participant

    Thanks.

    Maybe I’ll try to make a version that perceives a change of indent to be a paragraph boundary…

    #9293

    webern
    Member

    I have added a line of code to perceive an indent as the paragraph boundary.
    Also the code has been slightly optimized.
    Recheck it.

    #9426

    gning
    Participant

    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.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone