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

Paren matching in code editor #1075

Closed
technomancy opened this issue May 4, 2020 · 7 comments · Fixed by #1076 or #1077
Closed

Paren matching in code editor #1075

technomancy opened this issue May 4, 2020 · 7 comments · Fixed by #1076 or #1077
Assignees
Labels
editor: code Issues related to code editor enhancement Improvement of existing feature or adding something new

Comments

@technomancy
Copy link
Contributor

When I'm using TIC without an external editor, it's great, but one difficulty I have is with matching parentheses up. In other editors sometimes when you put the cursor on a paren, it colors the matching paren on the other side in a way that helps you know which correspond to which.

Do you think this would be a good addition in the TIC code editor? I could give it a shot if so.

@nesbox
Copy link
Owner

nesbox commented May 4, 2020

I think it sounds good, pls give it a shot if you have time.
Thank you.

@technomancy
Copy link
Contributor Author

I made a lot of progress on this; I have an initial implementation here: technomancy@f383b45

It works in the case of having nested delimiters in between the outer ones; for instance hello(1, 2, abc[a()], {}) will match the outer parens, and the ones on the inside won't interfere.

However, I got stuck on two problems:

  • If the cursor is inside a string or comment, it shouldn't even attempt to find a match.
  • If it is looking for a closing delimiter, it should skip matches which are inside a string or comment.

If I had a function like isInsideString(Code* code, char* position) and isInComment(Code* code, char* position) then this would be easy, but I could find nothing in code.c that knows about strings or comments other than the parseCode function, which does not seem reusable. Do you have any suggestion for how to proceed?

I am very inexperienced at writing C, so please let me know if you have any other suggestions for making the code better too.

@technomancy
Copy link
Contributor Author

Also, unrelated to this change, I would like to get some changes to Fennel in before the 0.80.0 release goes out; do you think that will be soon or do we have a bit more time to get that ready?

@nesbox
Copy link
Owner

nesbox commented May 5, 2020

If I had a function like isInsideString(Code* code, char* position) and isInComment(Code* code, char* position) then this would be easy, but I could find nothing in code.c that knows about strings or comments other than the parseCode function, which does not seem reusable. Do you have any suggestion for how to proceed?

I think we could use code->colorBuffer to detect string or comment, but it has to be rewritten a bit. I'm going to fill the buffer with keyword types (number/string/api/...) instead of colors and it will be easier to detect and skip these parts while you're matching parentheses.

@nesbox
Copy link
Owner

nesbox commented May 5, 2020

Also, unrelated to this change, I would like to get some changes to Fennel in before the 0.80.0 release goes out; do you think that will be soon or do we have a bit more time to get that ready?

I hope we have a month at least :)

@nesbox
Copy link
Owner

nesbox commented May 5, 2020

I added syntax buffer here c98eb4a,
now you can use

if(code->syntax[pos] == SyntaxTypeComment)...

or

if(code->syntax[pos] == SyntaxTypeString)...

to determine string type.

nesbox added a commit that referenced this issue May 5, 2020
@technomancy
Copy link
Contributor Author

That's exactly what I needed; thank you!

@nesbox nesbox added editor: code Issues related to code editor enhancement Improvement of existing feature or adding something new labels May 6, 2020
@nesbox nesbox added this to the 0.80.0 milestone May 6, 2020
@nesbox nesbox linked a pull request May 6, 2020 that will close this issue
@nesbox nesbox removed this from the 0.80.0 milestone Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor: code Issues related to code editor enhancement Improvement of existing feature or adding something new
Projects
None yet
2 participants