dotfiles/mzte-nv/conf/lua/eval.fnl

25 lines
934 B
Text
Raw Normal View History

(local fnl-eval (. (require :mzte_nv) :fennel :eval))
2023-06-30 23:12:34 +02:00
(vim.api.nvim_create_user_command :Fnl
(fn [args] (vim.print (fnl-eval args.args)))
{:nargs "+"})
(fn insert-at-cursor [txt]
(let [[_ row col _ _] (vim.fn.getcurpos)
rpos {:line (- row 1) :character (- col 1)}
range {:start rpos :end rpos}]
(vim.lsp.util.apply_text_edits [{: range :newText (tostring txt)}] 0 :utf-8)))
;; Fennel Eval
(vim.keymap.set :i :<C-f>
(fn []
(vim.ui.input {:prompt "fnleval> "}
(fn [inp]
(insert-at-cursor (fnl-eval inp))))))
;; Lua Eval
(vim.keymap.set :i :<C-l>
(fn []
(vim.ui.input {:prompt "luaeval> "}
(fn [inp]
(insert-at-cursor (vim.fn.luaeval inp))))))