Hacker News new | ask | show | jobs
by kazinator 2547 days ago
Tabs could plausibly work if the editors were smart enough to treat this:

    myFunctionThatDoesStuff(someArgument,
                            andThisCalculatedOne(anArgumentThatMeansSomething,
                                                 anotherWordyName));
as being all at the same indentation level. If this is at indentation level 2 then all these lines should start with two tabs. All whitespace after those tabs should be spaces. Then you can adjust the tab size without spoiling the relative alignment.

The editor has to understand the language fairly well. (In the case of C or C++, it also has to recognize preprocessor lines and treat them specially, as well as certain elements like goto labels that are out of indentation.)

It won't work in Lisps, because in Lisp, nested expressions have their own internal indentation which can be relative to alignment:

  (long-function-name (lambda (arg)
                        (aligned ...)
                        (stuff ...)))
Basically the only thing that could work 100% would be the original typewriter/TTY/terminal concept of movable tab stops. The editor would grok each expression, and then set up custom tab stops for each line individually:

  (long-function-name (lambda (arg)
                        (let ((var ...))
                          (stuff arg arg
  v                   v v v      v
                                 arg))))
The v's indicate the tab stops for the last line, so five tabs are used. The algorithm for discovering these tab stops doesn't seem overly complicated. We shoot a ray upward at column zero. Whatever it intersects with is the anchor line. We then look for the first tab stops in the anchor line by moving the vertical ray. By this process we discover the ( in (long-function-name, and the ( on (lambda. After that, our vertical hit test encounters the (let line, so that yields a tab stop. If that weren't there, then the (arg) would be the next stop.

Basically tabs should intelligently be based on preceding material, as if an invisible helper were setting tab stops on our typewriter.

One problem with this is that any piece of software that has to format the code has to implement the same thing, exactly.