dccsillag / magma-nvim

Interact with Jupyter from NeoVim.
GNU General Public License v3.0
977 stars 49 forks source link

TODO: rewrite suggested methods into proper lua #96

Open WhiteBlackGoose opened 1 year ago

WhiteBlackGoose commented 1 year ago

link

1fn0t commented 1 year ago

Hi @WhiteBlackGoose, I'm looking to contribute to open source I would like to be assigned this issue but I would also like to know what exactly I have to do.

WhiteBlackGoose commented 1 year ago

@1fn0t hi, I'm referring to this block, written half in vimscript. The second block is technically lua, but I invoke vimscript there via vim.cmd. It would be nice to have it rewritten into lua entirely.

Assigned you. Good luck

S-Y-rat commented 1 year ago

Example of keybindings configuration with lua and kitty protocol:

vim.keymap.set("n", "<LocalLeader>r", "<cmd>MagmaEvaluateOperator<CR>", { silent = true, expr = true, })
vim.keymap.set("n", "<LocalLeader>rr", "<cmd>MagmaEvaluateLine<CR>", { silent = true, })
vim.keymap.set({"n", "v"}, "<LocalLeader>r", ":<C-u>MagmaEvaluateVisual<CR>", { silent = true, })
vim.keymap.set("n", "<LocalLeader>rc", "<cmd>MagmaReevaluateCell<CR>", { silent = true, })
vim.keymap.set("n", "<LocalLeader>rd", "<cmd>MagmaDelete<CR>", { silent = true, })
vim.keymap.set("n", "<LocalLeader>ro", "<cmd>MagmaShowOutput<CR>", { silent = true, })

vim.api.nvim_set_var("magma_automatically_open_output", false)
vim.api.nvim_set_var("magma_image_provider", "kitty")
WhiteBlackGoose commented 1 year ago

For variables, there's vim.g.variable = value, no need for these scary calls. And the block with functions also needs to be rewritten

S-Y-rat commented 1 year ago

Maybe that is better:

magma_kbd = {
    { op = "EvaluateOperator", keys = "r", expr = true, },
    { op = "EvaluateLine", keys = "rr", },
    { op = "EvaluateVisual", keys = "r", v = true },
    { op = "ReevaluateCell", keys = "rc", },
    { op = "Delete", keys = "rd", },
    { op = "ShowOutput", keys = "ro" },
}

for _, row in ipairs(magma_kbd) do
    mod = (row.expr ~= nil) and { silent = true, expr = row.expr,} or { silent = true, }
    map = (row.v ~= nil) and { "n", "v", } or "n"
    command = (row.v ~= nil) and ":<C-u>" or "<cmd>"
    vim.keymap.set(
        map, "<LocalLeader>" .. row.keys,
        command .. "Magma" .. row.op .. "<CR>", mod)
end

vim.g.magma_automatically_open_output = false
vim.g.magma_image_provider = "kitty"