summaryrefslogtreecommitdiff
path: root/fnl
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-08-06 10:09:12 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-08-06 10:09:12 +0200
commita8d7323779e365bb7afcd700d894513867ebe881 (patch)
tree2f01e67a51d8c461d93be4b0bee7e654ae6ae095 /fnl
parent38c1445db8763e8f1b18b246540a971f2fba0a0d (diff)
Update sync logic
Diffstat (limited to 'fnl')
-rw-r--r--fnl/util.fnl33
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)]