Skip to content

Commit

Permalink
Add ep (eval previous) #518
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Aug 25, 2023
1 parent 95c3013 commit 2368068
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 45 deletions.
5 changes: 5 additions & 0 deletions doc/conjure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ configuring these values from Lua it's just `true` and `false`.
Evaluates the word under the cursor.
Default: `"ew"`

*g:conjure#mapping#eval_previous*
`g:conjure#mapping#eval_previous`
Evaluates the previous evaluation again.
Default: `"ep"`

*g:conjure#mapping#eval_comment_word*
`g:conjure#mapping#eval_comment_word`
Evaluates the word under the cursor and inserts the result as a
Expand Down
1 change: 1 addition & 0 deletions fnl/conjure/config.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
:eval_buf "eb"
:eval_visual "E"
:eval_motion "E"
:eval_previous "ep"
:def_word "gd"
:doc_word ["K"]

Expand Down
6 changes: 6 additions & 0 deletions fnl/conjure/eval.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
(with-last-result-hook opts)))
nil)

(defn previous []
(let [client-name (a.get (client.current-client-module-name) :module-name :unknown)
opts (a.get previous-evaluations client-name)]
(when opts
(eval-str opts))))

(defn wrap-emit [name f]
(fn [...]
(event.emit name)
Expand Down
5 changes: 5 additions & 0 deletions fnl/conjure/mapping.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@
(util.wrap-require-fn-call :conjure.eval :buf)
{:desc "Evaluate buffer"})

(buf
:EvalPrevious (cfg :eval_previous)
(util.wrap-require-fn-call :conjure.eval :previous)
{:desc "Evaluate previous evaluation"})

(buf
:EvalVisual (cfg :eval_visual)
(util.wrap-require-fn-call :conjure.eval :selection)
Expand Down
2 changes: 1 addition & 1 deletion lua/conjure/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ local function merge(tbl, opts, ks)
return nil
end
_2amodule_2a["merge"] = merge
merge({relative_file_root = nil, path_subs = nil, client_on_load = true, filetypes = {"clojure", "fennel", "janet", "hy", "julia", "racket", "scheme", "lua", "lisp", "python", "rust", "sql"}, filetype = {clojure = "conjure.client.clojure.nrepl", fennel = "conjure.client.fennel.aniseed", janet = "conjure.client.janet.netrepl", hy = "conjure.client.hy.stdio", julia = "conjure.client.julia.stdio", racket = "conjure.client.racket.stdio", scheme = "conjure.client.scheme.stdio", lua = "conjure.client.lua.neovim", lisp = "conjure.client.common-lisp.swank", python = "conjure.client.python.stdio", rust = "conjure.client.rust.evcxr", sql = "conjure.client.sql.stdio"}, filetype_suffixes = {racket = {"rkt"}, scheme = {"scm", "ss"}}, eval = {result_register = "c", inline_results = true, inline = {highlight = "comment", prefix = "=> "}, comment_prefix = nil, gsubs = {}}, mapping = {prefix = "<localleader>", log_split = "ls", log_vsplit = "lv", log_tab = "lt", log_buf = "le", log_toggle = "lg", log_close_visible = "lq", log_reset_soft = "lr", log_reset_hard = "lR", log_jump_to_latest = "ll", eval_current_form = "ee", eval_comment_current_form = "ece", eval_root_form = "er", eval_comment_root_form = "ecr", eval_word = "ew", eval_comment_word = "ecw", eval_replace_form = "e!", eval_marked_form = "em", eval_file = "ef", eval_buf = "eb", eval_visual = "E", eval_motion = "E", def_word = "gd", doc_word = {"K"}, enable_ft_mappings = true}, completion = {omnifunc = "ConjureOmnifunc", fallback = "syntaxcomplete#Complete"}, highlight = {group = "IncSearch", timeout = 500, enabled = false}, log = {hud = {width = 0.42, height = 0.3, enabled = true, passive_close_delay = 0, minimum_lifetime_ms = 20, overlap_padding = 0.1, border = "single", anchor = "NE", ignore_low_priority = false}, jump_to_latest = {cursor_scroll_position = "top", enabled = false}, break_length = 80, trim = {at = 10000, to = 6000}, strip_ansi_escape_sequences_line_limit = 1000, fold = {lines = 10, marker = {start = "~~~%{", ["end"] = "}%~~~"}, enabled = false}, wrap = false, botright = false}, extract = {context_header_lines = 24, form_pairs = {{"(", ")"}, {"{", "}"}, {"[", "]", true}}, tree_sitter = {enabled = true}}, preview = {sample_limit = 0.3}, debug = false})
merge({relative_file_root = nil, path_subs = nil, client_on_load = true, filetypes = {"clojure", "fennel", "janet", "hy", "julia", "racket", "scheme", "lua", "lisp", "python", "rust", "sql"}, filetype = {clojure = "conjure.client.clojure.nrepl", fennel = "conjure.client.fennel.aniseed", janet = "conjure.client.janet.netrepl", hy = "conjure.client.hy.stdio", julia = "conjure.client.julia.stdio", racket = "conjure.client.racket.stdio", scheme = "conjure.client.scheme.stdio", lua = "conjure.client.lua.neovim", lisp = "conjure.client.common-lisp.swank", python = "conjure.client.python.stdio", rust = "conjure.client.rust.evcxr", sql = "conjure.client.sql.stdio"}, filetype_suffixes = {racket = {"rkt"}, scheme = {"scm", "ss"}}, eval = {result_register = "c", inline_results = true, inline = {highlight = "comment", prefix = "=> "}, comment_prefix = nil, gsubs = {}}, mapping = {prefix = "<localleader>", log_split = "ls", log_vsplit = "lv", log_tab = "lt", log_buf = "le", log_toggle = "lg", log_close_visible = "lq", log_reset_soft = "lr", log_reset_hard = "lR", log_jump_to_latest = "ll", eval_current_form = "ee", eval_comment_current_form = "ece", eval_root_form = "er", eval_comment_root_form = "ecr", eval_word = "ew", eval_comment_word = "ecw", eval_replace_form = "e!", eval_marked_form = "em", eval_file = "ef", eval_buf = "eb", eval_visual = "E", eval_motion = "E", eval_previous = "ep", def_word = "gd", doc_word = {"K"}, enable_ft_mappings = true}, completion = {omnifunc = "ConjureOmnifunc", fallback = "syntaxcomplete#Complete"}, highlight = {group = "IncSearch", timeout = 500, enabled = false}, log = {hud = {width = 0.42, height = 0.3, enabled = true, passive_close_delay = 0, minimum_lifetime_ms = 20, overlap_padding = 0.1, border = "single", anchor = "NE", ignore_low_priority = false}, jump_to_latest = {cursor_scroll_position = "top", enabled = false}, break_length = 80, trim = {at = 10000, to = 6000}, strip_ansi_escape_sequences_line_limit = 1000, fold = {lines = 10, marker = {start = "~~~%{", ["end"] = "}%~~~"}, enabled = false}, wrap = false, botright = false}, extract = {context_header_lines = 24, form_pairs = {{"(", ")"}, {"{", "}"}, {"[", "]", true}}, tree_sitter = {enabled = true}}, preview = {sample_limit = 0.3}, debug = false})
return _2amodule_2a
98 changes: 54 additions & 44 deletions lua/conjure/eval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,22 @@ local function eval_str(opts)
return nil
end
_2amodule_2a["eval-str"] = eval_str
local function previous()
local client_name = a.get(client["current-client-module-name"](), "module-name", "unknown")
local opts = a.get(previous_evaluations, client_name)
if opts then
return eval_str(opts)
else
return nil
end
end
_2amodule_2a["previous"] = previous
local function wrap_emit(name, f)
local function _21_(...)
local function _22_(...)
event.emit(name)
return f(...)
end
return _21_
return _22_
end
_2amodule_2a["wrap-emit"] = wrap_emit
local doc_str = wrap_emit("doc", client_exec_fn("doc", "doc-str"))
Expand All @@ -182,9 +192,9 @@ do end (_2amodule_locals_2a)["def-str"] = def_str
local function current_form(extra_opts)
local form = extract.form({})
if form then
local _let_22_ = form
local content = _let_22_["content"]
local range = _let_22_["range"]
local _let_23_ = form
local content = _let_23_["content"]
local range = _let_23_["range"]
eval_str(a.merge({code = content, range = range, origin = "current-form"}, extra_opts))
return form
else
Expand All @@ -197,14 +207,14 @@ local function replace_form()
local win = nvim.tabpage_get_win(0)
local form = extract.form({})
if form then
local _let_24_ = form
local content = _let_24_["content"]
local range = _let_24_["range"]
local function _25_(result)
local _let_25_ = form
local content = _let_25_["content"]
local range = _let_25_["range"]
local function _26_(result)
buffer["replace-range"](buf, range, result)
return editor["go-to"](win, a["get-in"](range, {"start", 1}), a.inc(a["get-in"](range, {"start", 2})))
end
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _25_})
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _26_})
return form
else
return nil
Expand All @@ -214,9 +224,9 @@ _2amodule_2a["replace-form"] = replace_form
local function root_form()
local form = extract.form({["root?"] = true})
if form then
local _let_27_ = form
local content = _let_27_["content"]
local range = _let_27_["range"]
local _let_28_ = form
local content = _let_28_["content"]
local range = _let_28_["range"]
return eval_str({code = content, range = range, origin = "root-form"})
else
return nil
Expand All @@ -227,10 +237,10 @@ local function marked_form(mark)
local comment_prefix = client.get("comment-prefix")
local mark0 = (mark or extract["prompt-char"]())
local ok_3f, err = nil, nil
local function _29_()
local function _30_()
return editor["go-to-mark"](mark0)
end
ok_3f, err = pcall(_29_)
ok_3f, err = pcall(_30_)
if ok_3f then
current_form({origin = str.join({"marked-form [", mark0, "]"})})
editor["go-back"]()
Expand All @@ -244,13 +254,13 @@ local function insert_result_comment(tag, input)
local buf = nvim.win_get_buf(0)
local comment_prefix = (config["get-in"]({"eval", "comment_prefix"}) or client.get("comment-prefix"))
if input then
local _let_31_ = input
local content = _let_31_["content"]
local range = _let_31_["range"]
local function _32_(result)
local _let_32_ = input
local content = _let_32_["content"]
local range = _let_32_["range"]
local function _33_(result)
return buffer["append-prefixed-line"](buf, range["end"], comment_prefix, result)
end
eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _32_})
eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _33_})
return input
else
return nil
Expand All @@ -270,9 +280,9 @@ local function comment_word()
end
_2amodule_2a["comment-word"] = comment_word
local function word()
local _let_34_ = extract.word()
local content = _let_34_["content"]
local range = _let_34_["range"]
local _let_35_ = extract.word()
local content = _let_35_["content"]
local range = _let_35_["range"]
if not a["empty?"](content) then
return eval_str({code = content, range = range, origin = "word"})
else
Expand All @@ -281,9 +291,9 @@ local function word()
end
_2amodule_2a["word"] = word
local function doc_word()
local _let_36_ = extract.word()
local content = _let_36_["content"]
local range = _let_36_["range"]
local _let_37_ = extract.word()
local content = _let_37_["content"]
local range = _let_37_["range"]
if not a["empty?"](content) then
return doc_str({code = content, range = range, origin = "word"})
else
Expand All @@ -292,9 +302,9 @@ local function doc_word()
end
_2amodule_2a["doc-word"] = doc_word
local function def_word()
local _let_38_ = extract.word()
local content = _let_38_["content"]
local range = _let_38_["range"]
local _let_39_ = extract.word()
local content = _let_39_["content"]
local range = _let_39_["range"]
if not a["empty?"](content) then
return def_str({code = content, range = range, origin = "word"})
else
Expand All @@ -303,9 +313,9 @@ local function def_word()
end
_2amodule_2a["def-word"] = def_word
local function buf()
local _let_40_ = extract.buf()
local content = _let_40_["content"]
local range = _let_40_["range"]
local _let_41_ = extract.buf()
local content = _let_41_["content"]
local range = _let_41_["range"]
return eval_str({code = content, range = range, origin = "buf"})
end
_2amodule_2a["buf"] = buf
Expand All @@ -314,16 +324,16 @@ local function command(code)
end
_2amodule_2a["command"] = command
local function range(start, _end)
local _let_41_ = extract.range(start, _end)
local content = _let_41_["content"]
local range0 = _let_41_["range"]
local _let_42_ = extract.range(start, _end)
local content = _let_42_["content"]
local range0 = _let_42_["range"]
return eval_str({code = content, range = range0, origin = "range"})
end
_2amodule_2a["range"] = range
local function selection(kind)
local _let_42_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
local content = _let_42_["content"]
local range0 = _let_42_["range"]
local _let_43_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
local content = _let_43_["content"]
local range0 = _let_43_["range"]
return eval_str({code = content, range = range0, origin = "selection"})
end
_2amodule_2a["selection"] = selection
Expand All @@ -337,15 +347,15 @@ end
_2amodule_locals_2a["wrap-completion-result"] = wrap_completion_result
local function completions(prefix, cb)
local function cb_wrap(results)
local function _44_()
local _45_ = config["get-in"]({"completion", "fallback"})
if (nil ~= _45_) then
return nvim.call_function(_45_, {0, prefix})
local function _45_()
local _46_ = config["get-in"]({"completion", "fallback"})
if (nil ~= _46_) then
return nvim.call_function(_46_, {0, prefix})
else
return _45_
return _46_
end
end
return cb(a.map(wrap_completion_result, (results or _44_())))
return cb(a.map(wrap_completion_result, (results or _45_())))
end
if ("function" == type(client.get("completions"))) then
return client.call("completions", assoc_context({["file-path"] = extract["file-path"](), prefix = prefix, cb = cb_wrap}))
Expand Down
1 change: 1 addition & 0 deletions lua/conjure/mapping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ local function on_filetype()
buf("EvalMarkedForm", cfg("eval_marked_form"), _9_, {desc = "Evaluate marked form", ["repeat?"] = false})
buf("EvalFile", cfg("eval_file"), util["wrap-require-fn-call"]("conjure.eval", "file"), {desc = "Evaluate file"})
buf("EvalBuf", cfg("eval_buf"), util["wrap-require-fn-call"]("conjure.eval", "buf"), {desc = "Evaluate buffer"})
buf("EvalPrevious", cfg("eval_previous"), util["wrap-require-fn-call"]("conjure.eval", "previous"), {desc = "Evaluate previous evaluation"})
buf("EvalVisual", cfg("eval_visual"), util["wrap-require-fn-call"]("conjure.eval", "selection"), {desc = "Evaluate visual select", mode = "v", ["command-opts"] = {range = true}})
buf("DocWord", cfg("doc_word"), util["wrap-require-fn-call"]("conjure.eval", "doc-word"), {desc = "Get documentation under cursor"})
buf("DefWord", cfg("def_word"), util["wrap-require-fn-call"]("conjure.eval", "def-word"), {desc = "Get definition under cursor"})
Expand Down

0 comments on commit 2368068

Please sign in to comment.