diff options
Diffstat (limited to 'fnl/util.fnl')
-rw-r--r-- | fnl/util.fnl | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/fnl/util.fnl b/fnl/util.fnl index dd82b23..555768c 100644 --- a/fnl/util.fnl +++ b/fnl/util.fnl @@ -1,26 +1,37 @@ ;; Utility functions. (module util {autoload {a aniseed.core nvim aniseed.nvim : packer}}) -(def- plugins (require :plugins)) - (def- path (.. (vim.fn.stdpath :data) :/site/pack/packer/start)) -(defn- num-plugins [] (var i 0) - (each [_ _ (pairs plugins)] - (set i (+ i 1))) i) +(def- installed-plugins (vim.fn.readdir path)) + +(def- configured-plugins (require :plugins)) + +(defn- parse-plugins-names [plugins] (var names []) + (each [plugin _ (pairs plugins)] + (table.insert names (string.match plugin "/(.*)"))) names) + +(defn- contains [ys xs] (var equal true) + (each [_ x (pairs xs)] + (if (not= (vim.tbl_contains ys x) true) + (set equal false))) equal) + +(defn- deep-equal [xs ys] (and (contains xs ys) (contains ys xs))) -(defn- num-installed-plugins [] (length (vim.fn.readdir path))) +(defn- synchronized [configured installed] + (and (= (vim.tbl_count configured) (vim.tbl_count installed)) + (deep-equal configured installed))) (defn- install [] (packer.startup (fn [use] - (each [plugin opts (pairs plugins)] + (each [plugin opts (pairs configured-plugins)] (use (a.assoc opts 1 plugin)))))) (defn load-plugins [] (install) - (let [num-installed-plugins (num-installed-plugins) - num-plugins (num-plugins)] - (if (not= num-installed-plugins num-plugins) - (packer.sync))) (require :config)) + (if (not= (synchronized (parse-plugins-names configured-plugins) + installed-plugins) true) + (packer.sync) + (require :config))) (defn load-plugin [name] (let [(ok? val-or-err) (pcall require name)] |