Skip to content

Commit

Permalink
Don't rely on file name to recognize rdoc
Browse files Browse the repository at this point in the history
Close #350
  • Loading branch information
jalvesaq committed Feb 27, 2025
1 parent a211b56 commit ef3706b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lua/r/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,18 @@ M.show = function(rkeyword, txt)

txt = txt:gsub("\019", "'")
local lines
local is_help = false
if txt:find("\008") then
lines = require("r.rdoc").fix_rdoc(txt)
is_help = true
else
lines = vim.split(txt, "\020")
end
vim.api.nvim_buf_set_lines(0, 0, -1, true, lines)
if rkeyword:find("R History", 1, true) then
vim.api.nvim_set_option_value("filetype", "r", { scope = "local" })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
elseif rkeyword:find("(help)", 1, true) or vim.fn.search("\008", "nw") > 0 then
elseif is_help then
require("r.rdoc").set_buf_options()
vim.api.nvim_win_set_cursor(0, { 1, 0 })
elseif rkeyword:find("%.Rd$") then
Expand Down
8 changes: 7 additions & 1 deletion lua/r/rdoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ M.set_buf_options = function()
syn match rdocArgDelim / / contained conceal
hi def link rdocArgItem Identifier
]])

local buf = vim.api.nvim_get_current_buf()
if vim.fn.has("nvim-0.11") == 1 then
local ns = vim.api.nvim_create_namespace("RDocumentation")
vim.hl.range(buf, ns, "Title", { 0, 1 }, { 0, -1 }, {})
else
vim.api.nvim_buf_add_highlight(buf, -1, "Title", 0, 0, -1)
end
require("r.config").real_setup()
require("r.maps").create("rdoc")
end
Expand Down
4 changes: 2 additions & 2 deletions nvimcom/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: nvimcom
Version: 0.9.64
Date: 2025-02-25
Version: 0.9.65
Date: 2025-02-27
Title: Intermediate the Communication Between R and Neovim
Author: Jakson Aquino
Maintainer: Jakson Alves de Aquino <[email protected]>
Expand Down
4 changes: 1 addition & 3 deletions nvimcom/R/help.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# R.nvim sets this option during nvimcom loading.
nvim.hmsg <- function(files, header, title, delete.file) {
doc <- nvim.fix.string(paste(readLines(files[1]), collapse = "\x14"))
ttl <- sub("R Help on '(.*)'", "\\1 (help)", title)
ttl <- sub("R Help on \u2018(.*)\u2019", "\\1 (help)", ttl)
ttl <- nvim.fix.string(ttl)
ttl <- nvim.fix.string(title)
.C(nvimcom_msg_to_nvim, paste0("lua require('r.doc').show('", ttl, "', '", doc, "')"))
return(invisible(NULL))
}
Expand Down

0 comments on commit ef3706b

Please sign in to comment.