about summary refs log tree commit diff
path: root/fnl/nvrc/macro/pack.fnl
blob: 841cc3525334964586bd0934c745ebbc9a2b4138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(fn str? [x]
  (= :string (type x)))

(fn nil? [x]
  (= nil x))

(fn tbl? [x]
  (= :table (type x)))

(local {: insert} table)

(global nvrc/pack [])

(lambda pack [identifier ?options]
  "Returns a mixed table with the identifier as the first sequential element
  and options as hash-table items.
  See https://github.com/folke/lazy.nvim for information about the
  options."
  (assert-compile (str? identifier) "expected string for identifier" identifier)
  (assert-compile (or (nil? ?options) (tbl? ?options))
                  "expected table for options" ?options)
  (let [options (or ?options {})
        options (collect [k v (pairs options)]
                         (if
                           (= k :req) (values :config `#(require (string.format "nvrc.packs.%s" ,v)))
                           (= k :init) (values :config `#((. (require ,v) :setup)))
                           (values k v)))]
    (doto options
          (tset 1 identifier))))

(lambda pack! [identifier ?options]
  "Declares a plugin with its options.
  This is a mixed table saved on the global compile-time variable nvrc/pack.
  See https://github.com/folke/lazy.nvim for information about the
  options."
  (assert-compile (str? identifier) "expected string for identifier" identifier)
  (assert-compile (or (nil? ?options) (tbl? ?options))
                  "expected table for options" ?options)
  (insert nvrc/pack (pack identifier ?options)))

(lambda unpack! []
  "Initializes the plugin manager with the previously declared plugins and
  their options."
  (let [packs [(unpack (icollect [_ v (ipairs nvrc/pack)]
                         v))]]
    `((. (require :lazy) :setup) ,packs)))

{: pack
 : pack!
 : unpack!}