Skip to content
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

Indenting can be slow #39

Open
tamzinblake opened this issue Aug 24, 2011 · 8 comments
Open

Indenting can be slow #39

tamzinblake opened this issue Aug 24, 2011 · 8 comments

Comments

@tamzinblake
Copy link
Owner

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
Copy link

dgutov commented Oct 26, 2011

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
Copy link
Owner Author

@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
Copy link
Owner Author

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
Copy link

dgutov commented Oct 26, 2011

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
Copy link
Owner Author

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
Copy link

sanbor commented Mar 29, 2013

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 added a commit that referenced this issue Jun 25, 2013
Per sanbor's suggestion

See #39
@tamzinblake
Copy link
Owner Author

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

@sanbor
Copy link

sanbor commented Jun 26, 2013

@thomblake Amazing, thank you very much, I'm starting to use it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants