8 ms·
Elastic Tab Stops: A Better Way to Indent and Align Code
- qhoxie 18y agoI have been using this is gedit and it really does make a world of difference. I used to emulate which just led to greater overhead and often poor code formatting.
- Stabback 18y agoThis may just seem silly and superficial, but I find the demonstration picture with colored indenting would actually be quite useful. Perhaps not coloring the code itself but more the number of tabstops until the code.
- axod 18y agoHow many people here use tabs? I find them pure evil. If I press left/right arrow, I want to move one character/space. Not 4/8. edit: obviously I setup tab to insert 4 spaces etc
- babo 18y agoI prefer tabs way more than spaces. It's faster to indenting back and better for search regexps, quite an important point for me. With Vim it's easy to retab a text if needed anyway.
- akkartik 18y agoWith vim you need sts. It lets you you backspace over spaces just like tabs. Now I never need tabs anymore. I don't understand your point about search regexps.
- babo 18y agoThanks for the softtabstop tip, that was a life saver as I'm forced to used spaces. For the regexps I'm used to search for tabs to distinguish lvalues but two spaces are the same for that patterns.
- orib 18y agothe indenting commands work the same way in vim with tabs or spaces -- either select a visual range and hit >, or hit >a} to indent a brace delimited block, or... well, you know the drill. the > or < compose in the same way you'd expect any other vim command to do.
- fuglymonkey 18y agoI'm normally very anti-tabs, but if vim supported this I'd switch in an instant.
- aston 18y agoIf you watch the screencast, it offers an option to save as spaces, so the "I hate tabs" argument is kind of irrelevant. Unless you also hate tabstops.
- markbao 18y agoTextMate. Now.
- unalone 18y agoAgreed, but for Coda.
- elai 18y agoUnfortunately, not really http://blog.macromates.com/2006/elastic-tabs/ http://blog.macromates.com/2006/elastic-tabs/ Who else has noticed that textmate has stagnated from 2006-2008
- sfamiliar 18y agomost textmate dev nowadays is being done in bundles. while the elastic tabs thing doesn't work quite right in textmate, textmate's tabbing (soft-tabs to convert tabs to spaces, backspace to go back a 'tab', autoindent based on syntax conventions) is pretty satisfactory. one thing it doesn't do that looks REALLY appealing with elastic tabs is multi-tabbing, especially to appropriate spacing on multiline parameter lists. i'll add 'write a bundle to do this stuff' to the long list of projects that fall behind the startup.
- tlrobinson 18y agoTextMate already has indentation issues. Why is it that every time I paste something it indents it one more tab? i.e. if I paste something 3 times I end up with something like this: Hello world Hello world Hello world
- newt0311 18y agoA better way to indent and align code: Use emacs and tell it to indent in any way you want. PS. Make sure you have (setq-default indent-tabs-mode nil) somewhere in your .emacs
- kirubakaran 18y agoYeah! It is so easy to line up columns in emacs. Just hit tab and emacs takes the cursor to the correct column.
- abstractbill 18y agoExactly. I'm honestly surprised there are still editors that don't do this.
- ajross 18y agoThat was my thought too: a cute hack in 2008 for a problem that was cleanly solved a quarter century earlier by software that remains popular to this day. I know it's easy to laugh at stuff like this, and I'm sure someone will use this and like it. But still, guys: software development is a mature field. The realm of useful tools for editing code is pretty tapped out. The good ideas lie elsewhere.
- elai 18y agoThat's a bit reminiscent of "you just need 512k of RAM!"
- ryanbooker 18y agoThis elastic tabs thingy, REINDENTS everything based on what you type on the next line... keeping your code formatted in consistent blocks. Honest question: Is that what emacs does?
- deleted 18y ago[deleted]
- brendano 18y agothanks mojombo!
- nex3 18y agoThis is even worse than forcing people to set their tab width to a certain value to read your code. If their editor isn't set up for it, they don't just have to change a setitng; if they're lucky, they just have to install a plugin, but if there isn't one available, they have to change editors entirely.
- Sujan 18y agoOr live with ugly code. Like they probably did before. But you're right, this is a thing where I also see a big problem. It's not downward compatible.
- cstejerean 18y agoActually I find the code produced by this elastic tabstop to be far uglier than the alternatives.
- wastedbrains 18y agoAwesome built in demo, made it way more interesting to get to play around with the idea a bit.
- huhtenberg 18y ago> While both strategies can be used if all of a project's programmers can agree on how many spaces wide a tab should be A better strategy that works just fine for a lot of developers (e.g. Linux kernel crowd) is to use tabs to indent the start of the line only. No tabs inside of the line, only spaces. Very simple and works really well.
- nihilocrat 18y agoI remember reading this several years ago. It's not something that is 100% implemented by configuring emacs or vi properly: read the entire article slowly. I'm surprised I haven't heard any Python coders piping up. We pick spaces or tabs, and stick with it; otherwise, our code doesn't run. Mixing tabs and spaces is pure evil. I prefer spaces, because a space is a space and will display as exactly one space in any text editor.
- arthurk 18y agoEven if you use tabs, the Python compiler will convert a tab to 8 spaces internally.
- njharman 18y ago> I'm surprised I haven't heard any Python coders piping up. Because either indentation is a non-issue for you or you don't use Python. Any decent editor solves this problem to the 98-99% mark. There's lots more interesting things to do than dick around with that 1-2% Python forces you to keep your indentation correct and sane so it's never so whacked you need special tools to deal with it. Proper indenting is subconscious like other languages ';' at end of line or parens around expressions in if/for. That is when it isn't automatically handled by your editor...
- DougBTX 18y agoWell, any editor with fixed width fonts, which the author of the article would like to move away from.
- hhm 18y agoMathematica has very nice auto-tabbing; not exactly what's shown here but something very similar, and even better as it goes beyond tabs: it also makes changes on the font depending on context.
- rflrob 18y agoHas anyone tried this with large source code files? I suppose, in the long run, if your source has too big of an overhead to implement this, you're probably doing it wrong, especially considering the relative power of computers to the amount of RAM raw text should take up.