Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17785
    Stefan
    Participant

    TASK:
    Jump / go to / move to next empty line between paragraphs (or TOF/EOF)

    How-To:
    Save this two macros (the CODE below) as text file with jsee extension in the EmEditor folder.
    Then execute them one time from menu Macros > Select…
    Next you can assign an shortcut to them via Help > Keyboard Map… ( search for “jump”, right click the macro, choose “Properties”, assign an Shortcut Key)

    CODE:
    JumpToNextBlankLineAbove.jsee (Ctrl+Shift+Arrow-Up)
    document.selection.Find("(^$|^\\s*?$)",eeFindPrevious | eeFindReplaceRegExp);
    JumpToNextBlankLineBelow.jsee (Ctrl+Shift+Arrow-Down)
    document.selection.Find("(^$|^\\s*?$)",eeFindNext | eeFindReplaceRegExp);

    ..

    That macro will regex search and goto lines which are empty or contain whitespace chars only (non-greedy), whatever cones first.

    Extra Tip:
    If you enable “Selection Mode” (read help about “F8” key) afore to executing this macro,
    you can use this to select paragraph-wise. (press ESC key to cancel selection mode after you’re done)

    HTH?

    #21920
    Stefan
    Participant

    “Yang Yang” wrote on June 8, 2017 at 9:21 pm
    Continuous blank lines are not treated as a block, and the caret cannot be moved to TOF/EOF as advertised. Both are easy to customize, though.

    Here is a better code

    //JumpToNextBlankLineBelow.jsee (Ctrl+Shift+Arrow-Down)
    Redraw = false;
       document.selection.Find("(\\w|\\.)$",eeFindNext | eeFindReplaceRegExp);
    if(document.selection.Find("(^\\s*?$)", eeFindNext | eeFindReplaceRegExp)==0){
       document.selection.EndOfDocument();}
       document.HighlightFind = false;
    //Redraw = true;

    //JumpToNextBlankLineAbove.jsee (Ctrl+Shift+Arrow-Up)
    Redraw = false;
       document.selection.Find("(\\w|\\.)$",eeFindPrevious | eeFindReplaceRegExp);
    if(document.selection.Find("^[[:blank:]]*?$",eeFindPrevious | eeFindReplaceRegExp)== 0){
       document.selection.StartOfDocument();}
       document.HighlightFind = false;
    //Redraw = true;

    But unfortunately the visible view doesn’t follow the cursor, if the cursor jumps out of view.

    That means:
    If the macro finds a line, the cursor is set to that line.
    But is that line position is above or below the current visible view,
    the windows is not scrolled to that line.

    But that happens only with “Redraw = false;” active.
    If I comment that command out, the scrolling works again, but the search highlighting is disturbing then.

    Tested here with 16.8.1, as 32-bit portable.

    #21927
    Yang Yang
    Participant

    Thank you for the update! Here is my version.

    // jumpabove
    function isblank(str) {
        return /^\s*$/.test(str);
    }
    
    var y = document.selection.GetActivePointY(eePosLogical);
    if(y > 1) {
        if(!isblank(document.GetLine(y))) {  // skip nonblank lines
            while(y > 1 && !isblank(document.GetLine(y))) y--;
        }
        else if(!isblank(document.GetLine(y-1))) {  // skip nonblank lines
            y--;
            while(y > 1 && !isblank(document.GetLine(y))) y--;
        }
        else {  // go to start of this block of blanks
            while(y > 1 && isblank(document.GetLine(y))) y--;
            if(y > 1 || !isblank(document.GetLine(1))) y++;
        }
        document.selection.SetActivePoint(eePosLogical, 1, y, false);
    }
    
    // jumpbelow
    function isblank(str) {
        return /^\s*$/.test(str);
    }
    
    var y = document.selection.GetActivePointY(eePosLogical);
    var n = document.GetLines();
    if(y < n) {
        if(!isblank(document.GetLine(y))) {  // skip nonblank lines
            while(y < n && !isblank(document.GetLine(y))) y++;
        }
        else if(!isblank(document.GetLine(y+1))) {  // skip nonblank lines
            y++;
            while(y < n && !isblank(document.GetLine(y))) y++;
        }
        else {  // go to end of this block of blanks
            while(y < n && isblank(document.GetLine(y))) y++;
            if(y < n || !isblank(document.GetLine(n))) y--;
        }
        document.selection.SetActivePoint(eePosLogical, 1, y, false);
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.