tamzinblake / js3-mode

A chimeric fork of js2-mode and js-mode
GNU General Public License v3.0
181 stars 13 forks source link

Incorrect indenting after var statements sometimes #4

Closed tamzinblake closed 13 years ago

tamzinblake commented 13 years ago

After a var statement (in cases where one is not using comma-first), lines are sometimes indented incorrectly if the js2-mode parser hasn't caught up yet. The current workaround is:

  1. notice this happens
  2. wait a second
  3. press tab again

In the future, this behavior shouldn't happen at all.

tamzinblake commented 13 years ago

An instance of this problem (was issue #3)

What happens:

var error_text = {
    code_label: 'Error Code: ',
    http_label: 'HTTP error',
}

What should happen:

var error_text = {
  code_label: 'Error Code: ',
  http_label: 'HTTP error',
}
tamzinblake commented 13 years ago

The previous strategy I was going to use to fix this was:

However, the parser is way too slow, so it would be really annoying if waiting for the parser to catch up was the usual behavior. Instead, the problem must be solved with more regexes!

tamzinblake commented 13 years ago

It is officially impossible to determine whether an identifier belongs to a preceding var statement without actually parsing the JS. This issue is closed - if you want better behavior, either repeat the 'var' statement or use comma-first notation which is insanely easier to line up correctly.

tamzinblake commented 13 years ago

Turns out we really just needed to reparse before indentation. Who knew?