Sublime Forum

Elastic tabs

#18

I don’t see why this wouldn’t be possible with a plugin to be honest. You’d only need to look between regions and the current line.

Not saying I could do it, but from what I understand of the plugin system (at least in V1.4) I see no reason for it not to be done?

0 Likes

#19

I’m actually working on a plugin for elastic tabstops right now.

0 Likes

#20

[quote=“adzenith”]

I’m actually working on a plugin for elastic tabstops right now.[/quote]

Cool! Looking forward to seeing it!

0 Likes

#21

+1 :smile:

0 Likes

#22

Here it is:
github.com/SublimeText/ElasticTabstops

NOTES

  • You can’t use the stock undo/redo/soft undo/soft redo commands, and instead need to use the wrappers that I’ve created for them (in the same file as the plugin). This is because undo and redo trigger on_modified, and on_modified is where this plugin does all of its processing. So every time you undo, the plugin will redo what you just undid, effectively taking away your ability to undo. My wrapper functions warn my plugin that an undo is coming so that it stands down.

  • Because you can’t change the width of individual tabstops in Sublime Text, this plugin works by inserting spaces in front of tabs in order to align text. This has the benefit of making your files 100% compatible with editors that don’t support elastic tabstops, but adds a couple of quirks to the behavior of the plugin that pretty much can’t be worked around.

  • You’ll need to be indenting with tabs.

Let me know of any questions or comments!

Edit: updated link.

0 Likes

#23

Thanks but it don’t work for me :frowning:
Nothing happen.

And I want the same plugin work with space indentation.
And elastic tabstop in real time when I write.

Thanks for your work :smile:

0 Likes

#24

The elasticity does in fact happen in real time.
I want the same plugin with space indentation too, but it’s approximately impossible given Sublime Text’s API right now—with spaces you have to guess intent, whereas with tabs you just have to count tabs, and Sublime Text’s API doesn’t tell you what changes have been made to a buffer (it just tells you that changes have been made), so it’s hard to guess what’s going on.

In terms of the plugin not working, can you give me more info? Are your files using tabs for indentation? Is the plugin loading correctly? etc.
You can run this for a little info:

import sublime_plugin sublime_plugin.all_callbacks.items()

0 Likes

#25

If you like this feature, please vote up : sublimetext.userecho.com/topic/1 … p-feature/

0 Likes

#26

up :smile:

0 Likes

#27

If anybody is looking for the elastic tab stops code, it apparently has moved to github.com/SublimeText/ElasticTabstops

0 Likes

#28

Before SublimeText, I needed this feature. But now, I just use multi-select…

0 Likes

#29

I guess I don’t really see how one substitutes for the other. I use multi-select and elastic tabstops together and it’s fantastic. :smile:

0 Likes

#30

This does not work at all with a proportional font!

PS: I had not realized this thread was old. But it’s still not working!

0 Likes

#31

[quote=“tobia”]This does not work at all with a proportional font!

PS: I had not realized this thread was old. But it’s still not working![/quote]

Unfortunately there’s no way to get it to work with a proportional font: the API doesn’t allow either determining character width or inserting arbitrary-width spaces. The first could be worked around by opening the font myself and figuring out the character widths, but the second is a dealbreaker. Sorry!

0 Likes

#32

Any chances that with the advent of ST3 elastic tabs could become reality?

0 Likes

#33

No, we still don’t have API support. This plugin is as close as you can get (and it doesn’t yet work in ST3 due to API changes).

0 Likes

#34

While I’m not a fan of elastic tabs per se, I do feel there’s room for improvement in Sublime’s tab handling, the implementation for which should be fairly straightforward.

What I’m talking about here is simply definable tabstops. Just about every decent editor has this, and it’s essential if an editor is to become a programmer or technician’s “go to” for editing any kind of text files in the field. I have to drive another editor simply because Sublime is lacking in this basic area. And it’s a showstopper for a whole bunch of colleagues.

So, my old favourite “Brief” had simply a command “tabs” that went something like this “tabs 5 25 40 45”. That would define tabstops for the current buffer at those positions, and the remaining tabstops would be at a repeating interval of the last two (50,55,60,65 etc.). Some editors augment this by allowing tabstops to be left, centre and right aligned, though I see this as fairly pointless and only useful for formatting tables that are coded into tab delimited text files (in that case, you may just as well load stuff up in your favourite WP)

This is needed because text output files from numerous sources are tab delimited, and it’s not possible to work with such files formatted even remotely correctly in Sublime. Traditional programmers prefer this approach since it gives flexibility as to how things are spaced out horizontally. Moreover, a number of older, less popular programming languages work with particular indentation positions. The above tabstop model would support use of tabs or spaces in much the same way that Sublime does presently; knowing tabstop positions allows Sublime to convert tabs to spaces and spaces to tabs in the same way it does at present.

Sublime is already set up with very flexible configuration for this with its default, user, filetype and project preferences.

0 Likes

#35

this would drive me absolutely CRAZY if i had the feature turned on.
it would drive me absolutely crazy if you didnt :smile:

0 Likes

#36

[quote=“mark4”]this would drive me absolutely CRAZY if i had the feature turned on.
it would drive me absolutely crazy if you didnt :smile:[/quote]

Wait, what?

0 Likes

#37

[quote=“adzenith”]

[quote=“mark4”]this would drive me absolutely CRAZY if i had the feature turned on.
it would drive me absolutely crazy if you didnt :smile:[/quote]

Wait, what?[/quote]

Lol… One of the things im MAJORLY anal retentive about is source formatting. Cluster $*&# scatterbrain source formatting just drives me up the wall. I always indent by the same distance and always using spaces NEVER tabs. I always place my comments in the same column (i avoid interleaving comments with code etc). My source formatting is very VERY consistent across all my source files!

Having my indentations automaticlaly adjust themselves as i wrote code would be like eating garlik flavored ice cream… just WRONG!

but 99 times out of 100, when i look at someone elses sources which are cluster *$%! scatter brained i have to first reformat them just to be able to read them and retain what little sanity i have left. If you (they?) used this auto formatting even if the end result was not exactly to my liking it would be MUCH MUCH more consistent within the source file. So… i could not use this feature if it was ever implemented but if everyone else did it would be cool :smile:

thats what i meant :stuck_out_tongue:~

0 Likes