├── .github ├── FUNDING.yml └── CODE_OF_CONDUCT.md ├── plugin └── conjure.vim ├── .lnvim.fnl ├── dev ├── bb-nrepl.sh ├── nrepl.sh └── clojure.cljc ├── .gitattributes ├── .gitignore ├── fnl └── conjure │ ├── bridge.fnl │ ├── main.fnl │ ├── bencode-stream.fnl │ ├── uuid.fnl │ ├── editor.fnl │ ├── text.fnl │ ├── buffer.fnl │ ├── config.fnl │ ├── linked-list.fnl │ ├── lang.fnl │ ├── mapping.fnl │ ├── lang │ ├── fennel-aniseed.fnl │ └── clojure-nrepl.fnl │ ├── eval.fnl │ ├── extract.fnl │ └── log.fnl ├── scripts └── dep.sh ├── deps.edn ├── .circleci ├── config.yml └── Dockerfile ├── Makefile ├── test └── fnl │ └── conjure │ ├── test │ └── buffer.fnl │ ├── text-test.fnl │ ├── linked-list-test.fnl │ ├── bencode-stream-test.fnl │ └── extract-test.fnl ├── lua └── conjure │ ├── aniseed │ ├── nvim.lua │ ├── view.lua │ ├── fennel.lua │ ├── dotfiles.lua │ ├── eval.lua │ ├── fs.lua │ ├── string.lua │ ├── nvim │ │ └── util.lua │ ├── macros.fnl │ ├── compile.lua │ ├── deps │ │ ├── fennelview.lua │ │ └── nvim.lua │ ├── test.lua │ ├── mapping.lua │ └── core.lua │ ├── bridge.lua │ ├── main.lua │ ├── uuid.lua │ ├── bencode-stream.lua │ ├── buffer.lua │ ├── text.lua │ ├── config.lua │ ├── lang.lua │ ├── editor.lua │ ├── linked-list.lua │ ├── bencode.lua │ ├── mapping.lua │ ├── lang │ └── fennel-aniseed.lua │ ├── eval.lua │ ├── log.lua │ └── extract.lua ├── UNLICENSE └── README.adoc /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: Olical 2 | ko_fi: olical 3 | -------------------------------------------------------------------------------- /plugin/conjure.vim: -------------------------------------------------------------------------------- 1 | lua require("conjure.main").main() 2 | -------------------------------------------------------------------------------- /.lnvim.fnl: -------------------------------------------------------------------------------- 1 | (set package.path (.. package.path ";test/lua/?.lua")) 2 | -------------------------------------------------------------------------------- /dev/bb-nrepl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "5678" > .nrepl-port 4 | bb --nrepl-server 5678 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.fnl linguist-language=Lisp 2 | lua/* linguist-generated 3 | lua/conjure/aniseed linguist-vendored 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /deps/ 2 | /.lnvim.lua 3 | /test/results.txt 4 | /test/lua/ 5 | /.cpcache/ 6 | /.cljs_node_repl/ 7 | /.nrepl-port 8 | -------------------------------------------------------------------------------- /dev/nrepl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | clj -m nrepl.cmdline --middleware "[cider.piggieback/wrap-cljs-repl]" --interactive 4 | -------------------------------------------------------------------------------- /fnl/conjure/bridge.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.bridge) 2 | 3 | (defn viml->lua [m f opts] 4 | (.. "lua require('" m "')['" f "'](" 5 | (or (and opts opts.args) "") ")")) 6 | -------------------------------------------------------------------------------- /fnl/conjure/main.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.main 2 | {require {mapping conjure.mapping 3 | config conjure.config}}) 4 | 5 | (defn main [] 6 | (mapping.setup-filetypes (config.filetypes))) 7 | -------------------------------------------------------------------------------- /scripts/dep.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | mkdir -p deps 4 | if [ ! -d "deps/$2" ]; then git clone "https://github.com/$1/$2.git" "deps/$2"; fi 5 | cd "deps/$2" && git fetch && git checkout "$3" 6 | 7 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | {:deps 2 | {org.clojure/clojure {:mvn/version "1.10.1"} 3 | org.clojure/clojurescript {:mvn/version "1.10.597"} 4 | nrepl {:mvn/version "0.7.0"} 5 | cider/piggieback {:mvn/version "0.4.2"}}} 6 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: olical/conjure-sourcery-circleci:0.0.3 6 | steps: 7 | - checkout 8 | - run: make deps 9 | - run: make test 10 | -------------------------------------------------------------------------------- /.circleci/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cimg/base:2020.01 2 | 3 | RUN mkdir -p ~/bin ~/nvim && \ 4 | cd ~/nvim && \ 5 | curl -L https://github.com/neovim/neovim/releases/download/v0.4.3/nvim.appimage -o nvim.appimage && \ 6 | chmod +x ./nvim.appimage && \ 7 | ./nvim.appimage --appimage-extract && \ 8 | ln -s ~/nvim/squashfs-root/usr/bin/nvim ~/bin/nvim 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: deps compile test 2 | 3 | deps: 4 | scripts/dep.sh Olical aniseed origin/develop 5 | scripts/dep.sh Olical bencode origin/master 6 | 7 | compile: 8 | rm -rf lua 9 | deps/aniseed/scripts/compile.sh 10 | deps/aniseed/scripts/embed.sh aniseed conjure 11 | cp deps/bencode/bencode.lua lua/conjure/bencode.lua 12 | 13 | test: 14 | rm -rf test/lua 15 | deps/aniseed/scripts/test.sh 16 | -------------------------------------------------------------------------------- /test/fnl/conjure/test/buffer.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.test.buffer 2 | {require {nvim conjure.aniseed.nvim}}) 3 | 4 | (defn with-buf [lines f] 5 | (let [at (fn [cursor] 6 | (nvim.win_set_cursor 0 cursor))] 7 | (nvim.ex.syntax :on) 8 | (nvim.ex.filetype :on) 9 | (nvim.ex.split (.. (nvim.fn.tempname) "_test.clj")) 10 | (set nvim.o.filetype :clojure) 11 | (nvim.buf_set_lines 0 0 -1 false lines) 12 | (f at) 13 | (nvim.ex.bdelete_))) 14 | -------------------------------------------------------------------------------- /dev/clojure.cljc: -------------------------------------------------------------------------------- 1 | (ns dev.foo) 2 | 3 | (defn add [a b] 4 | (+ a b)) 5 | 6 | (meta #'add) 7 | (time (add 10 20)) 8 | (println "foo" #?(:clj :clojure! :cljs :clojurescript!)) 9 | 10 | *1 *2 *3 *e 11 | 12 | (comment 13 | (throw (Error. "ohno")) 14 | (do (Thread/sleep 5000) 15 | (println "FOO")) 16 | (do (Thread/sleep 5000) 17 | (println "BAR")) 18 | 19 | (require '[cider.piggieback :as piggieback] 20 | '[cljs.repl.node :as node-repl]) 21 | (piggieback/cljs-repl (node-repl/repl-env)) 22 | (enable-console-print!) 23 | (throw (js/Error. "ohno")) 24 | :cljs/quit) 25 | -------------------------------------------------------------------------------- /fnl/conjure/bencode-stream.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.bencode-stream 2 | {require {bencode conjure.bencode 3 | a conjure.aniseed.core}}) 4 | 5 | (defn new [] 6 | {:data ""}) 7 | 8 | (defn decode-all [bs part] 9 | (var progress 1) 10 | (var end? false) 11 | (let [s (.. bs.data part) 12 | acc []] 13 | (while (and (< progress (a.count s)) (not end?)) 14 | (let [(msg consumed) (bencode.decode s progress)] 15 | (if (a.nil? msg) 16 | (set end? true) 17 | (do 18 | (table.insert acc msg) 19 | (set progress consumed))))) 20 | (a.assoc bs :data (string.sub s progress)) 21 | acc)) 22 | -------------------------------------------------------------------------------- /fnl/conjure/uuid.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.uuid) 2 | 3 | ;; Adapted from https://gist.github.com/jrus/3197011 4 | 5 | ; local random = math.random 6 | ; local function uuid() 7 | ; local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' 8 | ; return string.gsub(template, '[xy]', function (c) 9 | ; local v = (c == 'x') and random(0, 0xf) or random(8, 0xb) 10 | ; return string.format('%x', v) 11 | ; end) 12 | ; end 13 | 14 | (math.randomseed (os.time)) 15 | 16 | (defn v4 [] 17 | (string.gsub 18 | "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" 19 | "[xy]" 20 | #(string.format 21 | "%x" 22 | (or (and (= $1 "x") (math.random 0 0xf)) 23 | (math.random 8 0xb))))) 24 | 25 | (comment 26 | (v4)) 27 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/nvim.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.nvim" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = require("conjure.aniseed.deps.nvim") 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {} 19 | return {} 20 | end 21 | local _2_ = _1_(...) 22 | return ({nil, _0_0, nil})[2] 23 | -------------------------------------------------------------------------------- /fnl/conjure/editor.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.editor 2 | {require {a conjure.aniseed.core 3 | nvim conjure.aniseed.nvim}}) 4 | 5 | (defn- percent-fn [total-fn] 6 | (fn [pc] 7 | (math.floor (* (/ (total-fn) 100) (* pc 100))))) 8 | 9 | (defn width [] 10 | nvim.o.columns) 11 | 12 | (defn height [] 13 | nvim.o.lines) 14 | 15 | (def percent-width (percent-fn width)) 16 | (def percent-height (percent-fn height)) 17 | 18 | (defn cursor-left [] 19 | (nvim.fn.screencol)) 20 | 21 | (defn cursor-top [] 22 | (nvim.fn.screenrow)) 23 | 24 | (defn go-to [path line column] 25 | (nvim.ex.edit path) 26 | (nvim.win_set_cursor 0 [line (a.dec column)])) 27 | 28 | (defn go-to-mark [m] 29 | (nvim.ex.normal_ (.. "`" m))) 30 | 31 | (defn go-back [] 32 | (nvim.ex.normal_ (nvim.replace_termcodes "" true false true))) 33 | -------------------------------------------------------------------------------- /fnl/conjure/text.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.text 2 | {:require {a conjure.aniseed.core 3 | str conjure.aniseed.string}}) 4 | 5 | (defn- trim [s] 6 | (string.gsub s "^%s*(.-)%s*$" "%1")) 7 | 8 | (defn left-sample [s limit] 9 | (let [flat (-> (string.gsub s "\n" " ") 10 | (string.gsub "%s+" " ") 11 | (trim))] 12 | (if (>= limit (a.count flat)) 13 | flat 14 | (.. (string.sub flat 0 (a.dec limit)) "...")))) 15 | 16 | (defn right-sample [s limit] 17 | (string.reverse (left-sample (string.reverse s) limit))) 18 | 19 | (defn split-lines [s] 20 | (str.split s "[^\n]+")) 21 | 22 | (defn prefixed-lines [s prefix] 23 | (->> (split-lines s) 24 | (a.map (fn [line] 25 | (.. prefix line))))) 26 | 27 | (defn starts-with [str start] 28 | (= (string.sub str 1 (a.count start)) start)) 29 | -------------------------------------------------------------------------------- /fnl/conjure/buffer.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.buffer 2 | {require {nvim conjure.aniseed.nvim 3 | a conjure.aniseed.core}}) 4 | 5 | (defn unlist [buf] 6 | "The buflisted attribute is reset when a new window is opened. Since the 7 | buffer upsert is decoupled from the window we have to run this whenever we 8 | split the buffer into some new window." 9 | (nvim.buf_set_option buf :buflisted false)) 10 | 11 | (defn upsert-hidden [buf-name] 12 | (let [buf (nvim.fn.bufnr buf-name)] 13 | (if (= -1 buf) 14 | (let [buf (nvim.fn.bufadd buf-name)] 15 | (nvim.buf_set_option buf :buftype :nofile) 16 | (nvim.buf_set_option buf :bufhidden :hide) 17 | (nvim.buf_set_option buf :swapfile false) 18 | (unlist buf) 19 | buf) 20 | buf))) 21 | 22 | (defn empty? [buf] 23 | (and (<= (nvim.buf_line_count buf) 1) 24 | (= 0 (a.count (a.first (nvim.buf_get_lines buf 0 -1 false)))))) 25 | -------------------------------------------------------------------------------- /fnl/conjure/config.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.config 2 | {require {a conjure.aniseed.core}}) 3 | 4 | (def langs 5 | {:fennel :conjure.lang.fennel-aniseed 6 | :clojure :conjure.lang.clojure-nrepl}) 7 | 8 | (def mappings 9 | {:prefix "" 10 | :log-split "ls" 11 | :log-vsplit "lv" 12 | :log-tab "lt" 13 | :eval-current-form "ee" 14 | :eval-root-form "er" 15 | :eval-marked-form "em" 16 | :eval-word "ew" 17 | :eval-file "ef" 18 | :eval-buf "eb" 19 | :eval-visual "E" 20 | :eval-motion "E" 21 | :doc-word ["K"] 22 | :def-word ["gd"] 23 | :close-hud "q"}) 24 | 25 | (def log 26 | {:hud {:width 0.42 27 | :height 0.3 28 | :enabled? true} 29 | :break-length 0.42 30 | :trim {:at 10000 31 | :to 7000}}) 32 | 33 | (def extract 34 | {:context-header-lines 24}) 35 | 36 | (def preview 37 | {:sample-limit 0.3}) 38 | 39 | (defn filetypes [] 40 | (a.keys langs)) 41 | 42 | (defn filetype->module-name [filetype] 43 | (. langs filetype)) 44 | -------------------------------------------------------------------------------- /fnl/conjure/linked-list.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.linked-list 2 | {require {a conjure.aniseed.core}}) 3 | 4 | (defn create [xs prev] 5 | (when (not (a.empty? xs)) 6 | (let [rest (a.rest xs) 7 | node {}] 8 | (a.assoc node :val (a.first xs)) 9 | (a.assoc node :prev prev) 10 | (a.assoc node :next (create rest node))))) 11 | 12 | (defn val [l] 13 | (-?> l (a.get :val))) 14 | 15 | (defn next [l] 16 | (-?> l (a.get :next))) 17 | 18 | (defn prev [l] 19 | (-?> l (a.get :prev))) 20 | 21 | (defn first [l] 22 | (var c l) 23 | (while (prev c) 24 | (set c (prev c))) 25 | c) 26 | 27 | (defn last [l] 28 | (var c l) 29 | (while (next c) 30 | (set c (next c))) 31 | c) 32 | 33 | (defn until [f l] 34 | (var c l) 35 | (var r false) 36 | (fn step [] 37 | (set r (f c)) 38 | r) 39 | (while (and c (not (step))) 40 | (set c (next c))) 41 | (when r 42 | c)) 43 | 44 | (defn cycle [l] 45 | (let [start (first l) 46 | end (last l)] 47 | (a.assoc start :prev end) 48 | (a.assoc end :next start) 49 | l)) 50 | -------------------------------------------------------------------------------- /fnl/conjure/lang.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.lang 2 | {require {nvim conjure.aniseed.nvim 3 | fennel conjure.aniseed.fennel 4 | config conjure.config}}) 5 | 6 | (defn- safe-require [name] 7 | (let [(ok? result) (xpcall 8 | (fn [] 9 | (require name)) 10 | fennel.traceback)] 11 | (if ok? 12 | result 13 | (error result)))) 14 | 15 | (defonce- overrides {}) 16 | 17 | (defn with-filetype [ft f ...] 18 | (set overrides.filetype ft) 19 | (let [(ok? result) (pcall f ...)] 20 | (set overrides.filetype nil) 21 | (if ok? 22 | result 23 | (error result)))) 24 | 25 | (defn current [] 26 | (let [ft (or overrides.filetype nvim.bo.filetype) 27 | mod-name (config.filetype->module-name ft)] 28 | (if mod-name 29 | (safe-require mod-name) 30 | (error (.. "No Conjure language for filetype: '" ft "'"))))) 31 | 32 | (defn get [k] 33 | (-?> (current) 34 | (. k))) 35 | 36 | (defn call [fn-name ...] 37 | (let [f (get fn-name)] 38 | (when f 39 | (f ...)))) 40 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/view.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.view" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {view = "conjure.aniseed.deps.fennelview"}} 19 | return {require("conjure.aniseed.deps.fennelview")} 20 | end 21 | local _2_ = _1_(...) 22 | local view = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local serialise = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = view 29 | _0_0["serialise"] = v_23_0_0 30 | v_23_0_ = v_23_0_0 31 | end 32 | _0_0["aniseed/locals"]["serialise"] = v_23_0_ 33 | serialise = v_23_0_ 34 | end 35 | return nil 36 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/fennel.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.fennel" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = require("conjure.aniseed.deps.fennel") 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {fennel = "conjure.aniseed.deps.fennel", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.deps.fennel"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local fennel = _2_[1] 23 | local nvim = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | nvim.ex.let("&runtimepath = &runtimepath") 26 | fennel["path"] = string.gsub(string.gsub(string.gsub(package.path, "/lua/", "/fnl/"), ".lua;", ".fnl;"), ".lua$", ".fnl") 27 | return nil 28 | -------------------------------------------------------------------------------- /test/fnl/conjure/text-test.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.text-test 2 | {require {text conjure.text}}) 3 | 4 | (deftest left-sample 5 | (t.= "" (text.left-sample "" 0) "handles empty strings") 6 | (t.= "f" (text.left-sample "f" 1) "handles single characters") 7 | (t.= "foo bar" (text.left-sample "foo bar" 10) "does nothing if correct") 8 | (t.= "foo bar" (text.left-sample "foo \n\n bar" 10) "replaces lots of whitespace with a space") 9 | (t.= "foo bar b..." (text.left-sample "foo \n\n bar \n\n baz" 10) "cuts the string if too long") 10 | (t.= "foo bar" (text.left-sample " foo \n \n bar \n" 10) "trims leading and trailing whitespace")) 11 | 12 | (deftest right-sample 13 | (t.= "...o bar baz" (text.right-sample "foo \n\n bar \n\n baz" 10) "same as left-sample, but we want the right")) 14 | 15 | (deftest split-lines 16 | (t.pr= [] (text.split-lines "") "nothing to nothing") 17 | (t.pr= ["foo" "bar"] (text.split-lines "foo\nbar") "basic split")) 18 | 19 | (deftest prefixed-lines 20 | (t.pr= [] (text.prefixed-lines "" "; ") "nothing to nothing") 21 | (t.pr= ["; foo"] (text.prefixed-lines "foo" "; ") "single line") 22 | (t.pr= ["; foo" "; bar"] (text.prefixed-lines "foo\nbar" "; ") "multiple lines")) 23 | -------------------------------------------------------------------------------- /lua/conjure/bridge.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.bridge" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {} 19 | return {} 20 | end 21 | local _2_ = _1_(...) 22 | do local _ = ({nil, _0_0, nil})[2] end 23 | local viml__3elua = nil 24 | do 25 | local v_23_0_ = nil 26 | do 27 | local v_23_0_0 = nil 28 | local function viml__3elua0(m, f, opts) 29 | return ("lua require('" .. m .. "')['" .. f .. "'](" .. ((opts and opts.args) or "") .. ")") 30 | end 31 | v_23_0_0 = viml__3elua0 32 | _0_0["viml->lua"] = v_23_0_0 33 | v_23_0_ = v_23_0_0 34 | end 35 | _0_0["aniseed/locals"]["viml->lua"] = v_23_0_ 36 | viml__3elua = v_23_0_ 37 | end 38 | return nil -------------------------------------------------------------------------------- /lua/conjure/aniseed/dotfiles.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.dotfiles" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {compile = "conjure.aniseed.compile", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.compile"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local compile = _2_[1] 23 | local nvim = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | local config_dir = nil 26 | do 27 | local v_23_0_ = nvim.fn.stdpath("config") 28 | _0_0["aniseed/locals"]["config-dir"] = v_23_0_ 29 | config_dir = v_23_0_ 30 | end 31 | compile.glob("**/*.fnl", (config_dir .. "/fnl"), (config_dir .. "/lua")) 32 | return require("dotfiles.init") 33 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | 26 | -------------------------------------------------------------------------------- /lua/conjure/main.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.main" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {config = "conjure.config", mapping = "conjure.mapping"}} 19 | return {require("conjure.config"), require("conjure.mapping")} 20 | end 21 | local _2_ = _1_(...) 22 | local config = _2_[1] 23 | local mapping = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | local main = nil 26 | do 27 | local v_23_0_ = nil 28 | do 29 | local v_23_0_0 = nil 30 | local function main0() 31 | return mapping["setup-filetypes"](config.filetypes()) 32 | end 33 | v_23_0_0 = main0 34 | _0_0["main"] = v_23_0_0 35 | v_23_0_ = v_23_0_0 36 | end 37 | _0_0["aniseed/locals"]["main"] = v_23_0_ 38 | main = v_23_0_ 39 | end 40 | return nil -------------------------------------------------------------------------------- /lua/conjure/uuid.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.uuid" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {} 19 | return {} 20 | end 21 | local _2_ = _1_(...) 22 | do local _ = ({nil, _0_0, nil})[2] end 23 | math.randomseed(os.time()) 24 | local v4 = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = nil 29 | local function v40() 30 | local function _3_(_241) 31 | return string.format("%x", (((_241 == "x") and math.random(0, 15)) or math.random(8, 11))) 32 | end 33 | return string.gsub("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", "[xy]", _3_) 34 | end 35 | v_23_0_0 = v40 36 | _0_0["v4"] = v_23_0_0 37 | v_23_0_ = v_23_0_0 38 | end 39 | _0_0["aniseed/locals"]["v4"] = v_23_0_ 40 | v4 = v_23_0_ 41 | end 42 | -- (v4) 43 | return nil -------------------------------------------------------------------------------- /test/fnl/conjure/linked-list-test.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.linked-list-test 2 | {require {ll conjure.linked-list}}) 3 | 4 | (deftest basics 5 | (let [l (ll.create [1 2 3])] 6 | (t.= 1 (->> l (ll.val)) "get first value") 7 | (t.= 2 (->> l (ll.next) (ll.val)) "get second value") 8 | (t.= 1 (->> l (ll.next) (ll.prev) (ll.val)) "forward and back") 9 | (t.= 3 (->> l (ll.next) (ll.next) (ll.val)) "last by steps") 10 | (t.= nil (->> l (ll.next) (ll.next) (ll.next)) "off the end") 11 | (t.= nil (->> l (ll.prev)) "off the front") 12 | (t.= nil (ll.val nil) "val handles nils") 13 | (t.= 3 (->> l (ll.last) (ll.val)) "last") 14 | (t.= 1 (->> l (ll.first) (ll.val)) "first") 15 | (t.= 1 (->> l (ll.last) (ll.first) (ll.val)) "last then first"))) 16 | 17 | (deftest until 18 | (let [l (ll.create [1 2 3 4 5])] 19 | (t.= nil (->> l (ll.until #(= 8 (ll.val $1))) (ll.val)) "nil if not found") 20 | (t.= 3 (->> l (ll.until #(= 3 (ll.val $1))) (ll.val)) "target node if found") 21 | (t.= 2 (->> l (ll.until #(= 3 (->> $1 (ll.next) (ll.val)))) (ll.val)) 22 | "can find the one before"))) 23 | 24 | (deftest cycle 25 | (let [l (ll.cycle (ll.create [1 2 3]))] 26 | (t.= 1 (->> l (ll.val)) "first is still first") 27 | (t.= 2 (->> l (ll.next) (ll.val)) "can still next") 28 | (t.= 3 (->> l (ll.next) (ll.next) (ll.val)) "can still next next (last)") 29 | (t.= 1 (->> l (ll.next) (ll.next) (ll.next) (ll.val)) "off the end loops") 30 | (t.= 3 (->> l (ll.prev) (ll.val)) "off the front loops"))) 31 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/eval.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.eval" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {compile = "conjure.aniseed.compile", fennel = "conjure.aniseed.fennel", fs = "conjure.aniseed.fs", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.compile"), require("conjure.aniseed.fennel"), require("conjure.aniseed.fs"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local compile = _2_[1] 23 | local fennel = _2_[2] 24 | local fs = _2_[3] 25 | local nvim = _2_[4] 26 | do local _ = ({nil, _0_0, nil})[2] end 27 | local str = nil 28 | do 29 | local v_23_0_ = nil 30 | do 31 | local v_23_0_0 = nil 32 | local function str0(code, opts) 33 | local function _3_() 34 | return fennel.eval(compile["macros-prefix"](code), opts) 35 | end 36 | return xpcall(_3_, fennel.traceback) 37 | end 38 | v_23_0_0 = str0 39 | _0_0["str"] = v_23_0_0 40 | v_23_0_ = v_23_0_0 41 | end 42 | _0_0["aniseed/locals"]["str"] = v_23_0_ 43 | str = v_23_0_ 44 | end 45 | return nil 46 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/fs.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.fs" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local nvim = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local basename = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = nil 29 | local function basename0(path) 30 | return nvim.fn.fnamemodify(path, ":h") 31 | end 32 | v_23_0_0 = basename0 33 | _0_0["basename"] = v_23_0_0 34 | v_23_0_ = v_23_0_0 35 | end 36 | _0_0["aniseed/locals"]["basename"] = v_23_0_ 37 | basename = v_23_0_ 38 | end 39 | local mkdirp = nil 40 | do 41 | local v_23_0_ = nil 42 | do 43 | local v_23_0_0 = nil 44 | local function mkdirp0(dir) 45 | return nvim.fn.mkdir(dir, "p") 46 | end 47 | v_23_0_0 = mkdirp0 48 | _0_0["mkdirp"] = v_23_0_0 49 | v_23_0_ = v_23_0_0 50 | end 51 | _0_0["aniseed/locals"]["mkdirp"] = v_23_0_ 52 | mkdirp = v_23_0_ 53 | end 54 | return nil 55 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Conjure Sourcery 2 | 3 | * 10/04/2020 - This repo has served it's purpose and has been moved into the develop branch of the main https://github.com/Olical/conjure[Conjure] repository. 4 | ____ 5 | As they say in Discworld, we are trying to unravel the Mighty Infinite using a language which was designed to tell one another where the fresh fruit was. 6 | 7 | — Terry Pratchett in Sourcery 8 | ____ 9 | 10 | An experimental reimplementation of https://github.com/Olical/conjure[Conjure] in Lua via https://github.com/bakpakin/Fennel[Fennel]. This is mostly made possible by my precursor project to this one, https://github.com/Olical/aniseed[Aniseed]. It's a toolkit that aids development of Neovim plugins and configuration through Fennel. 11 | 12 | If this experiment is a success it'll eventually replace the main repository as the default Conjure implementation. I'm planning on carrying over a lot of the best behaviors and features while making it smoother, faster and easier to use. 13 | 14 | I'm also considering supporting other Lisps such as Scheme, Racket and Fennel. I think the model of selecting forms and working with results in alog buffer is universal, the thing that changes is how evaluations are performed and wrapped. Food for thought! 15 | 16 | == Unlicenced 17 | 18 | Find the full http://unlicense.org/[unlicense] in the `UNLICENSE` file, but here's a snippet. 19 | 20 | ____ 21 | This is free and unencumbered software released into the public domain. 22 | 23 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. 24 | ____ 25 | -------------------------------------------------------------------------------- /test/fnl/conjure/bencode-stream-test.fnl: -------------------------------------------------------------------------------- 1 | (module bencode-stream-test 2 | {require {bencode-stream conjure.bencode-stream 3 | bencode conjure.bencode}}) 4 | 5 | (deftest basic 6 | (let [bs (bencode-stream.new) 7 | data {:foo [:bar]}] 8 | (t.= bs.data "" "data starts empty") 9 | (t.pr= [data] 10 | (bencode-stream.decode-all bs (bencode.encode data)) 11 | "a single bencoded value") 12 | (t.= bs.data "" "data is empty after a decode"))) 13 | 14 | (deftest multiple-values 15 | (let [bs (bencode-stream.new) 16 | data-a {:foo [:bar]} 17 | data-b [1 2 3]] 18 | (t.= bs.data "" "data starts empty") 19 | (t.pr= [data-a data-b] 20 | (bencode-stream.decode-all 21 | bs 22 | (.. (bencode.encode data-a) 23 | (bencode.encode data-b))) 24 | "two bencoded values") 25 | (t.= bs.data "" "data is empty after a decode"))) 26 | 27 | (deftest partial-values 28 | (let [bs (bencode-stream.new) 29 | data-a {:foo [:bar]} 30 | data-b [1 2 3] 31 | encoded-b (bencode.encode data-b)] 32 | (t.= bs.data "" "data starts empty") 33 | (t.pr= [data-a] 34 | (bencode-stream.decode-all 35 | bs 36 | (.. (bencode.encode data-a) 37 | (string.sub encoded-b 1 3))) 38 | "first value") 39 | (t.= "li1" bs.data "after first, data contains partial data-b") 40 | (t.pr= [data-b] 41 | (bencode-stream.decode-all 42 | bs 43 | (string.sub encoded-b 4)) 44 | "second value after rest of data") 45 | (t.= bs.data "" "data is empty after a decode"))) 46 | -------------------------------------------------------------------------------- /lua/conjure/bencode-stream.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.bencode-stream" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", bencode = "conjure.bencode"}} 19 | return {require("conjure.aniseed.core"), require("conjure.bencode")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local bencode = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | local new = nil 26 | do 27 | local v_23_0_ = nil 28 | do 29 | local v_23_0_0 = nil 30 | local function new0() 31 | return {data = ""} 32 | end 33 | v_23_0_0 = new0 34 | _0_0["new"] = v_23_0_0 35 | v_23_0_ = v_23_0_0 36 | end 37 | _0_0["aniseed/locals"]["new"] = v_23_0_ 38 | new = v_23_0_ 39 | end 40 | local decode_all = nil 41 | do 42 | local v_23_0_ = nil 43 | do 44 | local v_23_0_0 = nil 45 | local function decode_all0(bs, part) 46 | local progress = 1 47 | local end_3f = false 48 | do 49 | local s = (bs.data .. part) 50 | local acc = {} 51 | while ((progress < a.count(s)) and not end_3f) do 52 | local msg, consumed = bencode.decode(s, progress) 53 | if a["nil?"](msg) then 54 | end_3f = true 55 | else 56 | table.insert(acc, msg) 57 | progress = consumed 58 | end 59 | end 60 | a.assoc(bs, "data", string.sub(s, progress)) 61 | return acc 62 | end 63 | end 64 | v_23_0_0 = decode_all0 65 | _0_0["decode-all"] = v_23_0_0 66 | v_23_0_ = v_23_0_0 67 | end 68 | _0_0["aniseed/locals"]["decode-all"] = v_23_0_ 69 | decode_all = v_23_0_ 70 | end 71 | return nil -------------------------------------------------------------------------------- /lua/conjure/buffer.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.buffer" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.core"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local nvim = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | local unlist = nil 26 | do 27 | local v_23_0_ = nil 28 | do 29 | local v_23_0_0 = nil 30 | local function unlist0(buf) 31 | return nvim.buf_set_option(buf, "buflisted", false) 32 | end 33 | v_23_0_0 = unlist0 34 | _0_0["unlist"] = v_23_0_0 35 | v_23_0_ = v_23_0_0 36 | end 37 | _0_0["aniseed/locals"]["unlist"] = v_23_0_ 38 | unlist = v_23_0_ 39 | end 40 | local upsert_hidden = nil 41 | do 42 | local v_23_0_ = nil 43 | do 44 | local v_23_0_0 = nil 45 | local function upsert_hidden0(buf_name) 46 | local buf = nvim.fn.bufnr(buf_name) 47 | if (-1 == buf) then 48 | local buf0 = nvim.fn.bufadd(buf_name) 49 | nvim.buf_set_option(buf0, "buftype", "nofile") 50 | nvim.buf_set_option(buf0, "bufhidden", "hide") 51 | nvim.buf_set_option(buf0, "swapfile", false) 52 | unlist(buf0) 53 | return buf0 54 | else 55 | return buf 56 | end 57 | end 58 | v_23_0_0 = upsert_hidden0 59 | _0_0["upsert-hidden"] = v_23_0_0 60 | v_23_0_ = v_23_0_0 61 | end 62 | _0_0["aniseed/locals"]["upsert-hidden"] = v_23_0_ 63 | upsert_hidden = v_23_0_ 64 | end 65 | local empty_3f = nil 66 | do 67 | local v_23_0_ = nil 68 | do 69 | local v_23_0_0 = nil 70 | local function empty_3f0(buf) 71 | return ((nvim.buf_line_count(buf) <= 1) and (0 == a.count(a.first(nvim.buf_get_lines(buf, 0, -1, false))))) 72 | end 73 | v_23_0_0 = empty_3f0 74 | _0_0["empty?"] = v_23_0_0 75 | v_23_0_ = v_23_0_0 76 | end 77 | _0_0["aniseed/locals"]["empty?"] = v_23_0_ 78 | empty_3f = v_23_0_ 79 | end 80 | return nil -------------------------------------------------------------------------------- /lua/conjure/aniseed/string.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.string" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core"}} 19 | return {require("conjure.aniseed.core")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local join = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = nil 29 | local function join0(...) 30 | local args = {...} 31 | local function _3_(...) 32 | if (2 == a.count(args)) then 33 | return args 34 | else 35 | return {"", a.first(args)} 36 | end 37 | end 38 | local _4_ = _3_(...) 39 | local sep = _4_[1] 40 | local xs = _4_[2] 41 | local count = a.count(xs) 42 | local result = "" 43 | if (count > 0) then 44 | for i = 1, count do 45 | local x = xs[i] 46 | local function _5_(...) 47 | if (1 == i) then 48 | return "" 49 | else 50 | return sep 51 | end 52 | end 53 | local function _6_(...) 54 | if a["string?"](x) then 55 | return x 56 | elseif a["nil?"](x) then 57 | return "" 58 | else 59 | return a["pr-str"](x) 60 | end 61 | end 62 | result = (result .. _5_(...) .. _6_(...)) 63 | end 64 | end 65 | return result 66 | end 67 | v_23_0_0 = join0 68 | _0_0["join"] = v_23_0_0 69 | v_23_0_ = v_23_0_0 70 | end 71 | _0_0["aniseed/locals"]["join"] = v_23_0_ 72 | join = v_23_0_ 73 | end 74 | local split = nil 75 | do 76 | local v_23_0_ = nil 77 | do 78 | local v_23_0_0 = nil 79 | local function split0(s, pat) 80 | local acc = {} 81 | local function _3_(part) 82 | return table.insert(acc, part) 83 | end 84 | string.gsub(s, pat, _3_) 85 | return acc 86 | end 87 | v_23_0_0 = split0 88 | _0_0["split"] = v_23_0_0 89 | v_23_0_ = v_23_0_0 90 | end 91 | _0_0["aniseed/locals"]["split"] = v_23_0_ 92 | split = v_23_0_ 93 | end 94 | return nil 95 | -------------------------------------------------------------------------------- /fnl/conjure/mapping.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.mapping 2 | {require {nvim conjure.aniseed.nvim 3 | a conjure.aniseed.core 4 | str conjure.aniseed.string 5 | config conjure.config 6 | extract conjure.extract 7 | lang conjure.lang 8 | eval conjure.eval 9 | bridge conjure.bridge}}) 10 | 11 | (defn buf [mode keys ...] 12 | (let [args [...]] 13 | (nvim.buf_set_keymap 14 | 0 mode 15 | (if (a.string? keys) 16 | (.. config.mappings.prefix keys) 17 | (a.first keys)) 18 | (if (= 2 (a.count args)) 19 | (.. ":" (bridge.viml->lua (unpack args)) "") 20 | (unpack args)) 21 | {:silent true 22 | :noremap true}))) 23 | 24 | (defn on-filetype [] 25 | (buf :n config.mappings.eval-motion ":set opfunc=ConjureEvalMotiong@") 26 | (buf :n config.mappings.log-split :conjure.log :split) 27 | (buf :n config.mappings.log-vsplit :conjure.log :vsplit) 28 | (buf :n config.mappings.log-tab :conjure.log :tab) 29 | (buf :n config.mappings.eval-current-form :conjure.eval :current-form) 30 | (buf :n config.mappings.eval-root-form :conjure.eval :root-form) 31 | (buf :n config.mappings.eval-marked-form :conjure.eval :marked-form) 32 | (buf :n config.mappings.eval-word :conjure.eval :word) 33 | (buf :n config.mappings.eval-file :conjure.eval :file) 34 | (buf :n config.mappings.eval-buf :conjure.eval :buf) 35 | (buf :v config.mappings.eval-visual :conjure.eval :selection) 36 | (buf :n config.mappings.close-hud :conjure.log :close-hud) 37 | (buf :n config.mappings.doc-word :conjure.eval :doc-word) 38 | (buf :n config.mappings.def-word :conjure.eval :def-word) 39 | 40 | (nvim.ex.autocmd 41 | :CursorMoved : 42 | (bridge.viml->lua :conjure.log :close-hud {})) 43 | 44 | (nvim.ex.autocmd 45 | :CursorMovedI : 46 | (bridge.viml->lua :conjure.log :close-hud {})) 47 | 48 | (lang.call :on-filetype)) 49 | 50 | (defn setup-filetypes [filetypes] 51 | (nvim.ex.augroup :conjure_init_filetypes) 52 | (nvim.ex.autocmd_) 53 | (nvim.ex.autocmd 54 | :FileType (str.join "," filetypes) 55 | (bridge.viml->lua :conjure.mapping :on-filetype {})) 56 | (nvim.ex.augroup :END)) 57 | 58 | (defn eval-ranged-command [start end code] 59 | (if (= "" code) 60 | (eval.range (a.dec start) end) 61 | (eval.command code))) 62 | 63 | (nvim.ex.function_ 64 | (->> ["ConjureEvalMotion(kind)" 65 | "call luaeval(\"require('conjure.eval')['selection'](_A)\", a:kind)" 66 | "endfunction"] 67 | (str.join "\n"))) 68 | 69 | ;; TODO Add completion via -complete=custom,{func} 70 | (nvim.ex.command_ 71 | "-nargs=? -range ConjureEval" 72 | (bridge.viml->lua 73 | :conjure.mapping :eval-ranged-command 74 | {:args ", , "})) 75 | -------------------------------------------------------------------------------- /fnl/conjure/lang/fennel-aniseed.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.lang.fennel-aniseed 2 | {require {nvim conjure.aniseed.nvim 3 | a conjure.aniseed.core 4 | str conjure.aniseed.string 5 | view conjure.aniseed.view 6 | ani-core aniseed.core 7 | ani-eval aniseed.eval 8 | ani-test aniseed.test 9 | lang conjure.lang 10 | mapping conjure.mapping 11 | text conjure.text 12 | log conjure.log 13 | extract conjure.extract}}) 14 | 15 | ;; TODO Display all results from multi returns. 16 | 17 | (def buf-suffix ".fnl") 18 | (def context-pattern "[(]%s*module%s*(.-)[%s){]") 19 | (def comment-prefix "; ") 20 | 21 | (def config 22 | {:mappings {:run-buf-tests "tt" 23 | :run-all-tests "ta"}}) 24 | 25 | (defn- display [lines opts] 26 | (lang.with-filetype :fennel log.append lines opts)) 27 | 28 | (defn display-result [opts] 29 | (when opts 30 | (let [{: ok? : result} opts 31 | result-str (if ok? 32 | (view.serialise result) 33 | result) 34 | result-lines (str.split result-str "[^\n]+")] 35 | (display (if ok? 36 | result-lines 37 | (a.map #(.. "; " $1) result-lines)))))) 38 | 39 | (defn eval-str [opts] 40 | (let [code (.. (.. "(module " (or opts.context "aniseed.user") ") ") 41 | opts.code "\n") 42 | out (ani-core.with-out-str 43 | (fn [] 44 | (let [(ok? result) (ani-eval.str code {:filename opts.file-path})] 45 | (set opts.ok? ok?) 46 | (set opts.result result))))] 47 | (when (not (a.empty? out)) 48 | (display (text.prefixed-lines out "; (out) "))) 49 | (display-result opts))) 50 | 51 | (defn doc-str [opts] 52 | (a.assoc opts :code (.. "(doc " opts.code ")")) 53 | (eval-str opts)) 54 | 55 | (defn- not-implemented [] 56 | (display ["; Not implemented for conjure.lang.fennel-aniseed"])) 57 | 58 | (defn def-str [opts] 59 | (not-implemented)) 60 | 61 | (defn eval-file [opts] 62 | (set opts.code (a.slurp opts.file-path)) 63 | (when opts.code 64 | (eval-str opts))) 65 | 66 | (defn- wrapped-test [req-lines f] 67 | (display req-lines {:break? true}) 68 | (let [res (ani-core.with-out-str f)] 69 | (display 70 | (-> (if (= "" res) 71 | "No results." 72 | res) 73 | (text.prefixed-lines "; "))))) 74 | 75 | (defn run-buf-tests [] 76 | (let [c (extract.context)] 77 | (when c 78 | (wrapped-test 79 | [(.. "; run-buf-tests (" c ")")] 80 | #(ani-test.run c))))) 81 | 82 | (defn run-all-tests [] 83 | (wrapped-test ["; run-all-tests"] ani-test.run-all)) 84 | 85 | (defn on-filetype [] 86 | (mapping.buf :n config.mappings.run-buf-tests 87 | :conjure.lang.fennel-aniseed :run-buf-tests) 88 | (mapping.buf :n config.mappings.run-all-tests 89 | :conjure.lang.fennel-aniseed :run-all-tests)) 90 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/nvim/util.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.nvim.util" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local nvim = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local normal = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = nil 29 | local function normal0(keys) 30 | return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) 31 | end 32 | v_23_0_0 = normal0 33 | _0_0["normal"] = v_23_0_0 34 | v_23_0_ = v_23_0_0 35 | end 36 | _0_0["aniseed/locals"]["normal"] = v_23_0_ 37 | normal = v_23_0_ 38 | end 39 | local fn_bridge = nil 40 | do 41 | local v_23_0_ = nil 42 | do 43 | local v_23_0_0 = nil 44 | local function fn_bridge0(viml_name, mod, lua_name, opts) 45 | local _3_ = (opts or {}) 46 | local range = _3_["range"] 47 | local _return = _3_["return"] 48 | local function _4_() 49 | if range then 50 | return " range" 51 | else 52 | return "" 53 | end 54 | end 55 | local function _5_() 56 | if _return then 57 | return "return" 58 | else 59 | return "call" 60 | end 61 | end 62 | local function _6_() 63 | if range then 64 | return "\" . a:firstline . \", \" . a:lastline . \", " 65 | else 66 | return "" 67 | end 68 | end 69 | return nvim.ex.function_((viml_name .. "(...)" .. _4_() .. "\n " .. _5_() .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _6_() .. "unpack(_A))\", a:000)\n endfunction")) 70 | end 71 | v_23_0_0 = fn_bridge0 72 | _0_0["fn-bridge"] = v_23_0_0 73 | v_23_0_ = v_23_0_0 74 | end 75 | _0_0["aniseed/locals"]["fn-bridge"] = v_23_0_ 76 | fn_bridge = v_23_0_ 77 | end 78 | local ft_map = nil 79 | do 80 | local v_23_0_ = nil 81 | do 82 | local v_23_0_0 = nil 83 | local function ft_map0(ft, mode, from, to) 84 | return nvim.ex.autocmd("FileType", ft, (mode .. "map"), "", ("" .. from), to) 85 | end 86 | v_23_0_0 = ft_map0 87 | _0_0["ft-map"] = v_23_0_0 88 | v_23_0_ = v_23_0_0 89 | end 90 | _0_0["aniseed/locals"]["ft-map"] = v_23_0_ 91 | ft_map = v_23_0_ 92 | end 93 | local plug = nil 94 | do 95 | local v_23_0_ = nil 96 | do 97 | local v_23_0_0 = nil 98 | local function plug0(cmd) 99 | return ("(" .. cmd .. ")") 100 | end 101 | v_23_0_0 = plug0 102 | _0_0["plug"] = v_23_0_0 103 | v_23_0_ = v_23_0_0 104 | end 105 | _0_0["aniseed/locals"]["plug"] = v_23_0_ 106 | plug = v_23_0_ 107 | end 108 | return nil 109 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at ollie@oli.me.uk. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /lua/conjure/text.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.text" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", str = "conjure.aniseed.string"}} 19 | return {require("conjure.aniseed.core"), require("conjure.aniseed.string")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local str = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | local trim = nil 26 | do 27 | local v_23_0_ = nil 28 | local function trim0(s) 29 | return string.gsub(s, "^%s*(.-)%s*$", "%1") 30 | end 31 | v_23_0_ = trim0 32 | _0_0["aniseed/locals"]["trim"] = v_23_0_ 33 | trim = v_23_0_ 34 | end 35 | local left_sample = nil 36 | do 37 | local v_23_0_ = nil 38 | do 39 | local v_23_0_0 = nil 40 | local function left_sample0(s, limit) 41 | local flat = trim(string.gsub(string.gsub(s, "\n", " "), "%s+", " ")) 42 | if (limit >= a.count(flat)) then 43 | return flat 44 | else 45 | return (string.sub(flat, 0, a.dec(limit)) .. "...") 46 | end 47 | end 48 | v_23_0_0 = left_sample0 49 | _0_0["left-sample"] = v_23_0_0 50 | v_23_0_ = v_23_0_0 51 | end 52 | _0_0["aniseed/locals"]["left-sample"] = v_23_0_ 53 | left_sample = v_23_0_ 54 | end 55 | local right_sample = nil 56 | do 57 | local v_23_0_ = nil 58 | do 59 | local v_23_0_0 = nil 60 | local function right_sample0(s, limit) 61 | return string.reverse(left_sample(string.reverse(s), limit)) 62 | end 63 | v_23_0_0 = right_sample0 64 | _0_0["right-sample"] = v_23_0_0 65 | v_23_0_ = v_23_0_0 66 | end 67 | _0_0["aniseed/locals"]["right-sample"] = v_23_0_ 68 | right_sample = v_23_0_ 69 | end 70 | local split_lines = nil 71 | do 72 | local v_23_0_ = nil 73 | do 74 | local v_23_0_0 = nil 75 | local function split_lines0(s) 76 | return str.split(s, "[^\n]+") 77 | end 78 | v_23_0_0 = split_lines0 79 | _0_0["split-lines"] = v_23_0_0 80 | v_23_0_ = v_23_0_0 81 | end 82 | _0_0["aniseed/locals"]["split-lines"] = v_23_0_ 83 | split_lines = v_23_0_ 84 | end 85 | local prefixed_lines = nil 86 | do 87 | local v_23_0_ = nil 88 | do 89 | local v_23_0_0 = nil 90 | local function prefixed_lines0(s, prefix) 91 | local function _3_(line) 92 | return (prefix .. line) 93 | end 94 | return a.map(_3_, split_lines(s)) 95 | end 96 | v_23_0_0 = prefixed_lines0 97 | _0_0["prefixed-lines"] = v_23_0_0 98 | v_23_0_ = v_23_0_0 99 | end 100 | _0_0["aniseed/locals"]["prefixed-lines"] = v_23_0_ 101 | prefixed_lines = v_23_0_ 102 | end 103 | local starts_with = nil 104 | do 105 | local v_23_0_ = nil 106 | do 107 | local v_23_0_0 = nil 108 | local function starts_with0(str0, start) 109 | return (string.sub(str0, 1, a.count(start)) == start) 110 | end 111 | v_23_0_0 = starts_with0 112 | _0_0["starts-with"] = v_23_0_0 113 | v_23_0_ = v_23_0_0 114 | end 115 | _0_0["aniseed/locals"]["starts-with"] = v_23_0_ 116 | starts_with = v_23_0_ 117 | end 118 | return nil -------------------------------------------------------------------------------- /lua/conjure/config.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.config" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core"}} 19 | return {require("conjure.aniseed.core")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local langs = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = {clojure = "conjure.lang.clojure-nrepl", fennel = "conjure.lang.fennel-aniseed"} 29 | _0_0["langs"] = v_23_0_0 30 | v_23_0_ = v_23_0_0 31 | end 32 | _0_0["aniseed/locals"]["langs"] = v_23_0_ 33 | langs = v_23_0_ 34 | end 35 | local mappings = nil 36 | do 37 | local v_23_0_ = nil 38 | do 39 | local v_23_0_0 = {["close-hud"] = "q", ["def-word"] = {"gd"}, ["doc-word"] = {"K"}, ["eval-buf"] = "eb", ["eval-current-form"] = "ee", ["eval-file"] = "ef", ["eval-marked-form"] = "em", ["eval-motion"] = "E", ["eval-root-form"] = "er", ["eval-visual"] = "E", ["eval-word"] = "ew", ["log-split"] = "ls", ["log-tab"] = "lt", ["log-vsplit"] = "lv", prefix = ""} 40 | _0_0["mappings"] = v_23_0_0 41 | v_23_0_ = v_23_0_0 42 | end 43 | _0_0["aniseed/locals"]["mappings"] = v_23_0_ 44 | mappings = v_23_0_ 45 | end 46 | local log = nil 47 | do 48 | local v_23_0_ = nil 49 | do 50 | local v_23_0_0 = {["break-length"] = 0.41999999999999998, hud = {["enabled?"] = true, height = 0.29999999999999999, width = 0.41999999999999998}, trim = {at = 10000, to = 7000}} 51 | _0_0["log"] = v_23_0_0 52 | v_23_0_ = v_23_0_0 53 | end 54 | _0_0["aniseed/locals"]["log"] = v_23_0_ 55 | log = v_23_0_ 56 | end 57 | local extract = nil 58 | do 59 | local v_23_0_ = nil 60 | do 61 | local v_23_0_0 = {["context-header-lines"] = 24} 62 | _0_0["extract"] = v_23_0_0 63 | v_23_0_ = v_23_0_0 64 | end 65 | _0_0["aniseed/locals"]["extract"] = v_23_0_ 66 | extract = v_23_0_ 67 | end 68 | local preview = nil 69 | do 70 | local v_23_0_ = nil 71 | do 72 | local v_23_0_0 = {["sample-limit"] = 0.29999999999999999} 73 | _0_0["preview"] = v_23_0_0 74 | v_23_0_ = v_23_0_0 75 | end 76 | _0_0["aniseed/locals"]["preview"] = v_23_0_ 77 | preview = v_23_0_ 78 | end 79 | local filetypes = nil 80 | do 81 | local v_23_0_ = nil 82 | do 83 | local v_23_0_0 = nil 84 | local function filetypes0() 85 | return a.keys(langs) 86 | end 87 | v_23_0_0 = filetypes0 88 | _0_0["filetypes"] = v_23_0_0 89 | v_23_0_ = v_23_0_0 90 | end 91 | _0_0["aniseed/locals"]["filetypes"] = v_23_0_ 92 | filetypes = v_23_0_ 93 | end 94 | local filetype__3emodule_name = nil 95 | do 96 | local v_23_0_ = nil 97 | do 98 | local v_23_0_0 = nil 99 | local function filetype__3emodule_name0(filetype) 100 | return langs[filetype] 101 | end 102 | v_23_0_0 = filetype__3emodule_name0 103 | _0_0["filetype->module-name"] = v_23_0_0 104 | v_23_0_ = v_23_0_0 105 | end 106 | _0_0["aniseed/locals"]["filetype->module-name"] = v_23_0_ 107 | filetype__3emodule_name = v_23_0_ 108 | end 109 | return nil -------------------------------------------------------------------------------- /test/fnl/conjure/extract-test.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.extract-test 2 | {require {extract conjure.extract 3 | buffer conjure.test.buffer}}) 4 | 5 | (deftest current-form 6 | (buffer.with-buf 7 | ["(ns foo)" 8 | "" 9 | "(+ 10 20 (* 10 2))"] 10 | (fn [at] 11 | (at [3 10]) 12 | (t.pr= {:range {:start [3 9] 13 | :end [3 16]} 14 | :content "(* 10 2)"} 15 | (extract.form {}) 16 | "inside the form") 17 | 18 | (at [3 9]) 19 | (t.pr= {:range {:start [3 9] 20 | :end [3 16]} 21 | :content "(* 10 2)"} 22 | (extract.form {}) 23 | "on the opening paren") 24 | 25 | (at [3 16]) 26 | (t.pr= {:range {:start [3 9] 27 | :end [3 16]} 28 | :content "(* 10 2)"} 29 | (extract.form {}) 30 | "on the closing paren") 31 | 32 | (at [3 8]) 33 | (t.pr= {:range {:start [3 0] 34 | :end [3 17]} 35 | :content "(+ 10 20 (* 10 2))"} 36 | (extract.form {}) 37 | "one before the inner form") 38 | 39 | (at [3 17]) 40 | (t.pr= {:range {:start [3 0] 41 | :end [3 17]} 42 | :content "(+ 10 20 (* 10 2))"} 43 | (extract.form {}) 44 | "on the last paren of the outer form") 45 | 46 | (at [2 0]) 47 | (t.= nil (extract.form {}) "matching nothing") 48 | 49 | (at [1 0]) 50 | (t.pr= {:range {:start [1 0] 51 | :end [1 7]} 52 | :content "(ns foo)"} 53 | (extract.form {}) 54 | "ns form")))) 55 | 56 | (deftest root-form 57 | (buffer.with-buf 58 | ["(ns foo)" 59 | "" 60 | "(+ 10 20 (* 10 2))"] 61 | (fn [at] 62 | (at [3 10]) 63 | (t.pr= {:range {:start [3 0] 64 | :end [3 17]} 65 | :content "(+ 10 20 (* 10 2))"} 66 | (extract.form {:root? true}) 67 | "root from inside a child form") 68 | 69 | (at [3 6]) 70 | (t.pr= {:range {:start [3 0] 71 | :end [3 17]} 72 | :content "(+ 10 20 (* 10 2))"} 73 | (extract.form {:root? true}) 74 | "root from the root") 75 | 76 | (at [3 0]) 77 | (t.pr= {:range {:start [3 0] 78 | :end [3 17]} 79 | :content "(+ 10 20 (* 10 2))"} 80 | (extract.form {:root? true}) 81 | "root from the opening paren of the root") 82 | 83 | (at [3 9]) 84 | (t.pr= {:range {:start [3 0] 85 | :end [3 17]} 86 | :content "(+ 10 20 (* 10 2))"} 87 | (extract.form {:root? true}) 88 | "root from the opening paren of the child form") 89 | 90 | (at [2 0]) 91 | (t.= nil (extract.form {:root? true}) "matching nothing for root")))) 92 | 93 | (deftest ignoring-comments 94 | (buffer.with-buf 95 | ["(ns ohno)" 96 | "" 97 | "(inc" 98 | " ; )" 99 | " 5)"] 100 | (fn [at] 101 | (at [4 0]) 102 | (t.pr= {:range {:start [3 0] 103 | :end [5 2]} 104 | :content "(inc\n ;)\n 5)"} 105 | (extract.form {}) 106 | "skips the comment paren with current form") 107 | 108 | (at [4 0]) 109 | (t.pr= {:range {:start [3 0] 110 | :end [5 2]} 111 | :content "(inc\n ;)\n 5)"} 112 | (extract.form {:root? true}) 113 | "skips the comment paren with root form")))) 114 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/macros.fnl: -------------------------------------------------------------------------------- 1 | ;; All of Aniseed's macros in one place. 2 | ;; Can't be compiled to Lua directly. 3 | 4 | ;; Automatically loaded through require-macros for all Aniseed based evaluations. 5 | 6 | (local module-sym (gensym)) 7 | 8 | (fn sorted-each [f x] 9 | (let [acc []] 10 | (each [k v (pairs x)] 11 | (table.insert acc [k v])) 12 | (table.sort 13 | acc 14 | (fn [a b] 15 | (< (. a 1) (. b 1)))) 16 | (each [_ [k v] (ipairs acc)] 17 | (f k v)))) 18 | 19 | (fn module [name new-local-fns initial-mod] 20 | `(-> [(local ,module-sym 21 | (let [name# ,(tostring name) 22 | loaded# (. package.loaded name#) 23 | module# (if (= :table (type loaded#)) 24 | loaded# 25 | ,(or initial-mod {}))] 26 | (tset module# :aniseed/module name#) 27 | (tset module# :aniseed/locals (or (. module# :aniseed/locals) {})) 28 | (tset module# :aniseed/local-fns (or (. module# :aniseed/local-fns) {})) 29 | (tset package.loaded name# module#) 30 | module#)) 31 | 32 | ,module-sym 33 | 34 | ,(let [aliases [] 35 | vals [] 36 | locals (-?> package.loaded 37 | (. (tostring name)) 38 | (. :aniseed/locals)) 39 | local-fns (or (-?> package.loaded 40 | (. (tostring name)) 41 | (. :aniseed/local-fns)) 42 | {})] 43 | 44 | (when new-local-fns 45 | (each [action binds (pairs new-local-fns)] 46 | (let [action-str (tostring action) 47 | current (or (. local-fns action-str) {})] 48 | (tset local-fns action-str current) 49 | (each [alias module (pairs binds)] 50 | (tset current (tostring alias) (tostring module)))))) 51 | 52 | (sorted-each 53 | (fn [action binds] 54 | (sorted-each 55 | (fn [alias module] 56 | (table.insert aliases (sym alias)) 57 | (table.insert vals `(,(sym action) ,module))) 58 | binds)) 59 | local-fns) 60 | 61 | (when locals 62 | (sorted-each 63 | (fn [alias val] 64 | (table.insert aliases (sym alias)) 65 | (table.insert vals `(-> ,module-sym (. :aniseed/locals) (. ,alias)))) 66 | locals)) 67 | 68 | `(var ,aliases 69 | (do 70 | (tset ,module-sym :aniseed/local-fns ,local-fns) 71 | ,vals)))] 72 | (. 2))) 73 | 74 | (fn def- [name value] 75 | `(var ,name 76 | (let [v# ,value] 77 | (tset (. ,module-sym :aniseed/locals) ,(tostring name) v#) 78 | v#))) 79 | 80 | (fn def [name value] 81 | `(def- ,name 82 | (do 83 | (let [v# ,value] 84 | (tset ,module-sym ,(tostring name) v#) 85 | v#)))) 86 | 87 | (fn defn- [name ...] 88 | `(def- ,name (fn ,name ,...))) 89 | 90 | (fn defn [name ...] 91 | `(def ,name (fn ,name ,...))) 92 | 93 | (fn defonce- [name value] 94 | `(def- ,name 95 | (or (. (. ,module-sym :aniseed/locals) ,(tostring name)) 96 | ,value))) 97 | 98 | (fn defonce [name value] 99 | `(def ,name 100 | (or (. ,module-sym ,(tostring name)) 101 | ,value))) 102 | 103 | (fn deftest [name ...] 104 | `(let [tests# (or (. ,module-sym :aniseed/tests) {})] 105 | (tset tests# ,(tostring name) (fn [,(sym :t)] ,...)) 106 | (tset ,module-sym :aniseed/tests tests#))) 107 | 108 | {:module module 109 | :def- def- :def def 110 | :defn- defn- :defn defn 111 | :defonce- defonce- :defonce defonce 112 | :deftest deftest} 113 | -------------------------------------------------------------------------------- /lua/conjure/lang.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.lang" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {config = "conjure.config", fennel = "conjure.aniseed.fennel", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.config"), require("conjure.aniseed.fennel"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local config = _2_[1] 23 | local fennel = _2_[2] 24 | local nvim = _2_[3] 25 | do local _ = ({nil, _0_0, nil})[2] end 26 | local safe_require = nil 27 | do 28 | local v_23_0_ = nil 29 | local function safe_require0(name) 30 | local ok_3f, result = nil, nil 31 | local function _3_() 32 | return require(name) 33 | end 34 | ok_3f, result = xpcall(_3_, fennel.traceback) 35 | if ok_3f then 36 | return result 37 | else 38 | return error(result) 39 | end 40 | end 41 | v_23_0_ = safe_require0 42 | _0_0["aniseed/locals"]["safe-require"] = v_23_0_ 43 | safe_require = v_23_0_ 44 | end 45 | local overrides = nil 46 | do 47 | local v_23_0_ = (_0_0["aniseed/locals"].overrides or {}) 48 | _0_0["aniseed/locals"]["overrides"] = v_23_0_ 49 | overrides = v_23_0_ 50 | end 51 | local with_filetype = nil 52 | do 53 | local v_23_0_ = nil 54 | do 55 | local v_23_0_0 = nil 56 | local function with_filetype0(ft, f, ...) 57 | overrides.filetype = ft 58 | do 59 | local ok_3f, result = pcall(f, ...) 60 | overrides.filetype = nil 61 | if ok_3f then 62 | return result 63 | else 64 | return error(result) 65 | end 66 | end 67 | end 68 | v_23_0_0 = with_filetype0 69 | _0_0["with-filetype"] = v_23_0_0 70 | v_23_0_ = v_23_0_0 71 | end 72 | _0_0["aniseed/locals"]["with-filetype"] = v_23_0_ 73 | with_filetype = v_23_0_ 74 | end 75 | local current = nil 76 | do 77 | local v_23_0_ = nil 78 | do 79 | local v_23_0_0 = nil 80 | local function current0() 81 | local ft = (overrides.filetype or nvim.bo.filetype) 82 | local mod_name = config["filetype->module-name"](ft) 83 | if mod_name then 84 | return safe_require(mod_name) 85 | else 86 | return error(("No Conjure language for filetype: '" .. ft .. "'")) 87 | end 88 | end 89 | v_23_0_0 = current0 90 | _0_0["current"] = v_23_0_0 91 | v_23_0_ = v_23_0_0 92 | end 93 | _0_0["aniseed/locals"]["current"] = v_23_0_ 94 | current = v_23_0_ 95 | end 96 | local get = nil 97 | do 98 | local v_23_0_ = nil 99 | do 100 | local v_23_0_0 = nil 101 | local function get0(k) 102 | local _3_0 = current() 103 | if _3_0 then 104 | return _3_0[k] 105 | else 106 | return _3_0 107 | end 108 | end 109 | v_23_0_0 = get0 110 | _0_0["get"] = v_23_0_0 111 | v_23_0_ = v_23_0_0 112 | end 113 | _0_0["aniseed/locals"]["get"] = v_23_0_ 114 | get = v_23_0_ 115 | end 116 | local call = nil 117 | do 118 | local v_23_0_ = nil 119 | do 120 | local v_23_0_0 = nil 121 | local function call0(fn_name, ...) 122 | local f = get(fn_name) 123 | if f then 124 | return f(...) 125 | end 126 | end 127 | v_23_0_0 = call0 128 | _0_0["call"] = v_23_0_0 129 | v_23_0_ = v_23_0_0 130 | end 131 | _0_0["aniseed/locals"]["call"] = v_23_0_ 132 | call = v_23_0_ 133 | end 134 | return nil -------------------------------------------------------------------------------- /lua/conjure/aniseed/compile.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.compile" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", fennel = "conjure.aniseed.fennel", fs = "conjure.aniseed.fs", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.core"), require("conjure.aniseed.fennel"), require("conjure.aniseed.fs"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local fennel = _2_[2] 24 | local fs = _2_[3] 25 | local nvim = _2_[4] 26 | do local _ = ({nil, _0_0, nil})[2] end 27 | local function _3_(...) 28 | local fnl_suffixes = string.gsub(string.gsub(package.path, "%.lua;", ".fnl;"), "%.lua$", ".fnl") 29 | fennel.path = (string.gsub(fnl_suffixes, "/lua/", "/fnl/") .. ";" .. fnl_suffixes) 30 | return nil 31 | end 32 | _3_(...) 33 | local macros_prefix = nil 34 | do 35 | local v_23_0_ = nil 36 | do 37 | local v_23_0_0 = nil 38 | local function macros_prefix0(code) 39 | local macros_module = "conjure.aniseed.macros" 40 | return ("(require-macros \"" .. macros_module .. "\")\n" .. code) 41 | end 42 | v_23_0_0 = macros_prefix0 43 | _0_0["macros-prefix"] = v_23_0_0 44 | v_23_0_ = v_23_0_0 45 | end 46 | _0_0["aniseed/locals"]["macros-prefix"] = v_23_0_ 47 | macros_prefix = v_23_0_ 48 | end 49 | local str = nil 50 | do 51 | local v_23_0_ = nil 52 | do 53 | local v_23_0_0 = nil 54 | local function str0(code, opts) 55 | local function _4_() 56 | return fennel.compileString(macros_prefix(code), opts) 57 | end 58 | return xpcall(_4_, fennel.traceback) 59 | end 60 | v_23_0_0 = str0 61 | _0_0["str"] = v_23_0_0 62 | v_23_0_ = v_23_0_0 63 | end 64 | _0_0["aniseed/locals"]["str"] = v_23_0_ 65 | str = v_23_0_ 66 | end 67 | local file = nil 68 | do 69 | local v_23_0_ = nil 70 | do 71 | local v_23_0_0 = nil 72 | local function file0(src, dest, opts) 73 | if ((a["table?"](opts) and opts.force) or (nvim.fn.getftime(src) > nvim.fn.getftime(dest))) then 74 | local code = a.slurp(src) 75 | do 76 | local _4_0, _5_0 = str(code, {filename = src}) 77 | if ((_4_0 == false) and (nil ~= _5_0)) then 78 | local err = _5_0 79 | return nvim.err_writeln(err) 80 | elseif ((_4_0 == true) and (nil ~= _5_0)) then 81 | local result = _5_0 82 | do 83 | fs.mkdirp(fs.basename(dest)) 84 | return a.spit(dest, result) 85 | end 86 | end 87 | end 88 | end 89 | end 90 | v_23_0_0 = file0 91 | _0_0["file"] = v_23_0_0 92 | v_23_0_ = v_23_0_0 93 | end 94 | _0_0["aniseed/locals"]["file"] = v_23_0_ 95 | file = v_23_0_ 96 | end 97 | local glob = nil 98 | do 99 | local v_23_0_ = nil 100 | do 101 | local v_23_0_0 = nil 102 | local function glob0(src_expr, src_dir, dest_dir, opts) 103 | local src_dir_len = a.inc(string.len(src_dir)) 104 | local src_paths = nil 105 | local function _4_(path) 106 | return string.sub(path, src_dir_len) 107 | end 108 | src_paths = a.map(_4_, nvim.fn.globpath(src_dir, src_expr, true, true)) 109 | for _, path in ipairs(src_paths) do 110 | file((src_dir .. path), string.gsub((dest_dir .. path), ".fnl$", ".lua"), opts) 111 | end 112 | return nil 113 | end 114 | v_23_0_0 = glob0 115 | _0_0["glob"] = v_23_0_0 116 | v_23_0_ = v_23_0_0 117 | end 118 | _0_0["aniseed/locals"]["glob"] = v_23_0_ 119 | glob = v_23_0_ 120 | end 121 | return nil 122 | -------------------------------------------------------------------------------- /fnl/conjure/eval.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.eval 2 | {require {a conjure.aniseed.core 3 | nvim conjure.aniseed.nvim 4 | extract conjure.extract 5 | lang conjure.lang 6 | text conjure.text 7 | config conjure.config 8 | editor conjure.editor 9 | log conjure.log}}) 10 | 11 | ;; TODO Completion. 12 | ;; TODO Languages: Janet, Racket, MIT Scheme. 13 | 14 | (defn- preview [opts] 15 | (let [sample-limit (editor.percent-width 16 | config.preview.sample-limit)] 17 | (.. (lang.get :comment-prefix) 18 | opts.action " (" opts.origin "): " 19 | (if (or (= :file opts.origin) (= :buf opts.origin)) 20 | (text.right-sample opts.file-path sample-limit) 21 | (text.left-sample opts.code sample-limit))))) 22 | 23 | (defn- display-request [opts] 24 | (log.append [opts.preview] {:break? true})) 25 | 26 | (defn file [] 27 | (let [opts {:file-path (extract.file-path) 28 | :origin :file 29 | :action :eval}] 30 | (set opts.preview (preview opts)) 31 | (display-request opts) 32 | (lang.call :eval-file opts))) 33 | 34 | (defn- lang-exec-fn [action f-name] 35 | (fn [opts] 36 | (set opts.action action) 37 | (set opts.context 38 | (or nvim.b.conjure_context 39 | (extract.context))) 40 | (set opts.file-path (extract.file-path)) 41 | (set opts.preview (preview opts)) 42 | (display-request opts) 43 | (lang.call f-name opts))) 44 | 45 | (def- eval-str (lang-exec-fn :eval :eval-str)) 46 | (def- doc-str (lang-exec-fn :doc :doc-str)) 47 | (def- def-str (lang-exec-fn :def :def-str)) 48 | 49 | (defn current-form [extra-opts] 50 | (let [form (extract.form {})] 51 | (when form 52 | (let [{: content : range} form] 53 | (eval-str 54 | (a.merge 55 | {:code content 56 | :range range 57 | :origin :current-form} 58 | extra-opts)))))) 59 | 60 | (defn root-form [] 61 | (let [form (extract.form {:root? true})] 62 | (when form 63 | (let [{: content : range} form] 64 | (eval-str 65 | {:code content 66 | :range range 67 | :origin :root-form}))))) 68 | 69 | (defn marked-form [] 70 | (let [mark (extract.prompt-char) 71 | comment-prefix (lang.get :comment-prefix) 72 | (ok? err) (pcall #(editor.go-to-mark mark))] 73 | (if ok? 74 | (do 75 | (current-form {:origin (.. "marked-form [" mark "]")}) 76 | (editor.go-back)) 77 | (log.append [(.. comment-prefix "Couldn't eval form at mark: " mark) 78 | (.. comment-prefix err)] 79 | {:break? true})))) 80 | 81 | (defn word [] 82 | (let [{: content : range} (extract.word)] 83 | (when (not (a.empty? content)) 84 | (eval-str 85 | {:code content 86 | :range range 87 | :origin :word})))) 88 | 89 | (+ 10 20 30) 90 | 91 | (defn doc-word [] 92 | (let [{: content : range} (extract.word)] 93 | (when (not (a.empty? content)) 94 | (doc-str 95 | {:code content 96 | :range range 97 | :origin :word})))) 98 | 99 | (defn def-word [] 100 | (let [{: content : range} (extract.word)] 101 | (when (not (a.empty? content)) 102 | (def-str 103 | {:code content 104 | :range range 105 | :origin :word})))) 106 | 107 | (defn buf [] 108 | (let [{: content : range} (extract.buf)] 109 | (eval-str 110 | {:code content 111 | :range range 112 | :origin :buf}))) 113 | 114 | (defn command [code] 115 | (eval-str 116 | {:code code 117 | :origin :command})) 118 | 119 | (defn range [start end] 120 | (let [{: content : range} (extract.range start end)] 121 | (eval-str 122 | {:code content 123 | :range range 124 | :origin :range}))) 125 | 126 | (defn selection [kind] 127 | (let [{: content : range} 128 | (extract.selection 129 | {:kind (or kind (nvim.fn.visualmode)) 130 | :visual? (not kind)})] 131 | (eval-str 132 | {:code content 133 | :range range 134 | :origin :selection}))) 135 | -------------------------------------------------------------------------------- /fnl/conjure/extract.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.extract 2 | {require {a conjure.aniseed.core 3 | nvim conjure.aniseed.nvim 4 | nu conjure.aniseed.nvim.util 5 | str conjure.aniseed.string 6 | config conjure.config 7 | lang conjure.lang}}) 8 | 9 | (defn- read-range [[srow scol] [erow ecol]] 10 | (let [lines (nvim.buf_get_lines 11 | 0 (- srow 1) erow false)] 12 | (-> lines 13 | (a.update 14 | (length lines) 15 | (fn [s] 16 | (string.sub s 0 ecol))) 17 | (a.update 18 | 1 19 | (fn [s] 20 | (string.sub s scol))) 21 | (->> (str.join "\n"))))) 22 | 23 | (defn- current-char [] 24 | (let [[row col] (nvim.win_get_cursor 0) 25 | [line] (nvim.buf_get_lines 0 (- row 1) row false) 26 | char (+ col 1)] 27 | (string.sub line char char))) 28 | 29 | (defn- nil-pos? [pos] 30 | (or (not pos) 31 | (= 0 (unpack pos)))) 32 | 33 | (defn skip-match? [] 34 | (let [[row col] (nvim.win_get_cursor 0) 35 | stack (nvim.fn.synstack row (a.inc col)) 36 | stack-size (length stack)] 37 | (if (= :number 38 | (type 39 | (and (> stack-size 0) 40 | (let [name (nvim.fn.synIDattr (. stack stack-size) :name)] 41 | (or (name:find "Comment$") 42 | (name:find "String$") 43 | (name:find "Regexp$")))))) 44 | 1 45 | 0))) 46 | 47 | (defn form [{: root?}] 48 | (let [;; 'W' don't Wrap around the end of the file 49 | ;; 'n' do Not move the cursor 50 | ;; 'z' start searching at the cursor column instead of Zero 51 | ;; 'b' search Backward instead of forward 52 | ;; 'c' accept a match at the Cursor position 53 | ;; 'r' repeat until no more matches found; will find the outer pair 54 | flags (.. "Wnz" (if root? "r" "")) 55 | cursor-char (current-char) 56 | 57 | skip-match?-viml "luaeval(\"require('conjure.extract')['skip-match?']()\")" 58 | 59 | start (nvim.fn.searchpairpos 60 | "(" "" ")" 61 | (.. flags "b" (if (= cursor-char "(") "c" "")) 62 | skip-match?-viml) 63 | end (nvim.fn.searchpairpos 64 | "(" "" ")" 65 | (.. flags (if (= cursor-char ")") "c" "")) 66 | skip-match?-viml)] 67 | 68 | (when (and (not (nil-pos? start)) 69 | (not (nil-pos? end))) 70 | {:range {:start (a.update start 2 a.dec) 71 | :end (a.update end 2 a.dec)} 72 | :content (read-range start end)}))) 73 | 74 | (defn word [] 75 | {:content (nvim.fn.expand "") 76 | 77 | ;; This is wrong but that's okay. I hope. 78 | :range {:start (nvim.win_get_cursor 0) 79 | :end (nvim.win_get_cursor 0)}}) 80 | 81 | (defn file-path [] 82 | (nvim.fn.expand "%:p")) 83 | 84 | (defn- buf-last-line-length [buf] 85 | (a.count (a.first (nvim.buf_get_lines buf (a.dec (nvim.buf_line_count buf)) -1 false)))) 86 | 87 | (defn range [start end] 88 | {:content (str.join "\n" (nvim.buf_get_lines 0 start end false)) 89 | :range {:start [(a.inc start) 0] 90 | :end [end (buf-last-line-length 0)]}}) 91 | 92 | (defn buf [] 93 | (range 0 -1)) 94 | 95 | (defn- getpos [expr] 96 | (let [[_ start end _] (nvim.fn.getpos expr)] 97 | [start (a.dec end)])) 98 | 99 | (defn selection [{:kind kind :visual? visual?}] 100 | (let [sel-backup nvim.o.selection] 101 | (nvim.ex.let "g:conjure_selection_reg_backup = @@") 102 | (set nvim.o.selection :inclusive) 103 | 104 | (if 105 | visual? (nu.normal (.. "`<" kind "`>y")) 106 | (= kind :line) (nu.normal "'[V']y") 107 | (= kind :block) (nu.normal "`[`]y") 108 | (nu.normal "`[v`]y")) 109 | 110 | (let [content (nvim.eval "@@")] 111 | (set nvim.o.selection sel-backup) 112 | (nvim.ex.let "@@ = g:conjure_selection_reg_backup") 113 | {:content content 114 | :range {:start (getpos "'<") 115 | :end (getpos "'>")}}))) 116 | 117 | (defn context [] 118 | (let [header (->> (nvim.buf_get_lines 119 | 0 0 config.extract.context-header-lines false) 120 | (str.join "\n"))] 121 | (string.match header (lang.get :context-pattern)))) 122 | 123 | (defn prompt [prefix] 124 | (nvim.fn.input (or prefix ""))) 125 | 126 | (defn prompt-char [] 127 | (nvim.fn.nr2char (nvim.fn.getchar))) 128 | -------------------------------------------------------------------------------- /lua/conjure/editor.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.editor" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.core"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local nvim = _2_[2] 24 | do local _ = ({nil, _0_0, nil})[2] end 25 | local percent_fn = nil 26 | do 27 | local v_23_0_ = nil 28 | local function percent_fn0(total_fn) 29 | local function _3_(pc) 30 | return math.floor(((total_fn() / 100) * (pc * 100))) 31 | end 32 | return _3_ 33 | end 34 | v_23_0_ = percent_fn0 35 | _0_0["aniseed/locals"]["percent-fn"] = v_23_0_ 36 | percent_fn = v_23_0_ 37 | end 38 | local width = nil 39 | do 40 | local v_23_0_ = nil 41 | do 42 | local v_23_0_0 = nil 43 | local function width0() 44 | return nvim.o.columns 45 | end 46 | v_23_0_0 = width0 47 | _0_0["width"] = v_23_0_0 48 | v_23_0_ = v_23_0_0 49 | end 50 | _0_0["aniseed/locals"]["width"] = v_23_0_ 51 | width = v_23_0_ 52 | end 53 | local height = nil 54 | do 55 | local v_23_0_ = nil 56 | do 57 | local v_23_0_0 = nil 58 | local function height0() 59 | return nvim.o.lines 60 | end 61 | v_23_0_0 = height0 62 | _0_0["height"] = v_23_0_0 63 | v_23_0_ = v_23_0_0 64 | end 65 | _0_0["aniseed/locals"]["height"] = v_23_0_ 66 | height = v_23_0_ 67 | end 68 | local percent_width = nil 69 | do 70 | local v_23_0_ = nil 71 | do 72 | local v_23_0_0 = percent_fn(width) 73 | _0_0["percent-width"] = v_23_0_0 74 | v_23_0_ = v_23_0_0 75 | end 76 | _0_0["aniseed/locals"]["percent-width"] = v_23_0_ 77 | percent_width = v_23_0_ 78 | end 79 | local percent_height = nil 80 | do 81 | local v_23_0_ = nil 82 | do 83 | local v_23_0_0 = percent_fn(height) 84 | _0_0["percent-height"] = v_23_0_0 85 | v_23_0_ = v_23_0_0 86 | end 87 | _0_0["aniseed/locals"]["percent-height"] = v_23_0_ 88 | percent_height = v_23_0_ 89 | end 90 | local cursor_left = nil 91 | do 92 | local v_23_0_ = nil 93 | do 94 | local v_23_0_0 = nil 95 | local function cursor_left0() 96 | return nvim.fn.screencol() 97 | end 98 | v_23_0_0 = cursor_left0 99 | _0_0["cursor-left"] = v_23_0_0 100 | v_23_0_ = v_23_0_0 101 | end 102 | _0_0["aniseed/locals"]["cursor-left"] = v_23_0_ 103 | cursor_left = v_23_0_ 104 | end 105 | local cursor_top = nil 106 | do 107 | local v_23_0_ = nil 108 | do 109 | local v_23_0_0 = nil 110 | local function cursor_top0() 111 | return nvim.fn.screenrow() 112 | end 113 | v_23_0_0 = cursor_top0 114 | _0_0["cursor-top"] = v_23_0_0 115 | v_23_0_ = v_23_0_0 116 | end 117 | _0_0["aniseed/locals"]["cursor-top"] = v_23_0_ 118 | cursor_top = v_23_0_ 119 | end 120 | local go_to = nil 121 | do 122 | local v_23_0_ = nil 123 | do 124 | local v_23_0_0 = nil 125 | local function go_to0(path, line, column) 126 | nvim.ex.edit(path) 127 | return nvim.win_set_cursor(0, {line, a.dec(column)}) 128 | end 129 | v_23_0_0 = go_to0 130 | _0_0["go-to"] = v_23_0_0 131 | v_23_0_ = v_23_0_0 132 | end 133 | _0_0["aniseed/locals"]["go-to"] = v_23_0_ 134 | go_to = v_23_0_ 135 | end 136 | local go_to_mark = nil 137 | do 138 | local v_23_0_ = nil 139 | do 140 | local v_23_0_0 = nil 141 | local function go_to_mark0(m) 142 | return nvim.ex.normal_(("`" .. m)) 143 | end 144 | v_23_0_0 = go_to_mark0 145 | _0_0["go-to-mark"] = v_23_0_0 146 | v_23_0_ = v_23_0_0 147 | end 148 | _0_0["aniseed/locals"]["go-to-mark"] = v_23_0_ 149 | go_to_mark = v_23_0_ 150 | end 151 | local go_back = nil 152 | do 153 | local v_23_0_ = nil 154 | do 155 | local v_23_0_0 = nil 156 | local function go_back0() 157 | return nvim.ex.normal_(nvim.replace_termcodes("", true, false, true)) 158 | end 159 | v_23_0_0 = go_back0 160 | _0_0["go-back"] = v_23_0_0 161 | v_23_0_ = v_23_0_0 162 | end 163 | _0_0["aniseed/locals"]["go-back"] = v_23_0_ 164 | go_back = v_23_0_ 165 | end 166 | return nil -------------------------------------------------------------------------------- /lua/conjure/linked-list.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.linked-list" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core"}} 19 | return {require("conjure.aniseed.core")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local create = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = nil 29 | local function create0(xs, prev) 30 | if not a["empty?"](xs) then 31 | local rest = a.rest(xs) 32 | local node = {} 33 | a.assoc(node, "val", a.first(xs)) 34 | a.assoc(node, "prev", prev) 35 | return a.assoc(node, "next", create0(rest, node)) 36 | end 37 | end 38 | v_23_0_0 = create0 39 | _0_0["create"] = v_23_0_0 40 | v_23_0_ = v_23_0_0 41 | end 42 | _0_0["aniseed/locals"]["create"] = v_23_0_ 43 | create = v_23_0_ 44 | end 45 | local val = nil 46 | do 47 | local v_23_0_ = nil 48 | do 49 | local v_23_0_0 = nil 50 | local function val0(l) 51 | local _3_0 = l 52 | if _3_0 then 53 | return a.get(_3_0, "val") 54 | else 55 | return _3_0 56 | end 57 | end 58 | v_23_0_0 = val0 59 | _0_0["val"] = v_23_0_0 60 | v_23_0_ = v_23_0_0 61 | end 62 | _0_0["aniseed/locals"]["val"] = v_23_0_ 63 | val = v_23_0_ 64 | end 65 | local next = nil 66 | do 67 | local v_23_0_ = nil 68 | do 69 | local v_23_0_0 = nil 70 | local function next0(l) 71 | local _3_0 = l 72 | if _3_0 then 73 | return a.get(_3_0, "next") 74 | else 75 | return _3_0 76 | end 77 | end 78 | v_23_0_0 = next0 79 | _0_0["next"] = v_23_0_0 80 | v_23_0_ = v_23_0_0 81 | end 82 | _0_0["aniseed/locals"]["next"] = v_23_0_ 83 | next = v_23_0_ 84 | end 85 | local prev = nil 86 | do 87 | local v_23_0_ = nil 88 | do 89 | local v_23_0_0 = nil 90 | local function prev0(l) 91 | local _3_0 = l 92 | if _3_0 then 93 | return a.get(_3_0, "prev") 94 | else 95 | return _3_0 96 | end 97 | end 98 | v_23_0_0 = prev0 99 | _0_0["prev"] = v_23_0_0 100 | v_23_0_ = v_23_0_0 101 | end 102 | _0_0["aniseed/locals"]["prev"] = v_23_0_ 103 | prev = v_23_0_ 104 | end 105 | local first = nil 106 | do 107 | local v_23_0_ = nil 108 | do 109 | local v_23_0_0 = nil 110 | local function first0(l) 111 | local c = l 112 | while prev(c) do 113 | c = prev(c) 114 | end 115 | return c 116 | end 117 | v_23_0_0 = first0 118 | _0_0["first"] = v_23_0_0 119 | v_23_0_ = v_23_0_0 120 | end 121 | _0_0["aniseed/locals"]["first"] = v_23_0_ 122 | first = v_23_0_ 123 | end 124 | local last = nil 125 | do 126 | local v_23_0_ = nil 127 | do 128 | local v_23_0_0 = nil 129 | local function last0(l) 130 | local c = l 131 | while next(c) do 132 | c = next(c) 133 | end 134 | return c 135 | end 136 | v_23_0_0 = last0 137 | _0_0["last"] = v_23_0_0 138 | v_23_0_ = v_23_0_0 139 | end 140 | _0_0["aniseed/locals"]["last"] = v_23_0_ 141 | last = v_23_0_ 142 | end 143 | local _until = nil 144 | do 145 | local v_23_0_ = nil 146 | do 147 | local v_23_0_0 = nil 148 | local function _until0(f, l) 149 | local c = l 150 | local r = false 151 | local function step() 152 | r = f(c) 153 | return r 154 | end 155 | while (c and not step()) do 156 | c = next(c) 157 | end 158 | if r then 159 | return c 160 | end 161 | end 162 | v_23_0_0 = _until0 163 | _0_0["until"] = v_23_0_0 164 | v_23_0_ = v_23_0_0 165 | end 166 | _0_0["aniseed/locals"]["until"] = v_23_0_ 167 | _until = v_23_0_ 168 | end 169 | local cycle = nil 170 | do 171 | local v_23_0_ = nil 172 | do 173 | local v_23_0_0 = nil 174 | local function cycle0(l) 175 | local start = first(l) 176 | local _end = last(l) 177 | a.assoc(start, "prev", _end) 178 | a.assoc(_end, "next", start) 179 | return l 180 | end 181 | v_23_0_0 = cycle0 182 | _0_0["cycle"] = v_23_0_0 183 | v_23_0_ = v_23_0_0 184 | end 185 | _0_0["aniseed/locals"]["cycle"] = v_23_0_ 186 | cycle = v_23_0_ 187 | end 188 | return nil -------------------------------------------------------------------------------- /lua/conjure/bencode.lua: -------------------------------------------------------------------------------- 1 | -- public domain lua-module for handling bittorrent-bencoded data. 2 | -- This module includes both a recursive decoder and a recursive encoder. 3 | 4 | local sort, concat, insert = table.sort, table.concat, table.insert 5 | local pairs, ipairs, type, tonumber = pairs, ipairs, type, tonumber 6 | local sub, find = string.sub, string.find 7 | 8 | local bencode = {} 9 | 10 | -- helpers 11 | 12 | local function islist(t) 13 | local n = #t 14 | for k, v in pairs(t) do 15 | if type(k) ~= "number" 16 | or k % 1 ~= 0 -- integer? 17 | or k < 1 18 | or k > n 19 | then 20 | return false 21 | end 22 | end 23 | for i = 1, n do 24 | if t[i] == nil then 25 | return false 26 | end 27 | end 28 | return true 29 | end 30 | 31 | -- encoder functions 32 | 33 | local encode_rec -- encode_list/dict and encode_rec are mutually recursive... 34 | 35 | local function encode_list(t, x) 36 | 37 | insert(t, "l") 38 | 39 | for _,v in ipairs(x) do 40 | local err,ev = encode_rec(t, v); if err then return err,ev end 41 | end 42 | 43 | insert(t, "e") 44 | end 45 | 46 | local function encode_dict(t, x) 47 | insert(t, "d") 48 | -- bittorrent requires the keys to be sorted. 49 | local sortedkeys = {} 50 | for k, v in pairs(x) do 51 | if type(k) ~= "string" then 52 | return "bencoding requires dictionary keys to be strings", k 53 | end 54 | insert(sortedkeys, k) 55 | end 56 | sort(sortedkeys) 57 | 58 | for k, v in ipairs(sortedkeys) do 59 | local err,ev = encode_rec(t, v); if err then return err,ev end 60 | err,ev = encode_rec(t, x[v]); if err then return err,ev end 61 | end 62 | insert(t, "e") 63 | end 64 | 65 | local function encode_int(t, x) 66 | 67 | if x % 1 ~= 0 then return "number is not an integer", x end 68 | insert(t, "i" ) 69 | insert(t, x ) 70 | insert(t, "e" ) 71 | end 72 | 73 | local function encode_str(t, x) 74 | 75 | insert(t, #x ) 76 | insert(t, ":" ) 77 | insert(t, x ) 78 | end 79 | 80 | encode_rec = function(t, x) 81 | 82 | local typx = type(x) 83 | if typx == "string" then return encode_str (t, x) 84 | elseif typx == "number" then return encode_int (t, x) 85 | elseif typx == "table" then 86 | 87 | if islist(x) then return encode_list (t, x) 88 | else return encode_dict (t, x) 89 | end 90 | else 91 | return "type cannot be converted to an acceptable type for bencoding", typx 92 | end 93 | end 94 | 95 | -- call recursive bencoder function with empty table, stringify that table. 96 | -- this is the only encode* function visible to module users. 97 | function bencode.encode(x) 98 | 99 | local t = {} 100 | local err, val = encode_rec(t,x) 101 | if not err then 102 | return concat(t) 103 | else 104 | return nil, err, val 105 | end 106 | end 107 | 108 | -- decoder functions 109 | 110 | local function decode_integer(s, index) 111 | local a, b, int = find(s, "^(%-?%d+)e", index) 112 | if not int then return nil, "not a number", nil end 113 | int = tonumber(int) 114 | if not int then return nil, "not a number", int end 115 | return int, b + 1 116 | end 117 | 118 | local function decode_list(s, index) 119 | local t = {} 120 | while sub(s, index, index) ~= "e" do 121 | local obj, ev 122 | obj, index, ev = bencode.decode(s, index) 123 | if not obj then return obj, index, ev end 124 | insert(t, obj) 125 | end 126 | index = index + 1 127 | return t, index 128 | end 129 | 130 | local function decode_dictionary(s, index) 131 | local t = {} 132 | while sub(s, index, index) ~= "e" do 133 | local obj1, obj2, ev 134 | 135 | obj1, index, ev = bencode.decode(s, index) 136 | if not obj1 then return obj1, index, ev end 137 | 138 | obj2, index, ev = bencode.decode(s, index) 139 | if not obj2 then return obj2, index, ev end 140 | 141 | t[obj1] = obj2 142 | end 143 | index = index + 1 144 | return t, index 145 | end 146 | 147 | local function decode_string(s, index) 148 | local a, b, len = find(s, "^([0-9]+):", index) 149 | if not len then return nil, "not a length", len end 150 | index = b + 1 151 | 152 | local v = sub(s, index, index + len - 1) 153 | if #v < len - 1 then return nil, "truncated string at end of input", v end 154 | index = index + len 155 | return v, index 156 | end 157 | 158 | 159 | function bencode.decode(s, index) 160 | if not s then return nil, "no data", nil end 161 | index = index or 1 162 | local t = sub(s, index, index) 163 | if not t then return nil, "truncation error", nil end 164 | 165 | if t == "i" then 166 | return decode_integer(s, index + 1) 167 | elseif t == "l" then 168 | return decode_list(s, index + 1) 169 | elseif t == "d" then 170 | return decode_dictionary(s, index + 1) 171 | elseif t >= '0' and t <= '9' then 172 | return decode_string(s, index) 173 | else 174 | return nil, "invalid type", t 175 | end 176 | end 177 | 178 | return bencode 179 | -------------------------------------------------------------------------------- /fnl/conjure/log.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.log 2 | {require {a conjure.aniseed.core 3 | nvim conjure.aniseed.nvim 4 | buffer conjure.buffer 5 | lang conjure.lang 6 | config conjure.config 7 | editor conjure.editor}}) 8 | 9 | (defonce- state 10 | {:hud {:id nil}}) 11 | 12 | (defn- break [] 13 | (.. (lang.get :comment-prefix) 14 | (string.rep "-" (editor.percent-width config.log.break-length)))) 15 | 16 | (defn- log-buf-name [] 17 | (.. "conjure-log-" (nvim.fn.getpid) (lang.get :buf-suffix))) 18 | 19 | (defn- upsert-buf [] 20 | (buffer.upsert-hidden (log-buf-name))) 21 | 22 | (defn close-hud [] 23 | (when state.hud.id 24 | (pcall (fn [] (nvim.win_close state.hud.id true))) 25 | (set state.hud.id nil))) 26 | 27 | (defn- break-lines [buf] 28 | (let [break-str (break)] 29 | (->> (nvim.buf_get_lines buf 0 -1 false) 30 | (a.kv-pairs) 31 | (a.filter 32 | (fn [[n s]] 33 | (= s break-str))) 34 | (a.map a.first)))) 35 | 36 | (defn- display-hud [] 37 | (when config.log.hud.enabled? 38 | (let [buf (upsert-buf) 39 | cursor-top-right? (and (> (editor.cursor-left) (editor.percent-width 0.5)) 40 | (< (editor.cursor-top) (editor.percent-height 0.5))) 41 | last-break (a.last (break-lines buf)) 42 | line-count (nvim.buf_line_count buf) 43 | win-opts 44 | {:relative :editor 45 | :row (if cursor-top-right? 46 | (- (editor.height) 2) 47 | 0) 48 | :col (editor.width) 49 | :anchor :SE 50 | 51 | :width (editor.percent-width config.log.hud.width) 52 | :height (editor.percent-height config.log.hud.height) 53 | :focusable false 54 | :style :minimal}] 55 | 56 | (when (not state.hud.id) 57 | (set state.hud.id (nvim.open_win buf false win-opts)) 58 | (nvim.win_set_option state.hud.id :wrap false)) 59 | 60 | (if last-break 61 | (do 62 | (nvim.win_set_cursor state.hud.id [1 0]) 63 | (nvim.win_set_cursor 64 | state.hud.id 65 | [(math.min 66 | (+ last-break 67 | (a.inc (math.floor (/ win-opts.height 2)))) 68 | line-count) 69 | 0])) 70 | (nvim.win_set_cursor state.hud.id [line-count 0]))))) 71 | 72 | (defn- win-visible? [win] 73 | (= (nvim.fn.tabpagenr) 74 | (a.first (nvim.fn.win_id2tabwin win)))) 75 | 76 | (defn- with-buf-wins [buf f] 77 | (a.run! 78 | (fn [win] 79 | (when (= buf (nvim.win_get_buf win)) 80 | (f win))) 81 | (nvim.list_wins))) 82 | 83 | (defn- trim [buf] 84 | (let [line-count (nvim.buf_line_count buf)] 85 | (when (> line-count config.log.trim.at) 86 | (let [target-line-count (- line-count config.log.trim.to) 87 | last-break-line 88 | (->> (break-lines buf) 89 | (a.filter #(<= $1 target-line-count)) 90 | (a.last))] 91 | (nvim.buf_set_lines 92 | buf 0 93 | (or last-break-line target-line-count) 94 | false []) 95 | 96 | ;; This hack keeps all log window view ports correct after trim. 97 | ;; Without it the text moves off screen in the HUD. 98 | (let [line-count (nvim.buf_line_count buf)] 99 | (with-buf-wins 100 | buf 101 | (fn [win] 102 | (let [[row col] (nvim.win_get_cursor win)] 103 | (nvim.win_set_cursor win [1 0]) 104 | (nvim.win_set_cursor win [row col]))))))))) 105 | 106 | (defn append [lines opts] 107 | (when (not (a.empty? lines)) 108 | (var visible-scrolling-log? false) 109 | 110 | (let [buf (upsert-buf) 111 | lines (if (a.get opts :break?) 112 | (a.concat [(break)] lines) 113 | lines) 114 | old-lines (nvim.buf_line_count buf)] 115 | 116 | (nvim.buf_set_lines 117 | buf 118 | (if (buffer.empty? buf) 0 -1) 119 | -1 false lines) 120 | 121 | (let [new-lines (nvim.buf_line_count buf)] 122 | (with-buf-wins 123 | buf 124 | (fn [win] 125 | (let [[row col] (nvim.win_get_cursor win)] 126 | (when (= old-lines row) 127 | (when (and (not= win state.hud.id) (win-visible? win)) 128 | (set visible-scrolling-log? true)) 129 | (nvim.win_set_cursor win [new-lines 0])))))) 130 | 131 | (when (not visible-scrolling-log?) 132 | (display-hud)) 133 | 134 | (trim buf)))) 135 | 136 | (defn- create-win [split-fn] 137 | (let [buf (upsert-buf) 138 | win (split-fn (log-buf-name))] 139 | (nvim.win_set_cursor 140 | win 141 | [(nvim.buf_line_count buf) 0]) 142 | (nvim.win_set_option win :wrap false) 143 | (buffer.unlist buf))) 144 | 145 | (defn split [] 146 | (create-win nvim.ex.split)) 147 | 148 | (defn vsplit [] 149 | (create-win nvim.ex.vsplit)) 150 | 151 | (defn tab [] 152 | (create-win nvim.ex.tabnew)) 153 | -------------------------------------------------------------------------------- /lua/conjure/mapping.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.mapping" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", bridge = "conjure.bridge", config = "conjure.config", eval = "conjure.eval", extract = "conjure.extract", lang = "conjure.lang", nvim = "conjure.aniseed.nvim", str = "conjure.aniseed.string"}} 19 | return {require("conjure.aniseed.core"), require("conjure.bridge"), require("conjure.config"), require("conjure.eval"), require("conjure.extract"), require("conjure.lang"), require("conjure.aniseed.nvim"), require("conjure.aniseed.string")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local bridge = _2_[2] 24 | local config = _2_[3] 25 | local eval = _2_[4] 26 | local extract = _2_[5] 27 | local lang = _2_[6] 28 | local nvim = _2_[7] 29 | local str = _2_[8] 30 | do local _ = ({nil, _0_0, nil})[2] end 31 | local buf = nil 32 | do 33 | local v_23_0_ = nil 34 | do 35 | local v_23_0_0 = nil 36 | local function buf0(mode, keys, ...) 37 | local args = {...} 38 | local _3_ 39 | if a["string?"](keys) then 40 | _3_ = (config.mappings.prefix .. keys) 41 | else 42 | _3_ = a.first(keys) 43 | end 44 | local _5_ 45 | if (2 == a.count(args)) then 46 | _5_ = (":" .. bridge["viml->lua"](unpack(args)) .. "") 47 | else 48 | _5_ = unpack(args) 49 | end 50 | return nvim.buf_set_keymap(0, mode, _3_, _5_, {noremap = true, silent = true}) 51 | end 52 | v_23_0_0 = buf0 53 | _0_0["buf"] = v_23_0_0 54 | v_23_0_ = v_23_0_0 55 | end 56 | _0_0["aniseed/locals"]["buf"] = v_23_0_ 57 | buf = v_23_0_ 58 | end 59 | local on_filetype = nil 60 | do 61 | local v_23_0_ = nil 62 | do 63 | local v_23_0_0 = nil 64 | local function on_filetype0() 65 | buf("n", config.mappings["eval-motion"], ":set opfunc=ConjureEvalMotiong@") 66 | buf("n", config.mappings["log-split"], "conjure.log", "split") 67 | buf("n", config.mappings["log-vsplit"], "conjure.log", "vsplit") 68 | buf("n", config.mappings["log-tab"], "conjure.log", "tab") 69 | buf("n", config.mappings["eval-current-form"], "conjure.eval", "current-form") 70 | buf("n", config.mappings["eval-root-form"], "conjure.eval", "root-form") 71 | buf("n", config.mappings["eval-marked-form"], "conjure.eval", "marked-form") 72 | buf("n", config.mappings["eval-word"], "conjure.eval", "word") 73 | buf("n", config.mappings["eval-file"], "conjure.eval", "file") 74 | buf("n", config.mappings["eval-buf"], "conjure.eval", "buf") 75 | buf("v", config.mappings["eval-visual"], "conjure.eval", "selection") 76 | buf("n", config.mappings["close-hud"], "conjure.log", "close-hud") 77 | buf("n", config.mappings["doc-word"], "conjure.eval", "doc-word") 78 | buf("n", config.mappings["def-word"], "conjure.eval", "def-word") 79 | nvim.ex.autocmd("CursorMoved", "", bridge["viml->lua"]("conjure.log", "close-hud", {})) 80 | nvim.ex.autocmd("CursorMovedI", "", bridge["viml->lua"]("conjure.log", "close-hud", {})) 81 | return lang.call("on-filetype") 82 | end 83 | v_23_0_0 = on_filetype0 84 | _0_0["on-filetype"] = v_23_0_0 85 | v_23_0_ = v_23_0_0 86 | end 87 | _0_0["aniseed/locals"]["on-filetype"] = v_23_0_ 88 | on_filetype = v_23_0_ 89 | end 90 | local setup_filetypes = nil 91 | do 92 | local v_23_0_ = nil 93 | do 94 | local v_23_0_0 = nil 95 | local function setup_filetypes0(filetypes) 96 | nvim.ex.augroup("conjure_init_filetypes") 97 | nvim.ex.autocmd_() 98 | nvim.ex.autocmd("FileType", str.join(",", filetypes), bridge["viml->lua"]("conjure.mapping", "on-filetype", {})) 99 | return nvim.ex.augroup("END") 100 | end 101 | v_23_0_0 = setup_filetypes0 102 | _0_0["setup-filetypes"] = v_23_0_0 103 | v_23_0_ = v_23_0_0 104 | end 105 | _0_0["aniseed/locals"]["setup-filetypes"] = v_23_0_ 106 | setup_filetypes = v_23_0_ 107 | end 108 | local eval_ranged_command = nil 109 | do 110 | local v_23_0_ = nil 111 | do 112 | local v_23_0_0 = nil 113 | local function eval_ranged_command0(start, _end, code) 114 | if ("" == code) then 115 | return eval.range(a.dec(start), _end) 116 | else 117 | return eval.command(code) 118 | end 119 | end 120 | v_23_0_0 = eval_ranged_command0 121 | _0_0["eval-ranged-command"] = v_23_0_0 122 | v_23_0_ = v_23_0_0 123 | end 124 | _0_0["aniseed/locals"]["eval-ranged-command"] = v_23_0_ 125 | eval_ranged_command = v_23_0_ 126 | end 127 | nvim.ex.function_(str.join("\n", {"ConjureEvalMotion(kind)", "call luaeval(\"require('conjure.eval')['selection'](_A)\", a:kind)", "endfunction"})) 128 | return nvim.ex.command_("-nargs=? -range ConjureEval", bridge["viml->lua"]("conjure.mapping", "eval-ranged-command", {args = ", , "})) -------------------------------------------------------------------------------- /lua/conjure/aniseed/deps/fennelview.lua: -------------------------------------------------------------------------------- 1 | local function view_quote(str) 2 | return ("\"" .. str:gsub("\"", "\\\"") .. "\"") 3 | end 4 | local short_control_char_escapes = {["\11"] = "\\v", ["\12"] = "\\f", ["\13"] = "\\r", ["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "\\n"} 5 | local long_control_char_escapes = nil 6 | do 7 | local long = {} 8 | for i = 0, 31 do 9 | local ch = string.char(i) 10 | if not short_control_char_escapes[ch] then 11 | short_control_char_escapes[ch] = ("\\" .. i) 12 | long[ch] = ("\\%03d"):format(i) 13 | end 14 | end 15 | long_control_char_escapes = long 16 | end 17 | local function escape(str) 18 | local str0 = str:gsub("\\", "\\\\") 19 | local str1 = str0:gsub("(%c)%f[0-9]", long_control_char_escapes) 20 | return str1:gsub("%c", short_control_char_escapes) 21 | end 22 | local function sequence_key_3f(k, len) 23 | return ((type(k) == "number") and (1 <= k) and (k <= len) and (math.floor(k) == k)) 24 | end 25 | local type_order = {["function"] = 5, boolean = 2, number = 1, string = 3, table = 4, thread = 7, userdata = 6} 26 | local function sort_keys(a, b) 27 | local ta = type(a) 28 | local tb = type(b) 29 | if ((ta == tb) and (ta ~= "boolean") and ((ta == "string") or (ta == "number"))) then 30 | return (a < b) 31 | else 32 | local dta = type_order[a] 33 | local dtb = type_order[b] 34 | if (dta and dtb) then 35 | return (dta < dtb) 36 | elseif dta then 37 | return true 38 | elseif dtb then 39 | return false 40 | elseif "else" then 41 | return (ta < tb) 42 | end 43 | end 44 | end 45 | local function get_sequence_length(t) 46 | local len = 1 47 | for i in ipairs(t) do 48 | len = i 49 | end 50 | return len 51 | end 52 | local function get_nonsequential_keys(t) 53 | local keys = {} 54 | local sequence_length = get_sequence_length(t) 55 | for k in pairs(t) do 56 | if not sequence_key_3f(k, sequence_length) then 57 | table.insert(keys, k) 58 | end 59 | end 60 | table.sort(keys, sort_keys) 61 | return keys, sequence_length 62 | end 63 | local function count_table_appearances(t, appearances) 64 | if (type(t) == "table") then 65 | if not appearances[t] then 66 | appearances[t] = 1 67 | for k, v in pairs(t) do 68 | count_table_appearances(k, appearances) 69 | count_table_appearances(v, appearances) 70 | end 71 | end 72 | else 73 | if (t and (t == t)) then 74 | appearances[t] = ((appearances[t] or 0) + 1) 75 | end 76 | end 77 | return appearances 78 | end 79 | local put_value = nil 80 | local function puts(self, ...) 81 | for _, v in ipairs({...}) do 82 | table.insert(self.buffer, v) 83 | end 84 | return nil 85 | end 86 | local function tabify(self) 87 | return puts(self, "\n", (self.indent):rep(self.level)) 88 | end 89 | local function already_visited_3f(self, v) 90 | return (self.ids[v] ~= nil) 91 | end 92 | local function get_id(self, v) 93 | local id = self.ids[v] 94 | if not id then 95 | local tv = type(v) 96 | id = ((self["max-ids"][tv] or 0) + 1) 97 | self["max-ids"][tv] = id 98 | self.ids[v] = id 99 | end 100 | return tostring(id) 101 | end 102 | local function put_sequential_table(self, t, len) 103 | puts(self, "[") 104 | self.level = (self.level + 1) 105 | for i = 1, len do 106 | puts(self, " ") 107 | put_value(self, t[i]) 108 | end 109 | self.level = (self.level - 1) 110 | return puts(self, " ]") 111 | end 112 | local function put_key(self, k) 113 | if ((type(k) == "string") and k:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then 114 | return puts(self, ":", k) 115 | else 116 | return put_value(self, k) 117 | end 118 | end 119 | local function put_kv_table(self, t, ordered_keys) 120 | puts(self, "{") 121 | self.level = (self.level + 1) 122 | for _, k in ipairs(ordered_keys) do 123 | tabify(self) 124 | put_key(self, k) 125 | puts(self, " ") 126 | put_value(self, t[k]) 127 | end 128 | for i, v in ipairs(t) do 129 | tabify(self) 130 | put_key(self, i) 131 | puts(self, " ") 132 | put_value(self, v) 133 | end 134 | self.level = (self.level - 1) 135 | tabify(self) 136 | return puts(self, "}") 137 | end 138 | local function put_table(self, t) 139 | if (already_visited_3f(self, t) and self["detect-cycles?"]) then 140 | return puts(self, "#") 141 | elseif (self.level >= self.depth) then 142 | return puts(self, "{...}") 143 | elseif "else" then 144 | local non_seq_keys, len = get_nonsequential_keys(t) 145 | local id = get_id(self, t) 146 | if ((1 < (self.appearances[t] or 0)) and self["detect-cycles?"]) then 147 | return puts(self, "#") 148 | elseif ((#non_seq_keys == 0) and (#t == 0)) then 149 | return puts(self, "{}") 150 | elseif (#non_seq_keys == 0) then 151 | return put_sequential_table(self, t, len) 152 | elseif "else" then 153 | return put_kv_table(self, t, non_seq_keys) 154 | end 155 | end 156 | end 157 | local function _0_(self, v) 158 | local tv = type(v) 159 | if (tv == "string") then 160 | return puts(self, view_quote(escape(v))) 161 | elseif ((tv == "number") or (tv == "boolean") or (tv == "nil")) then 162 | return puts(self, tostring(v)) 163 | elseif (tv == "table") then 164 | return put_table(self, v) 165 | elseif "else" then 166 | return puts(self, "#<", tostring(v), ">") 167 | end 168 | end 169 | put_value = _0_ 170 | local function one_line(str) 171 | local ret = str:gsub("\n", " "):gsub("%[ ", "["):gsub(" %]", "]"):gsub("%{ ", "{"):gsub(" %}", "}"):gsub("%( ", "("):gsub(" %)", ")") 172 | return ret 173 | end 174 | local function fennelview(x, options) 175 | local options0 = (options or {}) 176 | local inspector = nil 177 | local function _1_() 178 | if options0["one-line"] then 179 | return "" 180 | else 181 | return " " 182 | end 183 | end 184 | inspector = {["detect-cycles?"] = not (false == options0["detect-cycles?"]), ["max-ids"] = {}, appearances = count_table_appearances(x, {}), buffer = {}, depth = (options0.depth or 128), ids = {}, indent = (options0.indent or _1_()), level = 0} 185 | put_value(inspector, x) 186 | do 187 | local str = table.concat(inspector.buffer) 188 | if options0["one-line"] then 189 | return one_line(str) 190 | else 191 | return str 192 | end 193 | end 194 | end 195 | return fennelview 196 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/test.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.test" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", nvim = "conjure.aniseed.nvim", str = "conjure.aniseed.string"}} 19 | return {require("conjure.aniseed.core"), require("conjure.aniseed.nvim"), require("conjure.aniseed.string")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local nvim = _2_[2] 24 | local str = _2_[3] 25 | do local _ = ({nil, _0_0, nil})[2] end 26 | local ok_3f = nil 27 | do 28 | local v_23_0_ = nil 29 | do 30 | local v_23_0_0 = nil 31 | local function ok_3f0(_3_0) 32 | local _4_ = _3_0 33 | local tests = _4_["tests"] 34 | local tests_passed = _4_["tests-passed"] 35 | return (tests == tests_passed) 36 | end 37 | v_23_0_0 = ok_3f0 38 | _0_0["ok?"] = v_23_0_0 39 | v_23_0_ = v_23_0_0 40 | end 41 | _0_0["aniseed/locals"]["ok?"] = v_23_0_ 42 | ok_3f = v_23_0_ 43 | end 44 | local display_results = nil 45 | do 46 | local v_23_0_ = nil 47 | do 48 | local v_23_0_0 = nil 49 | local function display_results0(results, prefix) 50 | do 51 | local _3_ = results 52 | local tests_passed = _3_["tests-passed"] 53 | local assertions_passed = _3_["assertions-passed"] 54 | local tests = _3_["tests"] 55 | local assertions = _3_["assertions"] 56 | local function _4_() 57 | if ok_3f(results) then 58 | return "OK" 59 | else 60 | return "FAILED" 61 | end 62 | end 63 | a.println((prefix .. " " .. _4_() .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) 64 | end 65 | return results 66 | end 67 | v_23_0_0 = display_results0 68 | _0_0["display-results"] = v_23_0_0 69 | v_23_0_ = v_23_0_0 70 | end 71 | _0_0["aniseed/locals"]["display-results"] = v_23_0_ 72 | display_results = v_23_0_ 73 | end 74 | local run = nil 75 | do 76 | local v_23_0_ = nil 77 | do 78 | local v_23_0_0 = nil 79 | local function run0(mod_name) 80 | local mod = package.loaded[mod_name] 81 | local tests = (a["table?"](mod) and mod["aniseed/tests"]) 82 | if a["table?"](tests) then 83 | local results = {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = #tests} 84 | for label, f in pairs(tests) do 85 | local test_failed = false 86 | a.update(results, "tests", a.inc) 87 | do 88 | local prefix = ("[" .. mod_name .. "/" .. label .. "]") 89 | local fail = nil 90 | local function _3_(desc, ...) 91 | test_failed = true 92 | local function _4_(...) 93 | if desc then 94 | return (" (" .. desc .. ")") 95 | else 96 | return "" 97 | end 98 | end 99 | return a.println((str.join({prefix, " ", ...}) .. _4_(...))) 100 | end 101 | fail = _3_ 102 | local begin = nil 103 | local function _4_() 104 | return a.update(results, "assertions", a.inc) 105 | end 106 | begin = _4_ 107 | local pass = nil 108 | local function _5_() 109 | return a.update(results, "assertions-passed", a.inc) 110 | end 111 | pass = _5_ 112 | local t = nil 113 | local function _6_(e, r, desc) 114 | begin() 115 | if (e == r) then 116 | return pass() 117 | else 118 | return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'") 119 | end 120 | end 121 | local function _7_(r, desc) 122 | begin() 123 | if r then 124 | return pass() 125 | else 126 | return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'") 127 | end 128 | end 129 | local function _8_(e, r, desc) 130 | begin() 131 | do 132 | local se = a["pr-str"](e) 133 | local sr = a["pr-str"](r) 134 | if (se == sr) then 135 | return pass() 136 | else 137 | return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'") 138 | end 139 | end 140 | end 141 | t = {["="] = _6_, ["ok?"] = _7_, ["pr="] = _8_} 142 | do 143 | local _9_0, _10_0 = nil, nil 144 | local function _11_() 145 | return f(t) 146 | end 147 | _9_0, _10_0 = pcall(_11_) 148 | if ((_9_0 == false) and (nil ~= _10_0)) then 149 | local err = _10_0 150 | fail("Exception: ", err) 151 | end 152 | end 153 | end 154 | if not test_failed then 155 | a.update(results, "tests-passed", a.inc) 156 | end 157 | end 158 | return display_results(results, ("[" .. mod_name .. "]")) 159 | end 160 | end 161 | v_23_0_0 = run0 162 | _0_0["run"] = v_23_0_0 163 | v_23_0_ = v_23_0_0 164 | end 165 | _0_0["aniseed/locals"]["run"] = v_23_0_ 166 | run = v_23_0_ 167 | end 168 | local run_all = nil 169 | do 170 | local v_23_0_ = nil 171 | do 172 | local v_23_0_0 = nil 173 | local function run_all0() 174 | local function _3_(totals, results) 175 | for k, v in pairs(results) do 176 | totals[k] = (v + totals[k]) 177 | end 178 | return totals 179 | end 180 | return display_results(a.reduce(_3_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") 181 | end 182 | v_23_0_0 = run_all0 183 | _0_0["run-all"] = v_23_0_0 184 | v_23_0_ = v_23_0_0 185 | end 186 | _0_0["aniseed/locals"]["run-all"] = v_23_0_ 187 | run_all = v_23_0_ 188 | end 189 | local suite = nil 190 | do 191 | local v_23_0_ = nil 192 | do 193 | local v_23_0_0 = nil 194 | local function suite0() 195 | nvim.ex.redir_("> test/results.txt") 196 | local function _3_(path) 197 | return require(string.gsub(string.match(path, "^test/fnl/(.-).fnl$"), "/", ".")) 198 | end 199 | a["run!"](_3_, nvim.fn.globpath("test/fnl", "**/*-test.fnl", false, true)) 200 | do 201 | local results = run_all() 202 | if ok_3f(results) then 203 | return nvim.ex.q() 204 | else 205 | return nvim.ex.cq() 206 | end 207 | end 208 | end 209 | v_23_0_0 = suite0 210 | _0_0["suite"] = v_23_0_0 211 | v_23_0_ = v_23_0_0 212 | end 213 | _0_0["aniseed/locals"]["suite"] = v_23_0_ 214 | suite = v_23_0_ 215 | end 216 | return nil 217 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/deps/nvim.lua: -------------------------------------------------------------------------------- 1 | -- Bring vim into local scope. 2 | local vim = vim 3 | local api = vim.api 4 | local inspect = vim.inspect 5 | 6 | local function extend(t, o) 7 | local mt = getmetatable(t) 8 | for k, v in pairs(o) do 9 | rawset(mt, k, v) 10 | end 11 | return t 12 | end 13 | 14 | -- Equivalent to `echo vim.inspect(...)` 15 | local function nvim_print(...) 16 | if select("#", ...) == 1 then 17 | api.nvim_out_write(inspect((...))) 18 | else 19 | api.nvim_out_write(inspect {...}) 20 | end 21 | api.nvim_out_write("\n") 22 | end 23 | 24 | --- Equivalent to `echo` EX command 25 | local function nvim_echo(...) 26 | for i = 1, select("#", ...) do 27 | local part = select(i, ...) 28 | api.nvim_out_write(tostring(part)) 29 | -- vim.api.nvim_out_write("\n") 30 | api.nvim_out_write(" ") 31 | end 32 | api.nvim_out_write("\n") 33 | end 34 | 35 | local window_options = { 36 | arab = true; arabic = true; breakindent = true; breakindentopt = true; 37 | bri = true; briopt = true; cc = true; cocu = true; 38 | cole = true; colorcolumn = true; concealcursor = true; conceallevel = true; 39 | crb = true; cuc = true; cul = true; cursorbind = true; 40 | cursorcolumn = true; cursorline = true; diff = true; fcs = true; 41 | fdc = true; fde = true; fdi = true; fdl = true; 42 | fdm = true; fdn = true; fdt = true; fen = true; 43 | fillchars = true; fml = true; fmr = true; foldcolumn = true; 44 | foldenable = true; foldexpr = true; foldignore = true; foldlevel = true; 45 | foldmarker = true; foldmethod = true; foldminlines = true; foldnestmax = true; 46 | foldtext = true; lbr = true; lcs = true; linebreak = true; 47 | list = true; listchars = true; nu = true; number = true; 48 | numberwidth = true; nuw = true; previewwindow = true; pvw = true; 49 | relativenumber = true; rightleft = true; rightleftcmd = true; rl = true; 50 | rlc = true; rnu = true; scb = true; scl = true; 51 | scr = true; scroll = true; scrollbind = true; signcolumn = true; 52 | spell = true; statusline = true; stl = true; wfh = true; 53 | wfw = true; winbl = true; winblend = true; winfixheight = true; 54 | winfixwidth = true; winhighlight = true; winhl = true; wrap = true; 55 | } 56 | 57 | local function validate(conf) 58 | assert(type(conf) == 'table') 59 | local type_names = { 60 | t='table', s='string', n='number', b='boolean', f='function', c='callable', 61 | ['table']='table', ['string']='string', ['number']='number', 62 | ['boolean']='boolean', ['function']='function', ['callable']='callable', 63 | ['nil']='nil', ['thread']='thread', ['userdata']='userdata', 64 | } 65 | for k, v in pairs(conf) do 66 | if not (v[3] and v[1] == nil) and type(v[1]) ~= type_names[v[2]] then 67 | error(string.format("validation_failed: %q: expected %s, received %s", k, type_names[v[2]], type(v[1]))) 68 | end 69 | end 70 | return true 71 | end 72 | 73 | local function make_meta_accessor(get, set, del) 74 | validate { 75 | get = {get, 'f'}; 76 | set = {set, 'f'}; 77 | del = {del, 'f', true}; 78 | } 79 | local mt = {} 80 | if del then 81 | function mt:__newindex(k, v) 82 | if v == nil then 83 | return del(k) 84 | end 85 | return set(k, v) 86 | end 87 | else 88 | function mt:__newindex(k, v) 89 | return set(k, v) 90 | end 91 | end 92 | function mt:__index(k) 93 | return get(k) 94 | end 95 | return setmetatable({}, mt) 96 | end 97 | 98 | local function pcall_ret(status, ...) 99 | if status then return ... end 100 | end 101 | 102 | local function nil_wrap(fn) 103 | return function(...) 104 | return pcall_ret(pcall(fn, ...)) 105 | end 106 | end 107 | 108 | local fn = setmetatable({}, { 109 | __index = function(t, k) 110 | local f = function(...) return api.nvim_call_function(k, {...}) end 111 | rawset(t, k, f) 112 | return f 113 | end 114 | }) 115 | 116 | local function getenv(k) 117 | local v = fn.getenv(k) 118 | if v == vim.NIL then 119 | return nil 120 | end 121 | return v 122 | end 123 | 124 | local function new_win_accessor(winnr) 125 | local function get(k) 126 | if winnr == nil and type(k) == 'number' then 127 | return new_win_accessor(k) 128 | end 129 | return api.nvim_win_get_var(winnr or 0, k) 130 | end 131 | local function set(k, v) return api.nvim_win_set_var(winnr or 0, k, v) end 132 | local function del(k) return api.nvim_win_del_var(winnr or 0, k) end 133 | return make_meta_accessor(nil_wrap(get), set, del) 134 | end 135 | 136 | local function new_win_opt_accessor(winnr) 137 | local function get(k) 138 | if winnr == nil and type(k) == 'number' then 139 | return new_win_opt_accessor(k) 140 | end 141 | return api.nvim_win_get_option(winnr or 0, k) 142 | end 143 | local function set(k, v) return api.nvim_win_set_option(winnr or 0, k, v) end 144 | return make_meta_accessor(nil_wrap(get), set) 145 | end 146 | 147 | local function new_buf_accessor(bufnr) 148 | local function get(k) 149 | if bufnr == nil and type(k) == 'number' then 150 | return new_buf_accessor(k) 151 | end 152 | return api.nvim_buf_get_var(bufnr or 0, k) 153 | end 154 | local function set(k, v) return api.nvim_buf_set_var(bufnr or 0, k, v) end 155 | local function del(k) return api.nvim_buf_del_var(bufnr or 0, k) end 156 | return make_meta_accessor(nil_wrap(get), set, del) 157 | end 158 | 159 | local function new_buf_opt_accessor(bufnr) 160 | local function get(k) 161 | if window_options[k] then 162 | return api.nvim_err_writeln(k.." is a window option, not a buffer option") 163 | end 164 | if bufnr == nil and type(k) == 'number' then 165 | return new_buf_opt_accessor(k) 166 | end 167 | return api.nvim_buf_get_option(bufnr or 0, k) 168 | end 169 | local function set(k, v) 170 | if window_options[k] then 171 | return api.nvim_err_writeln(k.." is a window option, not a buffer option") 172 | end 173 | return api.nvim_buf_set_option(bufnr or 0, k, v) 174 | end 175 | return make_meta_accessor(nil_wrap(get), set) 176 | end 177 | 178 | -- `nvim.$method(...)` redirects to `nvim.api.nvim_$method(...)` 179 | -- `nvim.fn.$method(...)` redirects to `vim.api.nvim_call_function($method, {...})` 180 | -- TODO `nvim.ex.$command(...)` is approximately `:$command {...}.join(" ")` 181 | -- `nvim.print(...)` is approximately `echo vim.inspect(...)` 182 | -- `nvim.echo(...)` is approximately `echo table.concat({...}, '\n')` 183 | -- Both methods cache the inital lookup in the metatable, but there is api small overhead regardless. 184 | return setmetatable({ 185 | print = nvim_print; 186 | echo = nvim_echo; 187 | fn = rawget(vim, "fn") or fn; 188 | validate = validate; 189 | g = rawget(vim, 'g') or make_meta_accessor(nil_wrap(api.nvim_get_var), api.nvim_set_var, api.nvim_del_var); 190 | v = rawget(vim, 'v') or make_meta_accessor(nil_wrap(api.nvim_get_vvar), api.nvim_set_vvar); 191 | o = rawget(vim, 'o') or make_meta_accessor(api.nvim_get_option, api.nvim_set_option); 192 | w = new_win_accessor(nil); 193 | b = new_buf_accessor(nil); 194 | env = rawget(vim, "env") or make_meta_accessor(getenv, fn.setenv); 195 | wo = rawget(vim, "wo") or new_win_opt_accessor(nil); 196 | bo = rawget(vim, "bo") or new_buf_opt_accessor(nil); 197 | buf = { 198 | line = api.nvim_get_current_line; 199 | nr = api.nvim_get_current_buf; 200 | }; 201 | ex = setmetatable({}, { 202 | __index = function(t, k) 203 | local command = k:gsub("_$", "!") 204 | local f = function(...) 205 | return api.nvim_command(table.concat(vim.tbl_flatten {command, ...}, " ")) 206 | end 207 | rawset(t, k, f) 208 | return f 209 | end 210 | }); 211 | }, { 212 | __index = function(t, k) 213 | local f = api['nvim_'..k] 214 | if f then 215 | rawset(t, k, f) 216 | end 217 | return f 218 | end 219 | }) 220 | -- vim:et ts=2 sw=2 221 | -------------------------------------------------------------------------------- /lua/conjure/lang/fennel-aniseed.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.lang.fennel-aniseed" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {["ani-core"] = "aniseed.core", ["ani-eval"] = "aniseed.eval", ["ani-test"] = "aniseed.test", a = "conjure.aniseed.core", extract = "conjure.extract", lang = "conjure.lang", log = "conjure.log", mapping = "conjure.mapping", nvim = "conjure.aniseed.nvim", str = "conjure.aniseed.string", text = "conjure.text", view = "conjure.aniseed.view"}} 19 | return {require("conjure.aniseed.core"), require("aniseed.core"), require("aniseed.eval"), require("aniseed.test"), require("conjure.extract"), require("conjure.lang"), require("conjure.log"), require("conjure.mapping"), require("conjure.aniseed.nvim"), require("conjure.aniseed.string"), require("conjure.text"), require("conjure.aniseed.view")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local ani_core = _2_[2] 24 | local ani_eval = _2_[3] 25 | local ani_test = _2_[4] 26 | local extract = _2_[5] 27 | local lang = _2_[6] 28 | local log = _2_[7] 29 | local mapping = _2_[8] 30 | local nvim = _2_[9] 31 | local str = _2_[10] 32 | local text = _2_[11] 33 | local view = _2_[12] 34 | do local _ = ({nil, _0_0, nil})[2] end 35 | local buf_suffix = nil 36 | do 37 | local v_23_0_ = nil 38 | do 39 | local v_23_0_0 = ".fnl" 40 | _0_0["buf-suffix"] = v_23_0_0 41 | v_23_0_ = v_23_0_0 42 | end 43 | _0_0["aniseed/locals"]["buf-suffix"] = v_23_0_ 44 | buf_suffix = v_23_0_ 45 | end 46 | local context_pattern = nil 47 | do 48 | local v_23_0_ = nil 49 | do 50 | local v_23_0_0 = "[(]%s*module%s*(.-)[%s){]" 51 | _0_0["context-pattern"] = v_23_0_0 52 | v_23_0_ = v_23_0_0 53 | end 54 | _0_0["aniseed/locals"]["context-pattern"] = v_23_0_ 55 | context_pattern = v_23_0_ 56 | end 57 | local comment_prefix = nil 58 | do 59 | local v_23_0_ = nil 60 | do 61 | local v_23_0_0 = "; " 62 | _0_0["comment-prefix"] = v_23_0_0 63 | v_23_0_ = v_23_0_0 64 | end 65 | _0_0["aniseed/locals"]["comment-prefix"] = v_23_0_ 66 | comment_prefix = v_23_0_ 67 | end 68 | local config = nil 69 | do 70 | local v_23_0_ = nil 71 | do 72 | local v_23_0_0 = {mappings = {["run-all-tests"] = "ta", ["run-buf-tests"] = "tt"}} 73 | _0_0["config"] = v_23_0_0 74 | v_23_0_ = v_23_0_0 75 | end 76 | _0_0["aniseed/locals"]["config"] = v_23_0_ 77 | config = v_23_0_ 78 | end 79 | local display = nil 80 | do 81 | local v_23_0_ = nil 82 | local function display0(lines, opts) 83 | return lang["with-filetype"]("fennel", log.append, lines, opts) 84 | end 85 | v_23_0_ = display0 86 | _0_0["aniseed/locals"]["display"] = v_23_0_ 87 | display = v_23_0_ 88 | end 89 | local display_result = nil 90 | do 91 | local v_23_0_ = nil 92 | do 93 | local v_23_0_0 = nil 94 | local function display_result0(opts) 95 | if opts then 96 | local _3_ = opts 97 | local result = _3_["result"] 98 | local ok_3f = _3_["ok?"] 99 | local result_str = nil 100 | if ok_3f then 101 | result_str = view.serialise(result) 102 | else 103 | result_str = result 104 | end 105 | local result_lines = str.split(result_str, "[^\n]+") 106 | local function _5_() 107 | if ok_3f then 108 | return result_lines 109 | else 110 | local function _5_(_241) 111 | return ("; " .. _241) 112 | end 113 | return a.map(_5_, result_lines) 114 | end 115 | end 116 | return display(_5_()) 117 | end 118 | end 119 | v_23_0_0 = display_result0 120 | _0_0["display-result"] = v_23_0_0 121 | v_23_0_ = v_23_0_0 122 | end 123 | _0_0["aniseed/locals"]["display-result"] = v_23_0_ 124 | display_result = v_23_0_ 125 | end 126 | local eval_str = nil 127 | do 128 | local v_23_0_ = nil 129 | do 130 | local v_23_0_0 = nil 131 | local function eval_str0(opts) 132 | local code = (("(module " .. (opts.context or "aniseed.user") .. ") ") .. opts.code .. "\n") 133 | local out = nil 134 | local function _3_() 135 | local ok_3f, result = ani_eval.str(code, {filename = opts["file-path"]}) 136 | opts["ok?"] = ok_3f 137 | opts.result = result 138 | return nil 139 | end 140 | out = ani_core["with-out-str"](_3_) 141 | if not a["empty?"](out) then 142 | display(text["prefixed-lines"](out, "; (out) ")) 143 | end 144 | return display_result(opts) 145 | end 146 | v_23_0_0 = eval_str0 147 | _0_0["eval-str"] = v_23_0_0 148 | v_23_0_ = v_23_0_0 149 | end 150 | _0_0["aniseed/locals"]["eval-str"] = v_23_0_ 151 | eval_str = v_23_0_ 152 | end 153 | local doc_str = nil 154 | do 155 | local v_23_0_ = nil 156 | do 157 | local v_23_0_0 = nil 158 | local function doc_str0(opts) 159 | a.assoc(opts, "code", ("(doc " .. opts.code .. ")")) 160 | return eval_str(opts) 161 | end 162 | v_23_0_0 = doc_str0 163 | _0_0["doc-str"] = v_23_0_0 164 | v_23_0_ = v_23_0_0 165 | end 166 | _0_0["aniseed/locals"]["doc-str"] = v_23_0_ 167 | doc_str = v_23_0_ 168 | end 169 | local not_implemented = nil 170 | do 171 | local v_23_0_ = nil 172 | local function not_implemented0() 173 | return display({"; Not implemented for conjure.lang.fennel-aniseed"}) 174 | end 175 | v_23_0_ = not_implemented0 176 | _0_0["aniseed/locals"]["not-implemented"] = v_23_0_ 177 | not_implemented = v_23_0_ 178 | end 179 | local def_str = nil 180 | do 181 | local v_23_0_ = nil 182 | do 183 | local v_23_0_0 = nil 184 | local function def_str0(opts) 185 | return not_implemented() 186 | end 187 | v_23_0_0 = def_str0 188 | _0_0["def-str"] = v_23_0_0 189 | v_23_0_ = v_23_0_0 190 | end 191 | _0_0["aniseed/locals"]["def-str"] = v_23_0_ 192 | def_str = v_23_0_ 193 | end 194 | local eval_file = nil 195 | do 196 | local v_23_0_ = nil 197 | do 198 | local v_23_0_0 = nil 199 | local function eval_file0(opts) 200 | opts.code = a.slurp(opts["file-path"]) 201 | if opts.code then 202 | return eval_str(opts) 203 | end 204 | end 205 | v_23_0_0 = eval_file0 206 | _0_0["eval-file"] = v_23_0_0 207 | v_23_0_ = v_23_0_0 208 | end 209 | _0_0["aniseed/locals"]["eval-file"] = v_23_0_ 210 | eval_file = v_23_0_ 211 | end 212 | local wrapped_test = nil 213 | do 214 | local v_23_0_ = nil 215 | local function wrapped_test0(req_lines, f) 216 | display(req_lines, {["break?"] = true}) 217 | do 218 | local res = ani_core["with-out-str"](f) 219 | local _3_ 220 | if ("" == res) then 221 | _3_ = "No results." 222 | else 223 | _3_ = res 224 | end 225 | return display(text["prefixed-lines"](_3_, "; ")) 226 | end 227 | end 228 | v_23_0_ = wrapped_test0 229 | _0_0["aniseed/locals"]["wrapped-test"] = v_23_0_ 230 | wrapped_test = v_23_0_ 231 | end 232 | local run_buf_tests = nil 233 | do 234 | local v_23_0_ = nil 235 | do 236 | local v_23_0_0 = nil 237 | local function run_buf_tests0() 238 | local c = extract.context() 239 | if c then 240 | local function _3_() 241 | return ani_test.run(c) 242 | end 243 | return wrapped_test({("; run-buf-tests (" .. c .. ")")}, _3_) 244 | end 245 | end 246 | v_23_0_0 = run_buf_tests0 247 | _0_0["run-buf-tests"] = v_23_0_0 248 | v_23_0_ = v_23_0_0 249 | end 250 | _0_0["aniseed/locals"]["run-buf-tests"] = v_23_0_ 251 | run_buf_tests = v_23_0_ 252 | end 253 | local run_all_tests = nil 254 | do 255 | local v_23_0_ = nil 256 | do 257 | local v_23_0_0 = nil 258 | local function run_all_tests0() 259 | return wrapped_test({"; run-all-tests"}, ani_test["run-all"]) 260 | end 261 | v_23_0_0 = run_all_tests0 262 | _0_0["run-all-tests"] = v_23_0_0 263 | v_23_0_ = v_23_0_0 264 | end 265 | _0_0["aniseed/locals"]["run-all-tests"] = v_23_0_ 266 | run_all_tests = v_23_0_ 267 | end 268 | local on_filetype = nil 269 | do 270 | local v_23_0_ = nil 271 | do 272 | local v_23_0_0 = nil 273 | local function on_filetype0() 274 | mapping.buf("n", config.mappings["run-buf-tests"], "conjure.lang.fennel-aniseed", "run-buf-tests") 275 | return mapping.buf("n", config.mappings["run-all-tests"], "conjure.lang.fennel-aniseed", "run-all-tests") 276 | end 277 | v_23_0_0 = on_filetype0 278 | _0_0["on-filetype"] = v_23_0_0 279 | v_23_0_ = v_23_0_0 280 | end 281 | _0_0["aniseed/locals"]["on-filetype"] = v_23_0_ 282 | on_filetype = v_23_0_ 283 | end 284 | return nil -------------------------------------------------------------------------------- /lua/conjure/eval.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.eval" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", config = "conjure.config", editor = "conjure.editor", extract = "conjure.extract", lang = "conjure.lang", log = "conjure.log", nvim = "conjure.aniseed.nvim", text = "conjure.text"}} 19 | return {require("conjure.aniseed.core"), require("conjure.config"), require("conjure.editor"), require("conjure.extract"), require("conjure.lang"), require("conjure.log"), require("conjure.aniseed.nvim"), require("conjure.text")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local config = _2_[2] 24 | local editor = _2_[3] 25 | local extract = _2_[4] 26 | local lang = _2_[5] 27 | local log = _2_[6] 28 | local nvim = _2_[7] 29 | local text = _2_[8] 30 | do local _ = ({nil, _0_0, nil})[2] end 31 | local preview = nil 32 | do 33 | local v_23_0_ = nil 34 | local function preview0(opts) 35 | local sample_limit = editor["percent-width"](config.preview["sample-limit"]) 36 | local function _3_() 37 | if (("file" == opts.origin) or ("buf" == opts.origin)) then 38 | return text["right-sample"](opts["file-path"], sample_limit) 39 | else 40 | return text["left-sample"](opts.code, sample_limit) 41 | end 42 | end 43 | return (lang.get("comment-prefix") .. opts.action .. " (" .. opts.origin .. "): " .. _3_()) 44 | end 45 | v_23_0_ = preview0 46 | _0_0["aniseed/locals"]["preview"] = v_23_0_ 47 | preview = v_23_0_ 48 | end 49 | local display_request = nil 50 | do 51 | local v_23_0_ = nil 52 | local function display_request0(opts) 53 | return log.append({opts.preview}, {["break?"] = true}) 54 | end 55 | v_23_0_ = display_request0 56 | _0_0["aniseed/locals"]["display-request"] = v_23_0_ 57 | display_request = v_23_0_ 58 | end 59 | local file = nil 60 | do 61 | local v_23_0_ = nil 62 | do 63 | local v_23_0_0 = nil 64 | local function file0() 65 | local opts = {["file-path"] = extract["file-path"](), action = "eval", origin = "file"} 66 | opts.preview = preview(opts) 67 | display_request(opts) 68 | return lang.call("eval-file", opts) 69 | end 70 | v_23_0_0 = file0 71 | _0_0["file"] = v_23_0_0 72 | v_23_0_ = v_23_0_0 73 | end 74 | _0_0["aniseed/locals"]["file"] = v_23_0_ 75 | file = v_23_0_ 76 | end 77 | local lang_exec_fn = nil 78 | do 79 | local v_23_0_ = nil 80 | local function lang_exec_fn0(action, f_name) 81 | local function _3_(opts) 82 | opts.action = action 83 | opts.context = (nvim.b.conjure_context or extract.context()) 84 | opts["file-path"] = extract["file-path"]() 85 | opts.preview = preview(opts) 86 | display_request(opts) 87 | return lang.call(f_name, opts) 88 | end 89 | return _3_ 90 | end 91 | v_23_0_ = lang_exec_fn0 92 | _0_0["aniseed/locals"]["lang-exec-fn"] = v_23_0_ 93 | lang_exec_fn = v_23_0_ 94 | end 95 | local eval_str = nil 96 | do 97 | local v_23_0_ = lang_exec_fn("eval", "eval-str") 98 | _0_0["aniseed/locals"]["eval-str"] = v_23_0_ 99 | eval_str = v_23_0_ 100 | end 101 | local doc_str = nil 102 | do 103 | local v_23_0_ = lang_exec_fn("doc", "doc-str") 104 | _0_0["aniseed/locals"]["doc-str"] = v_23_0_ 105 | doc_str = v_23_0_ 106 | end 107 | local def_str = nil 108 | do 109 | local v_23_0_ = lang_exec_fn("def", "def-str") 110 | _0_0["aniseed/locals"]["def-str"] = v_23_0_ 111 | def_str = v_23_0_ 112 | end 113 | local current_form = nil 114 | do 115 | local v_23_0_ = nil 116 | do 117 | local v_23_0_0 = nil 118 | local function current_form0(extra_opts) 119 | local form = extract.form({}) 120 | if form then 121 | local _3_ = form 122 | local range = _3_["range"] 123 | local content = _3_["content"] 124 | return eval_str(a.merge({code = content, origin = "current-form", range = range}, extra_opts)) 125 | end 126 | end 127 | v_23_0_0 = current_form0 128 | _0_0["current-form"] = v_23_0_0 129 | v_23_0_ = v_23_0_0 130 | end 131 | _0_0["aniseed/locals"]["current-form"] = v_23_0_ 132 | current_form = v_23_0_ 133 | end 134 | local root_form = nil 135 | do 136 | local v_23_0_ = nil 137 | do 138 | local v_23_0_0 = nil 139 | local function root_form0() 140 | local form = extract.form({["root?"] = true}) 141 | if form then 142 | local _3_ = form 143 | local range = _3_["range"] 144 | local content = _3_["content"] 145 | return eval_str({code = content, origin = "root-form", range = range}) 146 | end 147 | end 148 | v_23_0_0 = root_form0 149 | _0_0["root-form"] = v_23_0_0 150 | v_23_0_ = v_23_0_0 151 | end 152 | _0_0["aniseed/locals"]["root-form"] = v_23_0_ 153 | root_form = v_23_0_ 154 | end 155 | local marked_form = nil 156 | do 157 | local v_23_0_ = nil 158 | do 159 | local v_23_0_0 = nil 160 | local function marked_form0() 161 | local mark = extract["prompt-char"]() 162 | local comment_prefix = lang.get("comment-prefix") 163 | local ok_3f, err = nil, nil 164 | local function _3_() 165 | return editor["go-to-mark"](mark) 166 | end 167 | ok_3f, err = pcall(_3_) 168 | if ok_3f then 169 | current_form({origin = ("marked-form [" .. mark .. "]")}) 170 | return editor["go-back"]() 171 | else 172 | return log.append({(comment_prefix .. "Couldn't eval form at mark: " .. mark), (comment_prefix .. err)}, {["break?"] = true}) 173 | end 174 | end 175 | v_23_0_0 = marked_form0 176 | _0_0["marked-form"] = v_23_0_0 177 | v_23_0_ = v_23_0_0 178 | end 179 | _0_0["aniseed/locals"]["marked-form"] = v_23_0_ 180 | marked_form = v_23_0_ 181 | end 182 | local word = nil 183 | do 184 | local v_23_0_ = nil 185 | do 186 | local v_23_0_0 = nil 187 | local function word0() 188 | local _3_ = extract.word() 189 | local range = _3_["range"] 190 | local content = _3_["content"] 191 | if not a["empty?"](content) then 192 | return eval_str({code = content, origin = "word", range = range}) 193 | end 194 | end 195 | v_23_0_0 = word0 196 | _0_0["word"] = v_23_0_0 197 | v_23_0_ = v_23_0_0 198 | end 199 | _0_0["aniseed/locals"]["word"] = v_23_0_ 200 | word = v_23_0_ 201 | end 202 | do local _ = (10 + 20 + 30) end 203 | local doc_word = nil 204 | do 205 | local v_23_0_ = nil 206 | do 207 | local v_23_0_0 = nil 208 | local function doc_word0() 209 | local _3_ = extract.word() 210 | local range = _3_["range"] 211 | local content = _3_["content"] 212 | if not a["empty?"](content) then 213 | return doc_str({code = content, origin = "word", range = range}) 214 | end 215 | end 216 | v_23_0_0 = doc_word0 217 | _0_0["doc-word"] = v_23_0_0 218 | v_23_0_ = v_23_0_0 219 | end 220 | _0_0["aniseed/locals"]["doc-word"] = v_23_0_ 221 | doc_word = v_23_0_ 222 | end 223 | local def_word = nil 224 | do 225 | local v_23_0_ = nil 226 | do 227 | local v_23_0_0 = nil 228 | local function def_word0() 229 | local _3_ = extract.word() 230 | local range = _3_["range"] 231 | local content = _3_["content"] 232 | if not a["empty?"](content) then 233 | return def_str({code = content, origin = "word", range = range}) 234 | end 235 | end 236 | v_23_0_0 = def_word0 237 | _0_0["def-word"] = v_23_0_0 238 | v_23_0_ = v_23_0_0 239 | end 240 | _0_0["aniseed/locals"]["def-word"] = v_23_0_ 241 | def_word = v_23_0_ 242 | end 243 | local buf = nil 244 | do 245 | local v_23_0_ = nil 246 | do 247 | local v_23_0_0 = nil 248 | local function buf0() 249 | local _3_ = extract.buf() 250 | local range = _3_["range"] 251 | local content = _3_["content"] 252 | return eval_str({code = content, origin = "buf", range = range}) 253 | end 254 | v_23_0_0 = buf0 255 | _0_0["buf"] = v_23_0_0 256 | v_23_0_ = v_23_0_0 257 | end 258 | _0_0["aniseed/locals"]["buf"] = v_23_0_ 259 | buf = v_23_0_ 260 | end 261 | local command = nil 262 | do 263 | local v_23_0_ = nil 264 | do 265 | local v_23_0_0 = nil 266 | local function command0(code) 267 | return eval_str({code = code, origin = "command"}) 268 | end 269 | v_23_0_0 = command0 270 | _0_0["command"] = v_23_0_0 271 | v_23_0_ = v_23_0_0 272 | end 273 | _0_0["aniseed/locals"]["command"] = v_23_0_ 274 | command = v_23_0_ 275 | end 276 | local range = nil 277 | do 278 | local v_23_0_ = nil 279 | do 280 | local v_23_0_0 = nil 281 | local function range0(start, _end) 282 | local _3_ = extract.range(start, _end) 283 | local range1 = _3_["range"] 284 | local content = _3_["content"] 285 | return eval_str({code = content, origin = "range", range = range1}) 286 | end 287 | v_23_0_0 = range0 288 | _0_0["range"] = v_23_0_0 289 | v_23_0_ = v_23_0_0 290 | end 291 | _0_0["aniseed/locals"]["range"] = v_23_0_ 292 | range = v_23_0_ 293 | end 294 | local selection = nil 295 | do 296 | local v_23_0_ = nil 297 | do 298 | local v_23_0_0 = nil 299 | local function selection0(kind) 300 | local _3_ = extract.selection({["visual?"] = not kind, kind = (kind or nvim.fn.visualmode())}) 301 | local range0 = _3_["range"] 302 | local content = _3_["content"] 303 | return eval_str({code = content, origin = "selection", range = range0}) 304 | end 305 | v_23_0_0 = selection0 306 | _0_0["selection"] = v_23_0_0 307 | v_23_0_ = v_23_0_0 308 | end 309 | _0_0["aniseed/locals"]["selection"] = v_23_0_ 310 | selection = v_23_0_ 311 | end 312 | return nil -------------------------------------------------------------------------------- /lua/conjure/log.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.log" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", buffer = "conjure.buffer", config = "conjure.config", editor = "conjure.editor", lang = "conjure.lang", nvim = "conjure.aniseed.nvim"}} 19 | return {require("conjure.aniseed.core"), require("conjure.buffer"), require("conjure.config"), require("conjure.editor"), require("conjure.lang"), require("conjure.aniseed.nvim")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local buffer = _2_[2] 24 | local config = _2_[3] 25 | local editor = _2_[4] 26 | local lang = _2_[5] 27 | local nvim = _2_[6] 28 | do local _ = ({nil, _0_0, nil})[2] end 29 | local state = nil 30 | do 31 | local v_23_0_ = (_0_0["aniseed/locals"].state or {hud = {id = nil}}) 32 | _0_0["aniseed/locals"]["state"] = v_23_0_ 33 | state = v_23_0_ 34 | end 35 | local _break = nil 36 | do 37 | local v_23_0_ = nil 38 | local function _break0() 39 | return (lang.get("comment-prefix") .. string.rep("-", editor["percent-width"](config.log["break-length"]))) 40 | end 41 | v_23_0_ = _break0 42 | _0_0["aniseed/locals"]["break"] = v_23_0_ 43 | _break = v_23_0_ 44 | end 45 | local log_buf_name = nil 46 | do 47 | local v_23_0_ = nil 48 | local function log_buf_name0() 49 | return ("conjure-log-" .. nvim.fn.getpid() .. lang.get("buf-suffix")) 50 | end 51 | v_23_0_ = log_buf_name0 52 | _0_0["aniseed/locals"]["log-buf-name"] = v_23_0_ 53 | log_buf_name = v_23_0_ 54 | end 55 | local upsert_buf = nil 56 | do 57 | local v_23_0_ = nil 58 | local function upsert_buf0() 59 | return buffer["upsert-hidden"](log_buf_name()) 60 | end 61 | v_23_0_ = upsert_buf0 62 | _0_0["aniseed/locals"]["upsert-buf"] = v_23_0_ 63 | upsert_buf = v_23_0_ 64 | end 65 | local close_hud = nil 66 | do 67 | local v_23_0_ = nil 68 | do 69 | local v_23_0_0 = nil 70 | local function close_hud0() 71 | if state.hud.id then 72 | local function _3_() 73 | return nvim.win_close(state.hud.id, true) 74 | end 75 | pcall(_3_) 76 | state.hud.id = nil 77 | return nil 78 | end 79 | end 80 | v_23_0_0 = close_hud0 81 | _0_0["close-hud"] = v_23_0_0 82 | v_23_0_ = v_23_0_0 83 | end 84 | _0_0["aniseed/locals"]["close-hud"] = v_23_0_ 85 | close_hud = v_23_0_ 86 | end 87 | local break_lines = nil 88 | do 89 | local v_23_0_ = nil 90 | local function break_lines0(buf) 91 | local break_str = _break() 92 | local function _3_(_4_0) 93 | local _5_ = _4_0 94 | local n = _5_[1] 95 | local s = _5_[2] 96 | return (s == break_str) 97 | end 98 | return a.map(a.first, a.filter(_3_, a["kv-pairs"](nvim.buf_get_lines(buf, 0, -1, false)))) 99 | end 100 | v_23_0_ = break_lines0 101 | _0_0["aniseed/locals"]["break-lines"] = v_23_0_ 102 | break_lines = v_23_0_ 103 | end 104 | local display_hud = nil 105 | do 106 | local v_23_0_ = nil 107 | local function display_hud0() 108 | if config.log.hud["enabled?"] then 109 | local buf = upsert_buf() 110 | local cursor_top_right_3f = ((editor["cursor-left"]() > editor["percent-width"](0.5)) and (editor["cursor-top"]() < editor["percent-height"](0.5))) 111 | local last_break = a.last(break_lines(buf)) 112 | local line_count = nvim.buf_line_count(buf) 113 | local win_opts = nil 114 | local _3_ 115 | if cursor_top_right_3f then 116 | _3_ = (editor.height() - 2) 117 | else 118 | _3_ = 0 119 | end 120 | win_opts = {anchor = "SE", col = editor.width(), focusable = false, height = editor["percent-height"](config.log.hud.height), relative = "editor", row = _3_, style = "minimal", width = editor["percent-width"](config.log.hud.width)} 121 | if not state.hud.id then 122 | state.hud.id = nvim.open_win(buf, false, win_opts) 123 | nvim.win_set_option(state.hud.id, "wrap", false) 124 | end 125 | if last_break then 126 | nvim.win_set_cursor(state.hud.id, {1, 0}) 127 | return nvim.win_set_cursor(state.hud.id, {math.min((last_break + a.inc(math.floor((win_opts.height / 2)))), line_count), 0}) 128 | else 129 | return nvim.win_set_cursor(state.hud.id, {line_count, 0}) 130 | end 131 | end 132 | end 133 | v_23_0_ = display_hud0 134 | _0_0["aniseed/locals"]["display-hud"] = v_23_0_ 135 | display_hud = v_23_0_ 136 | end 137 | local win_visible_3f = nil 138 | do 139 | local v_23_0_ = nil 140 | local function win_visible_3f0(win) 141 | return (nvim.fn.tabpagenr() == a.first(nvim.fn.win_id2tabwin(win))) 142 | end 143 | v_23_0_ = win_visible_3f0 144 | _0_0["aniseed/locals"]["win-visible?"] = v_23_0_ 145 | win_visible_3f = v_23_0_ 146 | end 147 | local with_buf_wins = nil 148 | do 149 | local v_23_0_ = nil 150 | local function with_buf_wins0(buf, f) 151 | local function _3_(win) 152 | if (buf == nvim.win_get_buf(win)) then 153 | return f(win) 154 | end 155 | end 156 | return a["run!"](_3_, nvim.list_wins()) 157 | end 158 | v_23_0_ = with_buf_wins0 159 | _0_0["aniseed/locals"]["with-buf-wins"] = v_23_0_ 160 | with_buf_wins = v_23_0_ 161 | end 162 | local trim = nil 163 | do 164 | local v_23_0_ = nil 165 | local function trim0(buf) 166 | local line_count = nvim.buf_line_count(buf) 167 | if (line_count > config.log.trim.at) then 168 | local target_line_count = (line_count - config.log.trim.to) 169 | local last_break_line = nil 170 | local function _3_(_241) 171 | return (_241 <= target_line_count) 172 | end 173 | last_break_line = a.last(a.filter(_3_, break_lines(buf))) 174 | nvim.buf_set_lines(buf, 0, (last_break_line or target_line_count), false, {}) 175 | do 176 | local line_count0 = nvim.buf_line_count(buf) 177 | local function _4_(win) 178 | local _5_ = nvim.win_get_cursor(win) 179 | local row = _5_[1] 180 | local col = _5_[2] 181 | nvim.win_set_cursor(win, {1, 0}) 182 | return nvim.win_set_cursor(win, {row, col}) 183 | end 184 | return with_buf_wins(buf, _4_) 185 | end 186 | end 187 | end 188 | v_23_0_ = trim0 189 | _0_0["aniseed/locals"]["trim"] = v_23_0_ 190 | trim = v_23_0_ 191 | end 192 | local append = nil 193 | do 194 | local v_23_0_ = nil 195 | do 196 | local v_23_0_0 = nil 197 | local function append0(lines, opts) 198 | if not a["empty?"](lines) then 199 | local visible_scrolling_log_3f = false 200 | do 201 | local buf = upsert_buf() 202 | local lines0 = nil 203 | if a.get(opts, "break?") then 204 | lines0 = a.concat({_break()}, lines) 205 | else 206 | lines0 = lines 207 | end 208 | local old_lines = nvim.buf_line_count(buf) 209 | local _4_ 210 | if buffer["empty?"](buf) then 211 | _4_ = 0 212 | else 213 | _4_ = -1 214 | end 215 | nvim.buf_set_lines(buf, _4_, -1, false, lines0) 216 | do 217 | local new_lines = nvim.buf_line_count(buf) 218 | local function _6_(win) 219 | local _7_ = nvim.win_get_cursor(win) 220 | local row = _7_[1] 221 | local col = _7_[2] 222 | if (old_lines == row) then 223 | if ((win ~= state.hud.id) and win_visible_3f(win)) then 224 | visible_scrolling_log_3f = true 225 | end 226 | return nvim.win_set_cursor(win, {new_lines, 0}) 227 | end 228 | end 229 | with_buf_wins(buf, _6_) 230 | end 231 | if not visible_scrolling_log_3f then 232 | display_hud() 233 | end 234 | return trim(buf) 235 | end 236 | end 237 | end 238 | v_23_0_0 = append0 239 | _0_0["append"] = v_23_0_0 240 | v_23_0_ = v_23_0_0 241 | end 242 | _0_0["aniseed/locals"]["append"] = v_23_0_ 243 | append = v_23_0_ 244 | end 245 | local create_win = nil 246 | do 247 | local v_23_0_ = nil 248 | local function create_win0(split_fn) 249 | local buf = upsert_buf() 250 | local win = split_fn(log_buf_name()) 251 | nvim.win_set_cursor(win, {nvim.buf_line_count(buf), 0}) 252 | nvim.win_set_option(win, "wrap", false) 253 | return buffer.unlist(buf) 254 | end 255 | v_23_0_ = create_win0 256 | _0_0["aniseed/locals"]["create-win"] = v_23_0_ 257 | create_win = v_23_0_ 258 | end 259 | local split = nil 260 | do 261 | local v_23_0_ = nil 262 | do 263 | local v_23_0_0 = nil 264 | local function split0() 265 | return create_win(nvim.ex.split) 266 | end 267 | v_23_0_0 = split0 268 | _0_0["split"] = v_23_0_0 269 | v_23_0_ = v_23_0_0 270 | end 271 | _0_0["aniseed/locals"]["split"] = v_23_0_ 272 | split = v_23_0_ 273 | end 274 | local vsplit = nil 275 | do 276 | local v_23_0_ = nil 277 | do 278 | local v_23_0_0 = nil 279 | local function vsplit0() 280 | return create_win(nvim.ex.vsplit) 281 | end 282 | v_23_0_0 = vsplit0 283 | _0_0["vsplit"] = v_23_0_0 284 | v_23_0_ = v_23_0_0 285 | end 286 | _0_0["aniseed/locals"]["vsplit"] = v_23_0_ 287 | vsplit = v_23_0_ 288 | end 289 | local tab = nil 290 | do 291 | local v_23_0_ = nil 292 | do 293 | local v_23_0_0 = nil 294 | local function tab0() 295 | return create_win(nvim.ex.tabnew) 296 | end 297 | v_23_0_0 = tab0 298 | _0_0["tab"] = v_23_0_0 299 | v_23_0_ = v_23_0_0 300 | end 301 | _0_0["aniseed/locals"]["tab"] = v_23_0_ 302 | tab = v_23_0_ 303 | end 304 | return nil -------------------------------------------------------------------------------- /lua/conjure/aniseed/mapping.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.mapping" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", eval = "conjure.aniseed.eval", fennel = "conjure.aniseed.fennel", nu = "conjure.aniseed.nvim.util", nvim = "conjure.aniseed.nvim", str = "conjure.aniseed.string", test = "conjure.aniseed.test"}} 19 | return {require("conjure.aniseed.core"), require("conjure.aniseed.eval"), require("conjure.aniseed.fennel"), require("conjure.aniseed.nvim.util"), require("conjure.aniseed.nvim"), require("conjure.aniseed.string"), require("conjure.aniseed.test")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local eval = _2_[2] 24 | local fennel = _2_[3] 25 | local nu = _2_[4] 26 | local nvim = _2_[5] 27 | local str = _2_[6] 28 | local test = _2_[7] 29 | do local _ = ({nil, _0_0, nil})[2] end 30 | local handle_result = nil 31 | do 32 | local v_23_0_ = nil 33 | do 34 | local v_23_0_0 = nil 35 | local function handle_result0(ok_3f, result) 36 | if not ok_3f then 37 | return nvim.err_writeln(result) 38 | else 39 | local mod = (a["table?"](result) and result["aniseed/module"]) 40 | if mod then 41 | if (nil == package.loaded[mod]) then 42 | package.loaded[mod] = {} 43 | end 44 | for k, v in pairs(result) do 45 | package.loaded[mod][k] = v 46 | end 47 | end 48 | local function _4_() 49 | return a.pr(result) 50 | end 51 | return vim.schedule(_4_) 52 | end 53 | end 54 | v_23_0_0 = handle_result0 55 | _0_0["handle-result"] = v_23_0_0 56 | v_23_0_ = v_23_0_0 57 | end 58 | _0_0["aniseed/locals"]["handle-result"] = v_23_0_ 59 | handle_result = v_23_0_ 60 | end 61 | local selection = nil 62 | do 63 | local v_23_0_ = nil 64 | do 65 | local v_23_0_0 = nil 66 | local function selection0(type, ...) 67 | local sel_backup = nvim.o.selection 68 | local _3_ = {...} 69 | local visual_3f = _3_[1] 70 | nvim.ex.let("g:aniseed_reg_backup = @@") 71 | nvim.o.selection = "inclusive" 72 | if visual_3f then 73 | nu.normal(("`<" .. type .. "`>y")) 74 | elseif (type == "line") then 75 | nu.normal("'[V']y") 76 | elseif (type == "block") then 77 | nu.normal("`[\22`]y") 78 | else 79 | nu.normal("`[v`]y") 80 | end 81 | do 82 | local selection1 = nvim.eval("@@") 83 | nvim.o.selection = sel_backup 84 | nvim.ex.let("@@ = g:aniseed_reg_backup") 85 | return selection1 86 | end 87 | end 88 | v_23_0_0 = selection0 89 | _0_0["selection"] = v_23_0_0 90 | v_23_0_ = v_23_0_0 91 | end 92 | _0_0["aniseed/locals"]["selection"] = v_23_0_ 93 | selection = v_23_0_ 94 | end 95 | local buffer_header_length = nil 96 | do 97 | local v_23_0_ = 20 98 | _0_0["aniseed/locals"]["buffer-header-length"] = v_23_0_ 99 | buffer_header_length = v_23_0_ 100 | end 101 | local default_module_name = nil 102 | do 103 | local v_23_0_ = "conjure.aniseed.user" 104 | _0_0["aniseed/locals"]["default-module-name"] = v_23_0_ 105 | default_module_name = v_23_0_ 106 | end 107 | local buffer_module_pattern = nil 108 | do 109 | local v_23_0_ = "[(]%s*module%s*(.-)[%s){]" 110 | _0_0["aniseed/locals"]["buffer-module-pattern"] = v_23_0_ 111 | buffer_module_pattern = v_23_0_ 112 | end 113 | local buffer_module_name = nil 114 | do 115 | local v_23_0_ = nil 116 | local function buffer_module_name0() 117 | local header = str.join("\n", nvim.buf_get_lines(0, 0, buffer_header_length, false)) 118 | return (string.match(header, buffer_module_pattern) or default_module_name) 119 | end 120 | v_23_0_ = buffer_module_name0 121 | _0_0["aniseed/locals"]["buffer-module-name"] = v_23_0_ 122 | buffer_module_name = v_23_0_ 123 | end 124 | local eval_str = nil 125 | do 126 | local v_23_0_ = nil 127 | do 128 | local v_23_0_0 = nil 129 | local function eval_str0(code, opts) 130 | return handle_result(eval.str(("(module " .. buffer_module_name() .. ")" .. code), opts)) 131 | end 132 | v_23_0_0 = eval_str0 133 | _0_0["eval-str"] = v_23_0_0 134 | v_23_0_ = v_23_0_0 135 | end 136 | _0_0["aniseed/locals"]["eval-str"] = v_23_0_ 137 | eval_str = v_23_0_ 138 | end 139 | local eval_selection = nil 140 | do 141 | local v_23_0_ = nil 142 | do 143 | local v_23_0_0 = nil 144 | local function eval_selection0(...) 145 | return eval_str(selection(...)) 146 | end 147 | v_23_0_0 = eval_selection0 148 | _0_0["eval-selection"] = v_23_0_0 149 | v_23_0_ = v_23_0_0 150 | end 151 | _0_0["aniseed/locals"]["eval-selection"] = v_23_0_ 152 | eval_selection = v_23_0_ 153 | end 154 | local eval_range = nil 155 | do 156 | local v_23_0_ = nil 157 | do 158 | local v_23_0_0 = nil 159 | local function eval_range0(first_line, last_line) 160 | return eval_str(str.join("\n", nvim.fn.getline(first_line, last_line))) 161 | end 162 | v_23_0_0 = eval_range0 163 | _0_0["eval-range"] = v_23_0_0 164 | v_23_0_ = v_23_0_0 165 | end 166 | _0_0["aniseed/locals"]["eval-range"] = v_23_0_ 167 | eval_range = v_23_0_ 168 | end 169 | local eval_file = nil 170 | do 171 | local v_23_0_ = nil 172 | do 173 | local v_23_0_0 = nil 174 | local function eval_file0(filename) 175 | return handle_result(eval.str(a.slurp(filename), {filename = filename})) 176 | end 177 | v_23_0_0 = eval_file0 178 | _0_0["eval-file"] = v_23_0_0 179 | v_23_0_ = v_23_0_0 180 | end 181 | _0_0["aniseed/locals"]["eval-file"] = v_23_0_ 182 | eval_file = v_23_0_ 183 | end 184 | local run_tests = nil 185 | do 186 | local v_23_0_ = nil 187 | do 188 | local v_23_0_0 = nil 189 | local function run_tests0(name) 190 | return test.run(name) 191 | end 192 | v_23_0_0 = run_tests0 193 | _0_0["run-tests"] = v_23_0_0 194 | v_23_0_ = v_23_0_0 195 | end 196 | _0_0["aniseed/locals"]["run-tests"] = v_23_0_ 197 | run_tests = v_23_0_ 198 | end 199 | local run_all_tests = nil 200 | do 201 | local v_23_0_ = nil 202 | do 203 | local v_23_0_0 = nil 204 | local function run_all_tests0() 205 | return test["run-all"]() 206 | end 207 | v_23_0_0 = run_all_tests0 208 | _0_0["run-all-tests"] = v_23_0_0 209 | v_23_0_ = v_23_0_0 210 | end 211 | _0_0["aniseed/locals"]["run-all-tests"] = v_23_0_ 212 | run_all_tests = v_23_0_ 213 | end 214 | local init_commands = nil 215 | do 216 | local v_23_0_ = nil 217 | do 218 | local v_23_0_0 = nil 219 | local function init_commands0() 220 | nu["fn-bridge"]("AniseedSelection", "conjure.aniseed.mapping", "selection") 221 | nu["fn-bridge"]("AniseedEval", "conjure.aniseed.mapping", "eval-str") 222 | nu["fn-bridge"]("AniseedEvalFile", "conjure.aniseed.mapping", "eval-file") 223 | nu["fn-bridge"]("AniseedEvalRange", "conjure.aniseed.mapping", "eval-range", {range = true}) 224 | nu["fn-bridge"]("AniseedEvalSelection", "conjure.aniseed.mapping", "eval-selection") 225 | nu["fn-bridge"]("AniseedRunTests", "conjure.aniseed.mapping", "run-tests") 226 | nu["fn-bridge"]("AniseedRunAllTests", "conjure.aniseed.mapping", "run-all-tests") 227 | nvim.ex.command_("-nargs=1", "AniseedEval", "call AniseedEval()") 228 | nvim.ex.command_("-nargs=1", "AniseedEvalFile", "call AniseedEvalFile()") 229 | nvim.ex.command_("-range", "AniseedEvalRange", ",call AniseedEvalRange()") 230 | nvim.ex.command_("-nargs=1", "AniseedRunTests", "call AniseedRunTests()") 231 | nvim.ex.command_("-nargs=0", "AniseedRunAllTests", "call AniseedRunAllTests()") 232 | nvim.set_keymap("n", nu.plug("AniseedEval"), ":set opfunc=AniseedEvalSelectiong@", {noremap = true, silent = true}) 233 | nvim.set_keymap("n", nu.plug("AniseedEvalCurrentFile"), ":call AniseedEvalFile(expand('%'))", {noremap = true, silent = true}) 234 | return nvim.set_keymap("v", nu.plug("AniseedEvalSelection"), ":call AniseedEvalSelection(visualmode(), v:true)", {noremap = true, silent = true}) 235 | end 236 | v_23_0_0 = init_commands0 237 | _0_0["init-commands"] = v_23_0_0 238 | v_23_0_ = v_23_0_0 239 | end 240 | _0_0["aniseed/locals"]["init-commands"] = v_23_0_ 241 | init_commands = v_23_0_ 242 | end 243 | local init_mappings = nil 244 | do 245 | local v_23_0_ = nil 246 | do 247 | local v_23_0_0 = nil 248 | local function init_mappings0() 249 | nvim.ex.augroup("aniseed") 250 | nvim.ex.autocmd_() 251 | nu["ft-map"]("fennel", "n", "E", nu.plug("AniseedEval")) 252 | nu["ft-map"]("fennel", "n", "ee", (nu.plug("AniseedEval") .. "af")) 253 | nu["ft-map"]("fennel", "n", "er", (nu.plug("AniseedEval") .. "aF")) 254 | nu["ft-map"]("fennel", "n", "ef", nu.plug("AniseedEvalCurrentFile")) 255 | nu["ft-map"]("fennel", "v", "ee", nu.plug("AniseedEvalSelection")) 256 | nu["ft-map"]("fennel", "n", "eb", ":%AniseedEvalRange") 257 | nu["ft-map"]("fennel", "n", "t", ":AniseedRunAllTests") 258 | return nvim.ex.augroup("END") 259 | end 260 | v_23_0_0 = init_mappings0 261 | _0_0["init-mappings"] = v_23_0_0 262 | v_23_0_ = v_23_0_0 263 | end 264 | _0_0["aniseed/locals"]["init-mappings"] = v_23_0_ 265 | init_mappings = v_23_0_ 266 | end 267 | local init = nil 268 | do 269 | local v_23_0_ = nil 270 | do 271 | local v_23_0_0 = nil 272 | local function init0() 273 | init_commands() 274 | return init_mappings() 275 | end 276 | v_23_0_0 = init0 277 | _0_0["init"] = v_23_0_0 278 | v_23_0_ = v_23_0_0 279 | end 280 | _0_0["aniseed/locals"]["init"] = v_23_0_ 281 | init = v_23_0_ 282 | end 283 | return nil 284 | -------------------------------------------------------------------------------- /lua/conjure/extract.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.extract" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {a = "conjure.aniseed.core", config = "conjure.config", lang = "conjure.lang", nu = "conjure.aniseed.nvim.util", nvim = "conjure.aniseed.nvim", str = "conjure.aniseed.string"}} 19 | return {require("conjure.aniseed.core"), require("conjure.config"), require("conjure.lang"), require("conjure.aniseed.nvim.util"), require("conjure.aniseed.nvim"), require("conjure.aniseed.string")} 20 | end 21 | local _2_ = _1_(...) 22 | local a = _2_[1] 23 | local config = _2_[2] 24 | local lang = _2_[3] 25 | local nu = _2_[4] 26 | local nvim = _2_[5] 27 | local str = _2_[6] 28 | do local _ = ({nil, _0_0, nil})[2] end 29 | local read_range = nil 30 | do 31 | local v_23_0_ = nil 32 | local function read_range0(_3_0, _4_0) 33 | local _4_ = _3_0 34 | local srow = _4_[1] 35 | local scol = _4_[2] 36 | local _5_ = _4_0 37 | local erow = _5_[1] 38 | local ecol = _5_[2] 39 | do 40 | local lines = nvim.buf_get_lines(0, (srow - 1), erow, false) 41 | local function _6_(s) 42 | return string.sub(s, 0, ecol) 43 | end 44 | local function _7_(s) 45 | return string.sub(s, scol) 46 | end 47 | return str.join("\n", a.update(a.update(lines, #lines, _6_), 1, _7_)) 48 | end 49 | end 50 | v_23_0_ = read_range0 51 | _0_0["aniseed/locals"]["read-range"] = v_23_0_ 52 | read_range = v_23_0_ 53 | end 54 | local current_char = nil 55 | do 56 | local v_23_0_ = nil 57 | local function current_char0() 58 | local _3_ = nvim.win_get_cursor(0) 59 | local row = _3_[1] 60 | local col = _3_[2] 61 | local _4_ = nvim.buf_get_lines(0, (row - 1), row, false) 62 | local line = _4_[1] 63 | local char = (col + 1) 64 | return string.sub(line, char, char) 65 | end 66 | v_23_0_ = current_char0 67 | _0_0["aniseed/locals"]["current-char"] = v_23_0_ 68 | current_char = v_23_0_ 69 | end 70 | local nil_pos_3f = nil 71 | do 72 | local v_23_0_ = nil 73 | local function nil_pos_3f0(pos) 74 | return (not pos or (0 == unpack(pos))) 75 | end 76 | v_23_0_ = nil_pos_3f0 77 | _0_0["aniseed/locals"]["nil-pos?"] = v_23_0_ 78 | nil_pos_3f = v_23_0_ 79 | end 80 | local skip_match_3f = nil 81 | do 82 | local v_23_0_ = nil 83 | do 84 | local v_23_0_0 = nil 85 | local function skip_match_3f0() 86 | local _3_ = nvim.win_get_cursor(0) 87 | local row = _3_[1] 88 | local col = _3_[2] 89 | local stack = nvim.fn.synstack(row, a.inc(col)) 90 | local stack_size = #stack 91 | local function _4_() 92 | local name = nvim.fn.synIDattr(stack[stack_size], "name") 93 | return (name:find("Comment$") or name:find("String$") or name:find("Regexp$")) 94 | end 95 | if ("number" == type(((stack_size > 0) and _4_()))) then 96 | return 1 97 | else 98 | return 0 99 | end 100 | end 101 | v_23_0_0 = skip_match_3f0 102 | _0_0["skip-match?"] = v_23_0_0 103 | v_23_0_ = v_23_0_0 104 | end 105 | _0_0["aniseed/locals"]["skip-match?"] = v_23_0_ 106 | skip_match_3f = v_23_0_ 107 | end 108 | local form = nil 109 | do 110 | local v_23_0_ = nil 111 | do 112 | local v_23_0_0 = nil 113 | local function form0(_3_0) 114 | local _4_ = _3_0 115 | local root_3f = _4_["root?"] 116 | do 117 | local flags = nil 118 | local function _5_() 119 | if root_3f then 120 | return "r" 121 | else 122 | return "" 123 | end 124 | end 125 | flags = ("Wnz" .. _5_()) 126 | local cursor_char = current_char() 127 | local skip_match_3f_viml = "luaeval(\"require('conjure.extract')['skip-match?']()\")" 128 | local start = nil 129 | local function _6_() 130 | if (cursor_char == "(") then 131 | return "c" 132 | else 133 | return "" 134 | end 135 | end 136 | start = nvim.fn.searchpairpos("(", "", ")", (flags .. "b" .. _6_()), skip_match_3f_viml) 137 | local _end = nil 138 | local function _7_() 139 | if (cursor_char == ")") then 140 | return "c" 141 | else 142 | return "" 143 | end 144 | end 145 | _end = nvim.fn.searchpairpos("(", "", ")", (flags .. _7_()), skip_match_3f_viml) 146 | if (not nil_pos_3f(start) and not nil_pos_3f(_end)) then 147 | return {content = read_range(start, _end), range = {["end"] = a.update(_end, 2, a.dec), start = a.update(start, 2, a.dec)}} 148 | end 149 | end 150 | end 151 | v_23_0_0 = form0 152 | _0_0["form"] = v_23_0_0 153 | v_23_0_ = v_23_0_0 154 | end 155 | _0_0["aniseed/locals"]["form"] = v_23_0_ 156 | form = v_23_0_ 157 | end 158 | local word = nil 159 | do 160 | local v_23_0_ = nil 161 | do 162 | local v_23_0_0 = nil 163 | local function word0() 164 | return {content = nvim.fn.expand(""), range = {["end"] = nvim.win_get_cursor(0), start = nvim.win_get_cursor(0)}} 165 | end 166 | v_23_0_0 = word0 167 | _0_0["word"] = v_23_0_0 168 | v_23_0_ = v_23_0_0 169 | end 170 | _0_0["aniseed/locals"]["word"] = v_23_0_ 171 | word = v_23_0_ 172 | end 173 | local file_path = nil 174 | do 175 | local v_23_0_ = nil 176 | do 177 | local v_23_0_0 = nil 178 | local function file_path0() 179 | return nvim.fn.expand("%:p") 180 | end 181 | v_23_0_0 = file_path0 182 | _0_0["file-path"] = v_23_0_0 183 | v_23_0_ = v_23_0_0 184 | end 185 | _0_0["aniseed/locals"]["file-path"] = v_23_0_ 186 | file_path = v_23_0_ 187 | end 188 | local buf_last_line_length = nil 189 | do 190 | local v_23_0_ = nil 191 | local function buf_last_line_length0(buf) 192 | return a.count(a.first(nvim.buf_get_lines(buf, a.dec(nvim.buf_line_count(buf)), -1, false))) 193 | end 194 | v_23_0_ = buf_last_line_length0 195 | _0_0["aniseed/locals"]["buf-last-line-length"] = v_23_0_ 196 | buf_last_line_length = v_23_0_ 197 | end 198 | local range = nil 199 | do 200 | local v_23_0_ = nil 201 | do 202 | local v_23_0_0 = nil 203 | local function range0(start, _end) 204 | return {content = str.join("\n", nvim.buf_get_lines(0, start, _end, false)), range = {["end"] = {_end, buf_last_line_length(0)}, start = {a.inc(start), 0}}} 205 | end 206 | v_23_0_0 = range0 207 | _0_0["range"] = v_23_0_0 208 | v_23_0_ = v_23_0_0 209 | end 210 | _0_0["aniseed/locals"]["range"] = v_23_0_ 211 | range = v_23_0_ 212 | end 213 | local buf = nil 214 | do 215 | local v_23_0_ = nil 216 | do 217 | local v_23_0_0 = nil 218 | local function buf0() 219 | return range(0, -1) 220 | end 221 | v_23_0_0 = buf0 222 | _0_0["buf"] = v_23_0_0 223 | v_23_0_ = v_23_0_0 224 | end 225 | _0_0["aniseed/locals"]["buf"] = v_23_0_ 226 | buf = v_23_0_ 227 | end 228 | local getpos = nil 229 | do 230 | local v_23_0_ = nil 231 | local function getpos0(expr) 232 | local _3_ = nvim.fn.getpos(expr) 233 | local _ = _3_[1] 234 | local start = _3_[2] 235 | local _end = _3_[3] 236 | local _0 = _3_[4] 237 | return {start, a.dec(_end)} 238 | end 239 | v_23_0_ = getpos0 240 | _0_0["aniseed/locals"]["getpos"] = v_23_0_ 241 | getpos = v_23_0_ 242 | end 243 | local selection = nil 244 | do 245 | local v_23_0_ = nil 246 | do 247 | local v_23_0_0 = nil 248 | local function selection0(_3_0) 249 | local _4_ = _3_0 250 | local visual_3f = _4_["visual?"] 251 | local kind = _4_["kind"] 252 | do 253 | local sel_backup = nvim.o.selection 254 | nvim.ex.let("g:conjure_selection_reg_backup = @@") 255 | nvim.o.selection = "inclusive" 256 | if visual_3f then 257 | nu.normal(("`<" .. kind .. "`>y")) 258 | elseif (kind == "line") then 259 | nu.normal("'[V']y") 260 | elseif (kind == "block") then 261 | nu.normal("`[\22`]y") 262 | else 263 | nu.normal("`[v`]y") 264 | end 265 | do 266 | local content = nvim.eval("@@") 267 | nvim.o.selection = sel_backup 268 | nvim.ex.let("@@ = g:conjure_selection_reg_backup") 269 | return {content = content, range = {["end"] = getpos("'>"), start = getpos("'<")}} 270 | end 271 | end 272 | end 273 | v_23_0_0 = selection0 274 | _0_0["selection"] = v_23_0_0 275 | v_23_0_ = v_23_0_0 276 | end 277 | _0_0["aniseed/locals"]["selection"] = v_23_0_ 278 | selection = v_23_0_ 279 | end 280 | local context = nil 281 | do 282 | local v_23_0_ = nil 283 | do 284 | local v_23_0_0 = nil 285 | local function context0() 286 | local header = str.join("\n", nvim.buf_get_lines(0, 0, config.extract["context-header-lines"], false)) 287 | return string.match(header, lang.get("context-pattern")) 288 | end 289 | v_23_0_0 = context0 290 | _0_0["context"] = v_23_0_0 291 | v_23_0_ = v_23_0_0 292 | end 293 | _0_0["aniseed/locals"]["context"] = v_23_0_ 294 | context = v_23_0_ 295 | end 296 | local prompt = nil 297 | do 298 | local v_23_0_ = nil 299 | do 300 | local v_23_0_0 = nil 301 | local function prompt0(prefix) 302 | return nvim.fn.input((prefix or "")) 303 | end 304 | v_23_0_0 = prompt0 305 | _0_0["prompt"] = v_23_0_0 306 | v_23_0_ = v_23_0_0 307 | end 308 | _0_0["aniseed/locals"]["prompt"] = v_23_0_ 309 | prompt = v_23_0_ 310 | end 311 | local prompt_char = nil 312 | do 313 | local v_23_0_ = nil 314 | do 315 | local v_23_0_0 = nil 316 | local function prompt_char0() 317 | return nvim.fn.nr2char(nvim.fn.getchar()) 318 | end 319 | v_23_0_0 = prompt_char0 320 | _0_0["prompt-char"] = v_23_0_0 321 | v_23_0_ = v_23_0_0 322 | end 323 | _0_0["aniseed/locals"]["prompt-char"] = v_23_0_ 324 | prompt_char = v_23_0_ 325 | end 326 | return nil -------------------------------------------------------------------------------- /fnl/conjure/lang/clojure-nrepl.fnl: -------------------------------------------------------------------------------- 1 | (module conjure.lang.clojure-nrepl 2 | {require {nvim conjure.aniseed.nvim 3 | a conjure.aniseed.core 4 | str conjure.aniseed.string 5 | view conjure.aniseed.view 6 | log conjure.log 7 | lang conjure.lang 8 | text conjure.text 9 | extract conjure.extract 10 | mapping conjure.mapping 11 | bencode conjure.bencode 12 | bencode-stream conjure.bencode-stream 13 | eval conjure.aniseed.eval 14 | bridge conjure.bridge 15 | editor conjure.editor 16 | uuid conjure.uuid 17 | ll conjure.linked-list}}) 18 | 19 | ;; TODO Split up into multiple modules. 20 | ;; TODO Refreshing of namespaces. 21 | ;; TODO Test running. 22 | ;; TODO Handle stdin requests. 23 | 24 | (def buf-suffix ".cljc") 25 | (def context-pattern "[(]%s*ns%s*(.-)[%s){]") 26 | (def comment-prefix "; ") 27 | 28 | (def config 29 | {:debug? false 30 | :interrupt {:sample-limit 0.3} 31 | :mappings {:disconnect "cd" 32 | :connect-port-file "cf" 33 | 34 | :interrupt "ei" 35 | :last-exception "ex" 36 | :result-1 "e1" 37 | :result-2 "e2" 38 | :result-3 "e3" 39 | :view-source "es" 40 | 41 | :session-clone "sc" 42 | :session-fresh "sf" 43 | :session-close "sq" 44 | :session-close-all "sQ" 45 | :session-list "sl" 46 | :session-next "sn" 47 | :session-prev "sp" 48 | :session-select "ss" 49 | :session-type "st"}}) 50 | 51 | (defonce- state 52 | {:loaded? false 53 | :conn nil}) 54 | 55 | (defonce- bs (bencode-stream.new)) 56 | 57 | (defn- display [lines opts] 58 | (lang.with-filetype :clojure log.append lines opts)) 59 | 60 | (defn- with-conn-or-warn [f] 61 | (let [conn (a.get state :conn)] 62 | (if conn 63 | (f conn) 64 | (display ["; No connection"])))) 65 | 66 | (defn- display-conn-status [status] 67 | (with-conn-or-warn 68 | (fn [conn] 69 | (display [(.. "; " conn.host ":" conn.port " (" status ")")] 70 | {:break? true})))) 71 | 72 | (defn- dbg [desc data] 73 | (when config.debug? 74 | (display (a.concat 75 | [(.. "; debug " desc)] 76 | (text.split-lines (view.serialise data))))) 77 | data) 78 | 79 | (defn- send [msg cb] 80 | (let [conn (a.get state :conn)] 81 | (when conn 82 | (let [msg-id (uuid.v4)] 83 | (a.assoc msg :id msg-id) 84 | (dbg "->" msg) 85 | (a.assoc-in conn [:msgs msg-id] 86 | {:msg msg 87 | :cb (or cb (fn [])) 88 | :sent-at (os.time)}) 89 | (conn.sock:write (bencode.encode msg)) 90 | nil)))) 91 | 92 | (defn- status= [msg state] 93 | (and msg msg.status (a.some #(= state $1) msg.status))) 94 | 95 | (defn- with-all-msgs-fn [cb] 96 | (let [acc []] 97 | (fn [msg] 98 | (table.insert acc msg) 99 | (when (status= msg :done) 100 | (cb acc))))) 101 | 102 | (defn disconnect [] 103 | (with-conn-or-warn 104 | (fn [conn] 105 | (when (not (conn.sock:is_closing)) 106 | (conn.sock:read_stop) 107 | (conn.sock:shutdown) 108 | (conn.sock:close)) 109 | (display-conn-status :disconnected) 110 | (a.assoc state :conn nil)))) 111 | 112 | (defn- display-result [opts resp] 113 | (let [lines (if 114 | resp.out (text.prefixed-lines resp.out "; (out) ") 115 | resp.err (text.prefixed-lines resp.err "; (err) ") 116 | resp.value (text.split-lines resp.value) 117 | nil)] 118 | (display lines))) 119 | 120 | (defn- assume-session [session] 121 | (a.assoc-in state [:conn :session] session) 122 | (display [(.. "; Assumed session: " session)] 123 | {:break? true})) 124 | 125 | (defn- clone-session [session] 126 | (send 127 | {:op :clone 128 | :session session} 129 | (with-all-msgs-fn 130 | (fn [msgs] 131 | (assume-session (a.get (a.last msgs) :new-session)))))) 132 | 133 | (defn- with-sessions [cb] 134 | (with-conn-or-warn 135 | (fn [_] 136 | (send 137 | {:op :ls-sessions} 138 | (fn [msg] 139 | (let [sessions (->> (a.get msg :sessions) 140 | (a.filter 141 | (fn [session] 142 | (not= msg.session session))))] 143 | (table.sort sessions) 144 | (cb sessions))))))) 145 | 146 | (defn- eval-str-raw [opts cb] 147 | (with-conn-or-warn 148 | (fn [_] 149 | (send 150 | {:op :eval 151 | :code opts.code 152 | :file opts.file-path 153 | :line (a.get-in opts [:range :start 1]) 154 | :column (-?> (a.get-in opts [:range :start 2]) (a.inc)) 155 | :session (a.get-in state [:conn :session])} 156 | cb)))) 157 | 158 | (defn display-session-type [] 159 | (eval-str-raw 160 | {:code (.. "#?(" 161 | (str.join 162 | " " 163 | [":clj 'Clojure" 164 | ":cljs 'ClojureScript" 165 | ":cljr 'ClojureCLR" 166 | ":default 'Unknown"]) 167 | ")")} 168 | (with-all-msgs-fn 169 | (fn [msgs] 170 | (display [(.. "; Session type: " (a.get (a.first msgs) :value))] 171 | {:break? true}))))) 172 | 173 | (defn- assume-or-create-session [] 174 | (with-sessions 175 | (fn [sessions] 176 | (if (a.empty? sessions) 177 | (clone-session) 178 | (assume-session (a.first sessions)))))) 179 | 180 | (defn- handle-read-fn [] 181 | (vim.schedule_wrap 182 | (fn [err chunk] 183 | (let [conn (a.get state :conn)] 184 | (if 185 | err (display-conn-status err) 186 | (not chunk) (disconnect) 187 | (->> (bencode-stream.decode-all bs chunk) 188 | (a.run! 189 | (fn [msg] 190 | (dbg "<-" msg) 191 | (let [cb (a.get-in conn [:msgs msg.id :cb] #(display-result nil $1)) 192 | (ok? err) (pcall cb msg)] 193 | (when (not ok?) 194 | (display [(.. "; conjure.lang.clojure-nrepl error: " err)])) 195 | (when (status= msg :unknown-session) 196 | (display ["; Unknown session, correcting"]) 197 | (assume-or-create-session)) 198 | (when (status= msg :done) 199 | (a.assoc-in conn [:msgs msg.id] nil))))))))))) 200 | 201 | (defn- handle-connect-fn [] 202 | (vim.schedule_wrap 203 | (fn [err] 204 | (let [conn (a.get state :conn)] 205 | (if err 206 | (do 207 | (display-conn-status err) 208 | (disconnect)) 209 | 210 | (do 211 | (conn.sock:read_start (handle-read-fn)) 212 | (display-conn-status :connected) 213 | (assume-or-create-session))))))) 214 | 215 | (defn connect [{: host : port}] 216 | (let [conn {:sock (vim.loop.new_tcp) 217 | :host host 218 | :port port 219 | :msgs {} 220 | :session nil}] 221 | 222 | (when (a.get state :conn) 223 | (disconnect)) 224 | 225 | (a.assoc state :conn conn) 226 | (conn.sock:connect host port (handle-connect-fn)))) 227 | 228 | (defn connect-port-file [] 229 | (let [port (-?> (a.slurp ".nrepl-port") (tonumber))] 230 | (if port 231 | (connect 232 | {:host "127.0.0.1" 233 | :port port}) 234 | (display ["; No .nrepl-port file found"])))) 235 | 236 | (defn eval-str [opts] 237 | (with-conn-or-warn 238 | (fn [_] 239 | (let [context (a.get opts :context)] 240 | (eval-str-raw 241 | {:code (.. "(do " 242 | (if context 243 | (.. "(in-ns '" context ")") 244 | "(in-ns #?(:clj 'user, :cljs 'cljs.user))") 245 | " *1)")} 246 | (fn []))) 247 | (eval-str-raw opts (or opts.cb #(display-result opts $1)))))) 248 | 249 | (defn doc-str [opts] 250 | (eval-str 251 | (a.merge 252 | opts 253 | {:code (.. "(do (require 'clojure.repl)" 254 | " (clojure.repl/doc " opts.code "))") 255 | :cb (with-all-msgs-fn 256 | (fn [msgs] 257 | (-> msgs 258 | (->> (a.map #(a.get $1 :out)) 259 | (a.filter a.string?) 260 | (a.rest) 261 | (str.join "\n")) 262 | (text.prefixed-lines "; ") 263 | (display))))}))) 264 | 265 | (defn- jar->zip [path] 266 | (if (text.starts-with path "jar:file:") 267 | (string.gsub path "^jar:file:(.+)!/?(.+)$" 268 | (fn [zip file] 269 | (.. "zipfile:" zip "::" file))) 270 | path)) 271 | 272 | (defn def-str [opts] 273 | (eval-str 274 | (a.merge 275 | opts 276 | {:code (.. "(mapv #(% (meta #'" opts.code ")) 277 | [(comp #(.toString %) 278 | (some-fn (comp #?(:clj clojure.java.io/resource :cljs identity) 279 | :file) :file)) 280 | :line :column])") 281 | :cb (with-all-msgs-fn 282 | (fn [msgs] 283 | (let [val (a.get (a.first msgs) :value) 284 | (ok? res) (when val 285 | (eval.str val))] 286 | (if ok? 287 | (let [[path line column] res] 288 | (editor.go-to (jar->zip path) line column)) 289 | (display ["; Couldn't find definition."])))))}))) 290 | 291 | (defn eval-file [opts] 292 | (eval-str-raw 293 | (a.assoc opts :code (.. "(load-file \"" opts.file-path "\")")) 294 | #(display-result opts $1))) 295 | 296 | (defn interrupt [] 297 | (with-conn-or-warn 298 | (fn [conn] 299 | (let [msgs (->> (a.vals conn.msgs) 300 | (a.filter 301 | (fn [msg] 302 | (= :eval msg.msg.op))))] 303 | (if (a.empty? msgs) 304 | (display ["; Nothing to interrupt"] {:break? true}) 305 | (do 306 | (table.sort 307 | msgs 308 | (fn [a b] 309 | (< a.sent-at b.sent-at))) 310 | (let [oldest (a.first msgs)] 311 | (send {:op :interrupt 312 | :id oldest.msg.id 313 | :session oldest.msg.session}) 314 | (display 315 | [(.. "; Interrupted: " 316 | (text.left-sample 317 | oldest.msg.code 318 | (editor.percent-width 319 | config.interrupt.sample-limit)))] 320 | {:break? true})))))))) 321 | 322 | (defn- eval-str-fn [code] 323 | (fn [] 324 | (nvim.ex.ConjureEval code))) 325 | 326 | (def last-exception (eval-str-fn "*e")) 327 | (def result-1 (eval-str-fn "*1")) 328 | (def result-2 (eval-str-fn "*2")) 329 | (def result-3 (eval-str-fn "*3")) 330 | 331 | (defn view-source [] 332 | (let [word (a.get (extract.word) :content)] 333 | (when (not (a.empty? word)) 334 | (display [(.. "; source (word): " word)] {:break? true}) 335 | (eval-str 336 | {:code (.. "(do (require 'clojure.repl)" 337 | "(clojure.repl/source " word "))") 338 | :context (extract.context) 339 | :cb (with-all-msgs-fn 340 | (fn [msgs] 341 | (let [source (->> msgs 342 | (a.map #(a.get $1 :out)) 343 | (a.filter a.string?) 344 | (str.join "\n"))] 345 | (display 346 | (text.split-lines 347 | (if (= "Source not found\n" source) 348 | (.. "; " source) 349 | source))))))})))) 350 | 351 | (defn clone-current-session [] 352 | (with-conn-or-warn 353 | (fn [conn] 354 | (clone-session (a.get conn :session))))) 355 | 356 | (defn clone-fresh-session [] 357 | (with-conn-or-warn 358 | (fn [conn] 359 | (clone-session)))) 360 | 361 | (defn- close-session [session cb] 362 | (send {:op :close :session session} cb)) 363 | 364 | (defn close-current-session [] 365 | (with-conn-or-warn 366 | (fn [conn] 367 | (let [session (a.get conn :session)] 368 | (a.assoc conn :session nil) 369 | (display [(.. "; Closed current session: " session)] 370 | {:break? true}) 371 | (close-session session assume-or-create-session))))) 372 | 373 | (defn- display-given-sessions [sessions cb] 374 | (let [current (a.get-in state [:conn :session])] 375 | (display (a.concat [(.. "; Sessions (" (a.count sessions) "):")] 376 | (a.map-indexed (fn [[idx session]] 377 | (.. "; " idx " - " session 378 | (if (= current session) 379 | " (current)" 380 | ""))) 381 | sessions)) 382 | {:break? true}) 383 | (when cb 384 | (cb sessions)))) 385 | 386 | (defn display-sessions [cb] 387 | (with-sessions 388 | (fn [sessions] 389 | (display-given-sessions sessions cb)))) 390 | 391 | (defn close-all-sessions [] 392 | (with-sessions 393 | (fn [sessions] 394 | (a.run! close-session sessions) 395 | (display [(.. "; Closed all sessions (" (a.count sessions)")")] 396 | {:break? true}) 397 | (clone-session)))) 398 | 399 | (defn- cycle-session [f] 400 | (with-conn-or-warn 401 | (fn [conn] 402 | (with-sessions 403 | (fn [sessions] 404 | (if (= 1 (a.count sessions)) 405 | (display ["; No other sessions"] {:break? true}) 406 | (let [session (a.get conn :session)] 407 | (assume-session (->> sessions 408 | (ll.create) 409 | (ll.cycle) 410 | (ll.until #(f session $1)) 411 | (ll.val)))))))))) 412 | 413 | (defn next-session [] 414 | (cycle-session 415 | (fn [current node] 416 | (= current (->> node (ll.prev) (ll.val)))))) 417 | 418 | (defn prev-session [] 419 | (cycle-session 420 | (fn [current node] 421 | (= current (->> node (ll.next) (ll.val)))))) 422 | 423 | (defn select-session-interactive [] 424 | (with-sessions 425 | (fn [sessions] 426 | (if (= 1 (a.count sessions)) 427 | (display ["; No other sessions"] {:break? true}) 428 | (display-given-sessions 429 | sessions 430 | (fn [] 431 | (nvim.ex.redraw_) 432 | (let [n (nvim.fn.str2nr (extract.input "Session number: "))] 433 | (if (<= 1 n (a.count sessions)) 434 | (assume-session (a.get sessions n)) 435 | (display ["; Invalid session number."]))))))))) 436 | 437 | (defn on-filetype [] 438 | (mapping.buf :n config.mappings.disconnect 439 | :conjure.lang.clojure-nrepl :disconnect) 440 | (mapping.buf :n config.mappings.connect-port-file 441 | :conjure.lang.clojure-nrepl :connect-port-file) 442 | (mapping.buf :n config.mappings.interrupt 443 | :conjure.lang.clojure-nrepl :interrupt) 444 | 445 | (mapping.buf :n config.mappings.last-exception 446 | :conjure.lang.clojure-nrepl :last-exception) 447 | (mapping.buf :n config.mappings.result-1 :conjure.lang.clojure-nrepl :result-1) 448 | (mapping.buf :n config.mappings.result-2 :conjure.lang.clojure-nrepl :result-2) 449 | (mapping.buf :n config.mappings.result-3 :conjure.lang.clojure-nrepl :result-3) 450 | (mapping.buf :n config.mappings.view-source :conjure.lang.clojure-nrepl :view-source) 451 | 452 | (mapping.buf :n config.mappings.session-clone 453 | :conjure.lang.clojure-nrepl :clone-current-session) 454 | (mapping.buf :n config.mappings.session-fresh 455 | :conjure.lang.clojure-nrepl :clone-fresh-session) 456 | (mapping.buf :n config.mappings.session-close 457 | :conjure.lang.clojure-nrepl :close-current-session) 458 | (mapping.buf :n config.mappings.session-close-all 459 | :conjure.lang.clojure-nrepl :close-all-sessions) 460 | (mapping.buf :n config.mappings.session-list 461 | :conjure.lang.clojure-nrepl :display-sessions) 462 | (mapping.buf :n config.mappings.session-next 463 | :conjure.lang.clojure-nrepl :next-session) 464 | (mapping.buf :n config.mappings.session-prev 465 | :conjure.lang.clojure-nrepl :prev-session) 466 | (mapping.buf :n config.mappings.session-select 467 | :conjure.lang.clojure-nrepl :select-session-interactive) 468 | (mapping.buf :n config.mappings.session-type 469 | :conjure.lang.clojure-nrepl :display-session-type)) 470 | 471 | (when (not state.loaded?) 472 | (a.assoc state :loaded? true) 473 | (vim.schedule 474 | (fn [] 475 | (nvim.ex.augroup :conjure_clojure_nrepl_cleanup) 476 | (nvim.ex.autocmd_) 477 | (nvim.ex.autocmd 478 | "VimLeavePre *" 479 | (bridge.viml->lua :conjure.lang.clojure-nrepl :disconnect {})) 480 | (nvim.ex.augroup :END) 481 | 482 | (connect-port-file)))) 483 | -------------------------------------------------------------------------------- /lua/conjure/aniseed/core.lua: -------------------------------------------------------------------------------- 1 | local _0_0 = nil 2 | do 3 | local name_23_0_ = "conjure.aniseed.core" 4 | local loaded_23_0_ = package.loaded[name_23_0_] 5 | local module_23_0_ = nil 6 | if ("table" == type(loaded_23_0_)) then 7 | module_23_0_ = loaded_23_0_ 8 | else 9 | module_23_0_ = {} 10 | end 11 | module_23_0_["aniseed/module"] = name_23_0_ 12 | module_23_0_["aniseed/locals"] = (module_23_0_["aniseed/locals"] or {}) 13 | module_23_0_["aniseed/local-fns"] = (module_23_0_["aniseed/local-fns"] or {}) 14 | package.loaded[name_23_0_] = module_23_0_ 15 | _0_0 = module_23_0_ 16 | end 17 | local function _1_(...) 18 | _0_0["aniseed/local-fns"] = {require = {view = "conjure.aniseed.view"}} 19 | return {require("conjure.aniseed.view")} 20 | end 21 | local _2_ = _1_(...) 22 | local view = _2_[1] 23 | do local _ = ({nil, _0_0, nil})[2] end 24 | local string_3f = nil 25 | do 26 | local v_23_0_ = nil 27 | do 28 | local v_23_0_0 = nil 29 | local function string_3f0(x) 30 | return ("string" == type(x)) 31 | end 32 | v_23_0_0 = string_3f0 33 | _0_0["string?"] = v_23_0_0 34 | v_23_0_ = v_23_0_0 35 | end 36 | _0_0["aniseed/locals"]["string?"] = v_23_0_ 37 | string_3f = v_23_0_ 38 | end 39 | local nil_3f = nil 40 | do 41 | local v_23_0_ = nil 42 | do 43 | local v_23_0_0 = nil 44 | local function nil_3f0(x) 45 | return (nil == x) 46 | end 47 | v_23_0_0 = nil_3f0 48 | _0_0["nil?"] = v_23_0_0 49 | v_23_0_ = v_23_0_0 50 | end 51 | _0_0["aniseed/locals"]["nil?"] = v_23_0_ 52 | nil_3f = v_23_0_ 53 | end 54 | local table_3f = nil 55 | do 56 | local v_23_0_ = nil 57 | do 58 | local v_23_0_0 = nil 59 | local function table_3f0(x) 60 | return ("table" == type(x)) 61 | end 62 | v_23_0_0 = table_3f0 63 | _0_0["table?"] = v_23_0_0 64 | v_23_0_ = v_23_0_0 65 | end 66 | _0_0["aniseed/locals"]["table?"] = v_23_0_ 67 | table_3f = v_23_0_ 68 | end 69 | local count = nil 70 | do 71 | local v_23_0_ = nil 72 | do 73 | local v_23_0_0 = nil 74 | local function count0(xs) 75 | if table_3f(xs) then 76 | return table.maxn(xs) 77 | elseif not xs then 78 | return 0 79 | else 80 | return #xs 81 | end 82 | end 83 | v_23_0_0 = count0 84 | _0_0["count"] = v_23_0_0 85 | v_23_0_ = v_23_0_0 86 | end 87 | _0_0["aniseed/locals"]["count"] = v_23_0_ 88 | count = v_23_0_ 89 | end 90 | local empty_3f = nil 91 | do 92 | local v_23_0_ = nil 93 | do 94 | local v_23_0_0 = nil 95 | local function empty_3f0(xs) 96 | return (0 == count(xs)) 97 | end 98 | v_23_0_0 = empty_3f0 99 | _0_0["empty?"] = v_23_0_0 100 | v_23_0_ = v_23_0_0 101 | end 102 | _0_0["aniseed/locals"]["empty?"] = v_23_0_ 103 | empty_3f = v_23_0_ 104 | end 105 | local first = nil 106 | do 107 | local v_23_0_ = nil 108 | do 109 | local v_23_0_0 = nil 110 | local function first0(xs) 111 | if xs then 112 | return xs[1] 113 | end 114 | end 115 | v_23_0_0 = first0 116 | _0_0["first"] = v_23_0_0 117 | v_23_0_ = v_23_0_0 118 | end 119 | _0_0["aniseed/locals"]["first"] = v_23_0_ 120 | first = v_23_0_ 121 | end 122 | local second = nil 123 | do 124 | local v_23_0_ = nil 125 | do 126 | local v_23_0_0 = nil 127 | local function second0(xs) 128 | if xs then 129 | return xs[2] 130 | end 131 | end 132 | v_23_0_0 = second0 133 | _0_0["second"] = v_23_0_0 134 | v_23_0_ = v_23_0_0 135 | end 136 | _0_0["aniseed/locals"]["second"] = v_23_0_ 137 | second = v_23_0_ 138 | end 139 | local last = nil 140 | do 141 | local v_23_0_ = nil 142 | do 143 | local v_23_0_0 = nil 144 | local function last0(xs) 145 | if xs then 146 | return xs[count(xs)] 147 | end 148 | end 149 | v_23_0_0 = last0 150 | _0_0["last"] = v_23_0_0 151 | v_23_0_ = v_23_0_0 152 | end 153 | _0_0["aniseed/locals"]["last"] = v_23_0_ 154 | last = v_23_0_ 155 | end 156 | local inc = nil 157 | do 158 | local v_23_0_ = nil 159 | do 160 | local v_23_0_0 = nil 161 | local function inc0(n) 162 | return (n + 1) 163 | end 164 | v_23_0_0 = inc0 165 | _0_0["inc"] = v_23_0_0 166 | v_23_0_ = v_23_0_0 167 | end 168 | _0_0["aniseed/locals"]["inc"] = v_23_0_ 169 | inc = v_23_0_ 170 | end 171 | local dec = nil 172 | do 173 | local v_23_0_ = nil 174 | do 175 | local v_23_0_0 = nil 176 | local function dec0(n) 177 | return (n - 1) 178 | end 179 | v_23_0_0 = dec0 180 | _0_0["dec"] = v_23_0_0 181 | v_23_0_ = v_23_0_0 182 | end 183 | _0_0["aniseed/locals"]["dec"] = v_23_0_ 184 | dec = v_23_0_ 185 | end 186 | local keys = nil 187 | do 188 | local v_23_0_ = nil 189 | do 190 | local v_23_0_0 = nil 191 | local function keys0(t) 192 | local result = {} 193 | if t then 194 | for k, _ in pairs(t) do 195 | table.insert(result, k) 196 | end 197 | end 198 | return result 199 | end 200 | v_23_0_0 = keys0 201 | _0_0["keys"] = v_23_0_0 202 | v_23_0_ = v_23_0_0 203 | end 204 | _0_0["aniseed/locals"]["keys"] = v_23_0_ 205 | keys = v_23_0_ 206 | end 207 | local vals = nil 208 | do 209 | local v_23_0_ = nil 210 | do 211 | local v_23_0_0 = nil 212 | local function vals0(t) 213 | local result = {} 214 | if t then 215 | for _, v in pairs(t) do 216 | table.insert(result, v) 217 | end 218 | end 219 | return result 220 | end 221 | v_23_0_0 = vals0 222 | _0_0["vals"] = v_23_0_0 223 | v_23_0_ = v_23_0_0 224 | end 225 | _0_0["aniseed/locals"]["vals"] = v_23_0_ 226 | vals = v_23_0_ 227 | end 228 | local kv_pairs = nil 229 | do 230 | local v_23_0_ = nil 231 | do 232 | local v_23_0_0 = nil 233 | local function kv_pairs0(t) 234 | local result = {} 235 | if t then 236 | for k, v in pairs(t) do 237 | table.insert(result, {k, v}) 238 | end 239 | end 240 | return result 241 | end 242 | v_23_0_0 = kv_pairs0 243 | _0_0["kv-pairs"] = v_23_0_0 244 | v_23_0_ = v_23_0_0 245 | end 246 | _0_0["aniseed/locals"]["kv-pairs"] = v_23_0_ 247 | kv_pairs = v_23_0_ 248 | end 249 | local update = nil 250 | do 251 | local v_23_0_ = nil 252 | do 253 | local v_23_0_0 = nil 254 | local function update0(tbl, k, f) 255 | tbl[k] = f(tbl[k]) 256 | return tbl 257 | end 258 | v_23_0_0 = update0 259 | _0_0["update"] = v_23_0_0 260 | v_23_0_ = v_23_0_0 261 | end 262 | _0_0["aniseed/locals"]["update"] = v_23_0_ 263 | update = v_23_0_ 264 | end 265 | local run_21 = nil 266 | do 267 | local v_23_0_ = nil 268 | do 269 | local v_23_0_0 = nil 270 | local function run_210(f, xs) 271 | if xs then 272 | local nxs = count(xs) 273 | if (nxs > 0) then 274 | for i = 1, nxs do 275 | f(xs[i]) 276 | end 277 | return nil 278 | end 279 | end 280 | end 281 | v_23_0_0 = run_210 282 | _0_0["run!"] = v_23_0_0 283 | v_23_0_ = v_23_0_0 284 | end 285 | _0_0["aniseed/locals"]["run!"] = v_23_0_ 286 | run_21 = v_23_0_ 287 | end 288 | local filter = nil 289 | do 290 | local v_23_0_ = nil 291 | do 292 | local v_23_0_0 = nil 293 | local function filter0(f, xs) 294 | local result = {} 295 | local function _3_(x) 296 | if f(x) then 297 | return table.insert(result, x) 298 | end 299 | end 300 | run_21(_3_, xs) 301 | return result 302 | end 303 | v_23_0_0 = filter0 304 | _0_0["filter"] = v_23_0_0 305 | v_23_0_ = v_23_0_0 306 | end 307 | _0_0["aniseed/locals"]["filter"] = v_23_0_ 308 | filter = v_23_0_ 309 | end 310 | local map = nil 311 | do 312 | local v_23_0_ = nil 313 | do 314 | local v_23_0_0 = nil 315 | local function map0(f, xs) 316 | local result = {} 317 | local function _3_(x) 318 | local mapped = f(x) 319 | local function _4_() 320 | if (0 == select("#", mapped)) then 321 | return nil 322 | else 323 | return mapped 324 | end 325 | end 326 | return table.insert(result, _4_()) 327 | end 328 | run_21(_3_, xs) 329 | return result 330 | end 331 | v_23_0_0 = map0 332 | _0_0["map"] = v_23_0_0 333 | v_23_0_ = v_23_0_0 334 | end 335 | _0_0["aniseed/locals"]["map"] = v_23_0_ 336 | map = v_23_0_ 337 | end 338 | local map_indexed = nil 339 | do 340 | local v_23_0_ = nil 341 | do 342 | local v_23_0_0 = nil 343 | local function map_indexed0(f, xs) 344 | return map(f, kv_pairs(xs)) 345 | end 346 | v_23_0_0 = map_indexed0 347 | _0_0["map-indexed"] = v_23_0_0 348 | v_23_0_ = v_23_0_0 349 | end 350 | _0_0["aniseed/locals"]["map-indexed"] = v_23_0_ 351 | map_indexed = v_23_0_ 352 | end 353 | local identity = nil 354 | do 355 | local v_23_0_ = nil 356 | do 357 | local v_23_0_0 = nil 358 | local function identity0(x) 359 | return x 360 | end 361 | v_23_0_0 = identity0 362 | _0_0["identity"] = v_23_0_0 363 | v_23_0_ = v_23_0_0 364 | end 365 | _0_0["aniseed/locals"]["identity"] = v_23_0_ 366 | identity = v_23_0_ 367 | end 368 | local reduce = nil 369 | do 370 | local v_23_0_ = nil 371 | do 372 | local v_23_0_0 = nil 373 | local function reduce0(f, init, xs) 374 | local result = init 375 | local function _3_(x) 376 | result = f(result, x) 377 | return nil 378 | end 379 | run_21(_3_, xs) 380 | return result 381 | end 382 | v_23_0_0 = reduce0 383 | _0_0["reduce"] = v_23_0_0 384 | v_23_0_ = v_23_0_0 385 | end 386 | _0_0["aniseed/locals"]["reduce"] = v_23_0_ 387 | reduce = v_23_0_ 388 | end 389 | local some = nil 390 | do 391 | local v_23_0_ = nil 392 | do 393 | local v_23_0_0 = nil 394 | local function some0(f, xs) 395 | local result = nil 396 | local n = 1 397 | while (not result and (n <= count(xs))) do 398 | local candidate = f(xs[n]) 399 | if candidate then 400 | result = candidate 401 | end 402 | n = inc(n) 403 | end 404 | return result 405 | end 406 | v_23_0_0 = some0 407 | _0_0["some"] = v_23_0_0 408 | v_23_0_ = v_23_0_0 409 | end 410 | _0_0["aniseed/locals"]["some"] = v_23_0_ 411 | some = v_23_0_ 412 | end 413 | local butlast = nil 414 | do 415 | local v_23_0_ = nil 416 | do 417 | local v_23_0_0 = nil 418 | local function butlast0(xs) 419 | local total = count(xs) 420 | local function _3_(_4_0) 421 | local _5_ = _4_0 422 | local n = _5_[1] 423 | local v = _5_[2] 424 | return (n ~= total) 425 | end 426 | return map(second, filter(_3_, kv_pairs(xs))) 427 | end 428 | v_23_0_0 = butlast0 429 | _0_0["butlast"] = v_23_0_0 430 | v_23_0_ = v_23_0_0 431 | end 432 | _0_0["aniseed/locals"]["butlast"] = v_23_0_ 433 | butlast = v_23_0_ 434 | end 435 | local rest = nil 436 | do 437 | local v_23_0_ = nil 438 | do 439 | local v_23_0_0 = nil 440 | local function rest0(xs) 441 | local function _3_(_4_0) 442 | local _5_ = _4_0 443 | local n = _5_[1] 444 | local v = _5_[2] 445 | return (n ~= 1) 446 | end 447 | return map(second, filter(_3_, kv_pairs(xs))) 448 | end 449 | v_23_0_0 = rest0 450 | _0_0["rest"] = v_23_0_0 451 | v_23_0_ = v_23_0_0 452 | end 453 | _0_0["aniseed/locals"]["rest"] = v_23_0_ 454 | rest = v_23_0_ 455 | end 456 | local concat = nil 457 | do 458 | local v_23_0_ = nil 459 | do 460 | local v_23_0_0 = nil 461 | local function concat0(...) 462 | local result = {} 463 | local function _3_(xs) 464 | local function _4_(x) 465 | return table.insert(result, x) 466 | end 467 | return run_21(_4_, xs) 468 | end 469 | run_21(_3_, {...}) 470 | return result 471 | end 472 | v_23_0_0 = concat0 473 | _0_0["concat"] = v_23_0_0 474 | v_23_0_ = v_23_0_0 475 | end 476 | _0_0["aniseed/locals"]["concat"] = v_23_0_ 477 | concat = v_23_0_ 478 | end 479 | local mapcat = nil 480 | do 481 | local v_23_0_ = nil 482 | do 483 | local v_23_0_0 = nil 484 | local function mapcat0(f, xs) 485 | return concat(unpack(map(f, xs))) 486 | end 487 | v_23_0_0 = mapcat0 488 | _0_0["mapcat"] = v_23_0_0 489 | v_23_0_ = v_23_0_0 490 | end 491 | _0_0["aniseed/locals"]["mapcat"] = v_23_0_ 492 | mapcat = v_23_0_ 493 | end 494 | local _2aprinter_2a = nil 495 | do 496 | local v_23_0_ = print 497 | _0_0["aniseed/locals"]["*printer*"] = v_23_0_ 498 | _2aprinter_2a = v_23_0_ 499 | end 500 | local with_out_str = nil 501 | do 502 | local v_23_0_ = nil 503 | do 504 | local v_23_0_0 = nil 505 | local function with_out_str0(f) 506 | local acc = "" 507 | local function _3_(_241) 508 | acc = (acc .. _241 .. "\n") 509 | return nil 510 | end 511 | _2aprinter_2a = _3_ 512 | do 513 | local ok_3f, result = pcall(f) 514 | _2aprinter_2a = print 515 | if not ok_3f then 516 | error(result) 517 | end 518 | end 519 | return acc 520 | end 521 | v_23_0_0 = with_out_str0 522 | _0_0["with-out-str"] = v_23_0_0 523 | v_23_0_ = v_23_0_0 524 | end 525 | _0_0["aniseed/locals"]["with-out-str"] = v_23_0_ 526 | with_out_str = v_23_0_ 527 | end 528 | local pr_str = nil 529 | do 530 | local v_23_0_ = nil 531 | do 532 | local v_23_0_0 = nil 533 | local function pr_str0(...) 534 | local s = nil 535 | local function _3_(x) 536 | return view.serialise(x, {["one-line"] = true}) 537 | end 538 | s = table.concat(map(_3_, {...}), " ") 539 | if (not s or ("" == s)) then 540 | return "nil" 541 | else 542 | return s 543 | end 544 | end 545 | v_23_0_0 = pr_str0 546 | _0_0["pr-str"] = v_23_0_0 547 | v_23_0_ = v_23_0_0 548 | end 549 | _0_0["aniseed/locals"]["pr-str"] = v_23_0_ 550 | pr_str = v_23_0_ 551 | end 552 | local println = nil 553 | do 554 | local v_23_0_ = nil 555 | do 556 | local v_23_0_0 = nil 557 | local function println0(...) 558 | local function _3_(acc, s) 559 | return (acc .. s) 560 | end 561 | local function _4_(_5_0) 562 | local _6_ = _5_0 563 | local i = _6_[1] 564 | local s = _6_[2] 565 | if (1 == i) then 566 | return s 567 | else 568 | return (" " .. s) 569 | end 570 | end 571 | local function _6_(s) 572 | if string_3f(s) then 573 | return s 574 | else 575 | return pr_str(s) 576 | end 577 | end 578 | return _2aprinter_2a(reduce(_3_, "", map_indexed(_4_, map(_6_, {...})))) 579 | end 580 | v_23_0_0 = println0 581 | _0_0["println"] = v_23_0_0 582 | v_23_0_ = v_23_0_0 583 | end 584 | _0_0["aniseed/locals"]["println"] = v_23_0_ 585 | println = v_23_0_ 586 | end 587 | local pr = nil 588 | do 589 | local v_23_0_ = nil 590 | do 591 | local v_23_0_0 = nil 592 | local function pr0(...) 593 | return println(pr_str(...)) 594 | end 595 | v_23_0_0 = pr0 596 | _0_0["pr"] = v_23_0_0 597 | v_23_0_ = v_23_0_0 598 | end 599 | _0_0["aniseed/locals"]["pr"] = v_23_0_ 600 | pr = v_23_0_ 601 | end 602 | local slurp = nil 603 | do 604 | local v_23_0_ = nil 605 | do 606 | local v_23_0_0 = nil 607 | local function slurp0(path) 608 | local _3_0, _4_0 = io.open(path, "r") 609 | if ((_3_0 == nil) and (nil ~= _4_0)) then 610 | local msg = _4_0 611 | return println(("Could not open file: " .. msg)) 612 | elseif (nil ~= _3_0) then 613 | local f = _3_0 614 | do 615 | local content = f:read("*all") 616 | f:close() 617 | return content 618 | end 619 | end 620 | end 621 | v_23_0_0 = slurp0 622 | _0_0["slurp"] = v_23_0_0 623 | v_23_0_ = v_23_0_0 624 | end 625 | _0_0["aniseed/locals"]["slurp"] = v_23_0_ 626 | slurp = v_23_0_ 627 | end 628 | local spit = nil 629 | do 630 | local v_23_0_ = nil 631 | do 632 | local v_23_0_0 = nil 633 | local function spit0(path, content) 634 | local _3_0, _4_0 = io.open(path, "w") 635 | if ((_3_0 == nil) and (nil ~= _4_0)) then 636 | local msg = _4_0 637 | return println(("Could not open file: " .. msg)) 638 | elseif (nil ~= _3_0) then 639 | local f = _3_0 640 | do 641 | f:write(content) 642 | f:close() 643 | return nil 644 | end 645 | end 646 | end 647 | v_23_0_0 = spit0 648 | _0_0["spit"] = v_23_0_0 649 | v_23_0_ = v_23_0_0 650 | end 651 | _0_0["aniseed/locals"]["spit"] = v_23_0_ 652 | spit = v_23_0_ 653 | end 654 | local merge = nil 655 | do 656 | local v_23_0_ = nil 657 | do 658 | local v_23_0_0 = nil 659 | local function merge0(...) 660 | local function _3_(acc, m) 661 | if m then 662 | for k, v in pairs(m) do 663 | acc[k] = v 664 | end 665 | end 666 | return acc 667 | end 668 | return reduce(_3_, {}, {...}) 669 | end 670 | v_23_0_0 = merge0 671 | _0_0["merge"] = v_23_0_0 672 | v_23_0_ = v_23_0_0 673 | end 674 | _0_0["aniseed/locals"]["merge"] = v_23_0_ 675 | merge = v_23_0_ 676 | end 677 | local select_keys = nil 678 | do 679 | local v_23_0_ = nil 680 | do 681 | local v_23_0_0 = nil 682 | local function select_keys0(t, ks) 683 | if (t and ks) then 684 | local function _3_(acc, k) 685 | if k then 686 | acc[k] = t[k] 687 | end 688 | return acc 689 | end 690 | return reduce(_3_, {}, ks) 691 | else 692 | return {} 693 | end 694 | end 695 | v_23_0_0 = select_keys0 696 | _0_0["select-keys"] = v_23_0_0 697 | v_23_0_ = v_23_0_0 698 | end 699 | _0_0["aniseed/locals"]["select-keys"] = v_23_0_ 700 | select_keys = v_23_0_ 701 | end 702 | local get = nil 703 | do 704 | local v_23_0_ = nil 705 | do 706 | local v_23_0_0 = nil 707 | local function get0(t, k, d) 708 | local res = ((t and t[k]) or nil) 709 | if nil_3f(res) then 710 | return d 711 | else 712 | return res 713 | end 714 | end 715 | v_23_0_0 = get0 716 | _0_0["get"] = v_23_0_0 717 | v_23_0_ = v_23_0_0 718 | end 719 | _0_0["aniseed/locals"]["get"] = v_23_0_ 720 | get = v_23_0_ 721 | end 722 | local get_in = nil 723 | do 724 | local v_23_0_ = nil 725 | do 726 | local v_23_0_0 = nil 727 | local function get_in0(t, ks, d) 728 | local res = nil 729 | local function _3_(acc, k) 730 | if table_3f(acc) then 731 | return get(acc, k) 732 | end 733 | end 734 | res = reduce(_3_, t, ks) 735 | if nil_3f(res) then 736 | return d 737 | else 738 | return res 739 | end 740 | end 741 | v_23_0_0 = get_in0 742 | _0_0["get-in"] = v_23_0_0 743 | v_23_0_ = v_23_0_0 744 | end 745 | _0_0["aniseed/locals"]["get-in"] = v_23_0_ 746 | get_in = v_23_0_ 747 | end 748 | local assoc = nil 749 | do 750 | local v_23_0_ = nil 751 | do 752 | local v_23_0_0 = nil 753 | local function assoc0(t, k, v) 754 | local t0 = (t or {}) 755 | if not nil_3f(k) then 756 | t0[k] = v 757 | end 758 | return t0 759 | end 760 | v_23_0_0 = assoc0 761 | _0_0["assoc"] = v_23_0_0 762 | v_23_0_ = v_23_0_0 763 | end 764 | _0_0["aniseed/locals"]["assoc"] = v_23_0_ 765 | assoc = v_23_0_ 766 | end 767 | local assoc_in = nil 768 | do 769 | local v_23_0_ = nil 770 | do 771 | local v_23_0_0 = nil 772 | local function assoc_in0(t, ks, v) 773 | local path = butlast(ks) 774 | local final = last(ks) 775 | local t0 = (t or {}) 776 | local function _3_(acc, k) 777 | local step = get(acc, k) 778 | if nil_3f(step) then 779 | return get(assoc(acc, k, {}), k) 780 | else 781 | return step 782 | end 783 | end 784 | assoc(reduce(_3_, t0, path), final, v) 785 | return t0 786 | end 787 | v_23_0_0 = assoc_in0 788 | _0_0["assoc-in"] = v_23_0_0 789 | v_23_0_ = v_23_0_0 790 | end 791 | _0_0["aniseed/locals"]["assoc-in"] = v_23_0_ 792 | assoc_in = v_23_0_ 793 | end 794 | return nil 795 | --------------------------------------------------------------------------------