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

Enable config for auto-pairs #992

Closed
python128 opened this issue Nov 6, 2021 · 4 comments · Fixed by #1624
Closed

Enable config for auto-pairs #992

python128 opened this issue Nov 6, 2021 · 4 comments · Fixed by #1624
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-good-first-issue Call for participation: Issues suitable for new contributors

Comments

@python128
Copy link
Contributor

Describe your feature request

I feel it would be better if we could add our own set of auto-pairs in config.toml..
Eg:

"auto-pairs" = { ["<", ">"], ["'", "'"] }

or something like the above.

It would be helpful for those who use such combinations regularly.

@python128 python128 added the C-enhancement Category: Improvements label Nov 6, 2021
@kirawi kirawi added A-helix-term Area: Helix term improvements E-good-first-issue Call for participation: Issues suitable for new contributors labels Nov 6, 2021
@pickfire pickfire closed this as completed Nov 7, 2021
@pickfire pickfire reopened this Nov 7, 2021
@pickfire
Copy link
Contributor

pickfire commented Nov 7, 2021

I wonder if this should affect the existing match?

@python128
Copy link
Contributor Author

I suppose it should overwrite (if any) the hard-coded pairs..

@dead10ck
Copy link
Member

If folks don't mind a kind of slow pace, I'd like to take a crack at this and #1014. I've been looking over the basics of the code base, and I think I'm at a place now where I could work on this. I just don't have a ton of free time, so it may be days between bits of work.

If anyone sees this and gets impatient, please feel free to go your own way independent of me.

dead10ck added a commit to dead10ck/helix that referenced this issue Nov 23, 2021
@dead10ck
Copy link
Member

I wonder if this would be more appropriate as a language config. There are some languages that have unusual pairings, especially templating languages like Jinja's {% %}. Additionally, we may want a config option that somehow expresses when not to insert an auto pair, such as Rust's lifetime annotations.

The latter might have some interesting cases to consider. The Rust lifetime annotations in particular are a good case study. The simple obvious lexical way we could avoid an unwanted auto closure, which is mentioned in the comments already, would be to check if it's preceded by a < or &, and this might well be a good starting point. This could have a config like:

[[language]]
name = "rust"
scope = "source.rust"
...
[auto-pairs]
"(" = ")"
'"' = '"'
'<' = '>'
"'" = { close = "'", except_prefixes = ["<", "&"]
...

But this wouldn't completely cover all cases where it could happen, e.g. it would not help

fn foo<F: Display + 'a>(f: F) { ... }

So I wonder if it wouldn't be possible to make use of tree-sitter to help be aware of meaningful context, so instead of saying "except when preceded by these tokens", we could say "except when inside a generic type parameter or a reference type", and it could look something like:

[auto-pairs]
"(" = ")"
'"' = '"'
'<' = '>'
...

[auto-pairs."'"]
close = "'"
except_when_inside = ["type_parameters", "reference_type"]

If this seems like a good idea, I'll probably try the lexical option first, as that seems like it might be easier, but the second might also be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-good-first-issue Call for participation: Issues suitable for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants