mirror of
https://github.com/dwinkler1/nvimConfig.git
synced 2026-08-22 17:43:13 -04:00
fix: harden REPL/terminal code-sending paths
- lua/keymap/repl.lua
- Replace non-existent `:SlimeSendCurrentLine` with synchronous
`vim.fn["slime#send"](line .. "\n")` fallback.
- Support both modern `r.send` and older `r.run` R.nvim Lua APIs,
falling back to `<Plug>` mappings if neither module is available.
- lua/nix_smart_send.lua
- Refactor `send_repl()` to extract Tree-sitter node text and send it
directly via `slime#send`, eliminating the `feedkeys(..., "x", true)`
race between visual selection and cursor movement.
- Replace internal `slime#send_op` call in `slime_send_region()` with the
public `<Plug>SlimeRegionSend` mapping.
- Improve `move_to_next_non_empty_line()` to walk up the AST when a
node has no next sibling, so the cursor escapes nested blocks.
- plugin/03_terminal.lua
- Set `vim.g.slime_target = "neovim"` at the top of the module so the
target is guaranteed before any slime send.
- plugin/21_datascience.lua
- Remove duplicate `vim.g.slime_target = "neovim"` now that the
terminal module owns the setting.
This commit is contained in:
parent
137ec6d576
commit
6142f7d55e
4 changed files with 50 additions and 28 deletions
|
|
@ -20,12 +20,20 @@ function M.send_line()
|
|||
local ft = dispatch_ft()
|
||||
|
||||
if ft == "r" then
|
||||
-- R.nvim v1+ exposes a Lua API; fall back to the legacy <Plug> mappings
|
||||
-- if a v0.x build is still in use.
|
||||
local ok, rrun = pcall(require, "r.run")
|
||||
if ok and rrun and type(rrun.send_line) == "function" then
|
||||
rrun.send_line()
|
||||
return
|
||||
-- R.nvim v1+ exposes a Lua API; try the modern `r.send` module first,
|
||||
-- then fall back to the older `r.run` module, and finally to <Plug>.
|
||||
local ok, rmod = pcall(require, "r.send")
|
||||
if not ok or not rmod then
|
||||
ok, rmod = pcall(require, "r.run")
|
||||
end
|
||||
if ok and rmod then
|
||||
if type(rmod.line) == "function" then
|
||||
rmod.line()
|
||||
return
|
||||
elseif type(rmod.send_line) == "function" then
|
||||
rmod.send_line()
|
||||
return
|
||||
end
|
||||
end
|
||||
vim.api.nvim_feedkeys(
|
||||
vim.api.nvim_replace_termcodes("<Plug>RDSendLine", true, false, true),
|
||||
|
|
@ -48,7 +56,8 @@ function M.send_line()
|
|||
end
|
||||
|
||||
-- Default: vim-slime (terminal).
|
||||
vim.cmd("SlimeSendCurrentLine")
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
vim.fn["slime#send"](line .. "\n")
|
||||
-- Move to the next line, matching the previous behaviour.
|
||||
vim.cmd("normal! j")
|
||||
end
|
||||
|
|
@ -58,11 +67,20 @@ function M.send_selection()
|
|||
local ft = dispatch_ft()
|
||||
|
||||
if ft == "r" then
|
||||
-- Prefer R.nvim v1+ Lua API; fall back to <Plug> if unavailable.
|
||||
local ok, rrun = pcall(require, "r.run")
|
||||
if ok and rrun and type(rrun.send_selection) == "function" then
|
||||
rrun.send_selection()
|
||||
return
|
||||
-- Prefer R.nvim v1+ Lua API; try the modern `r.send` module first,
|
||||
-- then fall back to the older `r.run` module, and finally to <Plug>.
|
||||
local ok, rmod = pcall(require, "r.send")
|
||||
if not ok or not rmod then
|
||||
ok, rmod = pcall(require, "r.run")
|
||||
end
|
||||
if ok and rmod then
|
||||
if type(rmod.selection) == "function" then
|
||||
rmod.selection()
|
||||
return
|
||||
elseif type(rmod.send_selection) == "function" then
|
||||
rmod.send_selection()
|
||||
return
|
||||
end
|
||||
end
|
||||
vim.api.nvim_feedkeys(
|
||||
vim.api.nvim_replace_termcodes("<Plug>RSendSelection", true, false, true),
|
||||
|
|
|
|||
Loading…
Reference in a new issue