From 01586921b3d5f2ac1ccf8196d3ad9b4b3ddd31f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Vulquin?= Date: Wed, 24 Jul 2024 19:19:26 +0200 Subject: nvim: rewrite config in fennel One file isn't done, and there's also the question of ftplugin and co. One step at a time though, eh? --- dot_config/nvim/fnl/bindings/builtins.fnl | 5 +++ dot_config/nvim/fnl/bindings/init.fnl | 13 +++++++ dot_config/nvim/fnl/bindings/plugins.fnl | 4 ++ dot_config/nvim/fnl/plugins/bindings/init.fnl | 5 +++ dot_config/nvim/fnl/plugins/flash.fnl | 19 ++++++++++ dot_config/nvim/fnl/plugins/init.fnl | 28 ++++++++++++++ dot_config/nvim/fnl/plugins/langs.fnl | 25 +++++++++++++ dot_config/nvim/fnl/plugins/lsp/capabilities.fnl | 1 + dot_config/nvim/fnl/plugins/lsp/init.fnl | 33 +++++++++++++++++ dot_config/nvim/fnl/plugins/mini/init.fnl | 20 ++++++++++ dot_config/nvim/fnl/plugins/mini/starter.fnl | 15 ++++++++ dot_config/nvim/fnl/plugins/neo-tree.fnl | 8 ++++ dot_config/nvim/fnl/plugins/os/init.fnl | 1 + dot_config/nvim/fnl/plugins/os/linux.fnl | 1 + dot_config/nvim/fnl/plugins/os/osx.fnl | 1 + dot_config/nvim/fnl/plugins/surround.fnl | 5 +++ dot_config/nvim/fnl/plugins/telescope.fnl | 20 ++++++++++ dot_config/nvim/fnl/toast/core.fnl | 47 ++++++++++++++++++++++++ dot_config/nvim/fnl/toast/macros.fnl | 29 +++++++++++++++ dot_config/nvim/fnl/toast/table.fnl | 15 ++++++++ 20 files changed, 295 insertions(+) create mode 100644 dot_config/nvim/fnl/bindings/builtins.fnl create mode 100644 dot_config/nvim/fnl/bindings/init.fnl create mode 100644 dot_config/nvim/fnl/bindings/plugins.fnl create mode 100644 dot_config/nvim/fnl/plugins/bindings/init.fnl create mode 100644 dot_config/nvim/fnl/plugins/flash.fnl create mode 100644 dot_config/nvim/fnl/plugins/init.fnl create mode 100644 dot_config/nvim/fnl/plugins/langs.fnl create mode 100644 dot_config/nvim/fnl/plugins/lsp/capabilities.fnl create mode 100644 dot_config/nvim/fnl/plugins/lsp/init.fnl create mode 100644 dot_config/nvim/fnl/plugins/mini/init.fnl create mode 100644 dot_config/nvim/fnl/plugins/mini/starter.fnl create mode 100644 dot_config/nvim/fnl/plugins/neo-tree.fnl create mode 100644 dot_config/nvim/fnl/plugins/os/init.fnl create mode 100644 dot_config/nvim/fnl/plugins/os/linux.fnl create mode 100644 dot_config/nvim/fnl/plugins/os/osx.fnl create mode 100644 dot_config/nvim/fnl/plugins/surround.fnl create mode 100644 dot_config/nvim/fnl/plugins/telescope.fnl create mode 100644 dot_config/nvim/fnl/toast/core.fnl create mode 100644 dot_config/nvim/fnl/toast/macros.fnl create mode 100644 dot_config/nvim/fnl/toast/table.fnl (limited to 'dot_config/nvim/fnl') diff --git a/dot_config/nvim/fnl/bindings/builtins.fnl b/dot_config/nvim/fnl/bindings/builtins.fnl new file mode 100644 index 0000000..8c77e35 --- /dev/null +++ b/dot_config/nvim/fnl/bindings/builtins.fnl @@ -0,0 +1,5 @@ +; document missing builtins +(import-macros {: tbl : recc} :toast.macros) +(recc :which-key :add + [(tbl :gt & :desc "Next tab") + (tbl :gT & :desc "Previous tab")]) diff --git a/dot_config/nvim/fnl/bindings/init.fnl b/dot_config/nvim/fnl/bindings/init.fnl new file mode 100644 index 0000000..c350db4 --- /dev/null +++ b/dot_config/nvim/fnl/bindings/init.fnl @@ -0,0 +1,13 @@ +(import-macros {: tbl : recc} :toast.macros) + +(each [_ v (ipairs [:builtins + :plugins])] + (require (.. :bindings. v))) + +; general bindings that aren't specific to a plugin +(recc :which-key :add + ; diagnostics + [(tbl :e vim.diagnostic.open_float & :desc "diag float") + (tbl :q vim.diagnostic.setloclist & :desc "diag locations") + (tbl "[d" vim.diagnostic.goto_prev & :desc "prev diag") + (tbl "]d" vim.diagnostic.goto_next & :desc "next diag")]) diff --git a/dot_config/nvim/fnl/bindings/plugins.fnl b/dot_config/nvim/fnl/bindings/plugins.fnl new file mode 100644 index 0000000..ae0348d --- /dev/null +++ b/dot_config/nvim/fnl/bindings/plugins.fnl @@ -0,0 +1,4 @@ +; plugin-specific category bindings +(import-macros {: tbl : recc} :toast.macros) +(recc :which-key :add + [(tbl :f & :desc :+find)]) diff --git a/dot_config/nvim/fnl/plugins/bindings/init.fnl b/dot_config/nvim/fnl/plugins/bindings/init.fnl new file mode 100644 index 0000000..4cfb558 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/bindings/init.fnl @@ -0,0 +1,5 @@ +(import-macros {: tbl} :toast.macros) +[(tbl :folke/which-key.nvim & + :lazy true + :opts {}) + [:tpope/vim-rsi]] diff --git a/dot_config/nvim/fnl/plugins/flash.fnl b/dot_config/nvim/fnl/plugins/flash.fnl new file mode 100644 index 0000000..ece5de4 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/flash.fnl @@ -0,0 +1,19 @@ +(import-macros {: tbl : recc} :toast.macros) +[(tbl :folke/flash.nvim & + :opts {:modes {:search {:enabled false}}} + :event :VeryLazy + :keys [(tbl :s #(recc :flash :jump) & + :mode [:n :x :o] + :desc :Flash) + (tbl :S #(recc :flash :treesitter) & + :mode [:n :x :o] + :desc "Flash Treesitter") + (tbl :r #(recc :flash :remote) & + :mode :o + :desc "Remote Flash") + (tbl :R #(recc :flash :treesitter_search) & + :mode [:o :x] + :desc "Flash Treesitter Search") + (tbl : #(recc :flash :toggle) & + :mode :c + :desc "Toggle Flash Search")])] diff --git a/dot_config/nvim/fnl/plugins/init.fnl b/dot_config/nvim/fnl/plugins/init.fnl new file mode 100644 index 0000000..a867ecc --- /dev/null +++ b/dot_config/nvim/fnl/plugins/init.fnl @@ -0,0 +1,28 @@ +(import-macros {: tbl} :toast.macros) +(local conjureft [:clojure + :fennel + :hy + :janet + :julia + :lisp + :racket + :scheme]) + +; simple stuff that doesn't need any handling +; and doesn't fit in elsewhere +[(tbl :folke/lazy.nvim & :version false) + (tbl :Olical/nfnl & :ft :fennel) + (tbl :stevearc/dressing.nvim & + :opts {}) + (tbl :Olical/conjure & + :config (fn [_ opts] + (each [k v (pairs opts)] + (tset vim.g (.. :conjure# k) v))) + :opts {:mapping#prefix :e + :extract#tree_sitter#enabled true + ; disabling lua, python, rust + :filetypes conjureft + :filetype#fennel :conjure.client.fennel.stdio + :filetype#janet :conjure.client.janet.stdio} + :ft conjureft) + [:tpope/vim-repeat]] diff --git a/dot_config/nvim/fnl/plugins/langs.fnl b/dot_config/nvim/fnl/plugins/langs.fnl new file mode 100644 index 0000000..5bfb817 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/langs.fnl @@ -0,0 +1,25 @@ +(import-macros {: tbl} :toast.macros) +; language support +[(tbl :nvim-treesitter/nvim-treesitter & + :version false + :build ::TSUpdate + :dependnecies [:nvim-treesitter/nvim-treesitter-textobjects] + :main :nvim-treesitter.configs + :opts {:ensure_installed :all + :ignore_install [:norg] + :sync_install :true + :highlight {:enable true + :disable [:markdown] + :additional_vim_regex_highlighting [:markdown]}}) + ; non-treesitter languages + (tbl :janet-lang/janet.vim & :ft :janet) + (tbl :preservim/vim-markdown & + :version false + :dependencies [:godlygeek/tabular] + :ft :markdown) + ; helper for lisps + (tbl :gpanders/nvim-parinfer & + :ft [:clojure + :fennel + :janet + :scm])] diff --git a/dot_config/nvim/fnl/plugins/lsp/capabilities.fnl b/dot_config/nvim/fnl/plugins/lsp/capabilities.fnl new file mode 100644 index 0000000..607602c --- /dev/null +++ b/dot_config/nvim/fnl/plugins/lsp/capabilities.fnl @@ -0,0 +1 @@ +nil diff --git a/dot_config/nvim/fnl/plugins/lsp/init.fnl b/dot_config/nvim/fnl/plugins/lsp/init.fnl new file mode 100644 index 0000000..10685d2 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/lsp/init.fnl @@ -0,0 +1,33 @@ +(import-macros {: tbl : recc} :toast.macros) + +(fn gopts [plist] + {:clangd {} + :clojure_lsp {:root_dir (plist :project.clj :deps.edn :bb.edn :build.boot :shadow-cljs.edn :.git)} + :denols {:autostart false + :root_dir (plist :deno.json :deno.jsonc)} + :gopls {} + :ltex {} + :lua_ls {} + :texlab {:filetypes [:tex :plaintex :bib :latex]} + :tsserver {:autostart false + :root_dir (plist :tsconfig.json :package.json)} + :zls {}}) + +(local attach (require :plugins.lsp.attach)) +(local caps (require :plugins.lsp.capabilities)) + +[(tbl :neovim/nvim-lspconfig & + :config (fn [_ opts] + (each [k v (pairs opts)] + (set v.on_attach (or attach v.on_attach)) + (when (= :table (type caps)) + (set v.capabilities (or v.capabilities caps))) + (let [s (. (require :lspconfig) k) + c (or v.cmd s.document_config.default_config.cmd)] + (when (not= 0 (vim.fn.executable (. c 1))) + (s.setup v))))) + :opts (fn [] + (let [plist (fn [...] + (local p (recc :lspconfig.util :root_pattern ...)) + #(p $))] + (gopts plist))))] diff --git a/dot_config/nvim/fnl/plugins/mini/init.fnl b/dot_config/nvim/fnl/plugins/mini/init.fnl new file mode 100644 index 0000000..f175ed7 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/mini/init.fnl @@ -0,0 +1,20 @@ +(import-macros {: tbl : recc} :toast.macros) +[(tbl :echasnovski/mini.nvim & + :version false + :config (fn [_ opts] + (each [k v (pairs opts)] + (recc (.. :mini. k) :setup v))) + :opts (fn [] {:ai {} + :align {} + :basics {} + :bracketed {:indent {:options {:change_type :diff}}} + :comment {} + :completion {} + :cursorword {} + :indentscope {} + :move {} + :splitjoin {} + ; :starter (require :plugins.mini.starter) + :statusline {} + :tabline {} + :trailspace {}}))] diff --git a/dot_config/nvim/fnl/plugins/mini/starter.fnl b/dot_config/nvim/fnl/plugins/mini/starter.fnl new file mode 100644 index 0000000..99d71f9 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/mini/starter.fnl @@ -0,0 +1,15 @@ +(let [starter (require :mini.starter) + telescope [{:action "Telescope commands" + :name :Commands} + {:action "Telescope find_files" + :name :Files} + {:action "Telescope help_tags" + :name "Help tags"} + {:action "Telescope live_grep" + :name "Live grep"} + {:action "Telescope oldfiles" + :name "Old files"}]] + (each [_ v (ipairs telescope)] + (set v.section :Telescope)) + {:items [telescope + (starter.sections.builtin_actions)]}) diff --git a/dot_config/nvim/fnl/plugins/neo-tree.fnl b/dot_config/nvim/fnl/plugins/neo-tree.fnl new file mode 100644 index 0000000..396f420 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/neo-tree.fnl @@ -0,0 +1,8 @@ +(import-macros {: tbl : recc} :toast.macros) +[(tbl :nvim-neo-tree/neo-tree.nvim & + :cmd :Neotree + :dependencies [:nvim-lua/plenary.nvim + :MunifTanjim/nui.nvim] + :keys [(tbl :n #(recc :neo-tree.command :execute {:toggle true}) & + :desc :Neotree)] + :opts {})] diff --git a/dot_config/nvim/fnl/plugins/os/init.fnl b/dot_config/nvim/fnl/plugins/os/init.fnl new file mode 100644 index 0000000..44afc2c --- /dev/null +++ b/dot_config/nvim/fnl/plugins/os/init.fnl @@ -0,0 +1 @@ +(require (.. :plugins.os. (jit.os:lower))) diff --git a/dot_config/nvim/fnl/plugins/os/linux.fnl b/dot_config/nvim/fnl/plugins/os/linux.fnl new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/os/linux.fnl @@ -0,0 +1 @@ +{} diff --git a/dot_config/nvim/fnl/plugins/os/osx.fnl b/dot_config/nvim/fnl/plugins/os/osx.fnl new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/os/osx.fnl @@ -0,0 +1 @@ +{} diff --git a/dot_config/nvim/fnl/plugins/surround.fnl b/dot_config/nvim/fnl/plugins/surround.fnl new file mode 100644 index 0000000..6fdb678 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/surround.fnl @@ -0,0 +1,5 @@ +(import-macros {: tbl} :toast.macros) +[(tbl :kylechui/nvim-surround & + :version :* ; omit to use main branch for latest features + :event :VeryLazy + :opts {})] diff --git a/dot_config/nvim/fnl/plugins/telescope.fnl b/dot_config/nvim/fnl/plugins/telescope.fnl new file mode 100644 index 0000000..44aa9d5 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/telescope.fnl @@ -0,0 +1,20 @@ +(import-macros {: tbl : recc} :toast.macros) + +(fn gen [key fun desc] + (tbl (.. :f key) #(recc :telescope.builtin fun) & :desc desc)) + +[(tbl :nvim-telescope/telescope.nvim & + :dependencies [:nvim-lua/plenary.nvim + (tbl :nvim-telescope/telescope-fzf-native.nvim & + :build :make)] + :config (fn [_ opts] + (let [ts (require :telescope)] + (ts.setup opts) + (ts.load_extension :fzf))) + :cmd :Telescope + :keys [(gen :f :find_files "Find File") + (gen :g :live_grep "Live Grep") + (gen :b :buffers "Find Buffer") + (gen :h :help_tags "Find Help") + (gen :c :commands "Find Command") + (gen :t :treesitter "Find Treesitter")])] diff --git a/dot_config/nvim/fnl/toast/core.fnl b/dot_config/nvim/fnl/toast/core.fnl new file mode 100644 index 0000000..54b0455 --- /dev/null +++ b/dot_config/nvim/fnl/toast/core.fnl @@ -0,0 +1,47 @@ +(local {: insert} (require :toast.table)) + +(fn dec [n] + "Decrement n by 1." + (- n 1)) +(fn inc [n] + "Increment n by 1." + (+ n 1)) +(fn drop [n xs] + "Returns a table of all but the first n elements in xs." + (let [out []] + (each [i v (ipairs xs)] + (when (> i n) (insert out v))) + out)) +(fn first [xs] + "The first element in a sequential table." + (. xs 1)) +(fn last [xs] + "The last element in a sequential table." + (. xs (length xs))) +(fn group [n xs] + "Group elements in xs in groups of n. + Extra elements at the end will sit in the final group. + For example, (group 2 [1 2 3 4 5]) results in [[1 2] [3 4] [5]]." + (let [ll #(length (last $)) + donext #(= (ll $) n)] + (accumulate [out [[]] + _ v (ipairs xs)] + (do (when (donext out) + (insert out [])) + (insert (last out) v) + out)))) +(fn map [f xs] + "Returns a sequential table consisting of the result of apply f to every item in xs." + (accumulate [out [] + _ v (ipairs xs)] + (let [mapped (f v)] + (insert out (if (= 0 (select :# mapped)) + nil + mapped))))) + +{: dec + : inc + : drop + : group + : first + : last} diff --git a/dot_config/nvim/fnl/toast/macros.fnl b/dot_config/nvim/fnl/toast/macros.fnl new file mode 100644 index 0000000..bb4375b --- /dev/null +++ b/dot_config/nvim/fnl/toast/macros.fnl @@ -0,0 +1,29 @@ +;; [nfnl-macro] + +(local {: inc + : drop + : group} (require :toast.core)) +(local {: from-pairs + : insert} (require :toast.table)) + +(fn tbl [...] + "Generate a mixed table. + The format is (tbl 1 2 3 & :a :b) to produce {1; 2; 3; a = 'b'}. + This macro simply expands to the correct data during compile-time." + (let [args [...] + pre (accumulate [out [] + _ v (ipairs args) + &until (= v '&)] + (insert out v)) + post (drop (inc (length pre)) args)] + (from-pairs (group 2 post) pre))) + +(fn recc [reqspec key ...] + "A common lua pattern is `require 'something'.call(arg1, arg2)`. + The fennel equivalent is ((require :something).call arg1 arg2) + This macro makes it easier to do this elegantly. + The equivalent call is (recc :something :call arg1 arg2)" + `((. (require ,reqspec) ,key) ,...)) + +{: tbl + : recc} diff --git a/dot_config/nvim/fnl/toast/table.fnl b/dot_config/nvim/fnl/toast/table.fnl new file mode 100644 index 0000000..a294b14 --- /dev/null +++ b/dot_config/nvim/fnl/toast/table.fnl @@ -0,0 +1,15 @@ +(fn from-pairs [t ?mut] + "Convert a list of [k v] pairs to a table. + If an initial table ?mut is provided, it will be mutated and returned." + (let [out (or ?mut {})] + (each [_ [k v] (ipairs t)] + (tset out k v)) + out)) + +(fn insert [t ...] + "Like table.insert, but returns the mutated table." + (table.insert t ...) + t) + +{: from-pairs + : insert} -- cgit v1.2.3