6 ms·
A 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) somewher
by newt0311 18y ago
A 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]
- deleted 18y ago[deleted]
- deleted 18y ago[deleted]
- mechanical_fish 18y agoWell, emacs lets you hit tab anywhere on a line, at which point it reindents the line to the appropriate depth, depending on the syntax of the current and preceding lines. I'm pretty sure that most of the modes I use don't look at lines after the current line when performing indentation, but I'm not sure there's any reason why they couldn't. If you want to reformat an entire block of code in this way, you can set a region (the emacs equivalent of "selection") and then press Ctrl-Meta-\, which stands for "indent-region". Then either the whole region will magically become properly indented, or emacs will yell at you because your XHTML syntax is broken (at least, that's what just happened when I tried this in XHTML mode. Every major mode can be slightly different.) I know that emacs supports all the indentation tricks shown in this guy's example ... except that I don't know about the end-of-line comments. I never use end-of-line comments.
- ryanbooker 18y agoThat sounds like it is simply indenting the whole line... not reformatting the actual block... i.e. respacing internally within the line. Which is what the elastic tabstops is doing. It's not simply realigning each line. It's reformatting the entire block, realigning ALL tabstops within the lines, so that blocks of text are all positioned within a grid.
- d0mine 18y ago"simply indenting the whole line" </quote> "the package cc-engine (including its cc-* helper packages) bundled with GNU Emacs 22 is approximately 27,000 lines of lisp code, and it's all dedicated to indentation." </quote> http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascr... It seems realigning each line is not that simple.