Plugin: Convert Leading v1.01

Browse, download and discuss plugins for Blumentals code editors

Plugin: Convert Leading v1.01

Postby pmk65 » Sat Jan 14, 2017 11:19 pm

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 560 times
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: Plugin: Convert Leading v1.01

Postby cf1 » Wed Aug 30, 2023 12:06 pm

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[i];

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[i]);
}

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");
cf1
 
Posts: 12
Joined: Thu Aug 16, 2012 10:40 am


Return to Plugins for HTMLPad / Rapid CSS / Rapid PHP / WeBuilder

Who is online

Users browsing this forum: No registered users and 1 guest