Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26460
    jic
    Participant

    Greetings!.

    I am trying to take a text file and break any line longer than 80 character using the closest space (blank) character as the breaking point. For example, this paragraph,

    This is a line. One of the lines. this is a long line. aaaa bbbb ccc ddd eeeeee fffff line break. Line break break aa bbb ccccc ddd eeee fffff This is a line. One of the lines. This is a long line. aaaa bbbb ccc ddd eeeeee fffff line break Line break break aa bbb ccccc ddd eeee fffff This is a line. One of the lines. this is a long line. aaaa bbbb ccc ddd eeeeee fffff line break Line break break aa bbb ccccc ddd eeee fffff This is a line. One of the lines. this is a long line. aaaa bbbb ccc ddd eeeeee fffff line break Line break break aa bbb ccccc ddd eeee fffff.

    will end up like this,

    >This is a line. One of the lines. this is a long line. aaaa bbbb ccc ddd
    > eeeeee fffff line break. Line break break aa bbb ccccc ddd eeee fffff This is
    > a line. One of the lines. This is a long line. aaaa bbbb ccc ddd eeeeee
    > fffff line break Line break break aa bbb ccccc ddd eeee fffff This is a line.
    > One of the lines. this is a long line. aaaa bbbb ccc ddd eeeeee fffff line
    > break Line break break aa bbb ccccc ddd eeee fffff This is a line. One of
    > the lines. this is a long line. aaaa bbbb ccc ddd eeeeee fffff line break
    > Line break break aa bbb ccccc ddd eeee fffff.

    I can write a quick python script, but I want to do it right in EmEditor. Any ideas? Thanks.

    josé

    #26461
    Yutaka Emura
    Keymaster

    Hi jic,

    Is this different from the Word Wrap feature?
    Please try Wrap by 80 characters with the Word Wrap turned on (default), select all text, and select “Edit” menu – “Convert Selection” – “Insert Newline Characters” or “Split Lines”.

    #26484
    LTT
    Participant

    After Yutaka’s steps, if you still wish to add “>”:
    Select the lines.
    Use “Select Beginning of Lines” command.
    Type “>”.

    You can record the whole procedure as a macro.

    —————
    Actually there are quite a few ways to do this in EmEditor.

    ▼ Here’s the most simple/economical way I think, to get an almost same result:

    Use “Wrap by Window” command.
    Resize the window to the wanted width. (Show and see the ruler at the top of the view.)
    (Or use “Wrap by Characters” command instead of the above two steps, if your “Normal Line Margin” setting is 80 (default).)
    Select the lines you want to convert.
    Copy.
    Use “Paste in Quotes and Newline Characters” command.

    ▲ You can find the commands and descriptions by searching in “Quick Launch” (default key: Ctrl+Q) if you don’t know where they are.
    ▲ You can assign shortcut keys to the often-used commands/macros.

    —————
    ▼ Another simple way, to get an exact same result as you presented:

    Use “Wrap by Characters” command. (Default = 80.)
    Open the current configuration properties:
    Wrap:
    Add a space in “Not Allowed at Line End”.
    OK.
    Select the lines you want to convert.
    Copy.
    Use “Paste in Quotes and Newline Characters” command.

    Compare the results in my screenshot:
    i.ibb.co/C8Lhx2m/Em-Editor-Wrap-By-Char-Q-NL.png
    Actually your max line length is 79. ;-)

    #26485
    LTT
    Participant

    By the way,
    I use the macro below to quickly change the line length for WrapByChar (according to ActivePointX, the caret position):


    //Wrap@ActivePointX.jsee

    nMarginMin = 10;
    nMarginMax = 32767;

    nMargin = document.selection.GetActivePointX(eePosLogicalA)-1;
    nMargin = Math.max(nMarginMin, nMargin);
    nMargin = Math.min(nMarginMax, nMargin);

    oCfg = document.Config;
    sTip = "WrapByChar ["+ nMarginMin +", "+ nMarginMax +"] = "+ oCfg.General.MarginNormal;
    do {
    nn = prompt(sTip, nMargin);
    if (isNaN(nn) || nn == "") Quit();
    nn = Math.ceil(nn);
    } while (nn < nMarginMin || nn > nMarginMax);

    oCfg.General.MarginNormal = nn;
    oCfg.Save();

    editor.ExecuteCommandByID (4209) //Wrap by Characters

    #26494
    jic
    Participant

    Thanks.

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