Plugin: Convert Leading v1.01

Browse, download and discuss plugins for Blumentals code editors
Post Reply
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Plugin: Convert Leading v1.01

Post by pmk65 »

WeBuilder Plugin: Convert Leading v1.01

Convert leading Tabs to Spaces or leading Spaces to Tabs.


Installation:
1) Download plugin .ZIP file.
2) Open WeBuilder and select "Plugins -> Manage Plugins" from the menu.
3) Click "Install" and select the .ZIP file you downloaded in step 1.

Feedback appreciated. ;)
(I only use WeBuilder, so I haven't tested if it works in HTMLPad, Rapid CSS or Rapid PHP.)
Attachments
Convert Leading.zip
(2.34 KiB) Downloaded 954 times
There are 10 types of people in the world: Those who understand binary and those who don't.
cf1
Posts: 13
Joined: Thu Aug 16, 2012 10:40 am

Re: Plugin: Convert Leading v1.01

Post by cf1 »

if you need to do this with selected text, add the following functions to convertleading.js:
/////////////////////////////////////////////
function SpacesToTabsSelected(Sender) {
var tabSize = Script.Settings.TabSize;
var userSelection = Editor.Selection;
if ((userSelection.SelStartLine >= 0) && (userSelection.SelEndLine >= 0)) {
Editor.BeginEditing;

var startLine = userSelection.SelStartLine;
var endLine = userSelection.SelEndLine;
if ((endLine > startLine) && (userSelection.SelEndCol == 0)) {
endLine--;
}

var line;
var s = "";
for (var i = startLine; i <= endLine; i++) {
line = Editor.Lines;

if(RegexMatchAll(line, "^(\\s*)(.*)$", true, match, p) == true) {
var len = Length(_v(match, [0, 1]));
var remainingSpaces = len - Round(len/tabSize)*tabSize;
line=
RepeatChar(chr(9), Round(len/tabSize)) + RepeatChar(" ", remainingSpaces) + _v(match, [0, 2]);
}

s += line;
if(i< endLine) s += "\n";
}

Editor.SelText = s;

Editor.EndEditing;
}
}

function TabsToSpacesSelected(Sender) {
var userSelection = Editor.Selection;
if ((userSelection.SelStartLine >= 0) && (userSelection.SelEndLine >= 0)) {
Editor.BeginEditing;

var startLine = userSelection.SelStartLine;
var endLine = userSelection.SelEndLine;
if ((endLine > startLine) && (userSelection.SelEndCol == 0)) {
endLine--;
}

var SL = new TStringList;
for (var i = startLine; i <= endLine; i++) {
SL.Add(Editor.LinesAsDisplayed);
}

Editor.SelText = SL.Text;
delete SL;

Editor.EndEditing;
}
}
/////////////////////////////////////////////

and lines to the end of the file:
var act3 = Script.RegisterDocumentAction("Convert Leading", "Spaces to Tabs in selected", "", "SpacesToTabsSelected");
var act4 = Script.RegisterDocumentAction("Convert Leading", "Tabs to Spaces in selected", "", "TabsToSpacesSelected");
Post Reply