Skip to content

Commit

Permalink
fix: slime-sending.
Browse files Browse the repository at this point in the history
and prepare for yarepl
  • Loading branch information
jmbuhr committed Jun 6, 2023
1 parent 2d3a334 commit 795133e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lua/quarto/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ M.setup = function(opt)
end

local function concat(ls)
if not (type(ls) == "table") then return ls .. '\n\n' end
local s = ''
for _, l in ipairs(ls) do
if l ~= '' then
Expand All @@ -165,17 +166,27 @@ local function concat(ls)
end

local function send(lines)
local yarepl = require 'yarepl'
lines = concat(lines)

if yarepl ~= nil then
yarepl._send_strings(0, 'ipython')
local success, yarepl = pcall(require, 'yarepl')
if success then
yarepl._send_strings(0)
else
local success, error = pcall(vim.fn[vim.fn['slime#send'](lines)])
if not success then
vim.fn['slime#send'](lines)
if success then
vim.fn.notify('Install a REPL code sending plugin to use this feature. Options are yarepl.nvim and vim-slim.')
end
end

end

M.quartoSend = function()
local lines = otterkeeper.get_language_lines_around_cursor()
if lines == nil then
print(
'No code chunk detected around cursor')
return
end
send(lines)
end

M.quartoSendAbove = function()
Expand Down
1 change: 1 addition & 0 deletions plugin/quarto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ api.nvim_create_user_command('QuartoClosePreview', quarto.quartoClosePreview, {}
api.nvim_create_user_command('QuartoActivate', quarto.activate, {})
api.nvim_create_user_command('QuartoHelp', quarto.searchHelp, { nargs = 1 })
api.nvim_create_user_command('QuartoHover', ':require"otter".ask_hover()<cr>', {})
api.nvim_create_user_command('QuartoSend', quarto.quartoSend, {})
api.nvim_create_user_command('QuartoSendAbove', quarto.quartoSendAbove, {})
api.nvim_create_user_command('QuartoSendBelow', quarto.quartoSendBelow, {})
api.nvim_create_user_command('QuartoSendAll', quarto.quartoSendAll, {})
Expand Down

0 comments on commit 795133e

Please sign in to comment.