@@ -60,12 +60,15 @@ features.eval_print = function(code, ns)
6060end
6161
6262--- Evaluate the current form or the given motion.
63- -- The result will replace the current form
63+ -- The result will be shown on a virtualtext next to the current form
64+ -- and also stored on the clipboard.
6465-- @tparam [opt] string mode motion mode
66+ -- @tparam [opt] boolean replace whether it should replace the form with its result
6567-- @tparam [opt] string ns Namespace to be used when evaluating the code.
6668-- Defaults to current file's ns.
67- features .eval_inplace = function (mode , ns )
69+ features .eval_expr = function (mode , replace , ns )
6870 local payload = {}
71+ local midlws
6972 local coord , form
7073 if mode == nil then
7174 form , coord = forms .form_under_cursor ()
@@ -83,47 +86,27 @@ features.eval_inplace = function(mode, ns)
8386 if ns ~= nil or ns ~= " " then
8487 payload .ns = ns
8588 end
86- acid .run (ops .eval (payload ):with_handler (middlewares
87- .refactor (utils .merge (coord , {accessor = function (dt )
88- if dt .value ~= nil then
89- return dt .value
90- else
91- return dt .out
92- end
93- end }))))
94- end
9589
96- --- Evaluate the current form or the given motion.
97- -- The result will be shown on a virtualtext next to the current form
98- -- and also stored on the clipboard.
99- -- @tparam [opt] string mode motion mode
100- -- @tparam [opt] string ns Namespace to be used when evaluating the code.
101- -- Defaults to current file's ns.
102- features .eval_expr = function (mode , ns )
103- local payload = {}
104- if mode == nil then
105- local form = forms .form_under_cursor ()
106- payload .code = table.concat (form , " \n " )
107- elseif mode == " symbol" then
108- payload .code = forms .symbol_under_cursor ()
109- elseif mode == " top" then
110- local form = forms .form_under_cursor (true )
111- payload .code = table.concat (form , " \n " )
90+ if replace then
91+ midlws = middlewares
92+ .refactor (utils .merge (coord , {accessor = function (dt )
93+ if dt .value ~= nil then
94+ return dt .value
95+ else
96+ return dt .out
97+ end
98+ end }))
11299 else
113- local lines = forms .form_from_motion (mode )
114- payload .code = table.concat (lines , " \n " )
115- end
116- ns = ns or vim .api .nvim_call_function (" AcidGetNs" , {})
117- if ns ~= nil or ns ~= " " then
118- payload .ns = ns
119- end
120- acid .run (ops .eval (payload ):with_handler (middlewares
100+ midlws = middlewares
121101 .print {}
122102 .clipboard {}
123- .virtualtext {}
124- ))
103+ .virtualtext (coord )
104+ end
105+
106+ acid .run (ops .eval (payload ):with_handler (midlws ))
125107end
126108
109+
127110--- Sends a `(require '[...])` function to the nrepl.
128111-- Will send an `AcidRequired` autocommand after complete.
129112-- @tparam [opt] string ns Namespace to be used when evaluating the code.
0 commit comments