2021-02-07 21:56:19 +00:00
|
|
|
(local util (require :lib.util))
|
|
|
|
(local core (require :core))
|
|
|
|
(local command (require :core.command))
|
|
|
|
(local keymap (require :core.keymap))
|
|
|
|
(local common (require :core.common))
|
|
|
|
|
2022-04-10 04:20:18 +00:00
|
|
|
(fn selected-form []
|
2021-02-07 21:56:19 +00:00
|
|
|
(let [ldoc core.active_view.doc
|
2022-04-10 04:20:18 +00:00
|
|
|
(aline acol bline bcol) (ldoc:get_selection)]
|
2021-02-07 21:56:19 +00:00
|
|
|
(if (and (= aline bline) (= acol bcol))
|
2022-04-10 04:20:18 +00:00
|
|
|
(ldoc:get_text aline 1 aline 10000000)
|
|
|
|
(ldoc:get_text aline acol bline bcol))))
|
|
|
|
|
2022-04-10 16:03:16 +00:00
|
|
|
(fn find-closest [s pattern i-target]
|
|
|
|
(var (start end) nil)
|
|
|
|
(set (start end) (s:find pattern))
|
|
|
|
(while (and start (< end (- i-target 1)))
|
|
|
|
(set (start end) (s:find pattern (+ end 1))))
|
|
|
|
(if (<= start i-target) (values start end)
|
|
|
|
(values 1 0)))
|
|
|
|
|
|
|
|
(local symbol-pattern "[a-zA-Z%!%@%#%$%%%^%&%*%<%>%?%/%~%-%_%=%+][a-zA-Z%!%@%#%$%%%^%&%*%<%>%?%/%~%-%_%=%+0-9%.%:]*")
|
|
|
|
(fn selected-symbol []
|
|
|
|
(let [ldoc core.active_view.doc
|
|
|
|
(aline acol bline bcol) (ldoc:get_selection)]
|
|
|
|
(if (and (= aline bline) (= acol bcol))
|
|
|
|
(let [line (ldoc:get_text aline 1 aline 10000000)
|
|
|
|
(start end) (find-closest line symbol-pattern acol)]
|
|
|
|
(ldoc:get_text aline start aline (+ end 1)))
|
|
|
|
(ldoc:get_text aline acol bline bcol))))
|
|
|
|
|
2022-04-10 04:20:18 +00:00
|
|
|
(fn inline-eval [eval]
|
|
|
|
(let [ldoc core.active_view.doc
|
|
|
|
(aline acol bline bcol) (ldoc:get_selection)]
|
|
|
|
(ldoc:insert bline bcol (eval (selected-form)))))
|
2021-02-07 21:56:19 +00:00
|
|
|
|
|
|
|
(require :editor.editmode)
|
|
|
|
|
2021-03-29 05:03:43 +00:00
|
|
|
(command.add :editor.replview {
|
|
|
|
"repl:submit" #(core.active_view:submit)
|
|
|
|
})
|
|
|
|
|
2022-04-10 04:20:18 +00:00
|
|
|
(local {: show : submit} (util.require :inspector.debug))
|
2022-04-10 16:03:16 +00:00
|
|
|
(local replsession (require :editor.replsession))
|
2021-03-29 05:03:43 +00:00
|
|
|
(command.add nil {
|
2022-04-10 04:20:18 +00:00
|
|
|
"repl:create" #(show)
|
|
|
|
})
|
2022-04-10 16:03:16 +00:00
|
|
|
|
|
|
|
(fn go-to-definition [symbol]
|
|
|
|
(fn jump-to-find-result [result]
|
|
|
|
(when (not (match result
|
|
|
|
{:vals [loc]}
|
|
|
|
(let [(filename line) (when loc (loc:match "(.*):([0-9]+)"))
|
|
|
|
filename (or filename "")
|
|
|
|
filename (if (filename:find "^%.%.%.") "" (or (filename:match "^%./(.*)") filename))
|
|
|
|
line (tonumber (or line 0))
|
|
|
|
doc (when (> (length filename) 0) (core.open_doc filename))]
|
|
|
|
(when doc
|
|
|
|
(core.root_view:open_doc doc)
|
|
|
|
(doc:set_selection line 1 line 1)
|
|
|
|
true))))
|
|
|
|
(core.log (.. "Unable to find symbol " symbol))))
|
|
|
|
(: (replsession.session) :submit (.. ",find " symbol) jump-to-find-result))
|
|
|
|
|
2022-04-10 04:20:18 +00:00
|
|
|
(command.add :core.docview {
|
|
|
|
"repl:eval" #(submit nil (selected-form))
|
2022-04-10 16:03:16 +00:00
|
|
|
"repl:go-to-definition" #(go-to-definition (selected-symbol))
|
2021-03-29 05:03:43 +00:00
|
|
|
})
|
2022-04-10 16:03:16 +00:00
|
|
|
|
2021-03-29 05:03:43 +00:00
|
|
|
(keymap.add {
|
|
|
|
:return "repl:submit"
|
2022-04-10 04:20:18 +00:00
|
|
|
"alt+e" "repl:eval"
|
2022-04-10 16:03:16 +00:00
|
|
|
"alt+d" "repl:go-to-definition"
|
2021-03-29 05:03:43 +00:00
|
|
|
})
|
|
|
|
|
2022-04-10 16:03:16 +00:00
|
|
|
{: inline-eval : symbol-pattern}
|
|
|
|
|