From 8ff882a9032ba86bfcc8b611904851cd0f622801 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Sat, 1 Feb 2025 02:29:18 -0800 Subject: [PATCH] feat: add fennel and test fennel configuration --- .nfnl.fnl | 32 ++++++++++++++++++++++++++++++++ flake.nix | 2 ++ flsproject.fnl | 1 + fnl/config/macros.fnl | 14 ++++++++++++++ fnl/keymaps.fnl | 41 +++++++++++++++++++++++++++++++++++++++++ lua/keymaps.lua | 30 +++++++++--------------------- lua/plugins/conform.lua | 1 + lua/plugins/lz-spec.lua | 1 + 8 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 .nfnl.fnl create mode 100644 flsproject.fnl create mode 100644 fnl/config/macros.fnl create mode 100644 fnl/keymaps.fnl diff --git a/.nfnl.fnl b/.nfnl.fnl new file mode 100644 index 0000000..fdc1458 --- /dev/null +++ b/.nfnl.fnl @@ -0,0 +1,32 @@ +{;; Enables verbose notifications from nfnl, including notifications about + ;; when it starts up and when it compiles successfully. Useful for debugging + ;; the plugin itself and checking that it's running when you expect it to. + :verbose true + ;; Passed to fennel.compileString when your code is compiled. + ;; See https://fennel-lang.org/api for more information. + :compiler-options {;; Disables ansi escape sequences in compiler output. + :error-pinpoint false + :compilerEnv _G} + ;; Warning! In reality these paths are absolute and set to the root directory + ;; of your project (where your .nfnl.fnl file is). This means even if you + ;; open a .fnl file from outside your project's cwd the compiler will still + ;; find your macro files. If you use relative paths like I'm demonstrating here + ;; then macros will only work if your cwd is in the project you're working on. + ;; They also use OS specific path separators, what you see below is just an example really. + ;; I'm not including nfnl's directory from your runtimepath, but it would be there by default. + ;; See :rtp-patterns below for more information on including other plugins in your path. + ;; String to set the compiler's fennel.path to before compilation. + :fennel-path "./?.fnl;./?/init.fnl;./fnl/?.fnl;./fnl/?/init.fnl" + ;; String to set the compiler's fennel.macro-path to before compilation. + :fennel-macro-path "./?.fnl;./?/init-macros.fnl;./?/init.fnl;./fnl/?.fnl;./fnl/?/init-macros.fnl;./fnl/?/init.fnl" + ;; A list of glob patterns (autocmd pattern syntax) of files that + ;; should be compiled. This is used as configuration for the BufWritePost + ;; autocmd, so it'll only apply to buffers you're interested in. + ;; Will use backslashes on Windows. + ;; Defaults to compiling all .fnl files, you may want to limit it to your fnl/ directory. + :source-file-patterns [:./fnl/.*.fnl :./fnl/*.fnl :./fnl/**/*.fnl :init.fnl] + ;; A function that is given the absolute path of a Fennel file and should return + ;; the equivalent Lua path, by default this will translate `fnl/foo/bar.fnl` to `lua/foo/bar.lua`. + ;; See the "Writing Lua elsewhere" tip below for an example function that writes to a sub directory. + ;:fnl-path->lua-path (fn [fnl-path] ...) + } diff --git a/flake.nix b/flake.nix index 4c38138..32ee818 100644 --- a/flake.nix +++ b/flake.nix @@ -106,6 +106,7 @@ p: (with p; [ lua + fennel c javascript typescript @@ -306,6 +307,7 @@ stylua fennel-ls fennel + fnlfmt ] ); }; diff --git a/flsproject.fnl b/flsproject.fnl new file mode 100644 index 0000000..8774ef3 --- /dev/null +++ b/flsproject.fnl @@ -0,0 +1 @@ +{:extra-globals :vim} diff --git a/fnl/config/macros.fnl b/fnl/config/macros.fnl new file mode 100644 index 0000000..f53371c --- /dev/null +++ b/fnl/config/macros.fnl @@ -0,0 +1,14 @@ +;; [nfnl-macro] + +(fn tx [& args] + "Mixed sequential and associative tables at compile time. Because the Neovim ecosystem loves them but Fennel has no neat way to express them (which I think is fine, I don't like the idea of them in general)." + (let [to-merge (when (table? (. args (length args))) + (table.remove args))] + (if to-merge + (do + (each [key value (pairs to-merge)] + (tset args key value)) + args) + args))) + +{: tx} diff --git a/fnl/keymaps.fnl b/fnl/keymaps.fnl new file mode 100644 index 0000000..4b0ef16 --- /dev/null +++ b/fnl/keymaps.fnl @@ -0,0 +1,41 @@ +;; Mostly remaps of existing keys. New keybinds are generally defined directly +;; in their plugin specs for `lz.n` +(set vim.g.mapleader " ") +(vim.keymap.set :n : :) +(vim.keymap.set :t : "") +(vim.keymap.set :n : :zz) +(vim.keymap.set :n : :zz) + +;; when searching, also center screen and reopen folds +(vim.keymap.set :n :n :nzzzv) +(vim.keymap.set :n :N :Nzzzv) + +;; The greatest remap of all time -- the primeagen +(vim.keymap.set [:n :v] :D "\"_D" + {:desc "same as D but send to black hole register"}) + +(vim.keymap.set [:n :v] :d "\"_d" + {:desc "same as `d` but send to black hole register"}) + +;; The real greatest remap(s) of all time -- me +(vim.keymap.set [:n :v] :y "\"+y" {:desc "yank to clipboard"}) +(vim.keymap.set [:n :v] :Y "\"+Y" + {:desc "yank rest of line to clipboard"}) + +(vim.keymap.set [:n :v] :p "\"+p" + {:desc "put after cursor from clipboard"}) + +(vim.keymap.set [:n :v] :P "\"+P" + {:desc "put before cursor from clipboard"}) + +;; lsp +(vim.keymap.set :n :cr vim.lsp.buf.rename) + +;; misc +(vim.keymap.set :v : :gv) +(vim.keymap.set :v : :gv) +(vim.keymap.set :v :g :ggv) +(vim.keymap.set :v :g :ggv) +(vim.keymap.set :i : (. (require :scripts.intellitab) :indent)) + +{} diff --git a/lua/keymaps.lua b/lua/keymaps.lua index f0572c3..b14694c 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -1,33 +1,21 @@ --- Mostly remaps of existing keys. New keybinds are generally defined directly --- in their plugin specs for `lz.n` - +-- [nfnl] Compiled from ./fnl/keymaps.fnl by https://github.com/Olical/nfnl, do not edit. vim.g.mapleader = " " vim.keymap.set("n", "", "") - vim.keymap.set("t", "", "") - vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "zz") - --- when searching, also center screen and reopen folds vim.keymap.set("n", "n", "nzzzv") vim.keymap.set("n", "N", "Nzzzv") - --- The greatest remap of all time -- the primeagen -vim.keymap.set({ "n", "v" }, "d", '"_d', { desc = "same as `d` but send to black hole register" }) -vim.keymap.set({ "n", "v" }, "D", '"_D', { desc = "same as `D` but send to black hole register" }) --- The real greatest remap(s) of all time -- me -vim.keymap.set({ "n", "v" }, "y", '"+y', { desc = "yank to clipboard" }) -vim.keymap.set({ "n", "v" }, "Y", '"+Y', { desc = "yank rest of line to clipboard" }) -vim.keymap.set({ "n", "v" }, "p", '"+p', { desc = "put after cursor from clipboard" }) -vim.keymap.set({ "n", "v" }, "P", '"+P', { desc = "put before cursor from clipboard" }) - --- Allow increment/decrement repeatedly in visual +vim.keymap.set({"n", "v"}, "D", "\"_D", {desc = "same as D but send to black hole register"}) +vim.keymap.set({"n", "v"}, "d", "\"_d", {desc = "same as `d` but send to black hole register"}) +vim.keymap.set({"n", "v"}, "y", "\"+y", {desc = "yank to clipboard"}) +vim.keymap.set({"n", "v"}, "Y", "\"+Y", {desc = "yank rest of line to clipboard"}) +vim.keymap.set({"n", "v"}, "p", "\"+p", {desc = "put after cursor from clipboard"}) +vim.keymap.set({"n", "v"}, "P", "\"+P", {desc = "put before cursor from clipboard"}) +vim.keymap.set("n", "cr", vim.lsp.buf.rename) vim.keymap.set("v", "", "gv") vim.keymap.set("v", "", "gv") vim.keymap.set("v", "g", "ggv") vim.keymap.set("v", "g", "ggv") - -vim.keymap.set("n", "cr", vim.lsp.buf.rename) - vim.keymap.set("i", "", require("scripts.intellitab").indent) +return {} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index 06b4b1b..42464b3 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -67,6 +67,7 @@ return { tex = { "latexindent" }, cpp = { "clang-format", lsp_format = "fallback" }, c = { "clang-format", lsp_format = "fallback" }, + fennel = { "fnlfmt", lsp_format = "fallback" }, }, }) diff --git a/lua/plugins/lz-spec.lua b/lua/plugins/lz-spec.lua index 8e29dc5..0ece430 100644 --- a/lua/plugins/lz-spec.lua +++ b/lua/plugins/lz-spec.lua @@ -304,4 +304,5 @@ return { end) end, }, + { "nfnl", ft = { "fennel" } }, }