(fn tbl? [x] (= :table (type x))) (fn count [xs] (if (tbl? xs) (table.maxn xs) (not xs) 0 (length xs))) (fn run! [f xs] "Execute the function (for side effects) for every xs." (when xs (let [nxs (count xs)] (when (> nxs 0) (for [i 1 nxs] (f (. xs i))))))) (fn reduce [f init xs] "Reduce xs into a result by passing each subsequent value into the fn with the previous value as the first arg. Starting with init." (var result init) (run! (fn [x] (set result (f result x))) xs) result) (fn merge! [base ...] (reduce (fn [acc m] (when m (each [k v (pairs m)] (tset acc k v))) acc) (or base {}) [...])) (fn merge [...] (merge! {} ...)) (fn del_buf [] (let [buflisted (vim.fn.getbufinfo {:buflisted 1}) (cur-winnr cur-bufnr) (values (vim.fn.winnr) (vim.fn.bufnr))] (when (< (length buflisted) 2) (vim.cmd "confirm qall") (lua "return ")) (each [_ winid (ipairs (. (. (vim.fn.getbufinfo cur-bufnr) 1) :windows))] (vim.cmd (string.format "%d wincmd w" (vim.fn.win_id2win winid))) (vim.cmd (or (and (= cur-bufnr (. (. buflisted (length buflisted)) :bufnr)) :bp) :bn))) (vim.cmd (string.format "%d wincmd w" cur-winnr)) (local is-terminal (= (vim.fn.getbufvar cur-bufnr :&buftype) :terminal)) (vim.cmd (or (and is-terminal "bd! #") "silent! confirm bd #")))) {: merge : del_buf}