Improving code chunk manipulation #360
Replies: 33 comments 18 replies
-
With this file:
Trying
Trying
|
Beta Was this translation helpful? Give feedback.
-
Good tx. Should be ok now. |
Beta Was this translation helpful? Give feedback.
-
I noted only one more problem, a missing feature. If we have this First child paragraph.
```{r}
xc <- 1
``` And this First paragraph.
```{r, child="child.Rmd"}
```
Second paragraph.
```{r}
x <- xc + 2
```
The value of x is `r x`. And if the cursor is over the header of the first chunk of
On the main branch, we have this: if cline:find("^```.*child *= *") then
return "chunk_child"
[...] |
Beta Was this translation helpful? Give feedback.
-
Nice, was not even aware of this feature. Should be fixed now. |
Beta Was this translation helpful? Give feedback.
-
Still not working... |
Beta Was this translation helpful? Give feedback.
-
Humm it works on my side |
Beta Was this translation helpful? Give feedback.
-
ah ok because I have an extra line. in the chunk because of my formatter. Fix incoming. |
Beta Was this translation helpful? Give feedback.
-
It's very interesting to have the fields |
Beta Was this translation helpful? Give feedback.
-
I had to change the TS query to account for empty content in chunks. Doing some tests and will send a push. |
Beta Was this translation helpful? Give feedback.
-
Testing here... There is a code that is not supported on the main branch, but is valid Quarto code: First paragraph.
```{r}
#| child: child.Rmd
xc <- 9
```
Second paragraph.
```{r}
x <- xc + 2
```
The value of x is `r x`. Note: the line |
Beta Was this translation helpful? Give feedback.
-
What should be the behaviour if we have this
if the cursor is inside the first chunk. Should if knit the child, send Also if the cursor is on the header of the first chunk? Just knit? |
Beta Was this translation helpful? Give feedback.
-
Idea of behavior change:
This change would allow easily to send code blocks one at a time and jump to the next. What do you think? Is the current behavior preferable? |
Beta Was this translation helpful? Give feedback.
-
Can you test with
and child.rmd
|
Beta Was this translation helpful? Give feedback.
-
The thing I am not sure is the |
Beta Was this translation helpful? Give feedback.
-
Only now I could try it... It's excellent!
The only thing that doesn't seem correct that I noted was that |
Beta Was this translation helpful? Give feedback.
-
I added the highlighting of code blocks. Please, pull the changes and let me know whether it works on your side. Any suggestion of improvement? |
Beta Was this translation helpful? Give feedback.
-
I really like it. If fell it makes the document easier to read. Good job. Should we merge it? |
Beta Was this translation helpful? Give feedback.
-
The behavior of sending a line when the cursor is over the chunk's header has changed. I will document it in the README. Also, I'll try to highlight comments starting with |
Beta Was this translation helpful? Give feedback.
-
Did it. But now I have found a bug: sometimes, markdown code is recognized as "r" lang by |
Beta Was this translation helpful? Give feedback.
-
With this simple Quarto document: ---
author: "Someone"
title: "Testing"
---
If the cursor is on the last line (an empty one) and we type |
Beta Was this translation helpful? Give feedback.
-
Should we create an option to disable the different highlighting of comments prefixed with |
Beta Was this translation helpful? Give feedback.
-
One thing to fix is when the cursor is on a python chunk header. It now tries to send the python code as R code. |
Beta Was this translation helpful? Give feedback.
-
I also think everybody will like it and nobody will request an option to disable it. We can add the option in the future if someone requests it.
The |
Beta Was this translation helpful? Give feedback.
-
I have modified the We can now send the whole chunk if the cursor is on a python chunk. |
Beta Was this translation helpful? Give feedback.
-
I fixed a bug. In diff --git a/lua/r/utils.lua b/lua/r/utils.lua
index 137246b..ddc27f0 100644
--- a/lua/r/utils.lua
+++ b/lua/r/utils.lua
@@ -98,8 +98,7 @@ function M.get_lang()
local parser = require("nvim-treesitter.parsers").get_parser(buf)
if not parser then return "" end
-
- return parser:language_for_range(pos):lang()
+ return parser:language_for_range({ pos[1], pos[2], pos[1], pos[2] }):lang()
end |
Beta Was this translation helpful? Give feedback.
-
I'm testing it now... And there is another change that I want to make: don't highlight as the |
Beta Was this translation helpful? Give feedback.
-
I improved the highlighting of chunks with the child field: The line of the child field isn't highlighted with the color of the |
Beta Was this translation helpful? Give feedback.
-
I think we can merge it now... |
Beta Was this translation helpful? Give feedback.
-
Yes, I think so. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I made some changes in this branch: https://github.com/R-nvim/R.nvim/tree/feature/improve-chunk-handling
Basically, removing many uses of regex in favour of using Treesitter for navigating and sending code chunks/lines to the console.
Please feel free to test it and comment.
Beta Was this translation helpful? Give feedback.
All reactions