tamzinblake / js3-mode

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

Indenting can be slow #39

Open tamzinblake opened 12 years ago

tamzinblake commented 12 years ago

For JS files in excess of 100k characters, indenting a line can take a few seconds.

The interim solution is to keep your js files shorter than about 5k lines each.

dgutov commented 12 years ago

As a point of comparison, reindenting the whole buffer with mootools-core-1.3-full-nocompat.js (5368 lines) in the you-know-which version of js2-mode takes about 1.5 seconds.

tamzinblake commented 12 years ago

@dgutov Indeed - in the current version of js3-mode, 'reindenting the whole buffer' is simply not an operation to try; but indenting just doesn't work perfectly without parsing the ast. The fix might actually be to re-implement the ast parser from scratch with lisp in mind, instead of trying to use a port of Rhino. Some of the parsing might even be simplified by abstracting it out, since a lot of the subtler distinctions in the language can probably be dealt with as though they were not special cases since it's not going to be executed.

If I don't do that soon, I might just bring back some of the old regex-based code for a 'fast but not as good' config option.

tamzinblake commented 12 years ago

I'm not working fast on this bug since it doesn't actually affect my work; I tend to have js files that are very short, and then compile them later if necessary, which I heartily recommend.

dgutov commented 12 years ago

Some of the parsing might even be simplified by abstracting it out, since a lot of the subtler distinctions in the language can probably be dealt with as though they were not special cases since it's not going to be executed.

Do you have an example in mind? So far it doesn't sound like you'd need to do a full rewrite.

Rhino or no Rhino, to do 'reindent the buffer' and use the AST you'll probably need an incremental parser. Semantic has one, and they also have a JavaScript grammar for it, so you might want to look into that.

tamzinblake commented 12 years ago

This issue will be solved in the next (first!) major version of js3-mode, which will likely have another name. Expect it to have a completely rewritten parser.

sanbor commented 11 years ago

It would be nice to allow an option to indent 'by hand'. This means that when you press the tab button, you get 4 spaces (or 2 spaces or 1 tabulation character or 2 tabulation characters or whatever the user customises).

I know that a lot of people loves automatic indentation, but when it's slow, buggy, hard to customise, full of special cases, etc., I would like to have the choice to just indent by hand.

Thanks!

tamzinblake commented 11 years ago

@sanbor the latest has the option js3-manual-indentation which I think does what you were looking for.

sanbor commented 11 years ago

@thomblake Amazing, thank you very much, I'm starting to use it :+1: