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

Indent JSX in Emacs 27 outside js2-minor-mode #529

Open
jacksonrayhamilton opened this issue Jun 4, 2019 · 5 comments
Open

Indent JSX in Emacs 27 outside js2-minor-mode #529

jacksonrayhamilton opened this issue Jun 4, 2019 · 5 comments

Comments

@jacksonrayhamilton
Copy link
Contributor

jacksonrayhamilton commented Jun 4, 2019

JSX indentation is currently only available if

  • the user is using Emacs <26 and enables js2-jsx-mode (and this indentation is rather poor), or
  • the user is using Emacs >=27 and uses js-mode with js2-minor-mode enabled (this indentation is better), or
  • the user installs rjsx-mode.

It would be nice if in Emacs 27, JSX indentation would be available in plain old js2-mode as well.

Also, currently in Emacs 27, js2-jsx-mode no longer provides any indentation support (since indentation in Emacs 27 relies on certain text properties set by js-mode’s syntax-propertize-function, which JS2 does not use; we temporarily decided against that in #523). This is a regression.

If #527 is ever implemented, then during the parse, we can set the text properties needed by Emacs 27’s JSX indentation code. Then JSX indentation should work again. This issue proposes making that change. (Eventually, we may move over to using syntax-propertize for setting indentation-related text properties.)

Before we go forward with that, we’d like to ensure that this change will be compatible with derivative modes (like @felipeochoa’s rjsx-mode) which set syntax-table properties using the AST. Of particular interest is this line from rjsx-mode.

@felipeochoa
Copy link
Contributor

felipeochoa commented Jun 4, 2019 via email

@dgutov
Copy link
Collaborator

dgutov commented Jun 4, 2019

I think, if rjsx-mode is used (or merged, in any shape or form), the relevant code could be well-positioned to apply the necesarry syntax-table properties by itself.

The ones that make js-indent-line work with JSX in Emacs 27.

@jacksonrayhamilton
Copy link
Contributor Author

I think, if rjsx-mode is used (or merged, in any shape or form), the relevant code could be well-positioned to apply the necesarry syntax-table properties by itself.

The ones that make js-indent-line work with JSX in Emacs 27.

Yeah, that’s the alternative course of action I referred to. If we do that, there’s the potential for the properties to be applied more accurately and in better alignment with the AST, at the expense of needing a full parse to figure out where to put the properties.

syntax-propertize could be faster, being chunk-based. (Then again, it could also slow things down by adding more processing overhead overall on every keystroke.) Also, it could be easier to just delegate to js-mode rather than write more code. Decisions, decisions.

@dgutov
Copy link
Collaborator

dgutov commented Jun 6, 2019

at the expense of needing a full parse to figure out where to put the properties

The full parse will happen anyway, because we want the AST to be available.

syntax-propertize could be faster, being chunk-based

Could be, in certain respects. However, it's only available in Emacs 27. Even just for backward compatibility reasons, I think we should wait in adopting this approach until 27 is released and widely available.

@jacksonrayhamilton
Copy link
Contributor Author

Could be, in certain respects. However, it's only available in Emacs 27. Even just for backward compatibility reasons, I think we should wait in adopting this approach until 27 is released and widely available.

Yeah, this is a good argument for using the AST. I’ll update the OP to reflect this.

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

No branches or pull requests

3 participants