-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarification on tab indentation rules #255
Comments
Probably we should add something about this. I am somewhat embarrassed to say that djot.js does something fairly crude: // move parser position to first nonspace, adjusting indent
skipSpace(): void {
const subject = this.subject;
let newpos = this.pos;
while (isSpaceOrTab(subject.codePointAt(newpos))) newpos++;
this.indent = newpos - this.startline;
this.pos = newpos;
} which amounts to a tab stop of 1! I guess I'd be inclined to use a tab stop of 4 in computing this. (That's a bit different from treating a tab as four spaces, since SPACE + TAB and TAB might both put you in the same column.) The code would have to be modified a bit. Anyone have feedback on this? |
I believe for djot it only matters in the following two cases, and even then only when the actual tab stop is other than what djot assumes AND there is inconsistent use of spaces vs tabs: (
If tabs are used consistently, either because the writer is disciplined or the editor automatically converts spaces to tabs, it doesn't matter if the tab stop differs from djot's assumption:
The last observation suggests an out-of-box idea: interpret a tab to mean "take me to the next level of nesting". It may be a bad idea, but throwing it out for consideration. The motivation is that it might be more resilient than a fixed value of 4? I need to sleep now :) |
That's more or less how it works now. And, as you say, it won't cause a problem if tabs are used consistently and people don't put spaces before tabs. But that in practice people aren't consistent, so I think a tab stop would be less confusing. |
I was hoping for there to be some clarification on the rules for parsing indentation that includes tabs. I am currently (attempting, we'll see if I get far) to implement a parser for tree-sitter, and I was unsure if I should follow what commonmark does, and "treat" a tab as four spaces when handling indentation levels, or if it somehow differs in djot.
The text was updated successfully, but these errors were encountered: