Elastic tabstops


#1

A feature that almost no editor has, but which has great potential to replace every discussion about tabs vs. spaces and “how to visually align stuff?”

http://nickgravgaard.com/elastictabstops/


Indentation/TabWidth as Encoding, not style
#2

Hmm. that’s neat, but there are several problems. It’s seems really hard to predict where your next tab is going to be. I bet it just takes getting used to though.


#3

With a similar highlighting (maybe more transparent) of the region as in the animated example on the page linked above it will probably work fine.


#4

Yeah if it highlights I’d see it working great, as long as it doesn’t collide with syntax highlighting.


#5

Yes, it would be great if Atom had support for elastic tabstops. I’ve been looking for a good editor supporting it since forever. It is possible to support it with the tab-size CSS property, which is supported in Blink, which means that it can be done quite easily with Atom. Surely someone can create a package to add support for elastic tabstops? I don’t know the API offered by Atom, but it’s just a matter of adding span tags around tabs and setting the tab-size property after calculating to what it should be set.

This feature would really distinguish Atom from other editors for me. Sublime Text and Ace, for example, have implementations of elastic tabstops, but these implementations use spaces and do not work well; they pretty much ruin the whole point of elastic tabstops by using spaces. Having a correct implementation (which is easy to do with tab-size) would be great.


#6

I code in ruby and Go, and don’t even notice the difference between spaces or tabs anymore. Atom doesn’t have the elastic tab stuff from that post, but a plugin could probably be made to do that.


#7

I wrote the code for Elastic Tabstops in Ace. I had thought about porting it to Atom, but got distracted. They’re both JavaScript environments, so the addition would be easy enough.

Glad to see other people would enjoy the feature. I’ll see if I can get some time to crunch something out.


#8

Please, if you wish to make an implementation of it for Atom, do not do it using spaces, like the Sublime Text package and the Ace implementation do. It is possible to do it properly using the CSS tab-size property. Be warned that the browser compatibility table on MDN is outdated: caniuse.com indicates that tab-size is fully supported on all major browsers except IE, and requires the vendor prefix on Mozilla Firefox. Since Atom uses Chromium, there is no problem.

Atom currently already inserts a span element for each tabulation, with the classes hard-tab and indent-guide when indent guides are enabled. I’ve glanced at the API of the Atom Editor object and it doesn’t seem there is the functionality to change the length of individual tabulations, but considering tabs are already given a certain class and changing the length is easy in CSS, it should be simple to add this to the API when pull requests become possible. If that’s in too long, it’s possible to ask for the feature to be added or just cheat by directly editing the DOM. The rest is just a matter of calculating the correct length for each tab, and this should be simple since I believe the algorithm of the Ace implementation for calculating it can be re-used.


#9

+1 Rastus. If it has to use spaces, its not a real implementation as might as well not do it.


#10

what do you mean? the algorithm is pretty intuitive: a line with less tabstobs than the preceding line ends a block, and a line with more tabstops than the preceding line starts a block.


#11

yeah, it definitely has to be done with spans containing one tab and a style that either modifies tab-size (which would only allow it to work with fixed-width fonts) or width directly.

one could look at Nick’s Java implementation on the linked page for inspiration.


#12

I wrote the Sublime Text implementation, which unfortunately had to use spaces due to limitations in the API. Once I get my beta e-mail for Atom I would be very keen on making a real implementation that actually changes tab sizes, rather than the hamstrung version that was required for Sublime.


#13

It seemed confusing at first, but after trying it out with the java implementation it doesn’t seem too bad.


#14

Woo just got in! I’m gonna take a look this weekend hopefully.
So excited. Markdown previews in the editor??? Per-package preference panes??? Rock on.


#15

hi, any progress yet?


#16

I just invited Nick to the beta…does that count as progress? :wink:


#17

The introduction of a new proportionally-spaced coding font (Input: http://input.fontbureau.com/), inspired me to try and revive this topic. Is there still motivation to implement elastic tabstops?


#18

why shouldn’t it? :wink:


#19

Hi Nikolaus, are you still up for implementing this package?


#20

Yeah, maybe I’ll do that. I looked at it when Atom first came out, and the API was pretty much nonexistent and things were changing real fast. Now that the dust is starting to settle, maybe I’ll take another look.