Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Conversation

@chfritz
Copy link
Contributor

@chfritz chfritz commented Jan 11, 2016

Previously the logic lacked handling of multiple matches of the
increase/decrease regexs, so things like the following javascript
would not be handled correctly (the last line would be indented).

if (test) {
  foo({a:1
  })};
var t = "this should be at indentation 0";

Fixed that.

Also revisited the logic regarding decreaseIndent and
decreaseNextIndent. It did not seem very logical that decreaseIndent
did not correspond to increaseIndent: decreaseIndent regarded the
current line whereas increaseIndent regarded the next line (just like
decreaseNextIndent). For that reason I renamed decreaseIndent to
decreaseThisIndent and decreaseNextIndent to decreaseIndent. This way
we also avoid a whole lot of issues related to the concept of
decreaseNextIndent, because most of the language packages I looked at
have not yet adopted it but the semantics of decreaseIndent had
changed. So now the semantics of decreaseIndent is back to what it was
and decreaseThisIndent is the new concept.

Also now using the tokenized line to determine whether a in-/decrease
pattern appears within a quoted string (and ignoring it in that case),
rather than requiring regexes for checking whether or not the
occurrence is within a quoted string or not -- the examples I saw for
that were wrong, too (e.g., things like /} [^"] / are non-sense,
because things like } var x = "hey" are perfectly fine). One really
needs to reason about balanced quotation to get it right, and the
tokenizer already does that for us, so let's use it rather than
reinventing the wheel. The decrease/increase regexes can now be much
simpler in the language packages.

Previously the logic lacked handling of multiple matches of the
increase/decrease regexs, so things like the following javascript
would not be handled correctly (the last line would be indented).

if (test) {
  foo({a:1
  })};
var t = "this should be at indentation 0";

Fixed that.

Also revisited the logic regarding decreaseIndent and
decreaseNextIndent. It did not seem very logical that decreaseIndent
did *not* correspond to increaseIndent: decreaseIndent regarded the
current line whereas increaseIndent regarded the next line (just like
decreaseNextIndent). For that reason I renamed decreaseIndent to
decreaseThisIndent and decreaseNextIndent to decreaseIndent. This way
we also avoid a whole lot of issues related to the concept of
decreaseNextIndent, because most of the language packages I looked at
have not yet adopted it but the semantics of decreaseIndent had
changed. So now the semantics of decreaseIndent is back to what it was
and decreaseThisIndent is the new concept.
Previously the logic lacked handling of multiple matches of the
increase/decrease regexs, so things like the following javascript
would not be handled correctly (the last line would be indented).

if (test) {
  foo({a:1
  })};
var t = "this should be at indentation 0";

Fixed that.

Also revisited the logic regarding decreaseIndent and
decreaseNextIndent. It did not seem very logical that decreaseIndent
did *not* correspond to increaseIndent: decreaseIndent regarded the
current line whereas increaseIndent regarded the next line (just like
decreaseNextIndent). For that reason I renamed decreaseIndent to
decreaseThisIndent and decreaseNextIndent to decreaseIndent. This way
we also avoid a whole lot of issues related to the concept of
decreaseNextIndent, because most of the language packages I looked at
have not yet adopted it but the semantics of decreaseIndent had
changed. So now the semantics of decreaseIndent is back to what it was
and decreaseThisIndent is the new concept.

Also now using the tokenized line to determine whether a in-/decrease
pattern appears within a quoted string (and ignoring it in that case),
rather than requiring regexes for checking whether or not the
occurance is within a quoted string or not -- the examples I saw for
that were wrong, too (e.g., things like /} [^"] / are non-sense,
because things like '} var x = "hey"' are perfectly fine). One really
needs to reason about balanced quotation to get it right, and the
tokenizer already does that for us, so let's use it rather than
reinventing the wheel. The decrease/increase regexes can now be much
simpler in the language packages.
@chfritz
Copy link
Contributor Author

chfritz commented Jan 11, 2016

This new logic is best tried with the following PR for javascript: atom/language-javascript#301.

@alexandernst
Copy link

I don't usually post +1 answers. But, please oh please, +1 for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saying, YAML also has string.unquoted, so you might want to adjust for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I didn't know about that. However it seems that unquoted strings must not contain any special characters, so I'm not sure I can think of a language and example where this would be necessary. Can you think of a good test case (incl. language) we could add for that?

This way, if decreaseThisIndentPattern is not specified, we fall back
to the previous name for that pattern (decreaseIndentPattern), while
still being able to change the semantics for decreaseIndentPattern.
This is because we never outdent more than one on the
decreaseThisIndentPattern -- which is what the behavior used to be
(and which has some problems when closing more than one scope).
@chfritz
Copy link
Contributor Author

chfritz commented Jan 12, 2016

Found a way to make the transition smoother. Will create a new PR.

@chfritz chfritz closed this Jan 12, 2016
@chfritz
Copy link
Contributor Author

chfritz commented Jan 12, 2016

The new PR is #10384 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants