From d056253c63a9ea911719418a52f1085b5c590d41 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Thu, 22 Aug 2024 13:25:18 -1000 Subject: [PATCH] Convert another batch of source and test files --- fnl/conjure-spec/linked-list_spec.fnl | 74 ++++++++ fnl/conjure-spec/process_spec.fnl | 55 ++++++ fnl/conjure-spec/promise_spec.fnl | 48 ++++++ fnl/conjure-spec/school_spec.fnl | 19 ++ fnl/conjure/eval.fnl | 131 ++++++++------ fnl/conjure/hook.fnl | 29 ++-- fnl/conjure/inline.fnl | 24 +-- fnl/conjure/linked-list.fnl | 34 ++-- fnl/conjure/log.fnl | 133 +++++++------- fnl/conjure/main.fnl | 12 +- fnl/conjure/process.fnl | 30 ++-- fnl/conjure/promise.fnl | 33 ++-- fnl/conjure/school.fnl | 66 ++++--- lua/conjure-spec/linked-list_spec.lua | 102 +++++++++++ lua/conjure-spec/process_spec.lua | 72 ++++++++ lua/conjure-spec/promise_spec.lua | 68 ++++++++ lua/conjure-spec/school_spec.lua | 20 +++ lua/conjure/eval.lua | 238 +++++++++----------------- lua/conjure/hook.lua | 38 +--- lua/conjure/inline.lua | 42 ++--- lua/conjure/linked-list.lua | 55 ++---- lua/conjure/log.lua | 158 ++++------------- lua/conjure/main.lua | 30 +--- lua/conjure/process.lua | 67 +++----- lua/conjure/promise.lua | 44 +---- lua/conjure/school.lua | 78 ++------- 26 files changed, 930 insertions(+), 770 deletions(-) create mode 100644 fnl/conjure-spec/linked-list_spec.fnl create mode 100644 fnl/conjure-spec/process_spec.fnl create mode 100644 fnl/conjure-spec/promise_spec.fnl create mode 100644 fnl/conjure-spec/school_spec.fnl create mode 100644 lua/conjure-spec/linked-list_spec.lua create mode 100644 lua/conjure-spec/process_spec.lua create mode 100644 lua/conjure-spec/promise_spec.lua create mode 100644 lua/conjure-spec/school_spec.lua diff --git a/fnl/conjure-spec/linked-list_spec.fnl b/fnl/conjure-spec/linked-list_spec.fnl new file mode 100644 index 00000000..ab85e001 --- /dev/null +++ b/fnl/conjure-spec/linked-list_spec.fnl @@ -0,0 +1,74 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local ll (require :conjure.linked-list)) + +(describe "conjure.linked-list" + (fn [] + + (describe "basics" + (fn [] + (let [l (ll.create [1 2 3])] + (it "get first value" + (fn [] + (assert.are.equals 1 (->> l (ll.val))))) + (it "get second value" + (fn [] + (assert.are.equals 2 (->> l (ll.next) (ll.val))))) + (it "forward and back" + (fn [] + (assert.are.equals 1 (->> l (ll.next) (ll.prev) (ll.val))))) + (it "last by steps" + (fn [] + (assert.are.equals 3 (->> l (ll.next) (ll.next) (ll.val))))) + (it "off the end" + (fn [] + (assert.are.equals nil (->> l (ll.next) (ll.next) (ll.next))))) + (it "off the front" + (fn [] + (assert.are.equals nil (->> l (ll.prev))))) + (it "val handles nils" + (fn [] + (assert.are.equals nil (ll.val nil)))) + (it "last" + (fn [] + (assert.are.equals 3 (->> l (ll.last) (ll.val))))) + (it "first" + (fn [] + (assert.are.equals 1 (->> l (ll.first) (ll.val))))) + (it "last then first" + (fn [] + (assert.are.equals 1 (->> l (ll.last) (ll.first) (ll.val)))))))) + + (describe "until" + (fn [] + (let [l (ll.create [1 2 3 4 5])] + + (it "nil if not found" + (fn [] + (assert.are.equals nil (->> l (ll.until #(= 8 (ll.val $1))) (ll.val))))) + (it "target node if found" + (fn [] + (assert.are.equals 3 (->> l (ll.until #(= 3 (ll.val $1))) (ll.val))))) + (it "can find the one before" + (fn [] + (assert.are.equals 2 (->> l (ll.until #(= 3 (->> $1 (ll.next) (ll.val)))) (ll.val)))))))) + + (describe "cycle" + (fn [] + (let [l (ll.cycle (ll.create [1 2 3]))] + (it "first is still first" + (fn [] + (assert.are.equals 1 (->> l (ll.val))))) + (it "can still next" + (fn [] + (assert.are.equals 2 (->> l (ll.next) (ll.val))))) + (it "can still next next (last)" + (fn [] + (assert.are.equals 3 (->> l (ll.next) (ll.next) (ll.val))))) + (it "off the end loops" + (fn [] + (assert.are.equals 1 (->> l (ll.next) (ll.next) (ll.next) (ll.val))))) + (it "off the front loops" + (fn [] + (assert.are.equals 3 (->> l (ll.prev) (ll.val)))))))))) + diff --git a/fnl/conjure-spec/process_spec.fnl b/fnl/conjure-spec/process_spec.fnl new file mode 100644 index 00000000..9b3fcc3d --- /dev/null +++ b/fnl/conjure-spec/process_spec.fnl @@ -0,0 +1,55 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local nvim (require :conjure.aniseed.nvim)) +(local process (require :conjure.process)) + +(describe "conjure.process" + (fn [] + (describe "executable?" + (fn [] + (it "thing's that don't exist return false" + (fn [] + (assert.are.equals false (process.executable? "nope-this-does-not-exist")))) + (it "sh should always exist, I hope" + (fn [] + (assert.are.equals true (process.executable? "sh")))) + (it "only the first word is checked" + (fn [] + (assert.are.equals true (process.executable? "sh foo bar")))))) + + (describe "execute-stop-lifecycle" + (fn [] + (let [sh (process.execute "sh")] + (it "we get a table to identify the process" + (fn [] + (assert.are.equals :table (type sh)))) + (it "it starts out as running" + (fn [] + (assert.are.equals true (process.running? sh)))) + (it "the running check handles nils" + (fn [] + (assert.are.equals false (process.running? nil)))) + (it "a buffer is created for the terminal / process" + (fn [] + (assert.are.equals 1 (nvim.fn.bufexists sh.buf)))) + (it "stopping returns the process table" + (fn [] + (assert.are.equals sh (process.stop sh)))) + (it "stopping is idempotent" + (fn [] + (assert.are.equals sh (process.stop sh)))) + (it "now it's not running" + (fn [] + (assert.are.equals false (process.running? sh))))))) + + (describe "on-exit-hook" + (fn [] + (let [state {:args nil} + sh (process.execute + "sh" + {:on-exit (fn [...] + (tset state :args [...]))})] + (it "called and given the proc" + (fn [] + (process.stop sh) + (assert.same [sh] state.args)))))))) diff --git a/fnl/conjure-spec/promise_spec.fnl b/fnl/conjure-spec/promise_spec.fnl new file mode 100644 index 00000000..9817d0d5 --- /dev/null +++ b/fnl/conjure-spec/promise_spec.fnl @@ -0,0 +1,48 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local a (require :nfnl.core)) +(local promise (require :conjure.promise)) + +(describe "conjure.promise" + (fn [] + (describe "basics" + (let [p (promise.new)] + (fn [] + (it "starts incomplete" + (fn [] + (assert.are.equals false (promise.done? p)))) + (it "done after deliver" + (fn [] + (promise.deliver p :foo) + (assert.are.equals true (promise.done? p)))) + (it "returns the value on close" + (fn [] + (assert.are.equals :foo (promise.close p))))))) + + (describe "multiple-deliveries" + (fn [] + (let [p (promise.new)] + (it "only the first delivery works" + (fn [] + (promise.deliver p :foo) + (promise.deliver p :bar) + (assert.are.equals :foo (promise.close p))))))) + + (describe "async" + (let [p (promise.new) + del (promise.deliver-fn p)] + (vim.schedule (fn [] (del :later))) + (fn [] + (it "async delivery hasn't happened yet" + (fn [] + (assert.are.equals false (promise.done? p)))) + (it "await returns 0 from wait()" + (fn [] + (assert.are.equals 0 (promise.await p)))) + (it "complete after await" + (fn [] + (assert.are.equals true (promise.done? p)))) + (it "value is correct" + (fn [] + (assert.are.equals :later (promise.close p))))))) +)) diff --git a/fnl/conjure-spec/school_spec.fnl b/fnl/conjure-spec/school_spec.fnl new file mode 100644 index 00000000..c0159729 --- /dev/null +++ b/fnl/conjure-spec/school_spec.fnl @@ -0,0 +1,19 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local school (require :conjure.school)) +(local nvim (require :conjure.aniseed.nvim)) + +(describe "running :ConjureSchool" + (fn [] + (school.start) + + (it "buffer has correct name" + (fn [] + (assert.are.equals "conjure-school.fnl" (nvim.fn.bufname)))) + + (it "buffer requires conjure.school module" + (fn [] + (assert.same ["(local school (require :conjure.school))"] (nvim.buf_get_lines 0 1 2 false)))) + + (nvim.ex.bdelete "conjure-school.fnl") + )) diff --git a/fnl/conjure/eval.fnl b/fnl/conjure/eval.fnl index b9306cbf..4b2d8749 100644 --- a/fnl/conjure/eval.fnl +++ b/fnl/conjure/eval.fnl @@ -1,25 +1,23 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.eval - {autoload {a conjure.aniseed.core - str conjure.aniseed.string - nvim conjure.aniseed.nvim - nu conjure.aniseed.nvim.util - extract conjure.extract - client conjure.client - text conjure.text - fs conjure.fs - timer conjure.timer - config conjure.config - promise conjure.promise - editor conjure.editor - buffer conjure.buffer - inline conjure.inline - uuid conjure.uuid - log conjure.log - event conjure.event}}) - -(defn- preview [opts] +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local str (autoload :conjure.aniseed.string)) +(local nu (autoload :conjure.aniseed.nvim.util)) +(local extract (autoload :conjure.extract)) +(local client (autoload :conjure.client)) +(local text (autoload :conjure.text)) +(local fs (autoload :conjure.fs)) +(local timer (autoload :conjure.timer)) +(local config (autoload :conjure.config)) +(local promise (autoload :conjure.promise)) +(local editor (autoload :conjure.editor)) +(local buffer (autoload :conjure.buffer)) +(local inline (autoload :conjure.inline)) +(local uuid (autoload :conjure.uuid)) +(local log (autoload :conjure.log)) +(local event (autoload :conjure.event)) + +(fn preview [opts] (let [sample-limit (editor.percent-width (config.get-in [:preview :sample_limit]))] (str.join @@ -29,12 +27,12 @@ (text.right-sample opts.file-path sample-limit) (text.left-sample opts.code sample-limit))]))) -(defn- display-request [opts] +(fn display-request [opts] (log.append [opts.preview] (a.merge opts {:break? true}))) -(defn- highlight-range [range] +(fn highlight-range [range] (when (and (config.get-in [:highlight :enabled]) vim.highlight range) @@ -58,7 +56,7 @@ bufnr namespace 0 -1))) (config.get-in [:highlight :timeout]))))) -(defn- with-last-result-hook [opts] +(fn with-last-result-hook [opts] (let [buf (nvim.win_get_buf 0) line (a.dec (a.first (nvim.win_get_cursor 0)))] (a.update @@ -82,7 +80,7 @@ :line line})) (when f (f result))))))) -(defn file [] +(fn file [] (event.emit :eval :file) (let [opts {:file-path (fs.localise-path (extract.file-path)) :origin :file @@ -93,14 +91,14 @@ :eval-file (with-last-result-hook opts)))) -(defn- assoc-context [opts] +(fn assoc-context [opts] (when (not opts.context) (set opts.context (or nvim.b.conjure#context (extract.context)))) opts) -(defn- client-exec-fn [action f-name base-opts] +(fn client-exec-fn [action f-name base-opts] (fn [opts] (let [opts (a.merge opts base-opts {:action action @@ -129,7 +127,7 @@ (client.call f-name opts)))) -(defn- apply-gsubs [code] +(fn apply-gsubs [code] (when code (a.reduce (fn [code [name [pat rep]]] @@ -144,10 +142,10 @@ (a.kv-pairs (or nvim.b.conjure#eval#gsubs nvim.g.conjure#eval#gsubs))))) -(defonce previous-evaluations +(local previous-evaluations {}) -(defn eval-str [opts] +(fn eval-str [opts] (a.assoc previous-evaluations (a.get (client.current-client-module-name) :module-name :unknown) @@ -162,29 +160,29 @@ (with-last-result-hook opts))) nil) -(defn previous [] +(fn 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 wrap-emit [name f] (fn [...] (event.emit name) (f ...))) -(def- doc-str (wrap-emit +(local doc-str (wrap-emit :doc (client-exec-fn :doc :doc-str))) -(def- def-str (wrap-emit +(local def-str (wrap-emit :def (client-exec-fn :def :def-str {:suppress-hud? true :jumping? true}))) -(defn current-form [extra-opts] +(fn current-form [extra-opts] (let [form (extract.form {})] (when form (let [{: content : range} form] @@ -196,7 +194,7 @@ extra-opts)) form)))) -(defn replace-form [] +(fn replace-form [] (let [buf (nvim.win_get_buf 0) win (nvim.tabpage_get_win 0) form (extract.form {})] @@ -218,7 +216,7 @@ (a.inc (a.get-in range [:start 2]))))}) form)))) -(defn root-form [] +(fn root-form [] (let [form (extract.form {:root? true})] (when form (let [{: content : range} form] @@ -227,7 +225,7 @@ :range range :origin :root-form}))))) -(defn marked-form [mark] +(fn marked-form [mark] (let [comment-prefix (client.get :comment-prefix) mark (or mark (extract.prompt-char)) (ok? err) (pcall #(editor.go-to-mark mark))] @@ -240,7 +238,7 @@ {:break? true})) mark)) -(defn- insert-result-comment [tag input] +(fn insert-result-comment [tag input] (let [buf (nvim.win_get_buf 0) comment-prefix (or (config.get-in [:eval :comment_prefix]) @@ -261,16 +259,16 @@ result))}) input)))) -(defn comment-current-form [] +(fn comment-current-form [] (insert-result-comment :current-form (extract.form {}))) -(defn comment-root-form [] +(fn comment-root-form [] (insert-result-comment :root-form (extract.form {:root? true}))) -(defn comment-word [] +(fn comment-word [] (insert-result-comment :word (extract.word))) -(defn word [] +(fn word [] (let [{: content : range} (extract.word)] (when (not (a.empty? content)) (eval-str @@ -278,7 +276,7 @@ :range range :origin :word})))) -(defn doc-word [] +(fn doc-word [] (let [{: content : range} (extract.word)] (when (not (a.empty? content)) (doc-str @@ -286,7 +284,7 @@ :range range :origin :word})))) -(defn def-word [] +(fn def-word [] (let [{: content : range} (extract.word)] (when (not (a.empty? content)) (def-str @@ -294,26 +292,26 @@ :range range :origin :word})))) -(defn buf [] +(fn buf [] (let [{: content : range} (extract.buf)] (eval-str {:code content :range range :origin :buf}))) -(defn command [code] +(fn command [code] (eval-str {:code code :origin :command})) -(defn range [start end] +(fn range [start end] (let [{: content : range} (extract.range start end)] (eval-str {:code content :range range :origin :range}))) -(defn selection [kind] +(fn selection [kind] (let [{: content : range} (extract.selection {:kind (or kind (nvim.fn.visualmode)) @@ -323,12 +321,12 @@ :range range :origin :selection}))) -(defn- wrap-completion-result [result] +(fn wrap-completion-result [result] (if (a.string? result) {:word result} result)) -(defn completions [prefix cb] +(fn completions [prefix cb] (fn cb-wrap [results] (cb (a.map wrap-completion-result @@ -344,14 +342,37 @@ (assoc-context))) (cb-wrap))) -(defn completions-promise [prefix] +(fn completions-promise [prefix] (let [p (promise.new)] (completions prefix (promise.deliver-fn p)) p)) -(defn completions-sync [prefix] +(fn completions-sync [prefix] (let [p (completions-promise prefix)] (promise.await p) (promise.close p))) -*module* +{ + : file + : previous-evaluation + : eval-str + : previous + : wrap-emit + : current-form + : replace-form + : root-form + : marked-form + : comment-current-form + : comment-root-form + : comment-word + : word + : doc-word + : def-word + : buf + : command + : range + : selection + : completions + : completions-promise + : completions-sync + } diff --git a/fnl/conjure/hook.fnl b/fnl/conjure/hook.fnl index 7ac362c2..734a2483 100644 --- a/fnl/conjure/hook.fnl +++ b/fnl/conjure/hook.fnl @@ -1,29 +1,34 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.hook - {autoload {a conjure.aniseed.core - str conjure.aniseed.string}}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local str (autoload :conjure.aniseed.string)) ;; These are originals defined by Conjure. -(defonce hook-fns {}) +(local hook-fns {}) ;; These are user defined overrides. -(defonce hook-override-fns {}) +(local hook-override-fns {}) -(defn define [name f] +(fn define [name f] (a.assoc hook-fns name f)) -(defn override [name f] +(fn override [name f] (a.assoc hook-override-fns name f)) -(defn get [name] +(fn get [name] (a.get hook-fns name)) -(defn exec [name ...] +(fn exec [name ...] (let [f (or (a.get hook-override-fns name) (a.get hook-fns name))] (if f (f ...) (error (str.join " " ["conjure.hook: Hook not found, can not exec" name]))))) -*module* +{ + : hook-fns + : hook-override-fns + : define + : override + : get + : exec + } diff --git a/fnl/conjure/inline.fnl b/fnl/conjure/inline.fnl index 598b78e2..9e74fb39 100644 --- a/fnl/conjure/inline.fnl +++ b/fnl/conjure/inline.fnl @@ -1,25 +1,23 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local config (autoload :conjure.config)) +(local nvim (autoload :conjure.aniseed.nvim)) -(module conjure.inline - {autoload {a conjure.aniseed.core - config conjure.config - nvim conjure.aniseed.nvim}}) +(local ns-id (nvim.create_namespace :conjure.inline)) -(defonce ns-id (nvim.create_namespace *module-name*)) - -(defn sanitise-text [s] +(fn sanitise-text [s] (if (a.string? s) (s:gsub "%s+" " ") "")) -(defn clear [opts] +(fn clear [opts] "Clear all (Conjure related) virtual text for opts.buf, defaults to 0 which is the current buffer." (pcall (fn [] (nvim.buf_clear_namespace (a.get opts :buf 0) ns-id 0 -1)))) -(defn display [opts] +(fn display [opts] "Display virtual text for opts.buf on opts.line containing opts.text." (local hl-group (config.get-in [:eval :inline :highlight])) (pcall @@ -30,4 +28,8 @@ [[(sanitise-text opts.text) hl-group]] {})))) -*module* +{ + : sanitise-text + : clear + : display + } diff --git a/fnl/conjure/linked-list.fnl b/fnl/conjure/linked-list.fnl index 424127af..3ce046b5 100644 --- a/fnl/conjure/linked-list.fnl +++ b/fnl/conjure/linked-list.fnl @@ -1,9 +1,7 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) -(module conjure.linked-list - {autoload {a conjure.aniseed.core}}) - -(defn create [xs prev] +(fn create [xs prev] (when (not (a.empty? xs)) (let [rest (a.rest xs) node {}] @@ -11,28 +9,28 @@ (a.assoc node :prev prev) (a.assoc node :next (create rest node))))) -(defn val [l] +(fn val [l] (-?> l (a.get :val))) -(defn next [l] +(fn next [l] (-?> l (a.get :next))) -(defn prev [l] +(fn prev [l] (-?> l (a.get :prev))) -(defn first [l] +(fn first [l] (var c l) (while (prev c) (set c (prev c))) c) -(defn last [l] +(fn last [l] (var c l) (while (next c) (set c (next c))) c) -(defn until [f l] +(fn until [f l] (var c l) (var r false) (fn step [] @@ -43,11 +41,21 @@ (when r c)) -(defn cycle [l] +(fn cycle [l] (let [start (first l) end (last l)] (a.assoc start :prev end) (a.assoc end :next start) l)) -*module* +{ + : create + : val + : next + : prev + : first + : last + : until + : cycle + } + diff --git a/fnl/conjure/log.fnl b/fnl/conjure/log.fnl index c6526e58..e86bab22 100644 --- a/fnl/conjure/log.fnl +++ b/fnl/conjure/log.fnl @@ -1,20 +1,18 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.log - {autoload {a conjure.aniseed.core - nvim conjure.aniseed.nvim - str conjure.aniseed.string - buffer conjure.buffer - client conjure.client - hook conjure.hook - config conjure.config - view conjure.aniseed.view - text conjure.text - editor conjure.editor - timer conjure.timer} - require {sponsors conjure.sponsors}}) - -(defonce- state +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local str (autoload :conjure.aniseed.string)) +(local buffer (autoload :conjure.buffer)) +(local client (autoload :conjure.client)) +(local hook (autoload :conjure.hook)) +(local config (autoload :conjure.config)) +(local view (autoload :conjure.aniseed.view)) +(local text (autoload :conjure.text)) +(local editor (autoload :conjure.editor)) +(local timer (autoload :conjure.timer)) +(local sponsors (require :conjure.sponsors)) + +(local state {:last-open-cmd :vsplit :hud {:id nil :timer nil @@ -24,21 +22,21 @@ :jump-to-latest {:mark nil :ns (nvim.create_namespace "conjure_log_jump_to_latest")}}) -(defn- break [] +(fn break [] (str.join [(client.get :comment-prefix) (string.rep "-" (config.get-in [:log :break_length]))])) -(defn- state-key-header [] +(fn state-key-header [] (str.join [(client.get :comment-prefix) "State: " (client.state-key)])) -(defn- log-buf-name [] +(fn log-buf-name [] (str.join ["conjure-log-" (nvim.fn.getpid) (client.get :buf-suffix)])) -(defn log-buf? [name] +(fn log-buf? [name] (text.ends-with name (log-buf-name))) -(defn- on-new-log-buf [buf] +(fn on-new-log-buf [buf] (set state.jump-to-latest.mark (nvim.buf_set_extmark buf state.jump-to-latest.ns 0 0 {})) @@ -58,12 +56,12 @@ (a.get sponsors (a.inc (math.floor (a.rand (a.dec (a.count sponsors)))))) " ❤"])])) -(defn- upsert-buf [] +(fn upsert-buf [] (buffer.upsert-hidden (log-buf-name) (client.wrap on-new-log-buf))) -(defn clear-close-hud-passive-timer [] +(fn clear-close-hud-passive-timer [] (a.update-in state [:hud :timer] timer.destroy)) (hook.define @@ -73,14 +71,14 @@ (pcall nvim.win_close state.hud.id true) (set state.hud.id nil)))) -(defn close-hud [] +(fn close-hud [] (clear-close-hud-passive-timer) (hook.exec :close-hud)) -(defn hud-lifetime-ms [] +(fn hud-lifetime-ms [] (- (vim.loop.now) state.hud.created-at-ms)) -(defn close-hud-passive [] +(fn close-hud-passive [] (when (and state.hud.id (> (hud-lifetime-ms) (config.get-in [:log :hud :minimum_lifetime_ms]))) @@ -93,7 +91,7 @@ state [:hud :timer] (timer.defer close-hud delay))))))) -(defn- break-lines [buf] +(fn break-lines [buf] (let [break-str (break)] (->> (nvim.buf_get_lines buf 0 -1 false) (a.kv-pairs) @@ -102,7 +100,7 @@ (= s break-str))) (a.map a.first)))) -(defn- set-win-opts! [win] +(fn set-win-opts! [win] (nvim.win_set_option win :wrap (if (config.get-in [:log :wrap]) @@ -114,11 +112,11 @@ (config.get-in [:log :fold :marker :end]))) (nvim.win_set_option win :foldlevel 0)) -(defn- in-box? [box pos] +(fn in-box? [box pos] (and (>= pos.x box.x1) (<= pos.x box.x2) (>= pos.y box.y1) (<= pos.y box.y2))) -(defn- flip-anchor [anchor n] +(fn flip-anchor [anchor n] (let [chars [(anchor:sub 1 1) (anchor:sub 2)] flip {:N :S @@ -127,14 +125,14 @@ :W :E}] (str.join (a.update chars n #(a.get flip $1))))) -(defn- pad-box [box padding] +(fn pad-box [box padding] (-> box (a.update :x1 #(- $1 padding.x)) (a.update :y1 #(- $1 padding.y)) (a.update :x2 #(+ $1 padding.x)) (a.update :y2 #(+ $1 padding.y)))) -(defn- hud-window-pos [anchor size rec?] +(fn hud-window-pos [anchor size rec?] (let [north 0 west 0 south (- (editor.height) 2) east (editor.width) @@ -170,12 +168,12 @@ size true) pos))) -(defn- current-window-floating? [] +(fn current-window-floating? [] (= :number (type (a.get (nvim.win_get_config 0) :zindex)))) -(def- low-priority-streak-threshold 5) +(local low-priority-streak-threshold 5) -(defn- handle-low-priority-spam! [low-priority?] +(fn handle-low-priority-spam! [low-priority?] ;; When we see a bunch of low-priority? messages opening the HUD repeatedly ;; we display a bit of help _once_ that can prevent this spam in the future ;; for the user. @@ -242,7 +240,7 @@ 0])) (nvim.win_set_cursor state.hud.id [line-count 0]))))) -(defn- display-hud [opts] +(fn display-hud [opts] (when (and (config.get-in [:log :hud :enabled]) ;; Don't display when the user is already doing something in a floating window. @@ -255,24 +253,24 @@ (clear-close-hud-passive-timer) (hook.exec :display-hud opts))) -(defn- win-visible? [win] +(fn win-visible? [win] (= (nvim.fn.tabpagenr) (a.first (nvim.fn.win_id2tabwin win)))) -(defn- with-buf-wins [buf f] +(fn with-buf-wins [buf f] (a.run! (fn [win] (when (= buf (nvim.win_get_buf win)) (f win))) (nvim.list_wins))) -(defn- win-botline [win] +(fn win-botline [win] (-> win (nvim.fn.getwininfo) (a.first) (a.get :botline))) -(defn- trim [buf] +(fn trim [buf] (let [line-count (nvim.buf_line_count buf)] (when (> line-count (config.get-in [:log :trim :at])) (let [target-line-count (- line-count (config.get-in [:log :trim :to])) @@ -299,19 +297,19 @@ (nvim.win_set_cursor win [1 0]) (nvim.win_set_cursor win [row col])))))))))) -(defn last-line [buf extra-offset] +(fn last-line [buf extra-offset] (a.first (nvim.buf_get_lines (or buf (upsert-buf)) (+ -2 (or extra-offset 0)) -1 false))) -(def cursor-scroll-position->command +(local cursor-scroll-position->command {:top "normal zt" :center "normal zz" :bottom "normal zb" :none nil}) -(defn jump-to-latest [] +(fn jump-to-latest [] (let [buf (upsert-buf) last-eval-start (nvim.buf_get_extmark_by_id buf state.jump-to-latest.ns @@ -327,7 +325,7 @@ (when cmd (nvim.win_call win (fn [] (nvim.command cmd))))))))) -(defn append [lines opts] +(fn append [lines opts] (let [line-count (a.count lines)] (when (> line-count 0) (var visible-scrolling-log? false) @@ -448,7 +446,7 @@ (trim buf))))) -(defn- create-win [cmd] +(fn create-win [cmd] (set state.last-open-cmd cmd) (let [buf (upsert-buf)] (nvim.command @@ -462,32 +460,32 @@ (set-win-opts! 0) (buffer.unlist buf))) -(defn split [] +(fn split [] (create-win :split)) -(defn vsplit [] +(fn vsplit [] (create-win :vsplit)) -(defn tab [] +(fn tab [] (create-win :tabnew)) -(defn buf [] +(fn buf [] (create-win :buf)) -(defn- find-windows [] +(fn find-windows [] (let [buf (upsert-buf)] (a.filter (fn [win] (and (not= state.hud.id win) (= buf (nvim.win_get_buf win)))) (nvim.tabpage_list_wins 0)))) -(defn- close [windows] +(fn close [windows] (a.run! #(nvim.win_close $1 true) windows)) -(defn close-visible [] +(fn close-visible [] (close-hud) (close (find-windows))) -(defn toggle [] +(fn toggle [] (let [windows (find-windows)] (if (a.empty? windows) (when (or (= state.last-open-cmd :split) @@ -495,7 +493,7 @@ (create-win state.last-open-cmd)) (close-visible windows)))) -(defn dbg [desc ...] +(fn dbg [desc ...] (when (config.get-in [:debug]) (append (a.concat @@ -503,10 +501,29 @@ (text.split-lines (a.pr-str ...))))) ...) -(defn reset-soft [] +(fn reset-soft [] (on-new-log-buf (upsert-buf))) -(defn reset-hard [] +(fn reset-hard [] (nvim.ex.bwipeout_ (upsert-buf))) -*module* +{ + : log-buf? + : clear-close-hud-passive-timer + : close-hud + : hud-lifetime-ms + : close-hud-passive + : last-line + : cursor-scroll-position->command + : jump-to-latest + : append + : split + : vsplit + : tab + : buf + : close-visible + : toggle + : dbg + : reset-soft + : reset-hard + } diff --git a/fnl/conjure/main.fnl b/fnl/conjure/main.fnl index 3ca20aeb..e6413765 100644 --- a/fnl/conjure/main.fnl +++ b/fnl/conjure/main.fnl @@ -1,10 +1,8 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local mapping (autoload :conjure.mapping)) +(local config (autoload :conjure.config)) -(module conjure.main - {autoload {mapping conjure.mapping - config conjure.config}}) - -(defn main [] +(fn main [] (mapping.init (config.filetypes))) -*module* +{: main } diff --git a/fnl/conjure/process.fnl b/fnl/conjure/process.fnl index 811f7dff..cb460760 100644 --- a/fnl/conjure/process.fnl +++ b/fnl/conjure/process.fnl @@ -1,9 +1,7 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.process - {autoload {nvim conjure.aniseed.nvim - a conjure.aniseed.core - str conjure.aniseed.string}}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local str (autoload :conjure.aniseed.string)) ;; For the execution of external processes through Neovim's terminal ;; integration. This module only cares about checking for some required program @@ -14,19 +12,19 @@ ;; The initial use case for this is to start a babashka REPL for Clojure files ;; if no nREPL connection can be established. -(defn executable? [cmd] +(fn executable? [cmd] "Check if the given program name can be found on the system. If you give it a full command with arguments it'll just check the first word." (= 1 (nvim.fn.executable (a.first (str.split cmd "%s+"))))) -(defn running? [proc] +(fn running? [proc] (if proc (. proc :running?) false)) -(defonce- state {:jobs {}}) +(local state {:jobs {}}) -(defn on-exit [job-id] +(fn on-exit [job-id] (let [proc (. state.jobs job-id)] (when (running? proc) (a.assoc proc :running? false) @@ -50,7 +48,7 @@ "call luaeval(\"require('conjure.process')['on-exit'](unpack(_A))\", a:000)" "endfunction"])) -(defn execute [cmd opts] +(fn execute [cmd opts] (let [win (nvim.tabpage_get_win 0) original-buf (nvim.win_get_buf win) term-buf (nvim.create_buf (not (?. opts :hidden?)) true) @@ -67,10 +65,16 @@ (tset state.jobs job-id proc) (a.assoc proc :job-id job-id))) -(defn stop [proc] +(fn stop [proc] (when (running? proc) (nvim.fn.jobstop proc.job-id) (on-exit proc.job-id)) proc) -*module* +{ + : executable? + : running? + : on-exit + : execute + : stop + } diff --git a/fnl/conjure/promise.fnl b/fnl/conjure/promise.fnl index 27b0aedc..5caacc31 100644 --- a/fnl/conjure/promise.fnl +++ b/fnl/conjure/promise.fnl @@ -1,13 +1,11 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local uuid (autoload :conjure.uuid)) -(module conjure.promise - {autoload {a conjure.aniseed.core - nvim conjure.aniseed.nvim - uuid conjure.uuid}}) +(local state {}) -(defonce- state {}) - -(defn new [] +(fn new [] (let [id (uuid.v4)] (a.assoc state id @@ -16,27 +14,34 @@ :done? false}) id)) -(defn done? [id] +(fn done? [id] (a.get-in state [id :done?])) -(defn deliver [id val] +(fn deliver [id val] (when (= false (done? id)) (a.assoc-in state [id :val] val) (a.assoc-in state [id :done?] true)) nil) -(defn deliver-fn [id] +(fn deliver-fn [id] #(deliver id $1)) -(defn close [id] +(fn close [id] (let [val (a.get-in state [id :val])] (a.assoc state id nil) val)) -(defn await [id opts] +(fn await [id opts] (nvim.fn.wait (a.get opts :timeout 10000) (.. "luaeval(\"require('conjure.promise')['done?']('" id "')\")") (a.get opts :interval 50))) -*module* +{ + : new + : done? + : deliver + : deliver-fn + : close + : await + } diff --git a/fnl/conjure/school.fnl b/fnl/conjure/school.fnl index ae1474d5..1b981379 100644 --- a/fnl/conjure/school.fnl +++ b/fnl/conjure/school.fnl @@ -1,19 +1,17 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local buffer (autoload :conjure.buffer)) +(local config (autoload :conjure.config)) +(local editor (autoload :conjure.editor)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local str (autoload :conjure.aniseed.string)) -(module conjure.school - {autoload {nvim conjure.aniseed.nvim - buffer conjure.buffer - config conjure.config - editor conjure.editor - str conjure.aniseed.string - a conjure.aniseed.core}}) +(local buf-name "conjure-school.fnl") -(def- buf-name "conjure-school.fnl") - -(defn- upsert-buf [] +(fn upsert-buf [] (buffer.upsert-hidden buf-name)) -(defn- append [lines] +(fn append [lines] (let [buf (upsert-buf) current-buf-str (str.join "\n" (nvim.buf_get_lines 0 0 -1 true)) to-insert-str (str.join "\n" lines)] @@ -24,19 +22,19 @@ -1 false lines) true))) -(defn- map-str [m] +(fn map-str [m] (.. (config.get-in [:mapping :prefix]) (config.get-in [:mapping m]))) -(defn- progress [n] +(fn progress [n] (.. "Lesson ["n "/7] complete!")) -(defn- append-or-warn [current-progress lines] +(fn append-or-warn [current-progress lines] (if (append lines) (progress current-progress) "You've already completed this lesson! You can (u)ndo and run it again though if you'd like.")) -(defn start [] +(fn start [] (when (not (editor.has-filetype? :fennel)) (nvim.echo "Warning: No Fennel filetype found, falling back to Clojure syntax." @@ -58,8 +56,9 @@ (nvim.buf_set_lines buf 0 -1 false []) (append (a.concat - ["(module user.conjure-school" - " {require {school conjure.school}})" + [ + "(local {: autoload} (require :nfnl.module))" + "(local school (require :conjure.school))" "" ";; Welcome to Conjure school!" ";; Grab yourself a nice beverage and let's get evaluating. I hope you enjoy!" @@ -80,7 +79,7 @@ [(.. ";; Your is currently mapped to \"" nvim.g.maplocalleader "\"")]) ["(school.lesson-1)"])))) -(defn lesson-1 [] +(fn lesson-1 [] (append-or-warn 1 ["" @@ -108,7 +107,7 @@ "(comment" " (school.lesson-2))"])) -(defn lesson-2 [] +(fn lesson-2 [] (append-or-warn 2 ["" @@ -120,7 +119,7 @@ " (print \"Hello, World!\")" " (school.lesson-3))"])) -(defn lesson-3 [] +(fn lesson-3 [] (append-or-warn 3 ["" @@ -132,7 +131,7 @@ (.. ";; We'll try that in the next lesson, place your cursor inside the form below and press " (map-str :eval_replace_form)) "(school.lesson-4)"])) -(defn lesson-4 [] +(fn lesson-4 [] (append-or-warn 4 ["" @@ -143,10 +142,10 @@ ";; If you use a capital letter like mF you can even open a different file and evaluate that marked form without changing buffers!" "(school.lesson-5)"])) -(def lesson-5-message +(local lesson-5-message "This is the contents of school.lesson-5-message!") -(defn lesson-5 [] +(fn lesson-5 [] (append-or-warn 5 ["" @@ -161,10 +160,10 @@ ";; Try evaluating the form below using a visual selection." "(school.lesson-6)"])) -(def lesson-6-message +(local lesson-6-message "This is the contents of school.lesson-6-message!") -(defn lesson-6 [] +(fn lesson-6 [] (append-or-warn 6 ["" @@ -177,7 +176,7 @@ (.. ";; Use " (map-str :eval_motion) "a( to evaluate the lesson form.") "(school.lesson-7)"])) -(defn lesson-7 [] +(fn lesson-7 [] (append-or-warn 7 ["" @@ -188,4 +187,15 @@ "" ";; I hope you have a wonderful time in Conjure!"])) -*module* +{ + : start + : lesson-1 + : lesson-2 + : lesson-3 + : lesson-4 + : lesson-5 + : lesson-6 + : lesson-7 + : lesson-5-message + : lesson-6-message + } diff --git a/lua/conjure-spec/linked-list_spec.lua b/lua/conjure-spec/linked-list_spec.lua new file mode 100644 index 00000000..55eb1b37 --- /dev/null +++ b/lua/conjure-spec/linked-list_spec.lua @@ -0,0 +1,102 @@ +-- [nfnl] Compiled from fnl/conjure-spec/linked-list_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local ll = require("conjure.linked-list") +local function _2_() + local function _3_() + local l = ll.create({1, 2, 3}) + local function _4_() + return assert.are.equals(1, ll.val(l)) + end + it("get first value", _4_) + local function _5_() + return assert.are.equals(2, ll.val(ll.next(l))) + end + it("get second value", _5_) + local function _6_() + return assert.are.equals(1, ll.val(ll.prev(ll.next(l)))) + end + it("forward and back", _6_) + local function _7_() + return assert.are.equals(3, ll.val(ll.next(ll.next(l)))) + end + it("last by steps", _7_) + local function _8_() + return assert.are.equals(nil, ll.next(ll.next(ll.next(l)))) + end + it("off the end", _8_) + local function _9_() + return assert.are.equals(nil, ll.prev(l)) + end + it("off the front", _9_) + local function _10_() + return assert.are.equals(nil, ll.val(nil)) + end + it("val handles nils", _10_) + local function _11_() + return assert.are.equals(3, ll.val(ll.last(l))) + end + it("last", _11_) + local function _12_() + return assert.are.equals(1, ll.val(ll.first(l))) + end + it("first", _12_) + local function _13_() + return assert.are.equals(1, ll.val(ll.first(ll.last(l)))) + end + return it("last then first", _13_) + end + describe("basics", _3_) + local function _14_() + local l = ll.create({1, 2, 3, 4, 5}) + local function _15_() + local function _16_(_241) + return (8 == ll.val(_241)) + end + return assert.are.equals(nil, ll.val(ll["until"](_16_, l))) + end + it("nil if not found", _15_) + local function _17_() + local function _18_(_241) + return (3 == ll.val(_241)) + end + return assert.are.equals(3, ll.val(ll["until"](_18_, l))) + end + it("target node if found", _17_) + local function _19_() + local function _20_(_241) + return (3 == ll.val(ll.next(_241))) + end + return assert.are.equals(2, ll.val(ll["until"](_20_, l))) + end + return it("can find the one before", _19_) + end + describe("until", _14_) + local function _21_() + local l = ll.cycle(ll.create({1, 2, 3})) + local function _22_() + return assert.are.equals(1, ll.val(l)) + end + it("first is still first", _22_) + local function _23_() + return assert.are.equals(2, ll.val(ll.next(l))) + end + it("can still next", _23_) + local function _24_() + return assert.are.equals(3, ll.val(ll.next(ll.next(l)))) + end + it("can still next next (last)", _24_) + local function _25_() + return assert.are.equals(1, ll.val(ll.next(ll.next(ll.next(l))))) + end + it("off the end loops", _25_) + local function _26_() + return assert.are.equals(3, ll.val(ll.prev(l))) + end + return it("off the front loops", _26_) + end + return describe("cycle", _21_) +end +return describe("conjure.linked-list", _2_) diff --git a/lua/conjure-spec/process_spec.lua b/lua/conjure-spec/process_spec.lua new file mode 100644 index 00000000..6ee241b6 --- /dev/null +++ b/lua/conjure-spec/process_spec.lua @@ -0,0 +1,72 @@ +-- [nfnl] Compiled from fnl/conjure-spec/process_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local nvim = require("conjure.aniseed.nvim") +local process = require("conjure.process") +local function _2_() + local function _3_() + local function _4_() + return assert.are.equals(false, process["executable?"]("nope-this-does-not-exist")) + end + it("thing's that don't exist return false", _4_) + local function _5_() + return assert.are.equals(true, process["executable?"]("sh")) + end + it("sh should always exist, I hope", _5_) + local function _6_() + return assert.are.equals(true, process["executable?"]("sh foo bar")) + end + return it("only the first word is checked", _6_) + end + describe("executable?", _3_) + local function _7_() + local sh = process.execute("sh") + local function _8_() + return assert.are.equals("table", type(sh)) + end + it("we get a table to identify the process", _8_) + local function _9_() + return assert.are.equals(true, process["running?"](sh)) + end + it("it starts out as running", _9_) + local function _10_() + return assert.are.equals(false, process["running?"](nil)) + end + it("the running check handles nils", _10_) + local function _11_() + return assert.are.equals(1, nvim.fn.bufexists(sh.buf)) + end + it("a buffer is created for the terminal / process", _11_) + local function _12_() + return assert.are.equals(sh, process.stop(sh)) + end + it("stopping returns the process table", _12_) + local function _13_() + return assert.are.equals(sh, process.stop(sh)) + end + it("stopping is idempotent", _13_) + local function _14_() + return assert.are.equals(false, process["running?"](sh)) + end + return it("now it's not running", _14_) + end + describe("execute-stop-lifecycle", _7_) + local function _15_() + local state = {args = nil} + local sh + local function _16_(...) + state["args"] = {...} + return nil + end + sh = process.execute("sh", {["on-exit"] = _16_}) + local function _17_() + process.stop(sh) + return assert.same({sh}, state.args) + end + return it("called and given the proc", _17_) + end + return describe("on-exit-hook", _15_) +end +return describe("conjure.process", _2_) diff --git a/lua/conjure-spec/promise_spec.lua b/lua/conjure-spec/promise_spec.lua new file mode 100644 index 00000000..229b989f --- /dev/null +++ b/lua/conjure-spec/promise_spec.lua @@ -0,0 +1,68 @@ +-- [nfnl] Compiled from fnl/conjure-spec/promise_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local a = require("nfnl.core") +local promise = require("conjure.promise") +local function _2_() + local function _3_() + local p = promise.new() + local function _4_() + local function _5_() + return assert.are.equals(false, promise["done?"](p)) + end + it("starts incomplete", _5_) + local function _6_() + promise.deliver(p, "foo") + return assert.are.equals(true, promise["done?"](p)) + end + it("done after deliver", _6_) + local function _7_() + return assert.are.equals("foo", promise.close(p)) + end + return it("returns the value on close", _7_) + end + return _4_ + end + describe("basics", _3_()) + local function _8_() + local p = promise.new() + local function _9_() + promise.deliver(p, "foo") + promise.deliver(p, "bar") + return assert.are.equals("foo", promise.close(p)) + end + return it("only the first delivery works", _9_) + end + describe("multiple-deliveries", _8_) + local function _10_() + local p = promise.new() + local del = promise["deliver-fn"](p) + local function _11_() + return del("later") + end + vim.schedule(_11_) + local function _12_() + local function _13_() + return assert.are.equals(false, promise["done?"](p)) + end + it("async delivery hasn't happened yet", _13_) + local function _14_() + return assert.are.equals(0, promise.await(p)) + end + it("await returns 0 from wait()", _14_) + local function _15_() + return assert.are.equals(true, promise["done?"](p)) + end + it("complete after await", _15_) + local function _16_() + return assert.are.equals("later", promise.close(p)) + end + return it("value is correct", _16_) + end + return _12_ + end + return describe("async", _10_()) +end +return describe("conjure.promise", _2_) diff --git a/lua/conjure-spec/school_spec.lua b/lua/conjure-spec/school_spec.lua new file mode 100644 index 00000000..28d62cfe --- /dev/null +++ b/lua/conjure-spec/school_spec.lua @@ -0,0 +1,20 @@ +-- [nfnl] Compiled from fnl/conjure-spec/school_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local school = require("conjure.school") +local nvim = require("conjure.aniseed.nvim") +local function _2_() + school.start() + local function _3_() + return assert.are.equals("conjure-school.fnl", nvim.fn.bufname()) + end + it("buffer has correct name", _3_) + local function _4_() + return assert.same({"(local school (require :conjure.school))"}, nvim.buf_get_lines(0, 1, 2, false)) + end + it("buffer requires conjure.school module", _4_) + return nvim.ex.bdelete("conjure-school.fnl") +end +return describe("running :ConjureSchool", _2_) diff --git a/lua/conjure/eval.lua b/lua/conjure/eval.lua index cff5dbc3..6feabc96 100644 --- a/lua/conjure/eval.lua +++ b/lua/conjure/eval.lua @@ -1,78 +1,60 @@ -- [nfnl] Compiled from fnl/conjure/eval.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.eval" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -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") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["buffer"] = buffer -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["editor"] = editor -_2amodule_locals_2a["event"] = event -_2amodule_locals_2a["extract"] = extract -_2amodule_locals_2a["fs"] = fs -_2amodule_locals_2a["inline"] = inline -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["nu"] = nu -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["promise"] = promise -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["timer"] = timer -_2amodule_locals_2a["uuid"] = uuid -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local nvim = autoload("conjure.aniseed.nvim") +local str = autoload("conjure.aniseed.string") +local nu = autoload("conjure.aniseed.nvim.util") +local extract = autoload("conjure.extract") +local client = autoload("conjure.client") +local text = autoload("conjure.text") +local fs = autoload("conjure.fs") +local timer = autoload("conjure.timer") +local config = autoload("conjure.config") +local promise = autoload("conjure.promise") +local editor = autoload("conjure.editor") +local buffer = autoload("conjure.buffer") +local inline = autoload("conjure.inline") +local uuid = autoload("conjure.uuid") +local log = autoload("conjure.log") +local event = autoload("conjure.event") local function preview(opts) local sample_limit = editor["percent-width"](config["get-in"]({"preview", "sample_limit"})) - local function _1_() + local function _2_() if (("file" == opts.origin) or ("buf" == opts.origin)) then return text["right-sample"](opts["file-path"], sample_limit) else return text["left-sample"](opts.code, sample_limit) end end - return str.join({client.get("comment-prefix"), opts.action, " (", opts.origin, "): ", _1_()}) + return str.join({client.get("comment-prefix"), opts.action, " (", opts.origin, "): ", _2_()}) end -_2amodule_locals_2a["preview"] = preview -do local _ = {preview, nil} end local function display_request(opts) return log.append({opts.preview}, a.merge(opts, {["break?"] = true})) end -_2amodule_locals_2a["display-request"] = display_request -do local _ = {display_request, nil} end local function highlight_range(range) if (config["get-in"]({"highlight", "enabled"}) and vim.highlight and range) then local bufnr = (range.bufnr or nvim.buf.nr()) local namespace = vim.api.nvim_create_namespace("conjure_highlight") local hl_start = {(range.start[1] - 1), range.start[2]} - local hl_end = {((range["end"])[1] - 1), (range["end"])[2]} + local hl_end = {(range["end"][1] - 1), range["end"][2]} vim.highlight.range(bufnr, namespace, config["get-in"]({"highlight", "group"}), hl_start, hl_end, unpack({{regtype = "v", inclusive = true}})) - local function _2_() - local function _3_() + local function _3_() + local function _4_() return vim.api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1) end - return pcall(_3_) + return pcall(_4_) end - return timer.defer(_2_, config["get-in"]({"highlight", "timeout"})) + return timer.defer(_3_, config["get-in"]({"highlight", "timeout"})) else return nil end end -_2amodule_locals_2a["highlight-range"] = highlight_range -do local _ = {highlight_range, nil} end local function with_last_result_hook(opts) local buf = nvim.win_get_buf(0) local line = a.dec(a.first(nvim.win_get_cursor(0))) - local function _5_(f) - local function _6_(result) + local function _6_(f) + local function _7_(result) nvim.fn.setreg(config["get-in"]({"eval", "result_register"}), string.gsub(result, "%z", "")) if config["get-in"]({"eval", "inline_results"}) then inline.display({buf = buf, text = str.join({config["get-in"]({"eval", "inline", "prefix"}), result}), line = line}) @@ -84,12 +66,10 @@ local function with_last_result_hook(opts) return nil end end - return _6_ + return _7_ end - return a.update(opts, "on-result", _5_) + return a.update(opts, "on-result", _6_) end -_2amodule_locals_2a["with-last-result-hook"] = with_last_result_hook -do local _ = {with_last_result_hook, nil} end local function file() event.emit("eval", "file") local opts = {["file-path"] = fs["localise-path"](extract["file-path"]()), origin = "file", action = "eval"} @@ -97,8 +77,6 @@ local function file() display_request(opts) return client.call("eval-file", with_last_result_hook(opts)) end -_2amodule_2a["file"] = file -do local _ = {file, nil} end local function assoc_context(opts) if not opts.context then opts.context = (nvim.b["conjure#context"] or extract.context()) @@ -106,10 +84,8 @@ local function assoc_context(opts) end return opts end -_2amodule_locals_2a["assoc-context"] = assoc_context -do local _ = {assoc_context, nil} end local function client_exec_fn(action, f_name, base_opts) - local function _10_(opts) + local function _11_(opts) local opts0 = a.merge(opts, base_opts, {action = action, ["file-path"] = extract["file-path"]()}) assoc_context(opts0) opts0.preview = preview(opts0) @@ -118,7 +94,7 @@ local function client_exec_fn(action, f_name, base_opts) else end if opts0["jumping?"] then - local function _12_() + local function _13_() do local win = nvim.get_current_win() local buf = nvim.get_current_buf() @@ -126,21 +102,18 @@ local function client_exec_fn(action, f_name, base_opts) end return nu.normal("m'") end - pcall(_12_) + pcall(_13_) else end return client.call(f_name, opts0) end - return _10_ + return _11_ end -_2amodule_locals_2a["client-exec-fn"] = client_exec_fn -do local _ = {client_exec_fn, nil} end local function apply_gsubs(code) if code then - local function _17_(code0, _14_) - local _arg_15_ = _14_ - local name = _arg_15_[1] - local _arg_16_ = _arg_15_[2] + local function _17_(code0, _15_) + local name = _15_[1] + local _arg_16_ = _15_[2] local pat = _arg_16_[1] local rep = _arg_16_[2] local ok_3f, val_or_err = pcall(string.gsub, code0, pat, rep) @@ -156,11 +129,7 @@ local function apply_gsubs(code) return nil end end -_2amodule_locals_2a["apply-gsubs"] = apply_gsubs -do local _ = {apply_gsubs, nil} end -local previous_evaluations = ((_2amodule_2a)["previous-evaluations"] or {}) -do end (_2amodule_2a)["previous-evaluations"] = previous_evaluations -do local _ = {nil, nil} end +local previous_evaluations = {} local function eval_str(opts) a.assoc(previous_evaluations, a.get(client["current-client-module-name"](), "module-name", "unknown"), opts) highlight_range(opts.range) @@ -176,8 +145,6 @@ local function eval_str(opts) client_exec_fn("eval", "eval-str")(_20_()) return nil end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function previous() local client_name = a.get(client["current-client-module-name"](), "module-name", "unknown") local opts = a.get(previous_evaluations, client_name) @@ -187,8 +154,6 @@ local function previous() return nil end end -_2amodule_2a["previous"] = previous -do local _ = {previous, nil} end local function wrap_emit(name, f) local function _22_(...) event.emit(name) @@ -196,69 +161,54 @@ local function wrap_emit(name, f) end return _22_ end -_2amodule_2a["wrap-emit"] = wrap_emit -do local _ = {wrap_emit, nil} end local doc_str = wrap_emit("doc", client_exec_fn("doc", "doc-str")) -do end (_2amodule_locals_2a)["doc-str"] = doc_str -do local _ = {nil, nil} end local def_str = wrap_emit("def", client_exec_fn("def", "def-str", {["suppress-hud?"] = true, ["jumping?"] = true})) -do end (_2amodule_locals_2a)["def-str"] = def_str -do local _ = {nil, nil} end local function current_form(extra_opts) local form = extract.form({}) if form then - local _let_23_ = form - local content = _let_23_["content"] - local range = _let_23_["range"] + local content = form["content"] + local range = form["range"] eval_str(a.merge({code = content, range = range, origin = "current-form"}, extra_opts)) return form else return nil end end -_2amodule_2a["current-form"] = current_form -do local _ = {current_form, nil} end local function replace_form() local buf = nvim.win_get_buf(0) local win = nvim.tabpage_get_win(0) local form = extract.form({}) if form then - local _let_25_ = form - local content = _let_25_["content"] - local range = _let_25_["range"] - local function _26_(result) + local content = form["content"] + local range = form["range"] + local function _24_(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"] = _26_}) + eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _24_}) return form else return nil end end -_2amodule_2a["replace-form"] = replace_form -do local _ = {replace_form, nil} end local function root_form() local form = extract.form({["root?"] = true}) if form then - local _let_28_ = form - local content = _let_28_["content"] - local range = _let_28_["range"] + local content = form["content"] + local range = form["range"] return eval_str({code = content, range = range, origin = "root-form"}) else return nil end end -_2amodule_2a["root-form"] = root_form -do local _ = {root_form, nil} end 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 _30_() + local function _27_() return editor["go-to-mark"](mark0) end - ok_3f, err = pcall(_30_) + ok_3f, err = pcall(_27_) if ok_3f then current_form({origin = str.join({"marked-form [", mark0, "]"})}) editor["go-back"]() @@ -267,106 +217,81 @@ local function marked_form(mark) end return mark0 end -_2amodule_2a["marked-form"] = marked_form -do local _ = {marked_form, nil} end 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_32_ = input - local content = _let_32_["content"] - local range = _let_32_["range"] - local function _33_(result) + local content = input["content"] + local range = input["range"] + local function _29_(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"] = _33_}) + eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _29_}) return input else return nil end end -_2amodule_locals_2a["insert-result-comment"] = insert_result_comment -do local _ = {insert_result_comment, nil} end local function comment_current_form() return insert_result_comment("current-form", extract.form({})) end -_2amodule_2a["comment-current-form"] = comment_current_form -do local _ = {comment_current_form, nil} end local function comment_root_form() return insert_result_comment("root-form", extract.form({["root?"] = true})) end -_2amodule_2a["comment-root-form"] = comment_root_form -do local _ = {comment_root_form, nil} end local function comment_word() return insert_result_comment("word", extract.word()) end -_2amodule_2a["comment-word"] = comment_word -do local _ = {comment_word, nil} end local function word() - local _let_35_ = extract.word() - local content = _let_35_["content"] - local range = _let_35_["range"] + local _let_31_ = extract.word() + local content = _let_31_["content"] + local range = _let_31_["range"] if not a["empty?"](content) then return eval_str({code = content, range = range, origin = "word"}) else return nil end end -_2amodule_2a["word"] = word -do local _ = {word, nil} end local function doc_word() - local _let_37_ = extract.word() - local content = _let_37_["content"] - local range = _let_37_["range"] + local _let_33_ = extract.word() + local content = _let_33_["content"] + local range = _let_33_["range"] if not a["empty?"](content) then return doc_str({code = content, range = range, origin = "word"}) else return nil end end -_2amodule_2a["doc-word"] = doc_word -do local _ = {doc_word, nil} end local function def_word() - local _let_39_ = extract.word() - local content = _let_39_["content"] - local range = _let_39_["range"] + local _let_35_ = extract.word() + local content = _let_35_["content"] + local range = _let_35_["range"] if not a["empty?"](content) then return def_str({code = content, range = range, origin = "word"}) else return nil end end -_2amodule_2a["def-word"] = def_word -do local _ = {def_word, nil} end local function buf() - local _let_41_ = extract.buf() - local content = _let_41_["content"] - local range = _let_41_["range"] + local _let_37_ = extract.buf() + local content = _let_37_["content"] + local range = _let_37_["range"] return eval_str({code = content, range = range, origin = "buf"}) end -_2amodule_2a["buf"] = buf -do local _ = {buf, nil} end local function command(code) return eval_str({code = code, origin = "command"}) end -_2amodule_2a["command"] = command -do local _ = {command, nil} end local function range(start, _end) - local _let_42_ = extract.range(start, _end) - local content = _let_42_["content"] - local range0 = _let_42_["range"] + local _let_38_ = extract.range(start, _end) + local content = _let_38_["content"] + local range0 = _let_38_["range"] return eval_str({code = content, range = range0, origin = "range"}) end -_2amodule_2a["range"] = range -do local _ = {range, nil} end local function selection(kind) - local _let_43_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind}) - local content = _let_43_["content"] - local range0 = _let_43_["range"] + local _let_39_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind}) + local content = _let_39_["content"] + local range0 = _let_39_["range"] return eval_str({code = content, range = range0, origin = "selection"}) end -_2amodule_2a["selection"] = selection -do local _ = {selection, nil} end local function wrap_completion_result(result) if a["string?"](result) then return {word = result} @@ -374,19 +299,18 @@ local function wrap_completion_result(result) return result end end -_2amodule_locals_2a["wrap-completion-result"] = wrap_completion_result -do local _ = {wrap_completion_result, nil} end local function completions(prefix, cb) local function cb_wrap(results) - local function _45_() - local _46_ = config["get-in"]({"completion", "fallback"}) - if (nil ~= _46_) then - return nvim.call_function(_46_, {0, prefix}) + local or_41_ = results + if not or_41_ then + local tmp_3_auto = config["get-in"]({"completion", "fallback"}) + if (nil ~= tmp_3_auto) then + or_41_ = nvim.call_function(tmp_3_auto, {0, prefix}) else - return _46_ + or_41_ = nil end end - return cb(a.map(wrap_completion_result, (results or _45_()))) + return cb(a.map(wrap_completion_result, or_41_)) end if ("function" == type(client.get("completions"))) then return client.call("completions", assoc_context({["file-path"] = extract["file-path"](), prefix = prefix, cb = cb_wrap})) @@ -394,20 +318,14 @@ local function completions(prefix, cb) return cb_wrap() end end -_2amodule_2a["completions"] = completions -do local _ = {completions, nil} end local function completions_promise(prefix) local p = promise.new() completions(prefix, promise["deliver-fn"](p)) return p end -_2amodule_2a["completions-promise"] = completions_promise -do local _ = {completions_promise, nil} end local function completions_sync(prefix) local p = completions_promise(prefix) promise.await(p) return promise.close(p) end -_2amodule_2a["completions-sync"] = completions_sync -do local _ = {completions_sync, nil} end -return _2amodule_2a +return {file = file, ["previous-evaluation"] = __fnl_global__previous_2devaluation, ["eval-str"] = eval_str, previous = previous, ["wrap-emit"] = wrap_emit, ["current-form"] = current_form, ["replace-form"] = replace_form, ["root-form"] = root_form, ["marked-form"] = marked_form, ["comment-current-form"] = comment_current_form, ["comment-root-form"] = comment_root_form, ["comment-word"] = comment_word, word = word, ["doc-word"] = doc_word, ["def-word"] = def_word, buf = buf, command = command, range = range, selection = selection, completions = completions, ["completions-promise"] = completions_promise, ["completions-sync"] = completions_sync} diff --git a/lua/conjure/hook.lua b/lua/conjure/hook.lua index c3e8afb5..45e12f99 100644 --- a/lua/conjure/hook.lua +++ b/lua/conjure/hook.lua @@ -1,41 +1,19 @@ -- [nfnl] Compiled from fnl/conjure/hook.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.hook" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, str = autoload("conjure.aniseed.core"), autoload("conjure.aniseed.string") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["str"] = str -do local _ = {nil, nil, nil, nil, nil, nil, nil} end -local hook_fns = ((_2amodule_2a)["hook-fns"] or {}) -do end (_2amodule_2a)["hook-fns"] = hook_fns -do local _ = {nil, nil} end -local hook_override_fns = ((_2amodule_2a)["hook-override-fns"] or {}) -do end (_2amodule_2a)["hook-override-fns"] = hook_override_fns -do local _ = {nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local str = autoload("conjure.aniseed.string") +local hook_fns = {} +local hook_override_fns = {} local function define(name, f) return a.assoc(hook_fns, name, f) end -_2amodule_2a["define"] = define -do local _ = {define, nil} end local function override(name, f) return a.assoc(hook_override_fns, name, f) end -_2amodule_2a["override"] = override -do local _ = {override, nil} end local function get(name) return a.get(hook_fns, name) end -_2amodule_2a["get"] = get -do local _ = {get, nil} end local function exec(name, ...) local f = (a.get(hook_override_fns, name) or a.get(hook_fns, name)) if f then @@ -44,6 +22,4 @@ local function exec(name, ...) return error(str.join(" ", {"conjure.hook: Hook not found, can not exec", name})) end end -_2amodule_2a["exec"] = exec -do local _ = {exec, nil} end -return _2amodule_2a +return {["hook-fns"] = hook_fns, ["hook-override-fns"] = hook_override_fns, define = define, override = override, get = get, exec = exec} diff --git a/lua/conjure/inline.lua b/lua/conjure/inline.lua index a09ace87..a0eb0395 100644 --- a/lua/conjure/inline.lua +++ b/lua/conjure/inline.lua @@ -1,24 +1,10 @@ -- [nfnl] Compiled from fnl/conjure/inline.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.inline" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, config, nvim = autoload("conjure.aniseed.core"), autoload("conjure.config"), autoload("conjure.aniseed.nvim") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["nvim"] = nvim -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil} end -local ns_id = ((_2amodule_2a)["ns-id"] or nvim.create_namespace(_2amodule_name_2a)) -do end (_2amodule_2a)["ns-id"] = ns_id -do local _ = {nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local config = autoload("conjure.config") +local nvim = autoload("conjure.aniseed.nvim") +local ns_id = nvim.create_namespace("conjure.inline") local function sanitise_text(s) if a["string?"](s) then return s:gsub("%s+", " ") @@ -26,24 +12,18 @@ local function sanitise_text(s) return "" end end -_2amodule_2a["sanitise-text"] = sanitise_text -do local _ = {sanitise_text, nil} end local function clear(opts) - local function _2_() + local function _3_() return nvim.buf_clear_namespace(a.get(opts, "buf", 0), ns_id, 0, -1) end - return pcall(_2_) + return pcall(_3_) end -_2amodule_2a["clear"] = clear -do local _ = {clear, nil} end local function display(opts) local hl_group = config["get-in"]({"eval", "inline", "highlight"}) - local function _3_() + local function _4_() clear() return nvim.buf_set_virtual_text(a.get(opts, "buf", 0), ns_id, opts.line, {{sanitise_text(opts.text), hl_group}}, {}) end - return pcall(_3_) + return pcall(_4_) end -_2amodule_2a["display"] = display -do local _ = {display, nil} end -return _2amodule_2a +return {["sanitise-text"] = sanitise_text, clear = clear, display = display} diff --git a/lua/conjure/linked-list.lua b/lua/conjure/linked-list.lua index 16145f21..46667f4d 100644 --- a/lua/conjure/linked-list.lua +++ b/lua/conjure/linked-list.lua @@ -1,19 +1,7 @@ -- [nfnl] Compiled from fnl/conjure/linked-list.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.linked-list" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] local a = autoload("conjure.aniseed.core") -do end (_2amodule_locals_2a)["a"] = a -do local _ = {nil, nil, nil, nil, nil, nil} end local function create(xs, prev) if not a["empty?"](xs) then local rest = a.rest(xs) @@ -25,38 +13,27 @@ local function create(xs, prev) return nil end end -_2amodule_2a["create"] = create -do local _ = {create, nil} end local function val(l) - local _2_ = l - if (nil ~= _2_) then - return a.get(_2_, "val") + if (nil ~= l) then + return a.get(l, "val") else - return _2_ + return nil end end -_2amodule_2a["val"] = val -do local _ = {val, nil} end local function next(l) - local _4_ = l - if (nil ~= _4_) then - return a.get(_4_, "next") + if (nil ~= l) then + return a.get(l, "next") else - return _4_ + return nil end end -_2amodule_2a["next"] = next -do local _ = {next, nil} end local function prev(l) - local _6_ = l - if (nil ~= _6_) then - return a.get(_6_, "prev") + if (nil ~= l) then + return a.get(l, "prev") else - return _6_ + return nil end end -_2amodule_2a["prev"] = prev -do local _ = {prev, nil} end local function first(l) local c = l while prev(c) do @@ -64,8 +41,6 @@ local function first(l) end return c end -_2amodule_2a["first"] = first -do local _ = {first, nil} end local function last(l) local c = l while next(c) do @@ -73,8 +48,6 @@ local function last(l) end return c end -_2amodule_2a["last"] = last -do local _ = {last, nil} end local function _until(f, l) local c = l local r = false @@ -91,8 +64,6 @@ local function _until(f, l) return nil end end -_2amodule_2a["until"] = _until -do local _ = {_until, nil} end local function cycle(l) local start = first(l) local _end = last(l) @@ -100,6 +71,4 @@ local function cycle(l) a.assoc(_end, "next", start) return l end -_2amodule_2a["cycle"] = cycle -do local _ = {cycle, nil} end -return _2amodule_2a +return {create = create, val = val, next = next, prev = prev, first = first, last = last, ["until"] = _until, cycle = cycle} diff --git a/lua/conjure/log.lua b/lua/conjure/log.lua index 41d6f917..f578224b 100644 --- a/lua/conjure/log.lua +++ b/lua/conjure/log.lua @@ -1,53 +1,31 @@ -- [nfnl] Compiled from fnl/conjure/log.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.log" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, buffer, client, config, editor, hook, nvim, str, text, timer, view, sponsors = autoload("conjure.aniseed.core"), autoload("conjure.buffer"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.editor"), autoload("conjure.hook"), autoload("conjure.aniseed.nvim"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.timer"), autoload("conjure.aniseed.view"), require("conjure.sponsors") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["buffer"] = buffer -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["editor"] = editor -_2amodule_locals_2a["hook"] = hook -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["timer"] = timer -_2amodule_locals_2a["view"] = view -_2amodule_locals_2a["sponsors"] = sponsors -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end -local state = ((_2amodule_2a).state or {["last-open-cmd"] = "vsplit", hud = {id = nil, timer = nil, ["created-at-ms"] = 0, ["low-priority-spam"] = {streak = 0, ["help-displayed?"] = false}}, ["jump-to-latest"] = {mark = nil, ns = nvim.create_namespace("conjure_log_jump_to_latest")}}) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local nvim = autoload("conjure.aniseed.nvim") +local str = autoload("conjure.aniseed.string") +local buffer = autoload("conjure.buffer") +local client = autoload("conjure.client") +local hook = autoload("conjure.hook") +local config = autoload("conjure.config") +local view = autoload("conjure.aniseed.view") +local text = autoload("conjure.text") +local editor = autoload("conjure.editor") +local timer = autoload("conjure.timer") +local sponsors = require("conjure.sponsors") +local state = {["last-open-cmd"] = "vsplit", hud = {id = nil, timer = nil, ["created-at-ms"] = 0, ["low-priority-spam"] = {streak = 0, ["help-displayed?"] = false}}, ["jump-to-latest"] = {mark = nil, ns = nvim.create_namespace("conjure_log_jump_to_latest")}} local function _break() return str.join({client.get("comment-prefix"), string.rep("-", config["get-in"]({"log", "break_length"}))}) end -_2amodule_locals_2a["break"] = _break -do local _ = {_break, nil} end local function state_key_header() return str.join({client.get("comment-prefix"), "State: ", client["state-key"]()}) end -_2amodule_locals_2a["state-key-header"] = state_key_header -do local _ = {state_key_header, nil} end local function log_buf_name() return str.join({"conjure-log-", nvim.fn.getpid(), client.get("buf-suffix")}) end -_2amodule_locals_2a["log-buf-name"] = log_buf_name -do local _ = {log_buf_name, nil} end local function log_buf_3f(name) return text["ends-with"](name, log_buf_name()) end -_2amodule_2a["log-buf?"] = log_buf_3f -do local _ = {log_buf_3f, nil} end local function on_new_log_buf(buf) state["jump-to-latest"].mark = nvim.buf_set_extmark(buf, state["jump-to-latest"].ns, 0, 0, {}) if (vim.diagnostic and (false == config["get-in"]({"log", "diagnostics"}))) then @@ -65,18 +43,13 @@ local function on_new_log_buf(buf) end return nvim.buf_set_lines(buf, 0, -1, false, {str.join({client.get("comment-prefix"), "Sponsored by @", a.get(sponsors, a.inc(math.floor(a.rand(a.dec(a.count(sponsors)))))), " \226\157\164"})}) end -_2amodule_locals_2a["on-new-log-buf"] = on_new_log_buf -do local _ = {on_new_log_buf, nil} end local function upsert_buf() return buffer["upsert-hidden"](log_buf_name(), client.wrap(on_new_log_buf)) end -_2amodule_locals_2a["upsert-buf"] = upsert_buf -do local _ = {upsert_buf, nil} end local function clear_close_hud_passive_timer() return a["update-in"](state, {"hud", "timer"}, timer.destroy) end -_2amodule_2a["clear-close-hud-passive-timer"] = clear_close_hud_passive_timer -local function _4_() +local function _5_() if state.hud.id then pcall(nvim.win_close, state.hud.id, true) state.hud.id = nil @@ -85,18 +58,14 @@ local function _4_() return nil end end -hook.define("close-hud", _4_) +hook.define("close-hud", _5_) local function close_hud() clear_close_hud_passive_timer() return hook.exec("close-hud") end -_2amodule_2a["close-hud"] = close_hud -do local _ = {close_hud, nil} end local function hud_lifetime_ms() return (vim.loop.now() - state.hud["created-at-ms"]) end -_2amodule_2a["hud-lifetime-ms"] = hud_lifetime_ms -do local _ = {hud_lifetime_ms, nil} end local function close_hud_passive() if (state.hud.id and (hud_lifetime_ms() > config["get-in"]({"log", "hud", "minimum_lifetime_ms"}))) then local original_timer_id = state.hud["timer-id"] @@ -114,20 +83,15 @@ local function close_hud_passive() return nil end end -_2amodule_2a["close-hud-passive"] = close_hud_passive -do local _ = {close_hud_passive, nil} end local function break_lines(buf) local break_str = _break() - local function _11_(_9_) - local _arg_10_ = _9_ - local n = _arg_10_[1] - local s = _arg_10_[2] + local function _11_(_10_) + local n = _10_[1] + local s = _10_[2] return (s == break_str) end return a.map(a.first, a.filter(_11_, a["kv-pairs"](nvim.buf_get_lines(buf, 0, -1, false)))) end -_2amodule_locals_2a["break-lines"] = break_lines -do local _ = {break_lines, nil} end local function set_win_opts_21(win) local function _12_() if config["get-in"]({"log", "wrap"}) then @@ -141,13 +105,9 @@ local function set_win_opts_21(win) nvim.win_set_option(win, "foldmarker", (config["get-in"]({"log", "fold", "marker", "start"}) .. "," .. config["get-in"]({"log", "fold", "marker", "end"}))) return nvim.win_set_option(win, "foldlevel", 0) end -_2amodule_locals_2a["set-win-opts!"] = set_win_opts_21 -do local _ = {set_win_opts_21, nil} end local function in_box_3f(box, pos) return ((pos.x >= box.x1) and (pos.x <= box.x2) and (pos.y >= box.y1) and (pos.y <= box.y2)) end -_2amodule_locals_2a["in-box?"] = in_box_3f -do local _ = {in_box_3f, nil} end local function flip_anchor(anchor, n) local chars = {anchor:sub(1, 1), anchor:sub(2)} local flip = {N = "S", S = "N", E = "W", W = "E"} @@ -156,8 +116,6 @@ local function flip_anchor(anchor, n) end return str.join(a.update(chars, n, _13_)) end -_2amodule_locals_2a["flip-anchor"] = flip_anchor -do local _ = {flip_anchor, nil} end local function pad_box(box, padding) local function _14_(_241) return (_241 - padding.x) @@ -173,8 +131,6 @@ local function pad_box(box, padding) end return a.update(a.update(a.update(a.update(box, "x1", _14_), "y1", _15_), "x2", _16_), "y2", _17_) end -_2amodule_locals_2a["pad-box"] = pad_box -do local _ = {pad_box, nil} end local function hud_window_pos(anchor, size, rec_3f) local north = 0 local west = 0 @@ -209,16 +165,10 @@ local function hud_window_pos(anchor, size, rec_3f) return pos end end -_2amodule_locals_2a["hud-window-pos"] = hud_window_pos -do local _ = {hud_window_pos, nil} end local function current_window_floating_3f() return ("number" == type(a.get(nvim.win_get_config(0), "zindex"))) end -_2amodule_locals_2a["current-window-floating?"] = current_window_floating_3f -do local _ = {current_window_floating_3f, nil} end local low_priority_streak_threshold = 5 -_2amodule_locals_2a["low-priority-streak-threshold"] = low_priority_streak_threshold -do local _ = {nil, nil} end local function handle_low_priority_spam_21(low_priority_3f) if not a["get-in"](state, {"hud", "low-priority-spam", "help-displayed?"}) then if low_priority_3f then @@ -229,7 +179,7 @@ local function handle_low_priority_spam_21(low_priority_3f) if (a["get-in"](state, {"hud", "low-priority-spam", "streak"}) > low_priority_streak_threshold) then do local pref = client.get("comment-prefix") - client.schedule((_2amodule_2a).append, {(pref .. "Is the HUD popping up too much and annoying you in this project?"), (pref .. "Set this option to suppress this kind of output for this session."), (pref .. " :let g:conjure#log#hud#ignore_low_priority = v:true")}, {["break?"] = true}) + client.schedule(__fnl_global___2amodule_2a.append, {(pref .. "Is the HUD popping up too much and annoying you in this project?"), (pref .. "Set this option to suppress this kind of output for this session."), (pref .. " :let g:conjure#log#hud#ignore_low_priority = v:true")}, {["break?"] = true}) end return a["assoc-in"](state, {"hud", "low-priority-spam", "help-displayed?"}, true) else @@ -239,7 +189,6 @@ local function handle_low_priority_spam_21(low_priority_3f) return nil end end -_2amodule_locals_2a["handle-low-priority-spam!"] = handle_low_priority_spam_21 local function _25_(opts) local buf = upsert_buf() local last_break = a.last(break_lines(buf)) @@ -276,13 +225,9 @@ local function display_hud(opts) return nil end end -_2amodule_locals_2a["display-hud"] = display_hud -do local _ = {display_hud, nil} end local function win_visible_3f(win) return (nvim.fn.tabpagenr() == a.first(nvim.fn.win_id2tabwin(win))) end -_2amodule_locals_2a["win-visible?"] = win_visible_3f -do local _ = {win_visible_3f, nil} end local function with_buf_wins(buf, f) local function _30_(win) if (buf == nvim.win_get_buf(win)) then @@ -293,13 +238,9 @@ local function with_buf_wins(buf, f) end return a["run!"](_30_, nvim.list_wins()) end -_2amodule_locals_2a["with-buf-wins"] = with_buf_wins -do local _ = {with_buf_wins, nil} end local function win_botline(win) return a.get(a.first(nvim.fn.getwininfo(win)), "botline") end -_2amodule_locals_2a["win-botline"] = win_botline -do local _ = {win_botline, nil} end local function trim(buf) local line_count = nvim.buf_line_count(buf) if (line_count > config["get-in"]({"log", "trim", "at"})) then @@ -331,16 +272,10 @@ local function trim(buf) return nil end end -_2amodule_locals_2a["trim"] = trim -do local _ = {trim, nil} end local function last_line(buf, extra_offset) return a.first(nvim.buf_get_lines((buf or upsert_buf()), (-2 + (extra_offset or 0)), -1, false)) end -_2amodule_2a["last-line"] = last_line -do local _ = {last_line, nil} end local cursor_scroll_position__3ecommand = {top = "normal zt", center = "normal zz", bottom = "normal zb", none = nil} -_2amodule_2a["cursor-scroll-position->command"] = cursor_scroll_position__3ecommand -do local _ = {nil, nil} end local function jump_to_latest() local buf = upsert_buf() local last_eval_start = nvim.buf_get_extmark_by_id(buf, state["jump-to-latest"].ns, state["jump-to-latest"].mark, {}) @@ -361,8 +296,6 @@ local function jump_to_latest() end return with_buf_wins(buf, _38_) end -_2amodule_2a["jump-to-latest"] = jump_to_latest -do local _ = {jump_to_latest, nil} end local function append(lines, opts) local line_count = a.count(lines) if (line_count > 0) then @@ -468,68 +401,49 @@ local function append(lines, opts) return nil end end -_2amodule_2a["append"] = append -do local _ = {append, nil} end local function create_win(cmd) state["last-open-cmd"] = cmd local buf = upsert_buf() - local function _62_() - if config["get-in"]({"log", "botright"}) then - return "botright " - else - return "" - end + local _62_ + if config["get-in"]({"log", "botright"}) then + _62_ = "botright " + else + _62_ = "" end - nvim.command(("keepalt " .. _62_() .. cmd .. " " .. buffer.resolve(log_buf_name()))) + nvim.command(("keepalt " .. _62_ .. cmd .. " " .. buffer.resolve(log_buf_name()))) nvim.win_set_cursor(0, {nvim.buf_line_count(buf), 0}) set_win_opts_21(0) return buffer.unlist(buf) end -_2amodule_locals_2a["create-win"] = create_win -do local _ = {create_win, nil} end local function split() return create_win("split") end -_2amodule_2a["split"] = split -do local _ = {split, nil} end local function vsplit() return create_win("vsplit") end -_2amodule_2a["vsplit"] = vsplit -do local _ = {vsplit, nil} end local function tab() return create_win("tabnew") end -_2amodule_2a["tab"] = tab -do local _ = {tab, nil} end local function buf() return create_win("buf") end -_2amodule_2a["buf"] = buf -do local _ = {buf, nil} end local function find_windows() local buf0 = upsert_buf() - local function _63_(win) + local function _64_(win) return ((state.hud.id ~= win) and (buf0 == nvim.win_get_buf(win))) end - return a.filter(_63_, nvim.tabpage_list_wins(0)) + return a.filter(_64_, nvim.tabpage_list_wins(0)) end -_2amodule_locals_2a["find-windows"] = find_windows -do local _ = {find_windows, nil} end local function close(windows) - local function _64_(_241) + local function _65_(_241) return nvim.win_close(_241, true) end - return a["run!"](_64_, windows) + return a["run!"](_65_, windows) end -_2amodule_locals_2a["close"] = close -do local _ = {close, nil} end local function close_visible() close_hud() return close(find_windows()) end -_2amodule_2a["close-visible"] = close_visible -do local _ = {close_visible, nil} end local function toggle() local windows = find_windows() if a["empty?"](windows) then @@ -542,8 +456,6 @@ local function toggle() return close_visible(windows) end end -_2amodule_2a["toggle"] = toggle -do local _ = {toggle, nil} end local function dbg(desc, ...) if config["get-in"]({"debug"}) then append(a.concat({(client.get("comment-prefix") .. "debug: " .. desc)}, text["split-lines"](a["pr-str"](...)))) @@ -551,16 +463,10 @@ local function dbg(desc, ...) end return ... end -_2amodule_2a["dbg"] = dbg -do local _ = {dbg, nil} end local function reset_soft() return on_new_log_buf(upsert_buf()) end -_2amodule_2a["reset-soft"] = reset_soft -do local _ = {reset_soft, nil} end local function reset_hard() return nvim.ex.bwipeout_(upsert_buf()) end -_2amodule_2a["reset-hard"] = reset_hard -do local _ = {reset_hard, nil} end -return _2amodule_2a +return {["log-buf?"] = log_buf_3f, ["clear-close-hud-passive-timer"] = clear_close_hud_passive_timer, ["close-hud"] = close_hud, ["hud-lifetime-ms"] = hud_lifetime_ms, ["close-hud-passive"] = close_hud_passive, ["last-line"] = last_line, ["cursor-scroll-position->command"] = cursor_scroll_position__3ecommand, ["jump-to-latest"] = jump_to_latest, append = append, split = split, vsplit = vsplit, tab = tab, buf = buf, ["close-visible"] = close_visible, toggle = toggle, dbg = dbg, ["reset-soft"] = reset_soft, ["reset-hard"] = reset_hard} diff --git a/lua/conjure/main.lua b/lua/conjure/main.lua index 6cc77a25..eca41231 100644 --- a/lua/conjure/main.lua +++ b/lua/conjure/main.lua @@ -1,29 +1,9 @@ -- [nfnl] Compiled from fnl/conjure/main.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.main" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local config, mapping = autoload("conjure.config"), autoload("conjure.mapping") -do -end -(_2amodule_locals_2a)["config"] = config -_2amodule_locals_2a["mapping"] = mapping -do - local _ = { nil, nil, nil, nil, nil, nil, nil } -end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local mapping = autoload("conjure.mapping") +local config = autoload("conjure.config") local function main() return mapping.init(config.filetypes()) end -_2amodule_2a["main"] = main -do - local _ = { main, nil } -end -return _2amodule_2a +return {main = main} diff --git a/lua/conjure/process.lua b/lua/conjure/process.lua index dbec732d..326a76de 100644 --- a/lua/conjure/process.lua +++ b/lua/conjure/process.lua @@ -1,26 +1,12 @@ -- [nfnl] Compiled from fnl/conjure/process.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.process" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, nvim, str = autoload("conjure.aniseed.core"), autoload("conjure.aniseed.nvim"), autoload("conjure.aniseed.string") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["str"] = str -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local nvim = autoload("conjure.aniseed.nvim") +local str = autoload("conjure.aniseed.string") local function executable_3f(cmd) return (1 == nvim.fn.executable(a.first(str.split(cmd, "%s+")))) end -_2amodule_2a["executable?"] = executable_3f -do local _ = {executable_3f, nil} end local function running_3f(proc) if proc then return proc["running?"] @@ -28,16 +14,12 @@ local function running_3f(proc) return false end end -_2amodule_2a["running?"] = running_3f -do local _ = {running_3f, nil} end -local state = ((_2amodule_2a).state or {jobs = {}}) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +local state = {jobs = {}} local function on_exit(job_id) local proc = state.jobs[job_id] if running_3f(proc) then a.assoc(proc, "running?", false) - do end (state.jobs)[proc["job-id"]] = nil + state.jobs[proc["job-id"]] = nil pcall(nvim.buf_delete, proc.buf, {force = true}) local on_exit0 = a["get-in"](proc, {"opts", "on-exit"}) if on_exit0 then @@ -49,44 +31,37 @@ local function on_exit(job_id) return nil end end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end nvim.ex.function_(str.join("\n", {"ConjureProcessOnExit(...)", "call luaeval(\"require('conjure.process')['on-exit'](unpack(_A))\", a:000)", "endfunction"})) local function execute(cmd, opts) local win = nvim.tabpage_get_win(0) local original_buf = nvim.win_get_buf(win) local term_buf - local _5_ + local _6_ do - local t_4_ = opts - if (nil ~= t_4_) then - t_4_ = (t_4_)["hidden?"] + local t_5_ = opts + if (nil ~= t_5_) then + t_5_ = t_5_["hidden?"] else end - _5_ = t_4_ + _6_ = t_5_ end - term_buf = nvim.create_buf(not _5_, true) + term_buf = nvim.create_buf(not _6_, true) local proc = {cmd = cmd, buf = term_buf, ["running?"] = true, opts = opts} local job_id do nvim.win_set_buf(win, term_buf) job_id = nvim.fn.termopen(cmd, {on_exit = "ConjureProcessOnExit"}) end - do - local _7_ = job_id - if (_7_ == 0) then - error("invalid arguments or job table full") - elseif (_7_ == -1) then - error(("'" .. cmd .. "' is not executable")) - else - end + if (job_id == 0) then + error("invalid arguments or job table full") + elseif (job_id == -1) then + error(("'" .. cmd .. "' is not executable")) + else end nvim.win_set_buf(win, original_buf) - do end (state.jobs)[job_id] = proc + state.jobs[job_id] = proc return a.assoc(proc, "job-id", job_id) end -_2amodule_2a["execute"] = execute -do local _ = {execute, nil} end local function stop(proc) if running_3f(proc) then nvim.fn.jobstop(proc["job-id"]) @@ -95,6 +70,4 @@ local function stop(proc) end return proc end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end -return _2amodule_2a +return {["executable?"] = executable_3f, ["running?"] = running_3f, ["on-exit"] = on_exit, execute = execute, stop = stop} diff --git a/lua/conjure/promise.lua b/lua/conjure/promise.lua index 433d2794..e3ee5597 100644 --- a/lua/conjure/promise.lua +++ b/lua/conjure/promise.lua @@ -1,36 +1,18 @@ -- [nfnl] Compiled from fnl/conjure/promise.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.promise" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, nvim, uuid = autoload("conjure.aniseed.core"), autoload("conjure.aniseed.nvim"), autoload("conjure.uuid") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["uuid"] = uuid -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil} end -local state = ((_2amodule_2a).state or {}) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local nvim = autoload("conjure.aniseed.nvim") +local uuid = autoload("conjure.uuid") +local state = {} local function new() local id = uuid.v4() a.assoc(state, id, {id = id, val = nil, ["done?"] = false}) return id end -_2amodule_2a["new"] = new -do local _ = {new, nil} end local function done_3f(id) return a["get-in"](state, {id, "done?"}) end -_2amodule_2a["done?"] = done_3f -do local _ = {done_3f, nil} end local function deliver(id, val) if (false == done_3f(id)) then a["assoc-in"](state, {id, "val"}, val) @@ -39,26 +21,18 @@ local function deliver(id, val) end return nil end -_2amodule_2a["deliver"] = deliver -do local _ = {deliver, nil} end local function deliver_fn(id) - local function _2_(_241) + local function _3_(_241) return deliver(id, _241) end - return _2_ + return _3_ end -_2amodule_2a["deliver-fn"] = deliver_fn -do local _ = {deliver_fn, nil} end local function close(id) local val = a["get-in"](state, {id, "val"}) a.assoc(state, id, nil) return val end -_2amodule_2a["close"] = close -do local _ = {close, nil} end local function await(id, opts) return nvim.fn.wait(a.get(opts, "timeout", 10000), ("luaeval(\"require('conjure.promise')['done?']('" .. id .. "')\")"), a.get(opts, "interval", 50)) end -_2amodule_2a["await"] = await -do local _ = {await, nil} end -return _2amodule_2a +return {new = new, ["done?"] = done_3f, deliver = deliver, ["deliver-fn"] = deliver_fn, close = close, await = await} diff --git a/lua/conjure/school.lua b/lua/conjure/school.lua index 051cd130..2f42e57c 100644 --- a/lua/conjure/school.lua +++ b/lua/conjure/school.lua @@ -1,61 +1,39 @@ -- [nfnl] Compiled from fnl/conjure/school.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.school" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, buffer, config, editor, nvim, str = autoload("conjure.aniseed.core"), autoload("conjure.buffer"), autoload("conjure.config"), autoload("conjure.editor"), autoload("conjure.aniseed.nvim"), autoload("conjure.aniseed.string") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["buffer"] = buffer -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["editor"] = editor -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["str"] = str -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local buffer = autoload("conjure.buffer") +local config = autoload("conjure.config") +local editor = autoload("conjure.editor") +local nvim = autoload("conjure.aniseed.nvim") +local str = autoload("conjure.aniseed.string") local buf_name = "conjure-school.fnl" -_2amodule_locals_2a["buf-name"] = buf_name -do local _ = {nil, nil} end local function upsert_buf() return buffer["upsert-hidden"](buf_name) end -_2amodule_locals_2a["upsert-buf"] = upsert_buf -do local _ = {upsert_buf, nil} end local function append(lines) local buf = upsert_buf() local current_buf_str = str.join("\n", nvim.buf_get_lines(0, 0, -1, true)) local to_insert_str = str.join("\n", lines) if not string.find(current_buf_str, to_insert_str, 0, true) then - local _1_ + local _2_ if buffer["empty?"](buf) then - _1_ = 0 + _2_ = 0 else - _1_ = -1 + _2_ = -1 end - nvim.buf_set_lines(buf, _1_, -1, false, lines) + nvim.buf_set_lines(buf, _2_, -1, false, lines) return true else return nil end end -_2amodule_locals_2a["append"] = append -do local _ = {append, nil} end local function map_str(m) return (config["get-in"]({"mapping", "prefix"}) .. config["get-in"]({"mapping", m})) end -_2amodule_locals_2a["map-str"] = map_str -do local _ = {map_str, nil} end local function progress(n) return ("Lesson [" .. n .. "/7] complete!") end -_2amodule_locals_2a["progress"] = progress -do local _ = {progress, nil} end local function append_or_warn(current_progress, lines) if append(lines) then return progress(current_progress) @@ -63,8 +41,6 @@ local function append_or_warn(current_progress, lines) return "You've already completed this lesson! You can (u)ndo and run it again though if you'd like." end end -_2amodule_locals_2a["append-or-warn"] = append_or_warn -do local _ = {append_or_warn, nil} end local function start() if not editor["has-filetype?"]("fennel") then nvim.echo("Warning: No Fennel filetype found, falling back to Clojure syntax.", "Install https://github.com/Olical/aniseed for better Fennel support.") @@ -85,55 +61,35 @@ local function start() local buf = upsert_buf() nvim.ex.edit(buf_name) nvim.buf_set_lines(buf, 0, -1, false, {}) - local _7_ + local _8_ if maplocalleader_was_unset_3f then - _7_ = {";; Your wasn't configured so I've defaulted it to comma (,) for now.", ";; See :help localleader for more information. (let maplocalleader=\",\")"} + _8_ = {";; Your wasn't configured so I've defaulted it to comma (,) for now.", ";; See :help localleader for more information. (let maplocalleader=\",\")"} else - _7_ = {(";; Your is currently mapped to \"" .. nvim.g.maplocalleader .. "\"")} + _8_ = {(";; Your is currently mapped to \"" .. nvim.g.maplocalleader .. "\"")} end - return append(a.concat({"(module user.conjure-school", " {require {school conjure.school}})", "", ";; Welcome to Conjure school!", ";; Grab yourself a nice beverage and let's get evaluating. I hope you enjoy!", "", ";; This language is Fennel, it's quite similar to Clojure.", ";; Conjure is written in Fennel, it's compiled to Lua and executed inside Neovim itself.", ";; This means we can work with a Lisp without installing or running anything else.", "", ";; Note: Some colorschemes will make the HUD unreadable, see here for more: https://git.io/JJ1Hl", "", ";; Let's learn how to evaluate it using Conjure's assortment of mappings.", ";; You can learn how to change these mappings with :help conjure-mappings", "", (";; Let's begin by evaluating the whole buffer using " .. map_str("eval_buf"))}, _7_, {"(school.lesson-1)"})) + return append(a.concat({"(local {: autoload} (require :nfnl.module))", "(local school (require :conjure.school))", "", ";; Welcome to Conjure school!", ";; Grab yourself a nice beverage and let's get evaluating. I hope you enjoy!", "", ";; This language is Fennel, it's quite similar to Clojure.", ";; Conjure is written in Fennel, it's compiled to Lua and executed inside Neovim itself.", ";; This means we can work with a Lisp without installing or running anything else.", "", ";; Note: Some colorschemes will make the HUD unreadable, see here for more: https://git.io/JJ1Hl", "", ";; Let's learn how to evaluate it using Conjure's assortment of mappings.", ";; You can learn how to change these mappings with :help conjure-mappings", "", (";; Let's begin by evaluating the whole buffer using " .. map_str("eval_buf"))}, _8_, {"(school.lesson-1)"})) end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function lesson_1() return append_or_warn(1, {"", ";; Good job!", ";; You'll notice the heads up display (HUD) appeared showing the result of the evaluation.", ";; All results are appended to a log buffer. If that log is not open, the HUD will appear.", ";; The HUD closes automatically when you move your cursor.", "", ";; You can open the log buffer in a few ways:", (";; * Horizontally - " .. map_str("log_split")), (";; * Vertically - " .. map_str("log_vsplit")), (";; * New tab - " .. map_str("log_tab")), "", (";; All visible log windows (including the HUD) can be closed with " .. map_str("log_close_visible")), ";; Try opening and closing the log window to get the hang of those key mappings.", ";; It's a regular window and buffer, so you can edit and close it however you want.", ";; Feel free to leave the log open in a split for the next lesson to see how it behaves.", "", ";; If you ever need to clear your log you can use the reset mappings:", (";; * Soft reset (leaves windows open) - " .. map_str("log_reset_soft")), (";; * Hard reset (closes windows, deletes the buffer) - " .. map_str("log_reset_hard")), "", ";; Next, we have a form inside a comment. We want to evaluate that inner form, not the comment.", (";; Place your cursor on the inner form (the one inside the comment) and use " .. map_str("eval_current_form") .. " to evaluate it."), "(comment", " (school.lesson-2))"}) end -_2amodule_2a["lesson-1"] = lesson_1 -do local _ = {lesson_1, nil} end local function lesson_2() return append_or_warn(2, {"", ";; Awesome! You evaluated the inner form under your cursor.", (";; If we want to evaluate the outermost form under our cursor, we can use " .. map_str("eval_root_form") .. " instead."), ";; Try that below to print some output and advance to the next lesson.", ";; You can place your cursor anywhere inside the (do ...) form or it's children.", "(do", " (print \"Hello, World!\")", " (school.lesson-3))"}) end -_2amodule_2a["lesson-2"] = lesson_2 -do local _ = {lesson_2, nil} end local function lesson_3() return append_or_warn(3, {"", ";; You evaluated the outermost form! Nice!", ";; Notice that the print output was captured and displayed in the log too.", ";; The result of every evaluation is stored in a Neovim register as well as the log.", (";; Try pressing \"" .. config["get-in"]({"eval", "result_register"}) .. "p to paste the contents of the register into your buffer."), (";; We can also evaluate a form and replace it with the result of the evaluation with " .. map_str("eval_replace_form")), (";; We'll try that in the next lesson, place your cursor inside the form below and press " .. map_str("eval_replace_form")), "(school.lesson-4)"}) end -_2amodule_2a["lesson-3"] = lesson_3 -do local _ = {lesson_3, nil} end local function lesson_4() return append_or_warn(4, {"", ";; Well done! Notice how the resulting string in the log also replaced the form in the buffer!", ";; Next let's try evaluating a form at a mark.", ";; Place your cursor on the next lesson form below and use mf to set the f mark at that location.", (";; Now move your cursor elsewhere in the buffer and use " .. map_str("eval_marked_form") .. "f to evaluate it."), ";; If you use a capital letter like mF you can even open a different file and evaluate that marked form without changing buffers!", "(school.lesson-5)"}) end -_2amodule_2a["lesson-4"] = lesson_4 -do local _ = {lesson_4, nil} end local lesson_5_message = "This is the contents of school.lesson-5-message!" -_2amodule_2a["lesson-5-message"] = lesson_5_message -do local _ = {nil, nil} end local function lesson_5() return append_or_warn(5, {"", ";; Excellent!", ";; This is extremely useful when you want to evaluate a specific form repeatedly as you change code elsewhere in the file or project.", (";; Try inspecting the contents of the variable below by placing your cursor on it and pressing " .. map_str("eval_word")), "school.lesson-5-message", "", ";; You should see the contents in the HUD or log.", "", (";; You can evaluate visual selections with " .. map_str("eval_visual")), ";; Try evaluating the form below using a visual selection.", "(school.lesson-6)"}) end -_2amodule_2a["lesson-5"] = lesson_5 -do local _ = {lesson_5, nil} end local lesson_6_message = "This is the contents of school.lesson-6-message!" -_2amodule_2a["lesson-6-message"] = lesson_6_message -do local _ = {nil, nil} end local function lesson_6() return append_or_warn(6, {"", ";; Wonderful!", ";; Visual evaluation is great for specific sections of a form.", (";; You can also evaluate a given motion with " .. map_str("eval_motion")), (";; Try " .. map_str("eval_motion") .. "iw below to evaluate the word."), "school.lesson-6-message", "", (";; Use " .. map_str("eval_motion") .. "a( to evaluate the lesson form."), "(school.lesson-7)"}) end -_2amodule_2a["lesson-6"] = lesson_6 -do local _ = {lesson_6, nil} end local function lesson_7() return append_or_warn(7, {"", ";; Excellent job, you made it to the end!", ";; To learn more about configuring Conjure, install the plugin and check out :help conjure", ";; You can learn about specific languages with :help conjure-client- and then tab completion.", ";; For example, conjure-client-fennel-aniseed or conjure-client-clojure-nrepl.", "", ";; I hope you have a wonderful time in Conjure!"}) end -_2amodule_2a["lesson-7"] = lesson_7 -do local _ = {lesson_7, nil} end -return _2amodule_2a +return {start = start, ["lesson-1"] = lesson_1, ["lesson-2"] = lesson_2, ["lesson-3"] = lesson_3, ["lesson-4"] = lesson_4, ["lesson-5"] = lesson_5, ["lesson-6"] = lesson_6, ["lesson-7"] = lesson_7, ["lesson-5-message"] = lesson_5_message, ["lesson-6-message"] = lesson_6_message}