Skip to content

Commit

Permalink
Merge pull request #246 from she3o/various-small-improvements
Browse files Browse the repository at this point in the history
Refactor Codebase for Improved Modularity and Asynchronous Operations (WIP)
  • Loading branch information
PMassicotte authored Oct 14, 2024
2 parents ad7035e + 1934442 commit 4cf60ea
Show file tree
Hide file tree
Showing 32 changed files with 460 additions and 364 deletions.
8 changes: 3 additions & 5 deletions lua/r/browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ with the R backend and update the Object Browser interface accordingly.
]]

local config = require("r.config").get_config()
local warn = require("r").warn
local warn = require("r.log").warn
local job = require("r.job")
local hooks = require("r.hooks")
local send_to_nvimcom = require("r.run").send_to_nvimcom

-- Determine if the locale uses UTF-8 encoding
Expand Down Expand Up @@ -332,10 +333,7 @@ function M.start(_)
start_OB()
state.is_running = false

-- Execute any user-defined hooks after opening the Object Browser
if config.hook.after_ob_open then
vim.schedule(function() config.hook.after_ob_open() end)
end
hooks.run(config, "after_ob_open")
end

--- Return the active pane of the Object Browser
Expand Down
82 changes: 82 additions & 0 deletions lua/r/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
local config = require("r.config").get_config()

local M = {}

local function show_config(tbl)
local opt = tbl.args
local out = {}
if opt and opt:len() > 0 then
opt = opt:gsub(" .*", "")
table.insert(out, { vim.inspect(config[opt]) })
else
table.insert(out, { vim.inspect(config) })
end
vim.schedule(function() vim.api.nvim_echo(out, false, {}) end)
end

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

function M.create_user_commands()
vim.api.nvim_create_user_command(
"RStop",
function(_) require("r.run").signal_to_R("SIGINT") end,
{}
)
vim.api.nvim_create_user_command(
"RKill",
function(_) require("r.run").signal_to_R("SIGKILL") end,
{}
)
vim.api.nvim_create_user_command("RBuildTags", require("r.edit").build_tags, {})
vim.api.nvim_create_user_command("RDebugInfo", require("r.edit").show_debug_info, {})
vim.api.nvim_create_user_command("RMapsDesc", require("r.maps").show_map_desc, {})

vim.api.nvim_create_user_command(
"RSend",
function(tbl) require("r.send").cmd(tbl.args) end,
{ nargs = 1 }
)

vim.api.nvim_create_user_command(
"RFormat",
require("r.run").formart_code,
{ range = "%" }
)

vim.api.nvim_create_user_command(
"RInsert",
function(tbl) require("r.run").insert(tbl.args, "here") end,
{ nargs = 1 }
)

vim.api.nvim_create_user_command(
"RSourceDir",
function(tbl) require("r.run").source_dir(tbl.args) end,
{ nargs = 1, complete = "dir" }
)

vim.api.nvim_create_user_command(
"RHelp",
function(tbl) require("r.doc").ask_R_help(tbl.args) end,
{
nargs = "?",
complete = require("r.server").list_objs,
}
)

vim.api.nvim_create_user_command("RConfigShow", show_config, {
nargs = "?",
complete = function() return config_keys end,
})

vim.api.nvim_create_user_command(
"Roxygenize",
function() require("r.roxygen").insert_roxygen(vim.api.nvim_get_current_buf()) end,
{}
)
end

return M
Loading

0 comments on commit 4cf60ea

Please sign in to comment.