2021-04-03 14:14:56 +00:00
|
|
|
(module utils
|
|
|
|
{require {a aniseed.core
|
2021-05-01 13:20:02 +00:00
|
|
|
fennel aniseed.fennel
|
|
|
|
nvim aniseed.nvim}
|
2021-04-03 14:14:56 +00:00
|
|
|
require-macros [macros]})
|
2021-04-23 14:46:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defn dbg [x]
|
2021-05-01 13:20:02 +00:00
|
|
|
(a.println (fennel.view x))
|
2021-04-23 14:46:45 +00:00
|
|
|
x)
|
|
|
|
|
2021-05-01 13:20:02 +00:00
|
|
|
|
2021-04-23 14:46:45 +00:00
|
|
|
(defn contains? [list elem]
|
2021-05-01 13:20:02 +00:00
|
|
|
(or (a.some #(= elem $1) list)) false)
|
|
|
|
|
|
|
|
(defn filter-table [f t]
|
|
|
|
(collect [k v (pairs t)]
|
|
|
|
(when (f k v)
|
|
|
|
(values k v))))
|
2021-04-23 14:46:45 +00:00
|
|
|
|
|
|
|
(defn without-keys [keys t]
|
2021-05-01 13:20:02 +00:00
|
|
|
(filter-table #(not (contains? keys $1)) t))
|
2021-04-23 14:46:45 +00:00
|
|
|
|
|
|
|
(defn keymap [mode from to ?opts]
|
|
|
|
"Set a mapping in the given mode, and some optional parameters, defaulting to {:noremap true :silent true}.
|
|
|
|
If :buffer is set, uses buf_set_keymap rather than set_keymap"
|
|
|
|
(local full-opts
|
|
|
|
(->> (or ?opts {})
|
|
|
|
(a.merge {:noremap true :silent true})
|
2021-05-01 13:20:02 +00:00
|
|
|
(without-keys [:buffer])))
|
2021-04-23 14:46:45 +00:00
|
|
|
(if (and ?opts (?. ?opts :buffer))
|
|
|
|
(nvim.buf_set_keymap 0 mode from to full-opts)
|
|
|
|
(nvim.set_keymap mode from to full-opts)))
|
|
|
|
|
|
|
|
(defn del-keymap [mode from ?buf-local]
|
|
|
|
"Remove a keymap. Arguments: mode, mapping, bool if mapping should be buffer-local."
|
|
|
|
(if ?buf-local
|
|
|
|
(nvim.buf_del_keymap 0 mode from)
|
|
|
|
(nvim.del_keymap mode from)))
|
2021-04-03 14:14:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-02 15:15:33 +00:00
|
|
|
|
2021-05-02 16:13:37 +00:00
|
|
|
(def colors
|
2021-04-03 14:14:56 +00:00
|
|
|
{ :dark0_hard "#1d2021"
|
|
|
|
:dark0 "#282828"
|
|
|
|
:dark0_soft "#32302f"
|
|
|
|
:dark1 "#3c3836"
|
|
|
|
:dark2 "#504945"
|
|
|
|
:dark3 "#665c54"
|
|
|
|
:dark4 "#7c6f64"
|
|
|
|
:light0_hard "#f9f5d7"
|
|
|
|
:light0 "#fbf1c7"
|
|
|
|
:light0_soft "#f2e5bc"
|
|
|
|
:light1 "#ebdbb2"
|
|
|
|
:light2 "#d5c4a1"
|
|
|
|
:light3 "#bdae93"
|
|
|
|
:light4 "#a89984"
|
|
|
|
:bright_red "#fb4934"
|
|
|
|
:bright_green "#b8bb26"
|
|
|
|
:bright_yellow "#fabd2f"
|
|
|
|
:bright_blue "#83a598"
|
|
|
|
:bright_purple "#d3869b"
|
|
|
|
:bright_aqua "#8ec07c"
|
|
|
|
:bright_orange "#fe8019"
|
|
|
|
:neutral_red "#cc241d"
|
|
|
|
:neutral_green "#98971a"
|
|
|
|
:neutral_yellow "#d79921"
|
|
|
|
:neutral_blue "#458588"
|
|
|
|
:neutral_purple "#b16286"
|
|
|
|
:neutral_aqua "#689d6a"
|
|
|
|
:neutral_orange "#d65d0e"
|
|
|
|
:faded_red "#9d0006"
|
|
|
|
:faded_green "#79740e"
|
|
|
|
:faded_yellow "#b57614"
|
|
|
|
:faded_blue "#076678"
|
|
|
|
:faded_purple "#8f3f71"
|
|
|
|
:faded_aqua "#427b58"
|
|
|
|
:faded_orange "#af3a03"
|
|
|
|
:gray "#928374"})
|
|
|
|
|
2021-05-02 11:54:58 +00:00
|
|
|
(defn surround-if-present [a mid b]
|
|
|
|
(if mid
|
|
|
|
(.. a mid b)
|
|
|
|
""))
|
2021-04-03 14:14:56 +00:00
|
|
|
|
2021-05-02 11:54:58 +00:00
|
|
|
(defn highlight [group-arg colset]
|
2021-04-04 13:04:29 +00:00
|
|
|
(let [default { :fg "NONE" :bg "NONE" :gui "NONE"}
|
2021-04-30 14:41:57 +00:00
|
|
|
opts (a.merge default colset)
|
|
|
|
hl-groups (if (a.string? group-arg) [group-arg] group-arg)]
|
|
|
|
(each [_ group (ipairs hl-groups)]
|
|
|
|
(nvim.command (.. "hi! "group" guifg='"opts.fg"' guibg='"opts.bg"' gui='"opts.gui"'")))))
|
2021-04-03 17:43:27 +00:00
|
|
|
|
2021-05-02 11:54:58 +00:00
|
|
|
(defn highlight-add [group-arg colset]
|
|
|
|
(let [hl-groups (if (a.string? group-arg) [group-arg] group-arg)]
|
|
|
|
(each [_ group (ipairs hl-groups)]
|
|
|
|
(nvim.command
|
|
|
|
(.. "hi! "
|
|
|
|
group
|
|
|
|
(surround-if-present " guibg='"colset.bg"'")
|
|
|
|
(surround-if-present " guifg='"colset.fg"'")
|
|
|
|
(surround-if-present " gui='"colset.gui"'"))))))
|
|
|
|
|
2021-04-03 17:43:27 +00:00
|
|
|
|
2021-04-04 13:04:29 +00:00
|
|
|
(defn comp [f g]
|
|
|
|
(fn [...]
|
|
|
|
(f (g ...))))
|