EmEditor (text editor) Forum Index
   Questions and Answers about EmEditor Core
     -= Text Alignment =-
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
dmitryl
Posted on: 2/16/2012 6:45 am
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
-= Text Alignment =-
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!
dmitryl
Posted on: 2/16/2012 6:50 am
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: -= Text Alignment =-
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!
dmitryl
Posted on: 2/16/2012 7:35 am
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: -= Text Alignment =-
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;
}
dmitryl
Posted on: 2/18/2012 4:59 am
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: -= Text Alignment =-
Could anybody help with translation of the script above for using it with EmEditor?
Is it a big issue to translate it?
Thank you!
Stefan
Posted on: 2/18/2012 8:34 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 264
Text Alignment columns at given delimiter separator
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


.
dmitryl
Posted on: 2/18/2012 1:31 pm
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: Text Alignment columns at given delimiter separator
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?

dmitryl
Posted on: 2/18/2012 1:34 pm
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: Text Alignment columns at given delimiter separator
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?
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文