diff --git a/files/.config/nvim/fnl/init.fnl b/files/.config/nvim/fnl/init.fnl index 31965e6..e17a10b 100644 --- a/files/.config/nvim/fnl/init.fnl +++ b/files/.config/nvim/fnl/init.fnl @@ -137,17 +137,16 @@ ; :: autoclose empty unnamed buffers ----------------------------------------------- foldstart (fn _G.clean_no_name_empty_buffers [] - (let [bufs (a.filter #(and (vim.api.nvim_buf_get_option $1 "buflisted") - (a.empty? (vim.fn.bufname $1)) + (let [bufs (a.filter #(and (a.empty? (vim.fn.bufname $1)) (< (vim.fn.bufwinnr $1) 0) - (if (vim.api.nvim_buf_is_loaded $1) - (a.empty? (vim.api.nvim_buf_get_lines $1 0 -1 false)) - false)) + (vim.api.nvim_buf_is_loaded $1) + (= "" (str.join (utils.buffer-content $1))) + (vim.api.nvim_buf_get_option $1 "buflisted")) (vim.fn.range 1 (vim.api.nvim_buf_get_number "$")))] (when (not (a.empty? bufs)) - (nvim.command (.. "bd " (str.join " " bufs)))))) + (vim.cmd (.. "bdelete " (str.join " " bufs)))))) -(nvim.command "autocmd! BufCreate * :call v:lua.clean_no_name_empty_buffers()") +(vim.cmd "autocmd! BufCreate * :call v:lua.clean_no_name_empty_buffers()") ; foldend diff --git a/files/.config/nvim/fnl/macros.fnl b/files/.config/nvim/fnl/macros.fnl index 6b17487..eeac506 100644 --- a/files/.config/nvim/fnl/macros.fnl +++ b/files/.config/nvim/fnl/macros.fnl @@ -18,6 +18,12 @@ (fn [name] `(.. "lua require('" *module-name* "')['" ,(tostring name) "']()")) + :dbg + (fn [x] + `(let [view# (. (require "aniseed.fennel") :view)] + (print (.. `,(tostring x) " => " (view# ,x))) + ,x)) + :dbg-call (fn [x ...] `(do diff --git a/files/.config/nvim/fnl/utils.fnl b/files/.config/nvim/fnl/utils.fnl index af967ec..e07e134 100644 --- a/files/.config/nvim/fnl/utils.fnl +++ b/files/.config/nvim/fnl/utils.fnl @@ -10,9 +10,8 @@ (defn plugin-installed? [name] (~= nil (. packer_plugins name))) -(defn dbg [x] - (a.println (fennel.view x)) - x) +(defn all [f xs] + (not (a.some (not (f $1))))) (defn single-to-list [x] "Returns the list given to it. If given a single value, wraps it in a list" @@ -29,7 +28,6 @@ (defn without-keys [keys t] (filter-table #(not (contains? keys $1)) t)) - (defn keymap [modes from to ?opts] "Set a mapping in the given modes, and some optional parameters, defaulting to {:noremap true :silent true}. If :buffer is set, uses buf_set_keymap rather than set_keymap" @@ -68,6 +66,10 @@ (use (a.assoc opts 1 name))))))) +(defn buffer-content [bufnr] + "Returns a table of lines in the given buffer" + (vim.api.nvim_buf_get_lines bufnr 0 -1 false)) + (defn surround-if-present [a mid b] (if mid (.. a mid b)