Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This 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?



Well, 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.


That 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.


"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-javascr...

It seems realigning each line is not that simple.


That's hardly the point now is it? You knew exactly what the expression I used means in this context.


I've no idea what "simply indenting the whole line" could mean other then "simply indenting the whole line". :)


Elastic tab stops is actually orthogonal to this. Aligning elastic tab stops is easy (minor complications caused by blank lines), knowing how many tab stops to put in is where those 27 000 lines of lisp come in.


I use align-regexp for equal signs and end-of-line comments occasionally.


In some modes (e.g. C mode, plain text mode, several others), yes, though it's usually turned off by default. (I find it really distracting.) Usually, it automatically indents when you type a newline, add an opening or closing brace, an if statement, etc. The re-indent-as-you-go behavior seems to be used most in C mode, because you can specifically configure your indent style (http://en.wikipedia.org/wiki/Indent_style).

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.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: