diff --git a/.gitignore b/.gitignore index 6912fef..85768b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ deps/ +.build/ +.clj-kondo/ +.lsp/ diff --git a/fnl/formedit/init.fnl b/fnl/formedit/init.fnl index 744bf96..c8337bf 100644 --- a/fnl/formedit/init.fnl +++ b/fnl/formedit/init.fnl @@ -2,8 +2,9 @@ (local notify (autoload :nfnl.notify)) (local ts (require :nvim-treesitter.ts_utils)) -; (local current-node (ts.get_node_at_cursor)) -; (local cursor_pos (vim.api.nvim_win_get_cursor 0)) +(local current-node (ts.get_node_at_cursor)) +; Cursor {row, col} (Zero indexed) +(local cursor_pos (vim.api.nvim_win_get_cursor 0)) (fn setup [] (notify.info :hello)) diff --git a/fnl/spec/init.fnl b/fnl/spec/init.fnl new file mode 100644 index 0000000..5f9095f --- /dev/null +++ b/fnl/spec/init.fnl @@ -0,0 +1,12 @@ +(vim.opt.runtimepath:append :./.build/dependencies/plenary.nvim) +(vim.opt.runtimepath:append :./.build/dependencies/nvim-treesitter) +(vim.opt.runtimepath:append :./.build/parsers) +(vim.opt.runtimepath:append ".") +(vim.cmd.runtime {1 :plugin/plenary.vim :bang true}) +(vim.cmd.runtime {1 :plugin/nvim-treesitter.lua :bang true}) +(set vim.o.swapfile false) +(set vim.bo.swapfile false) +((. (require :nvim-treesitter.configs) :setup) {:ensure_installed [:clojure] + :parser_install_dir (.. (vim.fn.getcwd) + :/.build/parsers) + :sync_install true}) diff --git a/fnl/spec/nfnl/cursor_spec.fnl b/fnl/spec/nfnl/cursor_spec.fnl new file mode 100644 index 0000000..8d8cf45 --- /dev/null +++ b/fnl/spec/nfnl/cursor_spec.fnl @@ -0,0 +1,15 @@ +(local {: describe : it} (require :plenary.busted)) +(local h (require :spec.nfnl.helper)) + +(describe "move cursor" + (fn [] + (it :forward + (fn [] + (h.setup {:content "(a)" :cursor [1 1]}) + (vim.api.nvim_win_set_cursor 0 [1 2]) + (h.expect {:content "(a)" :cursor [1 2]}))) + (it :back + (fn [] + (h.setup {:content "(a)" :cursor [1 2]}) + (vim.api.nvim_win_set_cursor 0 [1 1]) + (h.expect {:content "(a)" :cursor [1 1]}))))) diff --git a/fnl/spec/nfnl/example_spec.fnl b/fnl/spec/nfnl/example_spec.fnl deleted file mode 100644 index 5b7a038..0000000 --- a/fnl/spec/nfnl/example_spec.fnl +++ /dev/null @@ -1,12 +0,0 @@ -(local {: describe : it} (require :plenary.busted)) -(local assert (require :luassert.assert)) -(local core (require :nfnl.core)) - -(describe :first (fn [] - (it "gets the first value" - (fn [] - (assert.equals 1 (core.first [1 2 3 4 5])))) - (it "returns nil for empty lists or nil" - (fn [] - (assert.is_nil (core.first nil)) - (assert.is_nil (core.first [])))))) diff --git a/fnl/spec/nfnl/helper.fnl b/fnl/spec/nfnl/helper.fnl new file mode 100644 index 0000000..c69ad39 --- /dev/null +++ b/fnl/spec/nfnl/helper.fnl @@ -0,0 +1,16 @@ +(local assert (require :luassert.assert)) +(local core (require :formedit.nfnl.core)) + +(fn setup [{: cursor : content}] + (vim.api.nvim_buf_set_option 0 :filetype :clojure) + (vim.api.nvim_buf_set_lines 0 0 -1 true [content]) + (vim.api.nvim_win_set_cursor 0 cursor)) + +(fn expect [{: cursor : content}] + (when content + (assert.are.same content + (core.first (vim.api.nvim_buf_get_lines 0 0 -1 false)))) + (when cursor + (assert.are.same cursor (vim.api.nvim_win_get_cursor 0)))) + +{: setup : expect} diff --git a/lua/formedit/init.lua b/lua/formedit/init.lua index 048b4bc..3d4f9f8 100644 --- a/lua/formedit/init.lua +++ b/lua/formedit/init.lua @@ -3,6 +3,8 @@ local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local notify = autoload("nfnl.notify") local ts = require("nvim-treesitter.ts_utils") +local current_node = ts.get_node_at_cursor() +local cursor_pos = vim.api.nvim_win_get_cursor(0) local function setup() return notify.info("hello") end diff --git a/lua/spec/init.lua b/lua/spec/init.lua index a0a8115..f2811f3 100644 --- a/lua/spec/init.lua +++ b/lua/spec/init.lua @@ -1,16 +1,10 @@ -vim.opt.runtimepath:append("./.build/dependencies/plenary.nvim") -vim.opt.runtimepath:append("./.build/dependencies/nvim-treesitter") -vim.opt.runtimepath:append("./.build/parsers") -vim.opt.runtimepath:append(".") - -vim.cmd.runtime({ "plugin/plenary.vim", bang = true }) -vim.cmd.runtime({ "plugin/nvim-treesitter.lua", bang = true }) - +-- [nfnl] Compiled from fnl/spec/init.fnl by https://github.com/Olical/nfnl, do not edit. +do end (vim.opt.runtimepath):append("./.build/dependencies/plenary.nvim") +do end (vim.opt.runtimepath):append("./.build/dependencies/nvim-treesitter") +do end (vim.opt.runtimepath):append("./.build/parsers") +do end (vim.opt.runtimepath):append(".") +vim.cmd.runtime({"plugin/plenary.vim", bang = true}) +vim.cmd.runtime({"plugin/nvim-treesitter.lua", bang = true}) vim.o.swapfile = false vim.bo.swapfile = false - -require("nvim-treesitter.configs").setup({ - parser_install_dir = vim.fn.getcwd() .. "/.build/parsers", - ensure_installed = { "clojure" }, - sync_install = true, -}) +return (require("nvim-treesitter.configs")).setup({ensure_installed = {"clojure"}, parser_install_dir = (vim.fn.getcwd() .. "/.build/parsers"), sync_install = true}) diff --git a/lua/spec/nfnl/cursor_spec.lua b/lua/spec/nfnl/cursor_spec.lua new file mode 100644 index 0000000..dc0ae9d --- /dev/null +++ b/lua/spec/nfnl/cursor_spec.lua @@ -0,0 +1,20 @@ +-- [nfnl] Compiled from fnl/spec/nfnl/cursor_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local h = require("spec.nfnl.helper") +local function _2_() + local function _3_() + h.setup({content = "(a)", cursor = {1, 1}}) + vim.api.nvim_win_set_cursor(0, {1, 2}) + return h.expect({content = "(a)", cursor = {1, 2}}) + end + it("forward", _3_) + local function _4_() + h.setup({content = "(a)", cursor = {1, 2}}) + vim.api.nvim_win_set_cursor(0, {1, 1}) + return h.expect({content = "(a)", cursor = {1, 1}}) + end + return it("back", _4_) +end +return describe("move cursor", _2_) diff --git a/lua/spec/nfnl/example_spec.lua b/lua/spec/nfnl/example_spec.lua deleted file mode 100644 index 6c4c3d6..0000000 --- a/lua/spec/nfnl/example_spec.lua +++ /dev/null @@ -1,18 +0,0 @@ --- [nfnl] Compiled from fnl/spec/nfnl/example_spec.fnl by https://github.com/Olical/nfnl, do not edit. -local _local_1_ = require("plenary.busted") -local describe = _local_1_["describe"] -local it = _local_1_["it"] -local assert = require("luassert.assert") -local core = require("nfnl.core") -local function _2_() - local function _3_() - return assert.equals(1, core.first({1, 2, 3, 4, 5})) - end - it("gets the first value", _3_) - local function _4_() - assert.is_nil(core.first(nil)) - return assert.is_nil(core.first({})) - end - return it("returns nil for empty lists or nil", _4_) -end -return describe("first", _2_) diff --git a/lua/spec/nfnl/helper.lua b/lua/spec/nfnl/helper.lua new file mode 100644 index 0000000..1156294 --- /dev/null +++ b/lua/spec/nfnl/helper.lua @@ -0,0 +1,26 @@ +-- [nfnl] Compiled from fnl/spec/nfnl/helper.fnl by https://github.com/Olical/nfnl, do not edit. +local assert = require("luassert.assert") +local core = require("formedit.nfnl.core") +local function setup(_1_) + local _arg_2_ = _1_ + local cursor = _arg_2_["cursor"] + local content = _arg_2_["content"] + vim.api.nvim_buf_set_option(0, "filetype", "clojure") + vim.api.nvim_buf_set_lines(0, 0, -1, true, {content}) + return vim.api.nvim_win_set_cursor(0, cursor) +end +local function expect(_3_) + local _arg_4_ = _3_ + local cursor = _arg_4_["cursor"] + local content = _arg_4_["content"] + if content then + assert.are.same(content, core.first(vim.api.nvim_buf_get_lines(0, 0, -1, false))) + else + end + if cursor then + return assert.are.same(cursor, vim.api.nvim_win_get_cursor(0)) + else + return nil + end +end +return {setup = setup, expect = expect}