Skip to content

Support markdown scope for targeting code blocks #1992

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

Closed
fidgetingbits opened this issue Nov 3, 2023 · 10 comments · Fixed by #2410
Closed

Support markdown scope for targeting code blocks #1992

fidgetingbits opened this issue Nov 3, 2023 · 10 comments · Fixed by #2410
Labels
lang-markdown Support for the Markdown family of markup languages

Comments

@fidgetingbits
Copy link
Collaborator

It would be useful to have a scope to target markdown blocks of code inside ``` pairs. I regularly find myself wanting to chuck them, change inside them, or move out of them, and it's often in a scenario where there's no visible ` characters to use instance with.

@auscompgeek
Copy link
Member

Wouldn't change inside skis work in this scenario?

@fidgetingbits
Copy link
Collaborator Author

It doesn't work for me no.

@josharian
Copy link
Collaborator

josharian commented Nov 3, 2023

Bringing over some comments from Slack:

I do a lot of work in a templating language with no cursorless support. There are lots of paired {{ and }}. I wonder whether more general text-based support for multiple paired delimiters would be helpful. That’d also handle Python’s “”” … “””.

ya I suppose I should try a regex scope in the meantime. haven't used one before so an excuse to dabble I guess.

some general text-based support seems like it coild be good. more examples: nix language uses double ticks ''foo'' for multi-line strings, lua uses [[foo]].

@auscompgeek auscompgeek added the lang-markdown Support for the Markdown family of markup languages label Nov 6, 2023
@auscompgeek
Copy link
Member

In light of #1980, it might make sense to call code blocks "notebook cells". That'd be consistent with various literate programming formats.

@fidgetingbits
Copy link
Collaborator Author

Ya I think that makes sense.

@pokey
Copy link
Member

pokey commented Nov 7, 2023

huh that's an interesting idea. I guess one problem thing to think about is what happens if there a markdown cell in a notebook, that itself contains a code block. Arguably that could just be a nested scope, but might be surprising? Idk, generally speaking I'm in favour of fewer scopes so I think it's fine, just can't help but point out corner cases 😅

@fidgetingbits
Copy link
Collaborator Author

Has there been discussion of something like 'outside' or 'parent' modifier similar to 'inside' where you target the parent scope?

I've never used jupyter so not sure, but say you were in a cell containing markdown containing a code block but the block was big enough you couldn't see any part of the parent jupyter cell but then wanted to target it, I believe atm you couldn't?

I wonder if something like that would make this type of problem you mention slightly more natural to deal with.

This type of modifier could help in other similar situations I suppose like if you are in a big python closure and have no hats from the containing function, but want to reference it? Similar how you can jump to a class from its method.

That also raises the question in relation to your counter example: if you are in a nested language that triggers a new treesitter parser, does that show up cleanly in the node tree in a way that we could query? And even if it did, I'm not sure if/how cursorless deals with nested languages atm.

@auscompgeek
Copy link
Member

if you are in a nested language that triggers a new treesitter parser

I believe Cursorless currently doesn't support nested languages. Definitely a feature everyone wants, and potentially doable after everything is moved to tree-sitter queries…

@pokey
Copy link
Member

pokey commented Nov 8, 2023

if you are in a nested language that triggers a new treesitter parser

I believe Cursorless currently doesn't support nested languages. Definitely a feature everyone wants, and potentially doable after everything is moved to tree-sitter queries…

Almost certainly doable, and technically doesn't need to wait for everything to be moved to tree-sitter queries. But it will definitely be a big effort. Follow #409 to track the effort

Has there been discussion of something like 'outside' or 'parent' modifier similar to 'inside' where you target the parent scope?

I've never used jupyter so not sure, but say you were in a cell containing markdown containing a code block but the block was big enough you couldn't see any part of the parent jupyter cell but then wanted to target it, I believe atm you couldn't?

I wonder if something like that would make this type of problem you mention slightly more natural to deal with.

This type of modifier could help in other similar situations I suppose like if you are in a big python closure and have no hats from the containing function, but want to reference it? Similar how you can jump to a class from its method.

That's tracked in #124

@saidelike
Copy link
Collaborator

same here
image
I would like it to select the whole code snippet starting from the three backticks starting at row 3306 up to the last three backticks ending at row 3309

github-merge-queue bot pushed a commit that referenced this issue Jun 13, 2024
This is me breaking out some functionality that was part of PR #1911
since that PR has lots of work to be done and it may still benefit other
languages that get in sooner. I've applied the suggested changes from
pokey in that PR's code review.

I've also added a placeholder map for lua which uses `[[ ]]` for
multiline support as noted in PR #1962, however I realized as I went to
add it that it's not as simple as the way I did it for nix because I
can't just reuse the existing `singleQuote` entry since lua actually
uses single quotes. So this may actually be a bit harder, and reminds me
of [this
discussion](#1992 (comment)).
So before I go randomly hacking stuff I'm curious what you think the
best approach here is.

These are the comments I had left in the Nix PR about these changes:

* I called returning delimiterToText as getSimpleDelimiterMap to kind of
mirror complexDelimiterMap.

* I'm not sure is if you still want a delimiterMap.ts standalone file,
and then a getSimpleDelimiterMap.ts only for that function. Now
delimiterToText isn't referenced anywhere else, so seemed maybe okay to
keep them together.

* I also thought about adding getComplexDelimiterMap(), but atm because
complexDelimiterMap only ever uses the keys from the delimiterToText it
won't change even if the language has different values, so seemed
unnecessary. These are all things I could guess at your preferences, but
may as well ask instead.

* I also noticed leftToRightMap in that file isn't actually used
anywhere so can be deleted I think, but also not sure about doing that
as part of a totally unrelated code change, to keep commits clean.


## Checklist

- [x] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [-] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [x] I have not broken the cheatsheet

---------

Co-authored-by: fidgetingbits <[email protected]>
Co-authored-by: Pokey Rule <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-markdown Support for the Markdown family of markup languages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants