javascriptmacrosemeditor

EmEditor script: extend the selection range to include multiple separate words?


I want to extract all the misspelled words in Emeditor. As in the script below, I would first mark all the misspelled work with a special string "@@@" which is then used for extrating the words.

I wonder whether it's possible to directly extend the selection range to include multiple separate words. If this is possible to the string "@@@" would be unnecessary. Thank you!

    document.selection.StartOfDocument(false);

    while (true) {

    var xPos = document.selection.GetActivePointX(eePosView)
    var yPos = document.selection.GetActivePointY(eePosView)

    editor.ExecuteCommandByID(4554);  // Next Misspelling

    var xPos2 = document.selection.GetActivePointX(eePosView)
    var yPos2 = document.selection.GetActivePointY(eePosView)

    if (xPos === xPos2 && yPos === yPos2) break

    document.selection.text = "@@@"
    }

    document.selection.Find("@@@[[:word:]]+", eeFindNext | eeFindReplaceRegExp | eeFindExtract | eeFindMatchedOnly, eeExFindSeparateCRLF | eeExFindRegexOnigmo)
    document.selection.Replace("@@@", "", eeReplaceAll, 0)

Solution

  • It isn't easy to extend the selection range to include multiple separate words, but I rewrote your macro by selecting misspelled words and appending them to a string variable (s).

    Redraw = false;
    var s = "";
    document.selection.StartOfDocument(false);
    while (true) {
        var xPos = document.selection.GetActivePointX(eePosView);
        var yPos = document.selection.GetActivePointY(eePosView);
    
        editor.ExecuteCommandByID(4554);  // Next Misspelling
    
        var xPos2 = document.selection.GetActivePointX(eePosView);
        var yPos2 = document.selection.GetActivePointY(eePosView);
    
        if (xPos === xPos2 && yPos === yPos2) break;
    
        document.selection.SelectWord();
        s += document.selection.Text + "\r\n";
    }
    
    editor.NewFile();
    document.selection.Text = s;