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

send_code_block feature compatibility with markdown dividers #415

Open
agbocsardi opened this issue Mar 13, 2025 · 1 comment
Open

send_code_block feature compatibility with markdown dividers #415

agbocsardi opened this issue Mar 13, 2025 · 1 comment

Comments

@agbocsardi
Copy link

This is a follow up from #391 (comment)

The current send_code_block feature doesn't work as intended for Markdown code cells, delimited by triple backtics:

---
title: "Example QMD notebook"
---
## R code chunk
```{r}
print('hello')

for (i in seq(1, 5)) {
    print(i)
}
```

## Python code chunk
```{python}
print('hello')

for i in range(5):
    print(i)
```

If you define the dividers to be "```", so it would recognize either language, the issue is that in the case of both languages, the send_code_block function also sends the first line, with the language indicator attached, breaking the REPL:

In [1]: ```{python}
   ...: print('hello')
   ...: 
   ...: for i in range(5):
   ...:     print(i)
   ...: 
  Cell In[1], line 1
    ```{python}
    ^
SyntaxError: invalid syntax

The suggested solution by @frere-jacques (thanks for the sppedy reply <3) involves incrementing the start of the block by one, with some consideration for edge cases such as empty blocks, and start/end of buffer.

@agbocsardi
Copy link
Author

Current workaround I use is based on treesitter-textobjects, since the @block query works for markdown code cells:

Inside my treesitter opts:

textobjects = {
        select = {
          enable = true,
          lookahead = false,

          keymaps = {
            ['ac'] = '@block.outer',
            ['ic'] = '@block.inner',
          },
        },
      }

This way I can visually select the whole code cell, then send it over to iron.

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

No branches or pull requests

1 participant