Customize Line Spacing with Vertical Align Feature in EmEditor Text Editor

Customize Line Spacing with Vertical Align Feature in EmEditor Text Editor

Jason Lv8

Customize Line Spacing with Vertical Align Feature in EmEditor Text Editor

Viewing 1 post (of 1 total)

  • Author
    Posts

  • May 21, 2012 at 3:08 pm #10375
    Stefan
    Participant
    Attention:
    this script HAD contain an Bug:
    IF an Line doesn’t had contain the delimiter
    THEN this line was excluded from the output!
    This was fixed at 13. July 2012 in the code below.
    Also there was added some improvements:
    – prompt for the sign to be used as alignment. e.g. use one space or one dot.
    – prompt for sing(s) to insert before this new alignment (i.e. at the place where the delimiter was found)
    – prompt for sign(s) to insert right in front of the found delimiter
    ————————-
    For example you can align at an “M” sign by inserting spaces:
    O Matches NUL character.
    n Matches a new line character
    f Matches a form feed character
    r Matches carriage return character
    t Matches a tab character
    v Matches a vertical tab character
    [b] Matches a backspace.
    xxx Matches the ASCII character expressed by the octal number xxx.
    xdd Matches the ASCII character expressed by the hex number dd.
    uxxxx Matches the ASCII character expressed by the UNICODE xxxx.
    O Matches NUL character.
    n Matches a new line character
    f Matches a form feed character
    r Matches carriage return character
    t Matches a tab character
    v Matches a vertical tab character
    [b] Matches a backspace.
    xxx Matches the ASCII character expressed by the octal number xxx.
    xdd Matches the ASCII character expressed by the hex number dd.
    uxxxx Matches the ASCII character expressed by the UNICODE xxxx.
    Or f.ex. at an semicolon by inserting dots
    and two extra spaces in front and after the alignment:
    FPGA.rbf;247942;8/5/2011;none;7/12/2012
    PDAManager.exe;136016;8/5/2011;1.0.0.1;7/12/2012
    uImage;1126214;8/5/2011;none;7/12/2012
    uRamdisk;6761355;8/5/2011;none;7/12/2012
    FPGA.rbf …… ;247942;8/5/2011;none;7/12/2012
    PDAManager.exe ;136016;8/5/2011;1.0.0.1;7/12/2012
    uImage …….. ;1126214;8/5/2011;none;7/12/2012
    uRamdisk …… ;6761355;8/5/2011;none;7/12/2012
    Do this two more times, with start at column 20 and then 40,
    align with spaces, and also insert one extra space “in
    front of the whole alignment”, you can get something like this:
    FPGA.rbf …… ;247942 ;8/5/2011;none ;7/12/2012
    PDAManager.exe ;136016 ;8/5/2011;1.0.0.1 ;7/12/2012
    uImage …….. ;1126214 ;8/5/2011;none ;7/12/2012
    uRamdisk …… ;6761355 ;8/5/2011;none ;7/12/2012
    (again: sometime i will add code to automatically align at all found delimiters at once.
    If i get the free time once…)
    ————————-
    Vertical align all selected lines at an given sign macro.
    If you have an list with different word length at the beginning
    and want to align the delimiter sign (e.g. “=” or “:”)
    on all lines to the same column position,
    then you may want to try this JavaScript macro.

    After that you may use other features to modify the text further.
    For example:
    – make an vertical zero-width selection to insert more text

    The code so far:
    (Updated 19.06.2012: added “StartPos”, now you can align at other pos then at the first delimiter pos only.
    OK, not well coded right now, i want to do that better sometimes (with an foreach-delim-IN-DelimS),
    but it works as an interim solution right now already:
    – just start this script the first time with StartPos=0.
    – next enter StartPos=x, where ‘x’ is an position behind the first delimiter. Just take an look at the ruler for this.)

    //http://www.emeditor.com/modules/newbb/viewtopic.php?topic_id=2044&forum=19

    // === Description/Purpose:
    // vertical align lines at an given sign,
    // e.g. at “=” or at “:”, or “” or “.” or “M”, or…

    //Version 0.02, 13. July 2012

    //Please note that i use Windows Line enders rn

    //Settings:
    o = document.selection;

    // Note: this script works on an text selection!
    // So select some text before executing it.
    if(o.IsEmpty == true){alert(“This script works on an selection only.nnScript quits here.”); quit();}
    Redraw = false;
    Delim = prompt(“Enter sign to vertical align all lines at:”, “=”);
    if (Delim == “”){quit();}

    //Not nice coded, but by entering the start pos you can align at several different positions.
    //Or just skip an delimiter at the beginning and align only the next one.
    StartPos = prompt(“Align “”+Delim+”” only if found after this column: “, “0”);
    if (StartPos == “”){quit();}

    //Additional:
    sInsert = prompt(“Enter ONE sign to use as alignment (default is one dot):”,”.”);
    if (sInsert == “”){sInsert = “ “;}

    sBefore = prompt(“Enter sign(s) to insert in front of the whole alignment:”, “”);
    sAfter = prompt(“Enter sign(s) to insert additional right before the found delim “”+Delim+”” :”,””);

    //Work on this lines:
    LineBeg = o.GetTopPointY(eePosLogical);
    LineEnd = o.GetBottomPointY(eePosLogical);

    //Get the lines and the col pos of the Delim into an array:
    var aLinesArr = new Array();
    var aDelimPos = new Array();

    //
    for (var L=LineBeg, i=0; L<=LineEnd; L++){
    sCuLi = document.GetLine(L);
    aLinesArr[i] = sCuLi;
    nDePos = sCuLi.indexOf(Delim, StartPos) +1;
    aDelimPos[i] = nDePos;
    i++;
    //Sort the MaxColumn Array
    // to find the longest right point of an Delim:
    aDelimMax = aDelimPos.slice();
    aDelimMax.sort(function(a,b){return a - b}).reverse();
    nMaxPos = aDelimMax[0];

    //Modify the lines inside the array and write to an new Array:
    var aOutArray = new Array();
    for(L=0,E=aLinesArr.length;L<E;L++){
    sLine = aLinesArr[L];
    nPos = aDelimPos[L];
    if ((nPos > 0)&&(nPos <= nMaxPos)){
    sOut = sLine.substring(0,nPos -1);
    sOut += sBefore;
    sOut += Array(nMaxPos - nPos +1).join(sInsert);
    sOut += sAfter;
    sOut += sLine.slice(nPos -1);
    }else{
    sOut = sLine;

    aOutArray[L] = sOut;


    //Output the new Array:
    o.text = aOutArray.join(“rn”);
    Done by Stefan with the kind help of Google.

I use this to align CSV files or to align code at an equal sign.
Or to align copy & pasted text from an web page.

  • Author
    Posts

Viewing 1 post (of 1 total)

  • You must be logged in to reply to this topic.

Also read:

  • Title: Customize Line Spacing with Vertical Align Feature in EmEditor Text Editor
  • Author: Jason
  • Created at : 2024-10-06 02:39:46
  • Updated at : 2024-10-10 17:06:00
  • Link: https://win-luxury.techidaily.com/customize-line-spacing-with-vertical-align-feature-in-emeditor-text-editor/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Customize Line Spacing with Vertical Align Feature in EmEditor Text Editor