Closed idavydov closed 1 month ago
When the browser
option isn't a string, R.nvim
receives an empty string as the browser's name, and, then, it calls either open
(Windows or macOS) or xdg-open
(Linux) to open the HTML.
Not sure if my solution is optimal, by happy to document it in a wiki.
Yes, please.
Perhaps, if the option "browser" is a function R.nvim
should use R to open the HTML document. Or, maybe, it should always use R to open HTML documents.
Here the first draft; at the end I mention the problem I currently have.
Yes, for the remote setup it would be great if R.nvim could call browseURL()
via R. I do not see any downsides of this approach.
Here the first draft; at the end I mention the problem I currently have.
Thanks!
Could you try the branch "browseURL", please?
Great, thanks a lot.
browserURL
seem to work great with .Rmd
. Quarto render doesn't open preview automatically, as far as I understand. For quarto preview one could set:
quarto_preview_args = ", port=.free_port()",
I will update the wiki once this is in main
.
So all seem to work great.
Merged now. Thanks for reporting the issue and for writing the page on the Wiki!
sorry for reopening this discussion. I am now getting suspicious messages after rendering an R Markdown file.
^I[C]: in function 'jobstart'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:128: in function 'start'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/doc.lua:223: in function 'load_html'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/doc.lua:237: in function 'open'
^I[string ":lua"]:1: in main chunk
^I[C]: in function 'execute'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:48: in function 'exec_stdout_cmd'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:69: in function <<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:58>
stack traceback:
^I[C]: in function 'execute'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:48: in function 'exec_stdout_cmd'
^I<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:69: in function <<...>/.local/share/nvim/lazy/R.nvim/lua/r/job.lua:58>
This isn't easy to debug without replicating locally. It's necessary to put nvimcom.verbose=6
and/or enable logging in rnvimserver
to know what message is causing the problem.
So let's say I have a minimal .Rmd
:
```{r}
cat("hi")
Every time I press `<localleader>kh` I get this output with `nvimcom.verbose=6`:
nvim.interlace.rmd("a.Rmd", outform = "html_document", rmddir = "
processing file: a.Rmd
output file: a.knit.md
<...>/bin/pandoc +RTS -K512m -RTS a.knit.md --to html4 --from markdown+au tolink_bare_uris+tex_math_single_backslash --output a.html --lua-filter /usr/l ocal/lib/R/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /us r/local/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resou rces --standalone --variable bs3=TRUE --section-divs --template /usr/local/lib /R/site-library/rmarkdown/rmd/h/default.html --no-highlight --variable highlig htjs=1 --variable theme=bootstrap --mathjax --variable 'mathjax-url=https://ma thjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in -header /tmp/Rtmp1xCtyo/rmarkdown-str1f8fb64200f6f.html [WARNING] This document format requires a nonempty
Output created: a.html
send_to_nvim [6] {3659219060}: lua require('r.doc').open('
and I get this in messages:
Vim(lua):E5108: Error executing lua Vim:E475: Invalid argument: expected String or List
stack traceback:
^I[C]: in function 'jobstart'
^I
<details>
<summary>R.nvim config</summary>
```lua
config = function() -- Create a table with the options to be passed to setup()
local opts = {
nvimpager = "tab",
close_term = false,
open_html = "open",
open_pdf = "no",
pdfviewer = "",
csv_app = "tmux new-window vd --theme=light",
quarto_preview_args = ", port=.free_port()",
R_args = { "--quiet", "--no-save", "--no-restore" },
hook = {
on_filetype = function()
-- This function will be called at the FileType event
-- of files supported by R.nvim. This is an
-- opportunity to create mappings local to buffers.
vim.api.nvim_buf_set_keymap(0, "n", "<Enter>", "<Plug>RDSendLine", {})
vim.api.nvim_buf_set_keymap(0, "v", "<Enter>", "<Plug>RSendSelection", {})
end,
},
min_editor_width = 72,
rconsole_width = 78,
disable_cmds = {
"RCustomStart",
"RSaveClose",
"RPackages",
},
}
if vim.env.R_AUTO_START == "1" then opts.auto_start = "on startup" end
require("r").setup(opts)
end,
I can reliably reproduce this error by calling: :lua require('r.doc').open('a.html', 'RbrowseURLfun')
I can reliably reproduce this error by calling: :lua require('r.doc').open('a.html', 'RbrowseURLfun')
This sends the command browseURL("a.html")
to R. Your setup is complex and requires R to run remotely, which I can't replicate because I currently don't have a spare computer to use as remote machine.
I'm looking at the code, and I think the problem might be here.
if browser == "" then
if config.is_windows or config.is_darwin then
cmd = { "open", fullpath }
else
cmd = { "xdg-open", fullpath }
end
elseif browser == "RbrowseURLfun" then
send_to_nvimcom("E", "browseURL('" .. fullpath .. "')")
else
cmd = vim.split(browser, " ")
table.insert(cmd, fullpath)
end
job.start(fullpath, cmd, { detach = true, on_exit = job.on_exit })
From my uninformed perspective the job.start
shouldn't happen if browser == "RbrowseURLfun"
.
It could be something like this (I'm do not know lua well):
if browser == "RbrowseURLfun" then
send_to_nvimcom("E", "browseURL('" .. fullpath .. "')")
else
if browser == "" then
local cmd
if config.is_windows or config.is_darwin then
cmd = { "open", fullpath }
else
cmd = { "xdg-open", fullpath }
end
else
cmd = vim.split(browser, " ")
table.insert(cmd, fullpath)
end
job.start(fullpath, cmd, { detach = true, on_exit = job.on_exit })
end
I tested this fix locally and it seems to work fine. I can make a PR if that helps, @jalvesaq .
Yes, please. It's better because your contribution is registered in Git history.
I noticed that if I set
options(browser=function(url) {...})
thenopen_html
setting is ignored.I think it's a valid option and is correctly used e.g. by
browserURL()
.Would it maybe be possible to allow browser which is a function? I am using this to view html's from a remote host using a combination of ssh port forwarding, servr and opener.
Not sure if my solution is optimal, by happy to document it in a wiki.