TextMate News

Anything vaguely related to TextMate and macOS.

Elastic Tabs

Nick Gravgaard proposed a new concept called Elastic Tabs.

Since this has gotten a lot of buzz here is the reply I sent to the mailing list (and a few people who wrote me in private):

Indeed it is interesting. I do think there would be too big a compatibility problem with actually saving such files, since all renderings of the file (cat it in terminal, paste it in an email, on the web, etc.) would be wrong — and it’s not easily fixable, e.g. by piping the text through something like expand, which would normally fix presenting a file with the wrong tab size.

But the actual editing mode might be useful to have. I’ll need to give it some further thoughts.

I have considered expanding the current smart tab behavior so that if tab is pressed while at the end of the line (rather than start) it would insert enough padding to align with what’s on the line above – I am however skeptical about this going to “feel right” instead of just getting in the way. But it’s worth doing some prototyping.

In a follow up Drew McLellan writes:

I use tabs for aligning assignment blocks, and so often find myself going back up to add extra tabs when the left side of the assignments becomes longer than I expected.

Daniel Käsmayr points to column selections as something which does ease this (and indeed it does, well, technically that would be column typing) but there actually is a TextMate command to align equal signs in a block by Chris Poirier.

Unless Chris objects, I will probably include this in the default source bundle, seeing how this is a frequent task done by people who like their assignment blocks aligned.

categories General

9 Comments

I have considered expanding the current smart tab behavior so that if tab is pressed while at the end of the line (rather than start) it would insert enough padding to align with what’s on the line above — I am however skeptical about this going to “feel right” instead of just getting in the way. But it’s worth doing some prototyping.

That behaviour would have been very welcome when I switched from (X)Emacs, but hopefully I’ve gotten it out of my system by now. :-)

Mmmm… Sounds nice

I’m all for making the editing experience slicker. <rant> This sounds like a lovely excuse to finally force my coworker into using tabs.

Just because spaces are the norm for Ruby doesn’t mean you should use them everywhere. </rant>

04 July 2006

by Anonymous

Actually, it’s not nice. Elastic tabs need to apply heuristics where you want your tabs - I’d really prefer my computer doesn’t guess on my formatting preferences.

And with any decent editor, there is no spaces/tabs problem. You agree on the number of spaces a tab represents, and the editor converts between the two at save/load time.

Nick is basically solving the wrong problem. If you’re concerned with improving the presentation of your source code, you need to base it on the syntax tree behind the source, not on spaces or tabs.

Hey elastic tabs are great! I don’t see any problem in at least supplying the option for them in the tab size status bar menu. As long as they can be turned off, then I can happily use them while complainers like “anonymous” above can turn them off.

I think these are fantastic.

UI would have to be included to ensure that the “guessing” can be controlled, but as long as that’s done, it is an option I would love to see.

Does TextMate already store per-file metadata (either in another fork, or in its own preferences?)

If so, perhaps the file text could be saved with spaces or tabs in the traditional style, but with the necessary info to convert them back into elastic tabs at load?

19 August 2006

by Per Wigren

My favourite programmers’ editor in the early 90s (GoldED for the Amiga) had a simpler variant. When you press TAB at the beginning of a line it will jump to where the previous line start. Pressing it once again will indent X columns more. Each time you press TAB in the middle of a line it will align to a word in the above line.

My personal solution to the TAB mess (in projects I control) is to use TAB for indention and spaces for alignment. If you want to align some text to the middle of the previous line, use the same amount of TABs as the previous line, then continue by using spaces until it is aligned correctly. This has the nice side-effect that each programmer can choose her level of indention without screwing up the source code for others.

02 October 2006

by milkfilk

He explicitly calls it elastic tabSTOPS not elastic tabs. He also explicitly says not to call it elastic tabs (at the bottom).

Fantastic idea. Abstract the tab character from the font. Might be able to use proportional fonts again. Although, this would have to be a standard feature across all text editors (including really old ones), which is not likely.

I’d like something in TextMate that’s like the Align module in vim.

http://mysite.verizon.net/astronaut/vim/align.html

It is very customizable and powerful. A normal use for me is to align the ‘=’ signs in multiple lines of code, but it goes way beyond that. Another of my everyday uses is to reformat lines in the current selection by the white space, which basically makes columns of the text, again really useful for looking at assignments of variables. Any variance in a line will stand out.

Other times I’ll want to align all the ‘{}’ or ‘[]’ or ‘()’ pairs in assignments, again because it makes differences in the lines stand out.

There’s a whole set of options allowing left, right, center alignment, multiple columns, aligning on different characters depending on which column it’s on, etc. That functionality is one of the most powerful things I like about vim, and miss in TextMate.

GregF: Try ⌃⌘T and enter “align” and you’ll see TextMate does have an “Align Assignments” function (in the Source bundle).

Also have a look at the Commands section of the manual. Writing alignment functionality should be simple, granted you know how to align the text :)