-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fix sending code to R from Rnoweb documents #299
Conversation
This pull request fixes an issue by calling a function that does nothing: if node then vim.schedule(function() end) end Clearly, this shouldn't be necessary and we are circumventing what seems to be a Neovim or tree-sitter bug. I don't know whether the fix works or introduces new bugs on macOs or Windows. So, the pull request needs review. |
Example of Rnoweb document that can be used to test the changes:
\documentclass{article}
\begin{document}
Here is a code chunk.
<<example>>=
x <- 1
print(x)
x |>
print()
@
And another one:
<<example2>>=
#| echo: false
#| fig-cap: "Example of Figure"
# Cursor on `a`. Send the line and jump to `b`.
a <- 1
b <- 2
# Cursor on `d`. Send the line and jump to `if`.
d <- data.frame(var1 = c(1, 2, 3, 4, 5), var2 = c(1, 2, 3, 3, 2))
# Cursor on `if`. Send the next two lines.
if (TRUE)
library("ggplot2")
# Cursor on `if`. Send the bracket block.
if (TRUE) {
# Cursor on `print`. Send the line.
print(1)
print(2)
}
# Cursor on `plus_one`. Send the bracket block.
plus_one <- function(a) {
# Cursor on `b`. Send the line.
b <- a + 1
# <LocalLeader>fc here. Send the function `plus_one`.
nested_fun <- function(x) {
# <LocalLeader>fc here. Send the function `plus_one`.
y <- x + 1
return(invisible(y))
}
b
}
# <LocalLeader>fa. Send the functions `plus_one` and `plus_two`.
# Cursor anywhere on the line below. Send the whole line and jump to `d`.
a <- 1 ; b <- 2
d <- "a;b"
library("dplyr")
library("ggplot2")
# Statements chained by a pipe operator
# Cursor anywhere in the three lines below. Send the three lines.
mtcars |>
select(mpg, qsec) |>
cor()
# Statements chained by arithmetic operator
# Cursor anywhere in the three lines below. Send the three lines.
ggplot(mtcars, aes(mpg, qsec)) +
geom_point() +
geom_smooth(span = 3.0)
@
End of document.
\end{document} |
0a5ba06
to
ffa636c
Compare
Testing it now... |
In your # <LocalLeader>fa. Send the functions `plus_one` and `plus_two`. I am getting |
It was my mistake to have included the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few comments.
In your example plus_one <- function(a) {
# Cursor on `b`. Send the line.
b <- a + 1
# <LocalLeader>fc here. Send the function `plus_one`.
nested_fun <- function(x) {
# <LocalLeader>fc here. Send the function `plus_one`.
y <- x + 1
return(invisible(y))
}
b
} If I place my cursor on |
It's because this chunk of R code is actually an R script that I use to check if the use of tree-sitter to send code to R is still working since tree-sitter is frequently changing and breaking our code in |
Close #298 Co-authored-by: Philippe Massicotte <[email protected]>
51961cd
to
ffd7f8d
Compare
If I comment out -- if vim.bo[bufnr].filetype ~= "r" then
-- inform("Not yet supported in '" .. vim.bo[bufnr].filetype .. "' files.")
-- return
-- end The fa command works in the |
I confirm that it works on my side too! This is great! |
It doesn't work in Rmd or Quarto, though. So, we have to bring back the previous informational message. |
It works, but strangely. Let me try to explain below. |
It doesn't seem to work on |
It looks like that the buffer type (filetype) is beeing changed somewhere when we try to run fX commands. |
I can replicate the same buggy behavior. If we move the cursor, R.nvim recovers the ability to send lines. Maybe, we could try the |
If I move the cursor anywhere and try to press enter, I still get EDIT: Ah it works if I move it outside the chunk and come back in. |
I just have to move one character above or ahead to bring it to normal behavior. The |
Maybe we can merge this PR and open another for the sending behaviour in rmd and qmd files. |
I agree, but let's restore the previous informational message before merging it... |
I suggest: if vim.bo[bufnr].filetype ~= "r" and vim.bo[bufnr].filetype ~= "rnoweb" then
inform("Not yet supported in '" .. vim.bo[bufnr].filetype .. "' files.")
return
end |
Sounds good, Then another issue to fix the |
Good job, thanks for the changes. |
Close #298 Co-authored-by: Philippe Massicotte <[email protected]>
Close #298