surround icon indicating copy to clipboard operation
surround copied to clipboard

Don't confuse open / close in strings

Open mkleehammer opened this issue 2 years ago • 2 comments

NOTE: I've not started working on this, so if this is a problem for you, please upvote this by adding a comment or an emoji.

The current algorithm for nested pairs (those where the open and close are different, like parens and braces) simply counts open and cloes as it finds them. But it could be smarter by paying attention to the syntax of each character (ppss).

For example:

(message "finding (, huh?")
                  ---------

If the cursor is anywhere past the paren inside the string, it will incorrectly identify the underlined portion as the pair instead of matching with the first paren before "message".

For this particular case, it would work if we use syntax-ppss and note that we started outside of a string, so we should ignore the paren inside the string. Would work for skipping over comments too.

On a similar note, we could figure out which direction to search for quotes. If we are on a closing quote in a comment and the next quote is not in a comment, we should try the other direction.

mkleehammer avatar Nov 28 '23 16:11 mkleehammer

does syntax-ppss work with TreeSitter-based modes?

ckruse avatar Nov 28 '23 17:11 ckruse

Good question @ckruse. I believe it does.

I considered using tree sitter originally, but started with this code since I also use matching inside of strings and quotes.

It might not hurt to use tree-sitter if the point is not in a comment or string, however. It would be foolproof, then. I'll look into that.

mkleehammer avatar Nov 28 '23 19:11 mkleehammer