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

Expose delimiters for uri_autolink #109

Open
musjj opened this issue Jul 7, 2023 · 7 comments
Open

Expose delimiters for uri_autolink #109

musjj opened this issue Jul 7, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@musjj
Copy link

musjj commented Jul 7, 2023

I want to make a query to conceal the delimiters for uri_autolink (the angle brackets in <https://www.google.com>), but the delimiters are not exposed in the tree.

For example for emphasis markers, you have this tree:

emphasis [12, 2] - [12, 8]
  emphasis_delimiter [12, 2] - [12, 3]
  emphasis_delimiter [12, 7] - [12, 8]

Can we have something similar for uri_autolink?

@musjj musjj added the enhancement New feature or request label Jul 7, 2023
@clason
Copy link
Collaborator

clason commented Jul 14, 2023

If you're using :InspectTree, you need to toggle anonymous nodes:

(section) ; [1:1 - 2:0]
 (paragraph) ; [1:1 - 2:0]
  (inline) ; [1:1 - 24]
   (uri_autolink) ; [1:1 - 24]
   "<" ; [1:1 - 1]
   ":" ; [1:7 - 7]
   "/" ; [1:8 - 8]
   "/" ; [1:9 - 9]
   "." ; [1:13 - 13]
   "." ; [1:20 - 20]
   ">" ; [1:24 - 24]

so you can just match them literally.

@musjj
Copy link
Author

musjj commented Jul 14, 2023

Hmm, is there a way to match literal characters in treesitter queries? I tried:

(uri_autolink
  [
    "<"
    ">"
  ] @conceal
  (#set! conceal ""))

But it's giving me errors.

@clason
Copy link
Collaborator

clason commented Jul 14, 2023

they're not children of uri_autolink, so you'd have to write a more complicated query using anchors

@musjj
Copy link
Author

musjj commented Jul 14, 2023

I tried to use match?, but it doesn't really help because it will still apply @conceal to the whole node. Is there really a way to apply it partially? I also tried offset!, but I don't think you can capture the individual delimiters this way.

@clason
Copy link
Collaborator

clason commented Jul 14, 2023

Yes, you need to capture the anonymous nodes themselves. You might need two individual queries, one for < and one for >. (#offset! could help with that).

Of course, you could also make a PR adding uri_autolink_delimiter nodes to the grammar.

@MDeiml
Copy link
Collaborator

MDeiml commented Jul 30, 2023

I think implementing a uri_autolink_delimiter would be quite complex, so I recommend sticking with the #offset! plan. If I see correctly though offset doesn't quite do what you want so the best way to go is probably to write your own directive.

@clason
Copy link
Collaborator

clason commented Jul 30, 2023

There's also #gsub! for more complex transformations. (Not cheap, though!)

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

No branches or pull requests

3 participants