Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #10308
    Stefan
    Participant

    I miss this feature in the EmEditor core:


    #language = "VBScript"
    ' Select whole paragraph macro.
    ' An paragraph is an block of text delimited by two empty lines.
    ' How to:
    ' 1. Have the cursor inside an paragraph
    ' 2. execute this macro.

    'Find next empty line UP:
    '''''''''''''''''''''''''
    Do While TRUE
    '//Returns the line number of the cursor position.
    yPos = document.selection.GetActivePointY( eePosLogical )
    yLine = yPos
    '//Retrieves the text on the specified line.
    str = document.GetLine( yLine ) '[, flag ] )
    '//Trim removes spaces on both sides of a string.
    str = Trim(str)
    If Len(str) > 0 Then
    '//Moves the cursor up a specified number of lines.
    document.selection.LineUp '[ bExtend [, nCount ] ]
    Else
    Exit Do
    End If
    Loop

    'Start the selection:
    '''''''''''''''''''''
    document.selection.LineDown
    '//Moves the cursor to the start of the line.
    document.selection.StartOfLine '[ bExtend [, nFlags ] ]
    '//Selects a line at the cursor.
    document.selection.SelectLine

    'Find next empty line DOWN:
    '''''''''''''''''''''''''''
    Do While TRUE
    '//Returns the line number of the cursor position.
    yPos = document.selection.GetActivePointY( eePosLogical )
    yLine = yPos
    '//Retrieves the text on the specified line.
    str = document.GetLine( yLine ) '[, flag ] )
    str = Trim(str)
    If Len(str) > 0 Then
    '//Moves the cursor down a specified number of lines.
    document.selection.LineDown True '[ bExtend [, nCount ] ]
    Else
    '//Select the trailing empty line too:
    'document.selection.LineDown True
    Exit Do
    End If
    Loop
    #10311
    Stefan
    Participant

    Shorter code, but takes more time due the use of regular expression:



    // language = "JavaScript"
    // Select whole paragraph macro.
    // An paragraph is an block of text delimited by two empty lines.
    // How to:
    // 1. Have the cursor inside an paragraph.
    // 2. execute this macro.

    o = document.selection;
    o.Find("^s*$",eeFindPrevious | eeFindReplaceRegExp);
    yPosBeg = o.GetActivePointY(eePosLogical) +1;
    o.Find("^s*$",eeFindNext | eeFindReplaceRegExp);
    yPosEnd = o.GetActivePointY(eePosLogical);
    o.SetAnchorPoint(eePosLogical, 1, yPosBeg);
    o.SetActivePoint(eePosLogical, 1, yPosEnd, True);

    #10312
    webern
    Member

    Just an old discussion and an example are here.

    #10313
    Stefan
    Participant

    Thanks for the link! :-)
    That seems to be an old need for many.
    I still wonder why such basics are not in the Edit menu.

    Meanwhile i got an Problem:

    My last macro was developed
    with “Head-start version v11.1.7 beta”

    And there it works fine. Even with the line
    o.SetActivePoint(eePosLogical, 1, yPosEnd, True);

    On THIS pc i tested it now with 11.0.5
    and got an problem:

    If i use the above line
    o.SetActivePoint(eePosLogical, 1, yPosEnd, True);
    then the “True” is not highlighted
    because it has to be lower case. OK. Fine.

    But, the script is working with that Upper case True.
    But then, after the selecting is done,
    i got the message: (“True is not defined”)

    OK, i can change it to lower case “true”
    o.SetActivePoint(eePosLogical, 1, yPosEnd, true);

    The true is highlighted now,
    but the script does not work anymore.
    It seems it do something, but nothing is selected.

    Where is the bug? :-D

    Update, checked again:
    with v11.1.7 beta only the upper case “True” works too.
    There is no message as with 11.0.5 after the selection.
    If i change to lower case “true”, the word is highlighted
    but the script does not work here too. Only with “True”.

    #10315
    webern
    Member

    You need to swap the yPosEnd with the yPosBeg in the last two lines, like this:

    o.SetAnchorPoint(eePosLogical, 1, yPosEnd);
    o.SetActivePoint(eePosLogical, 1, yPosBeg, true);

    instead of

    o.SetAnchorPoint(eePosLogical, 1, yPosBeg);
    o.SetActivePoint(eePosLogical, 1, yPosEnd, True);

    #10332
    Stefan
    Participant

    Thanks webern, but that doesn’t explains why it works in one version and not in the other.

    Anyway, i have now understood that i doesn’t need the part
    o.SetActivePoint(eePosLogical, 1, yPosEnd, true);

    and also not the part
    yPosEnd = o.GetActivePointY(eePosLogical);

    New version:


    // Shorten the object string, just for fewer typing:
    o = document.selection;

    // - - -

    // Find something backwards/up, here empty line:
    o.Find("^s*$",eeFindPrevious | eeFindReplaceRegExp);

    // Remember the current line number:
    yPosBegin = o.GetActivePointY(eePosLogical) +1;

    // - - -

    // Find again something downwards
    // (here: find an blank line, non-greedy)
    // AND move the cursor that way to the found position :
    o.Find("^s*$",eeFindNext | eeFindReplaceRegExp);

    // Do an selection.
    // Set the start of the selection to the remembered line.
    // The end of the selection will be the current line:
    o.SetAnchorPoint(eePosLogical, 1, yPosBegin);

    Similar i use now this to just select down
    to the next blank line:



    o = document.selection;

    //Remember the current line number:
    yPos = o.GetActivePointY( eePosLogical );

    //Move cursor to found position (here: find an blank line):
    o.Find("^$",eeFindNext | eeFindReplaceRegExp);

    //Do an selection.
    //Set the start of the selection to the remembered line:
    o.SetAnchorPoint( eePosLogical, 1, yPos );

    .

    #10436
    Stefan
    Participant

    //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);
    }
    #10803
    netsking
    Participant

    Thanks a lot. I tried it out. It works fine for me.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.