Skip to content

Commit

Permalink
Replace :RGetConfig with RConfigShow
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvesaq committed Feb 9, 2024
1 parent 083dd61 commit 9c1fe94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion doc/R-Nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ the `init.vim`. The workaround is do not include the superfluous command
|pdfviewer| PDF application used to open PDF documents
|openpdf| Open PDF after processing rnoweb file
|openhtml| Open HTML after processing Rmd or Quarto
|strict_rst| Code style for generated rst files
|insert_mode_cmds| Allow R commands in insert mode
|rmhidden| Remove hidden objects from R workspace
|wait| Time to wait for nvimcom loading
Expand Down
34 changes: 22 additions & 12 deletions lua/r/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ local config = {
skim_app_path = "",
source_args = "",
specialplot = false,
strict_rst = true,
synctex = true,
texerr = true,
tmpdir = nil,
Expand All @@ -86,9 +85,21 @@ local config = {

-- stylua: ignore end

local config_keys

local user_opts = {}
local did_global_setup = false

local show_config = function(tbl)
local opt = tbl.args
if opt and opt:len() > 0 then
opt = opt:gsub(" .*", "")
print(vim.inspect(config[opt]))
else
print(vim.inspect(config))
end
end

local set_editing_mode = function()
local em = "emacs"
local iprc = tostring(vim.fn.expand("~/.inputrc"))
Expand Down Expand Up @@ -155,14 +166,9 @@ end

local validate_user_opts = function()
-- We don't use vim.validate() because its error message has traceback details not useful for users.
local ckeys = {}
for k, _ in pairs(config) do
table.insert(ckeys, tostring(k))
end
local has_key = false

for k, _ in pairs(user_opts) do
for _, v in pairs(ckeys) do
for _, v in pairs(config_keys) do
if v == k then
has_key = true
break
Expand Down Expand Up @@ -768,11 +774,10 @@ local global_setup = function()
}
)

vim.api.nvim_create_user_command(
"RGetConfig",
function() print(vim.inspect(require("r.config").get_config())) end,
{}
)
vim.api.nvim_create_user_command("RConfigShow", show_config, {
nargs = "?",
complete = function() return config_keys end,
})

vim.fn.timer_start(1, require("r.nrs").check_nvimcom_version)
end
Expand Down Expand Up @@ -804,6 +809,11 @@ M.real_setup = function()

vim.g.R_Nvim_status = 1

config_keys = {}
for k, _ in pairs(config) do
table.insert(config_keys, tostring(k))
end

-- Check if b:pdf_is_open already exists to avoid errors at other places
if vim.fn.exists("b:pdf_is_open") == 0 then
vim.api.nvim_buf_set_var(0, "pdf_is_open", false)
Expand Down

0 comments on commit 9c1fe94

Please sign in to comment.