summaryrefslogtreecommitdiff
path: root/fnl
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-06-02 00:00:30 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-06-02 00:00:30 +0200
commit62534c1e62ec403b798c5e8f657169bc6f965449 (patch)
treed3e0fac2a1a10dadee7ee49123919ef7d34bf1cc /fnl
parent778f0d4fc6157a960f0efe90bc6dc535794efb1c (diff)
Convert utils to pure fns
Diffstat (limited to 'fnl')
-rw-r--r--fnl/init.fnl4
-rw-r--r--fnl/util.fnl28
2 files changed, 15 insertions, 17 deletions
diff --git a/fnl/init.fnl b/fnl/init.fnl
index dd6d1b0..ce1c84f 100644
--- a/fnl/init.fnl
+++ b/fnl/init.fnl
@@ -1,6 +1,4 @@
;; Install, load settings, and load plugin configs.
(module init {autoload {util util} require [settings config.packer]})
-(util.install)
-(util.sync)
-(util.load-config)
+(util.load-plugins)
diff --git a/fnl/util.fnl b/fnl/util.fnl
index a27d0bf..d1b3665 100644
--- a/fnl/util.fnl
+++ b/fnl/util.fnl
@@ -4,25 +4,25 @@
packer packer
plugins plugins}})
-(var num-plugins 0)
-
(def- path (.. (vim.fn.stdpath :data) :/site/pack/packer/start))
-(defn- num-installed-plugins [] (length (vim.fn.readdir path)))
+(defn- num-plugins [] (var i 0)
+ (each [_ _ (pairs plugins.plugins)]
+ (set i (+ i 1))) i)
-(defn sync [] (let [num-installed-plugins (num-installed-plugins)]
- (if (not= num-installed-plugins num-plugins)
- (packer.sync))))
+(defn- num-installed-plugins [] (length (vim.fn.readdir path)))
-(defn install []
- (packer.startup (fn [use]
- (each [plugin opts (pairs plugins.plugins)]
- (set num-plugins (+ num-plugins 1))
- (use (a.assoc opts 1 plugin))))))
+(defn- install []
+ (packer.startup (fn [use]
+ (each [plugin opts (pairs plugins.plugins)]
+ (use (a.assoc opts 1 plugin))))))
-(defn load-config [] (let [num-installed-plugins (num-installed-plugins)]
- (if (= num-installed-plugins num-plugins)
- (require :config))))
+(defn load-plugins [] (install)
+ (let [num-installed-plugins (num-installed-plugins)
+ num-plugins (num-plugins)]
+ (if (= num-installed-plugins num-plugins)
+ (require :config)
+ (packer.sync))))
(defn load-plugin [name]
(let [(ok? val-or-err) (pcall require name)]