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.)
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);
}
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");