diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2022-11-22 11:20:44 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2022-11-22 11:20:44 +0100 |
| commit | 532d58f386f6b7c35ef1d6404659e9f1508414bf (patch) | |
| tree | 4c234f4e6180ec271d49888be1694848e54c9f66 | |
| parent | ccc185d43e03db06fbb679770b164c2eab6b6b49 (diff) | |
niceify macros
| -rw-r--r-- | neovim/fnl/conf/macros.fnl | 78 | ||||
| -rw-r--r-- | neovim/fnl/conf/settings.fnl | 1 |
2 files changed, 56 insertions, 23 deletions
diff --git a/neovim/fnl/conf/macros.fnl b/neovim/fnl/conf/macros.fnl index 80568b6..ff08329 100644 --- a/neovim/fnl/conf/macros.fnl +++ b/neovim/fnl/conf/macros.fnl @@ -1,28 +1,62 @@ ;; cannot be at the bottom? + (fn settings [...] - (fn echo [l] (each [k v (ipairs l)] (print k v))) - (fn tbl-echo [tbl] (collect [k v (pairs tbl)] (print k v) (values k v))) - - (fn stringify [l] (icollect [_ v (ipairs l)] (tostring v))) - - (fn kv [l tbl] - (let [[first second & rest] l] - (when (and (not= first nil) (not= second nil)) - (tset tbl first second) - (kv rest tbl)) - tbl)) - - (let [opts-tbl (-> [...] - (stringify) - (kv {}))] - `(each [k# v# (pairs ,opts-tbl)] - (match [k# v#] - [a# "true"] (tset (. vim "opt") k# true) - [a# "false"] (tset (. vim "opt") k# false) - [a# b#] (tset (. vim "opt") k# v#))))) + (fn stringify [l] + (icollect [_ v (ipairs l)] + (tostring v))) + + (fn ->tbl [l] + (local tbl {}) + + (fn iter [i] + (let [k (. l (- i 1)) + v (. l i)] + (when (and k v) + (tset tbl k v) + (iter (+ i 2))))) + + (iter 2) + tbl) + + (fn value-type [v] + (match v + :on true + :no false + v v)) + + (fn template [k v method] + `(let [s# (. vim :opt ,k) + t# ,(value-type v)] + ,(match method + :append `(s#:append t#) + :remove `(s#:remove t#) + :set `(tset (. vim :opt) ,k t#)))) + + (fn transform [tbl] + (icollect [k v (pairs tbl)] + (match (string.sub k 1 1) + "+" (template (string.sub k 2) v :append) + "-" (template (string.sub k 2) v :remove) + _ (template k v :set)))) + + (let [l (-> [...] + (stringify) + (->tbl) + (transform))] + `,l)) + +(fn globals [...]) + +;; (let [opts-tbl (-> [...] +;; (stringify) +;; (->tbl {}))] +;; `(each [k# v# (pairs ,opts-tbl)] +;; (match [k# v#] +;; [a# :true] (tset (. vim :opt) k# true) +;; [a# :false] (tset (. vim :opt) k# false) +;; [a# b#] (tset (. vim :opt) k# v#))))) (fn P [p] `(print (vim.inspect ,p))) -{: settings - : P} +{: P : settings : globals} diff --git a/neovim/fnl/conf/settings.fnl b/neovim/fnl/conf/settings.fnl index 580ec91..7f22d82 100644 --- a/neovim/fnl/conf/settings.fnl +++ b/neovim/fnl/conf/settings.fnl @@ -3,4 +3,3 @@ backup false backupcopy yes foldmarker "///,///") - |
