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

Rewite indentation engine #53

Merged

Conversation

taku0
Copy link
Contributor

@taku0 taku0 commented Jan 11, 2020

New indentation engine, based on that of swift-mode.

See doc/indentation_logic/pages.pdf for its design.

Pros:

  • Better indentation for most cases
  • Electric indentations
  • Comprehensive tests

Cons:

  • Complex
  • Hard to read (sorry for a monolithic big commit)
  • Hard to maintain
  • Slower; indent-region on entire sample.kt takes a couple of seconds

Options:

  • Merge this branch as is (I wish so) or with minor tweaks.
  • Remove codes for corner cases and make it works only for practical cases.
  • Reject this PR and fix problems with other method.

@gregghz
Copy link
Member

gregghz commented May 6, 2020

do you have any sense of what can be done about performance? I'd say a couple seconds for one file might be too slow.

@taku0
Copy link
Contributor Author

taku0 commented May 9, 2020

Two measures may improve the performance:

  • Caching syntactic information
  • Moving some code from lexer to indentation logic

Caching syntactic information

When indenting a line, we analyze the text around the point. In most cases, analyzing a few lines is sufficient, but it may analyzes more lines in some cases. Caching analyzed information may improve the performance when indenting a bulk of lines. Actually, we analyze the position of brackets eagerly and cache them. Caching more information would complicate the code and might be slower for simple cases.

Moving some code from lexer to indentation logic

The code is separated into two layers: the lexer and the indentation logic.

The lexer is a pair of functions, kotlin-mode--forward-token and kotlin-mode--backward-token. For most cases, it just looks a char or a word, but for some tokens, it scans around for a few lines to distinguish ambiguous token types. The distinction of the types is not always required in the indentation logic, so moving some code into the indentation logic may improve the performance. It will complicate the indentation logic and may violate the abstraction.

@knobo
Copy link

knobo commented Oct 14, 2021

Has development of this patch stopped?

@taku0 taku0 force-pushed the rewite-indentation branch from 8f5e6f8 to 30a867d Compare February 23, 2022 06:28
@taku0
Copy link
Contributor Author

taku0 commented Feb 23, 2022

@knobo
I have rebased on the master branch and resolved conflicts.
This PR doesn't address Kotlin language updates, if any, since Jan 2020.

@taku0 taku0 force-pushed the rewite-indentation branch from 4b32eb1 to 132e7c1 Compare February 23, 2022 07:22
@taku0
Copy link
Contributor Author

taku0 commented Feb 23, 2022

Add support for value class.
https://kotlinlang.org/docs/inline-classes.html

@taku0 taku0 force-pushed the rewite-indentation branch from 132e7c1 to cc105de Compare February 23, 2022 07:56
@taku0 taku0 force-pushed the rewite-indentation branch from cc105de to 3dc0718 Compare July 10, 2022 07:25
@taku0
Copy link
Contributor Author

taku0 commented Jul 10, 2022

Rebased and fixed conflicts.

@pyloolex
Copy link

@taku0, did you get a chance to verify #74?

@taku0 taku0 force-pushed the rewite-indentation branch from 3dc0718 to 063f26d Compare January 11, 2023 11:36
@taku0 taku0 force-pushed the rewite-indentation branch from 30510b2 to 70de256 Compare January 15, 2023 04:50
@taku0
Copy link
Contributor Author

taku0 commented Jan 15, 2023

Is there any possibility that this PR will be merged?
I have improved performance so that indent-region on entire sample.kt takes only 0.164911s now.
Maintainability could still be a problem. If you add me to Emacs-Kotlin-Mode-Maintainers, I'll be glad to maintain it.

@gregghz
Copy link
Member

gregghz commented Jan 17, 2023

@taku0 Thanks for this work. I'm happy to add you as a maintainer. Myself and @russel haven't been very active here. I'll give @russel a few days to chime in, but if i don't hear anything I'll go ahead and add you as an owner/maintainer.

@gregghz gregghz merged commit 3a84689 into Emacs-Kotlin-Mode-Maintainers:master Jan 17, 2023
@taku0
Copy link
Contributor Author

taku0 commented Jan 23, 2023

@gregghz Thank you. I'm working on GitHub Actions for tests and linter for each Emacs versions. After that, I will investigate #55. Maybe porting code of swift-mode will fix it.

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

Successfully merging this pull request may close these issues.

4 participants