diff options
| author | 2024-07-24 22:10:02 +0200 | |
|---|---|---|
| committer | 2024-07-24 22:10:02 +0200 | |
| commit | 991091228f9e403015edd0106ccfc3a0ce62e304 (patch) | |
| tree | 44aa6357e395766f1a340fee08aea546ae69c16c /dot_config/nvim/fnl | |
| parent | nvim: add empty? and update group (diff) | |
nvim: continue fennel porting
Yeah I'm lazy but these are my dotfiles.
A quick summary:
* plugins.lsp.attach is now ported
* toast.core is reorganized
* new nil? and number? checks
* new assoc function
* new toast.table.unpack function (cross lua compat)
* toast.macros.tbl now uses assoc instead of from-pairs and group
* apparently I had forgotten to add {pre,post,init}.fnl before, so
that's done now
Still todo: ftplugin, colors.
Diffstat (limited to '')
| -rw-r--r-- | dot_config/nvim/fnl/plugins/lsp/attach.fnl | 31 | ||||
| -rw-r--r-- | dot_config/nvim/fnl/toast/core.fnl | 55 | ||||
| -rw-r--r-- | dot_config/nvim/fnl/toast/macros.fnl | 7 | ||||
| -rw-r--r-- | dot_config/nvim/fnl/toast/table.fnl | 5 |
4 files changed, 84 insertions, 14 deletions
diff --git a/dot_config/nvim/fnl/plugins/lsp/attach.fnl b/dot_config/nvim/fnl/plugins/lsp/attach.fnl new file mode 100644 index 0000000..1f23015 --- /dev/null +++ b/dot_config/nvim/fnl/plugins/lsp/attach.fnl @@ -0,0 +1,31 @@ +(import-macros {: tbl : recc} :toast.macros) +(local {: assoc : map} (require :toast.core)) +(local {: insert} (require :toast.table)) + +(fn [c b] + (let [lsp vim.lsp + lbf lsp.buf + ll [(tbl "" & :group :+lsp) + (tbl :w & :group :+workspace) + + (tbl :D lbf.declaration & :desc "goto declaration") + (tbl :d lbf.definition & :desc "goto definition") + (tbl :k lbf.hover & :desc "hover") + (tbl :K lbf.signature_help & :desc "signature help") + (tbl :i lbf.implementation & :desc "goto implementation") + (tbl :t lbf.type_definition & :desc "goto type definition") + (tbl :r lbf.rename & :desc "rename") + (tbl :c lbf.code_action & :desc "code action") + (tbl :R lbf.reference & :desc "list references") + + (tbl :wa lbf.add_workspace_folder & :desc "add folder") + (tbl :wr lbf.remove_workspace_folder & :desc "remove folder") + (tbl :wl #(print (vim.inspect (lbf.list_workspace_folders))) & + :desc "list folders")] + ll (map #(assoc $ 1 (.. :<localleader><localleader> (. $ 1))) ll)] + (vim.api.nvim_buf_set_option b :omnifunc :v:lua.vim.lsp.omnifunc) + (recc :which-key :add + (tbl (insert ll + (tbl :<leader>F #(vim.lsp.buf.format {:async true}) & + :desc "run format")) & + :buffer b)))) diff --git a/dot_config/nvim/fnl/toast/core.fnl b/dot_config/nvim/fnl/toast/core.fnl index 3c77e4a..16e69c2 100644 --- a/dot_config/nvim/fnl/toast/core.fnl +++ b/dot_config/nvim/fnl/toast/core.fnl @@ -1,20 +1,31 @@ -(local {: insert} (require :toast.table)) +(local {: insert : unpack} (require :toast.table)) +; math (fn dec [n] "Decrement n by 1." (- n 1)) (fn inc [n] "Increment n by 1." (+ n 1)) + +; checks? +(fn empty? [xs] + "Returns true if the lengthable contains no elements." + (= 0 (length xs))) +(fn nil? [x] + "Returns true if the argument is nil." + (= nil x)) +(fn number? [n] + "Returns true if the argument is a number." + (= :number (type n))) + +; sequences (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 empty? [xs] - "Returns true if the lengthable contains no elements." - (= 0 (length xs))) (fn first [xs] "The first element in a sequential table." (. xs 1)) @@ -36,19 +47,45 @@ (insert out [])) (insert (last out) v out)))))) + +; HOF +(fn assoc [?t ...] + "Sets the key `k` in table `t` to the value `v`. + Accepts an arbitrary amount of `k` and `v` pairs. + Returns the mutated table `t`." + (let [t (or ?t {}) + lt (inc (length t)) ; for numerical keys + [k v & xs] [...]] + (case k + nil nil + (where k (and (number? k) (> lt k))) (tset t k v) ; TODO: (set (. t k) v) + (where k (and (number? k) (= k lt))) (table.insert t k v) + _ (tset t k v)) + (case (length xs) + 0 t + 1 (error "assoc expects even number of arguments after table, found odd number") + _ (assoc t (unpack xs))))) (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)] + _ v (ipairs (or xs []))] (let [mapped (f v)] (insert out (if (= 0 (select :# mapped)) nil mapped))))) -{: dec +{;math + : dec : inc - : drop + ; checks? : empty? - : group + : nil? + : number? + ; sequences + : drop : first - : last} + : last + : group + ; HOF + : assoc + : map} diff --git a/dot_config/nvim/fnl/toast/macros.fnl b/dot_config/nvim/fnl/toast/macros.fnl index bb4375b..b81d8e6 100644 --- a/dot_config/nvim/fnl/toast/macros.fnl +++ b/dot_config/nvim/fnl/toast/macros.fnl @@ -2,9 +2,8 @@ (local {: inc : drop - : group} (require :toast.core)) -(local {: from-pairs - : insert} (require :toast.table)) + : assoc} (require :toast.core)) +(local {: insert} (require :toast.table)) (fn tbl [...] "Generate a mixed table. @@ -16,7 +15,7 @@ &until (= v '&)] (insert out v)) post (drop (inc (length pre)) args)] - (from-pairs (group 2 post) pre))) + (assoc pre (unpack post)))) (fn recc [reqspec key ...] "A common lua pattern is `require 'something'.call(arg1, arg2)`. diff --git a/dot_config/nvim/fnl/toast/table.fnl b/dot_config/nvim/fnl/toast/table.fnl index a294b14..fe118e8 100644 --- a/dot_config/nvim/fnl/toast/table.fnl +++ b/dot_config/nvim/fnl/toast/table.fnl @@ -11,5 +11,8 @@ (table.insert t ...) t) +(local unpack (or table.unpack unpack)) + {: from-pairs - : insert} + : insert + : unpack} |
