Elastic Tab Stops: A Better Way to Indent and Align Code
nickgravgaard.com
nickgravgaard.com
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.
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...
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.
edit: obviously I setup tab to insert 4 spaces etc
I don't understand your point about search regexps.
But you're right, this is a thing where I also see a big problem. It's not downward compatible.
i.e. if I paste something 3 times I end up with something like this:
Hello world
Hello world
Hello worldhttp://blog.macromates.com/2006/elastic-tabs/
Who else has noticed that textmate has stagnated from 2006-2008
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.
PS. Make sure you have (setq-default indent-tabs-mode nil) somewhere in your .emacs
Honest question: Is that what emacs does?
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.
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.
"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-javascr...
It seems realigning each line is not that simple.
Most modes also have a command such as c-fill-paragraph that re-indents the chunk of code (e.g. function body) that the cursor is in. (Emacs refers to this behavior as "filling", so that's what to search for.) I think people use this pretty often - it's alt-Q by default.
The automatic indentation is quite good for some modes (C, Lisps in general, Python, OCaml, Lua, probably many others), but not always perfect (haskell-mode comes to mind). I think the important thing is that Emacs provides a lot of hooks for building mode-specific indentation-control functions and is not terribly difficult to extend.