Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10025

    Just
    Participant

    Hi All,
    I have a text, which looks like as the following:
    erfqlqbf ; qlkhflkejf
    kqrjhfkjrkjf ; qkhkhfg
    jreh ; kejrhfgkjh
    But, I want it have aligned by the `;` sign.
    I mean I want to align the in-line comments in this text block.
    How can I do so? Is it possible to write a Java script, which would receive a character or/and a caret position as an input and makes all the required alignments?
    Comment alignments might be very useful! Please help!

    #10026

    Just
    Participant

    Here is a link to the same plug-in for VIM:
    http://www.vim.org/scripts/script.php?script_id=294
    Is it hard to make the same plugin for the EmEditor as well?
    Thank you!

    #10028

    Just
    Participant

    Hi,
    I’ve found a Java code, which makes alignments for the `=` sign (see it below). The code is written for the UltraEdit. Could anyone translate it to a general one so that it could be used in the EmEditor as well?
    Thank you!
    ————————————————————
    CODE:
    ————————————————————
    //alignEqual.js
    //Bego
    //Aligns the SELECTION by the Equal-sign. Might be configured with Left or Right alignment!
    //Version 1.1 25.10.2007 result once was shifting 1 column to the left for each run: pos1 = getColOfFirstChar();// – 1;
    // 1.2 25.10.2007 Now MYSIGN can be really sth. else like “=”, e.g. “/”, but yet still only ONE character
    // 1.3 25.10.2007 Shifting result in 1.1 was Problem of configuration of home-key when pressed twice. Made it safe now
    // CloseFile workaround 13.20+2
    var orgDoc;
    var sourceDoc;
    var maxColEqual = 0;
    var pos1 = 0;
    var myDocNo;
    var MYSIGN = “=”;
    var MYALIGN = “L”; //(L)eft or (R)ight
    sourceDoc = UltraEdit.document[getActiveDocumentIndex()];

    UltraEdit.outputWindow.showOutput = true;
    UltraEdit.outputWindow.clear();
    //UltraEdit.outputWindow.write(“Debug: Start”);
    UltraEdit.perlReOn();
    //ZUM TEST ALLES MARKIEREN UND KOPIEREN STATT MOVEN:
    //UltraEdit.activeDocument.selectAll();
    UltraEdit.selectClipboard(8);
    UltraEdit.activeDocument.cut();
    UltraEdit.newFile();
    orgDoc = UltraEdit.activeDocument;
    orgDoc.paste();
    orgDoc.top();

    pos1 = getColOfFirstChar();
    //UltraEdit.outputWindow.write(“Debug: ” + pos1);
    stripEqualRemoveLeadingSpaces();

    maxColEqual = getMaxColEqual();
    stuff(pos1, maxColEqual, MYALIGN);

    UltraEdit.selectClipboard(8);
    orgDoc.selectAll();
    orgDoc.copy();
    //UltraEdit.closeFile(); //13.20+2 does not work
    closeFile();

    //UltraEdit.document[3].setActive(); //CRASH. Still a bug !!!
    UltraEdit.selectClipboard(8);
    sourceDoc.paste();
    UltraEdit.selectClipboard(0);

    ///////////////////////////////////////////////////////////////////////////////////////////////////

    function closeFile() {
    UltraEdit.selectClipboard(9);
    orgDoc.copyFilePath();
    orgDoc.top();
    orgDoc.paste();
    orgDoc.selectToTop();
    var CurrentFileName = orgDoc.selection;
    orgDoc.deleteText();
    UltraEdit.closeFile(CurrentFileName,2);
    UltraEdit.clearClipboard();
    UltraEdit.selectClipboard(0);
    }

    function stuff(pPos1, pMaxCol, pAlign) {
    var col;
    var spaces = ” “

    orgDoc.top();
    //go through once again and stuff spaces, depending on the position of the equal-sign and the calculated maxPosition
    while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
    orgDoc.key(“LEFT ARROW”); orgDoc.key(“RIGHT ARROW”); //unmark selection
    col = orgDoc.currentColumnNum; //getCol();
    orgDoc.key(“HOME”);
    if (pAlign == “R”) {
    orgDoc.write(spaces.substring(0,pMaxCol – col + pPos1));
    }
    else
    {
    orgDoc.write(spaces.substring(0,pPos1));
    //reposition in front of sign and stuff here
    orgDoc.findReplace.find(MYSIGN);
    orgDoc.key(“LEFT ARROW”);
    orgDoc.write(spaces.substring(0,pMaxCol – col));
    }
    orgDoc.key(“END”);
    }
    }

    function getMaxColEqual() {
    //get the mostright equal-sign in the selection. This is the orientation for the stuffing-spaces at the beginning of the line.
    var max = 0;
    var col = 0;

    orgDoc.top();
    orgDoc.findReplace.replaceAll = false;
    orgDoc.findReplace.regExp = false;
    while ( (orgDoc.findReplace.find(MYSIGN)) && ! orgDoc.isEof() ) {
    col = orgDoc.currentColumnNum; //getCol();
    orgDoc.key(“END”);//continue search in next line
    if (col > max) {
    max = col;
    }
    }
    return max;
    }

    function stripEqualRemoveLeadingSpaces() {
    //ONE space before and after equal-sign. cut all leading spaces.
    orgDoc.top();
    orgDoc.findReplace.replaceAll = true;
    orgDoc.findReplace.regExp = true;
    var strFind = “s*” + MYSIGN + “s*”;
    orgDoc.findReplace.replace(strFind, ” ” + MYSIGN + ” “);
    orgDoc.findReplace.replace(“^s*”, “”);
    }

    function getColOfFirstChar() {
    //determins in which column the line starts with content. V1.3: maybe do it twice since HOME-key might toggle between Col0 and start of first char
    orgDoc.findReplace.regExp = true;
    orgDoc.key(“HOME”);
    if (orgDoc.currentColumnNum == 0) {
    orgDoc.key(“HOME”);
    }
    return orgDoc.currentColumnNum; //ab 13.10
    }

    function getActiveDocumentIndex() {
    var tabindex = -1; /* start value */

    for (i = 0; i < UltraEdit.document.length; i++)
    {
    if (UltraEdit.activeDocument.path == UltraEdit.document[i].path) {
    tabindex = i;
    break;
    }
    }
    return tabindex;
    }

    #10036

    Just
    Participant

    Could anybody help with translation of the script above for using it with EmEditor?
    Is it a big issue to translate it?
    Thank you!

    #10038

    Stefan
    Participant

    FROM:


    erfqlqbf ; qlkhflkejf
    kqrjhfkjrkjf ; qkhkhfg
    jreh ; kejrhfgkjh

    TO:


    erfqlqbf ; qlkhflkejf
    kqrjhfkjrkjf ; qkhkhfg
    jreh ; kejrhfgkjh

    USE:
    Edit > Separated Values/Sort
    CSV (Comma-separated), TSV (Tab-separated) or DSV (User-defined delimiter-separated)
    See: http://www.emeditor.com/modules/feature1/rewrite/tc_35.html#csv

    It was a bit difficult to me to find how to set the User-defined delimiter.
    Therefor go to Tools > Properties > [File] > Delimiter [;]

    Yutaka, I think there should be an link in the menu
    “Edit > Separated Values/Sort > Set User-defined delimiter…”

    But we can’t make this alignment stand forever.
    Once we leave this CSV mode, the alignment is lost.

    I already have asked for an improvement there:
    http://www.emeditor.com/modules/newbb/viewtopic.php?topic_id=1856&forum=4

    .

    #10041

    Just
    Participant

    Stefan,
    The CSV, TSV and DSV modes are just for the visualization, they do not make real alignments.
    Honestly, I’m already tired to align comments in my files…
    It seems the alignment feature should receive a first priority in the coming releases :-).
    Why Yutaka don’t answer?

    #10042

    Just
    Participant

    Could you please take a look on the Java code in my previously post? Could it be translated for using with EmEditor? It seems this script is exactly what’s we are looking for…
    Are you familiar with Java?

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone