Skip to content

Commit f4596fa

Browse files
author
Oliver Caldwell
committedJan 22, 2022
Set jump marks before going to definitions, closes #298
1 parent 2fc39c5 commit f4596fa

File tree

2 files changed

+70
-56
lines changed

2 files changed

+70
-56
lines changed
 

‎fnl/conjure/eval.fnl

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{autoload {a conjure.aniseed.core
33
str conjure.aniseed.string
44
nvim conjure.aniseed.nvim
5+
nu conjure.aniseed.nvim.util
56
extract conjure.extract
67
client conjure.client
78
text conjure.text
@@ -103,8 +104,13 @@
103104
:file-path (extract.file-path)})]
104105
(assoc-context opts)
105106
(set opts.preview (preview opts))
107+
106108
(when (not opts.passive?)
107109
(display-request opts))
110+
111+
(when base-opts.set-jump-mark?
112+
(pcall #(nu.normal "m'")))
113+
108114
(client.call f-name opts))))
109115

110116
(defn- apply-gsubs [code]
@@ -138,7 +144,7 @@
138144
(f ...)))
139145

140146
(def- doc-str (wrap-emit :doc (client-exec-fn :doc :doc-str)))
141-
(def- def-str (wrap-emit :def (client-exec-fn :def :def-str {:suppress-hud? true})))
147+
(def- def-str (wrap-emit :def (client-exec-fn :def :def-str {:suppress-hud? true :set-jump-mark? true})))
142148

143149
(defn current-form [extra-opts]
144150
(let [form (extract.form {})]

‎lua/conjure/eval.lua

+63-55
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ do
1111
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
1212
end
1313
local autoload = (require("conjure.aniseed.autoload")).autoload
14-
local a, buffer, client, config, editor, event, extract, fs, inline, log, nvim, promise, str, text, timer, uuid = autoload("conjure.aniseed.core"), autoload("conjure.buffer"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.editor"), autoload("conjure.event"), autoload("conjure.extract"), autoload("conjure.fs"), autoload("conjure.inline"), autoload("conjure.log"), autoload("conjure.aniseed.nvim"), autoload("conjure.promise"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.timer"), autoload("conjure.uuid")
14+
local a, buffer, client, config, editor, event, extract, fs, inline, log, nu, nvim, promise, str, text, timer, uuid = autoload("conjure.aniseed.core"), autoload("conjure.buffer"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.editor"), autoload("conjure.event"), autoload("conjure.extract"), autoload("conjure.fs"), autoload("conjure.inline"), autoload("conjure.log"), autoload("conjure.aniseed.nvim.util"), autoload("conjure.aniseed.nvim"), autoload("conjure.promise"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.timer"), autoload("conjure.uuid")
1515
do end (_2amodule_locals_2a)["a"] = a
1616
_2amodule_locals_2a["buffer"] = buffer
1717
_2amodule_locals_2a["client"] = client
@@ -22,6 +22,7 @@ _2amodule_locals_2a["extract"] = extract
2222
_2amodule_locals_2a["fs"] = fs
2323
_2amodule_locals_2a["inline"] = inline
2424
_2amodule_locals_2a["log"] = log
25+
_2amodule_locals_2a["nu"] = nu
2526
_2amodule_locals_2a["nvim"] = nvim
2627
_2amodule_locals_2a["promise"] = promise
2728
_2amodule_locals_2a["str"] = str
@@ -106,19 +107,26 @@ local function client_exec_fn(action, f_name, base_opts)
106107
display_request(opts0)
107108
else
108109
end
110+
if base_opts["set-jump-mark?"] then
111+
local function _11_()
112+
return nu.normal("m'")
113+
end
114+
pcall(_11_)
115+
else
116+
end
109117
return client.call(f_name, opts0)
110118
end
111119
return _9_
112120
end
113121
_2amodule_locals_2a["client-exec-fn"] = client_exec_fn
114122
local function apply_gsubs(code)
115123
if code then
116-
local function _14_(code0, _11_)
117-
local _arg_12_ = _11_
118-
local name = _arg_12_[1]
119-
local _arg_13_ = _arg_12_[2]
120-
local pat = _arg_13_[1]
121-
local rep = _arg_13_[2]
124+
local function _16_(code0, _13_)
125+
local _arg_14_ = _13_
126+
local name = _arg_14_[1]
127+
local _arg_15_ = _arg_14_[2]
128+
local pat = _arg_15_[1]
129+
local rep = _arg_15_[2]
122130
local ok_3f, val_or_err = pcall(string.gsub, code0, pat, rep)
123131
if ok_3f then
124132
return val_or_err
@@ -127,7 +135,7 @@ local function apply_gsubs(code)
127135
return code0
128136
end
129137
end
130-
return a.reduce(_14_, code, a["kv-pairs"]((nvim.b["conjure#eval#gsubs"] or nvim.g["conjure#eval#gsubs"])))
138+
return a.reduce(_16_, code, a["kv-pairs"]((nvim.b["conjure#eval#gsubs"] or nvim.g["conjure#eval#gsubs"])))
131139
else
132140
return nil
133141
end
@@ -137,35 +145,35 @@ local function eval_str(opts)
137145
highlight_range(opts.range)
138146
event.emit("eval", "str")
139147
a.update(opts, "code", apply_gsubs)
140-
local function _17_()
148+
local function _19_()
141149
if opts["passive?"] then
142150
return opts
143151
else
144152
return with_last_result_hook(opts)
145153
end
146154
end
147-
client_exec_fn("eval", "eval-str")(_17_())
155+
client_exec_fn("eval", "eval-str")(_19_())
148156
return nil
149157
end
150158
_2amodule_2a["eval-str"] = eval_str
151159
local function wrap_emit(name, f)
152-
local function _18_(...)
160+
local function _20_(...)
153161
event.emit(name)
154162
return f(...)
155163
end
156-
return _18_
164+
return _20_
157165
end
158166
_2amodule_2a["wrap-emit"] = wrap_emit
159167
local doc_str = wrap_emit("doc", client_exec_fn("doc", "doc-str"))
160168
do end (_2amodule_locals_2a)["doc-str"] = doc_str
161-
local def_str = wrap_emit("def", client_exec_fn("def", "def-str", {["suppress-hud?"] = true}))
169+
local def_str = wrap_emit("def", client_exec_fn("def", "def-str", {["suppress-hud?"] = true, ["set-jump-mark?"] = true}))
162170
do end (_2amodule_locals_2a)["def-str"] = def_str
163171
local function current_form(extra_opts)
164172
local form = extract.form({})
165173
if form then
166-
local _let_19_ = form
167-
local content = _let_19_["content"]
168-
local range = _let_19_["range"]
174+
local _let_21_ = form
175+
local content = _let_21_["content"]
176+
local range = _let_21_["range"]
169177
eval_str(a.merge({code = content, range = range, origin = "current-form"}, extra_opts))
170178
return form
171179
else
@@ -178,14 +186,14 @@ local function replace_form()
178186
local win = nvim.tabpage_get_win(0)
179187
local form = extract.form({})
180188
if form then
181-
local _let_21_ = form
182-
local content = _let_21_["content"]
183-
local range = _let_21_["range"]
184-
local function _22_(result)
189+
local _let_23_ = form
190+
local content = _let_23_["content"]
191+
local range = _let_23_["range"]
192+
local function _24_(result)
185193
buffer["replace-range"](buf, range, result)
186194
return editor["go-to"](win, a["get-in"](range, {"start", 1}), a.inc(a["get-in"](range, {"start", 2})))
187195
end
188-
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _22_})
196+
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _24_})
189197
return form
190198
else
191199
return nil
@@ -195,9 +203,9 @@ _2amodule_2a["replace-form"] = replace_form
195203
local function root_form()
196204
local form = extract.form({["root?"] = true})
197205
if form then
198-
local _let_24_ = form
199-
local content = _let_24_["content"]
200-
local range = _let_24_["range"]
206+
local _let_26_ = form
207+
local content = _let_26_["content"]
208+
local range = _let_26_["range"]
201209
return eval_str({code = content, range = range, origin = "root-form"})
202210
else
203211
return nil
@@ -208,10 +216,10 @@ local function marked_form(mark)
208216
local comment_prefix = client.get("comment-prefix")
209217
local mark0 = (mark or extract["prompt-char"]())
210218
local ok_3f, err = nil, nil
211-
local function _26_()
219+
local function _28_()
212220
return editor["go-to-mark"](mark0)
213221
end
214-
ok_3f, err = pcall(_26_)
222+
ok_3f, err = pcall(_28_)
215223
if ok_3f then
216224
current_form({origin = ("marked-form [" .. mark0 .. "]")})
217225
editor["go-back"]()
@@ -225,13 +233,13 @@ local function insert_result_comment(tag, input)
225233
local buf = nvim.win_get_buf(0)
226234
local comment_prefix = (config["get-in"]({"eval", "comment_prefix"}) or client.get("comment-prefix"))
227235
if input then
228-
local _let_28_ = input
229-
local content = _let_28_["content"]
230-
local range = _let_28_["range"]
231-
local function _29_(result)
236+
local _let_30_ = input
237+
local content = _let_30_["content"]
238+
local range = _let_30_["range"]
239+
local function _31_(result)
232240
return buffer["append-prefixed-line"](buf, range["end"], comment_prefix, result)
233241
end
234-
eval_str({code = content, range = range, origin = ("comment-" .. tag), ["suppress-hud?"] = true, ["on-result"] = _29_})
242+
eval_str({code = content, range = range, origin = ("comment-" .. tag), ["suppress-hud?"] = true, ["on-result"] = _31_})
235243
return input
236244
else
237245
return nil
@@ -251,9 +259,9 @@ local function comment_word()
251259
end
252260
_2amodule_2a["comment-word"] = comment_word
253261
local function word()
254-
local _let_31_ = extract.word()
255-
local content = _let_31_["content"]
256-
local range = _let_31_["range"]
262+
local _let_33_ = extract.word()
263+
local content = _let_33_["content"]
264+
local range = _let_33_["range"]
257265
if not a["empty?"](content) then
258266
return eval_str({code = content, range = range, origin = "word"})
259267
else
@@ -262,9 +270,9 @@ local function word()
262270
end
263271
_2amodule_2a["word"] = word
264272
local function doc_word()
265-
local _let_33_ = extract.word()
266-
local content = _let_33_["content"]
267-
local range = _let_33_["range"]
273+
local _let_35_ = extract.word()
274+
local content = _let_35_["content"]
275+
local range = _let_35_["range"]
268276
if not a["empty?"](content) then
269277
return doc_str({code = content, range = range, origin = "word"})
270278
else
@@ -273,9 +281,9 @@ local function doc_word()
273281
end
274282
_2amodule_2a["doc-word"] = doc_word
275283
local function def_word()
276-
local _let_35_ = extract.word()
277-
local content = _let_35_["content"]
278-
local range = _let_35_["range"]
284+
local _let_37_ = extract.word()
285+
local content = _let_37_["content"]
286+
local range = _let_37_["range"]
279287
if not a["empty?"](content) then
280288
return def_str({code = content, range = range, origin = "word"})
281289
else
@@ -284,9 +292,9 @@ local function def_word()
284292
end
285293
_2amodule_2a["def-word"] = def_word
286294
local function buf()
287-
local _let_37_ = extract.buf()
288-
local content = _let_37_["content"]
289-
local range = _let_37_["range"]
295+
local _let_39_ = extract.buf()
296+
local content = _let_39_["content"]
297+
local range = _let_39_["range"]
290298
return eval_str({code = content, range = range, origin = "buf"})
291299
end
292300
_2amodule_2a["buf"] = buf
@@ -295,16 +303,16 @@ local function command(code)
295303
end
296304
_2amodule_2a["command"] = command
297305
local function range(start, _end)
298-
local _let_38_ = extract.range(start, _end)
299-
local content = _let_38_["content"]
300-
local range0 = _let_38_["range"]
306+
local _let_40_ = extract.range(start, _end)
307+
local content = _let_40_["content"]
308+
local range0 = _let_40_["range"]
301309
return eval_str({code = content, range = range0, origin = "range"})
302310
end
303311
_2amodule_2a["range"] = range
304312
local function selection(kind)
305-
local _let_39_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
306-
local content = _let_39_["content"]
307-
local range0 = _let_39_["range"]
313+
local _let_41_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
314+
local content = _let_41_["content"]
315+
local range0 = _let_41_["range"]
308316
return eval_str({code = content, range = range0, origin = "selection"})
309317
end
310318
_2amodule_2a["selection"] = selection
@@ -318,15 +326,15 @@ end
318326
_2amodule_locals_2a["wrap-completion-result"] = wrap_completion_result
319327
local function completions(prefix, cb)
320328
local function cb_wrap(results)
321-
local function _42_()
322-
local _41_ = config["get-in"]({"completion", "fallback"})
323-
if (nil ~= _41_) then
324-
return nvim.call_function(_41_, {0, prefix})
329+
local function _44_()
330+
local _43_ = config["get-in"]({"completion", "fallback"})
331+
if (nil ~= _43_) then
332+
return nvim.call_function(_43_, {0, prefix})
325333
else
326-
return _41_
334+
return _43_
327335
end
328336
end
329-
return cb(a.map(wrap_completion_result, (results or _42_())))
337+
return cb(a.map(wrap_completion_result, (results or _44_())))
330338
end
331339
if ("function" == type(client.get("completions"))) then
332340
return client.call("completions", assoc_context({["file-path"] = extract["file-path"](), prefix = prefix, cb = cb_wrap}))

0 commit comments

Comments
 (0)
Please sign in to comment.