Recent

Author Topic: Tabify?  (Read 499 times)

del

  • Jr. Member
  • **
  • Posts: 68
Tabify?
« on: September 11, 2019, 01:22:09 am »
I understand that tabs are unpopular. I didn't like them either - but that's the rule at work and I've learned to like them. I like the enforced uniform intervals. Especially with whitespace "visible".

OK - so Visual Studio has "Edit->Advanced->Tabify" IIRC, which converts all leading spaces into the correct number of tabs. Geany and NotePad++ have this thing where you select the text to be "tabified" then hit the tab key, and follow it with the shift-tab combo. It works great - it only changes the leading spaces. I haven't found a way to tabify in Lazarus. Is there a way?

lainz

  • Hero Member
  • *****
  • Posts: 3219
    • Lainz
Re: Tabify?
« Reply #1 on: September 11, 2019, 01:53:26 am »
There should (not tested) be a setting in Jedi Code Format, so you don't need to add them by hand, plus your code is automatically formatted.

del

  • Jr. Member
  • **
  • Posts: 68
Re: Tabify?
« Reply #2 on: September 11, 2019, 02:29:04 am »
Thanks - I'll check that out. Jehi was a big help this weekend with 99% of what I wanted it to do (mostly related to begin, end, and case stuff) but it seemed to be better behaved in "space" mode than tab mode. But it made a huge improvement nonetheless. Then I put everything on a thumb drive and used Visual Studio to "tabify" the source files. But I figured there's a better way.

del

  • Jr. Member
  • **
  • Posts: 68
Re: Tabify?
« Reply #3 on: October 03, 2019, 01:04:08 am »
I just figured out how to do this with JEDI:

Source - JEDI Code Format - Format Settings
Spaces
check Turn spaces to tabs

Now here's the most important part ...

Indentation
Block indentation spaces 0

This forces everything to the left and wipes out all existing indentation.

OK

Source - JEDI Code Format - Current Editor Window

Now everything is along the left edge, all the previous indentation is erased. Now set the block indentation spaces to what you want it to be (they'll be converted to tabs if you checked that checkbox)

Source - JEDI Code Format - Format Settings
Indentation
Block indentation spaces 2

OK

Source - JEDI Code Format - Current Editor Window

Bingo! It's perfect! The key part was initially forcing 0 indentation. This gives JEDI a clean slate on the second pass when you apply your desired indentation.

winni

  • Sr. Member
  • ****
  • Posts: 307
Re: Tabify?
« Reply #4 on: October 03, 2019, 02:13:43 am »
What about a little bit pascal? All tools are on board if you make them.

Code: Pascal  [Select]
  1. function TabifyString(s: string) : string;
  2. const SpacesPerTab = 4;
  3.       Space = #32;
  4.       Tab = #9;
  5.  
  6. var count : integer = 0;
  7.     tabcount : integer;
  8.     SpacesLeft : integer;
  9.     TabString: string = '';
  10.     i : integer;
  11.     begin
  12.     while (length(s)> 0) and (s[1] = Space) do begin delete(s,1,1); inc(count);end;
  13.     tabCount := count div SpacesPerTab;
  14.     SpacesLeft := count mod SpacesPerTab;
  15.     for i := 1 to TabCount do Tabstring := Tabstring + Tab;
  16.     for i := 1 to SpacesLeft do TabString := Tabstring + Space;
  17.     result := tabstring + s;
  18. end;                    

Winni

lainz

  • Hero Member
  • *****
  • Posts: 3219
    • Lainz
Re: Tabify?
« Reply #5 on: October 03, 2019, 02:15:50 am »
Good. But how that can be integrated into the IDE, for those don't know how?

winni

  • Sr. Member
  • ****
  • Posts: 307
Re: Tabify?
« Reply #6 on: October 03, 2019, 02:21:27 am »
Hi Lainz!

And if they cannot: Make a little project to tabify files. Close lazarus. Tabify all pascal files. Maybe with a multiselected list. Done.

Solution without comfort!

Winni

del

  • Jr. Member
  • **
  • Posts: 68
Re: Tabify?
« Reply #7 on: October 03, 2019, 03:12:41 am »
That's pretty slick. "Fractional" tabs are replaced by single spaces. Which I would leave off. But my code is such a mess that I still need the JEDI logic to handle all the nested indents. My next goal is to figure out how to force every for loop to begin and end with a "begin" and an "end". But what I'm getting so far out of Lazarus / JEDI is totally cool.

del

  • Jr. Member
  • **
  • Posts: 68
Re: Tabify?
« Reply #8 on: October 03, 2019, 06:38:43 am »
HOWEVER - My OP asked for the equivalent to Visual Studio's Edit-Advanced-Tabify and that's exactly what this code does. So yeah, pretty cool.  8)

I'd go with the option of not padding "modulo" whitespace with spaces and just having pure tab indentation. I think VS just assumes that your space-based indentation is already the way you like it and tries to preserve it in tab form. And that's what this code does.