Fix empty buffer close thingy

This commit is contained in:
elkowar 2021-05-08 23:41:47 +02:00
parent 82cc8c3e1c
commit 399d32327d
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
3 changed files with 18 additions and 11 deletions

View file

@ -137,17 +137,16 @@
; :: autoclose empty unnamed buffers ----------------------------------------------- foldstart ; :: autoclose empty unnamed buffers ----------------------------------------------- foldstart
(fn _G.clean_no_name_empty_buffers [] (fn _G.clean_no_name_empty_buffers []
(let [bufs (a.filter #(and (vim.api.nvim_buf_get_option $1 "buflisted") (let [bufs (a.filter #(and (a.empty? (vim.fn.bufname $1))
(a.empty? (vim.fn.bufname $1))
(< (vim.fn.bufwinnr $1) 0) (< (vim.fn.bufwinnr $1) 0)
(if (vim.api.nvim_buf_is_loaded $1) (vim.api.nvim_buf_is_loaded $1)
(a.empty? (vim.api.nvim_buf_get_lines $1 0 -1 false)) (= "" (str.join (utils.buffer-content $1)))
false)) (vim.api.nvim_buf_get_option $1 "buflisted"))
(vim.fn.range 1 (vim.api.nvim_buf_get_number "$")))] (vim.fn.range 1 (vim.api.nvim_buf_get_number "$")))]
(when (not (a.empty? bufs)) (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 ; foldend

View file

@ -18,6 +18,12 @@
(fn [name] (fn [name]
`(.. "lua require('" *module-name* "')['" ,(tostring name) "']()")) `(.. "lua require('" *module-name* "')['" ,(tostring name) "']()"))
:dbg
(fn [x]
`(let [view# (. (require "aniseed.fennel") :view)]
(print (.. `,(tostring x) " => " (view# ,x)))
,x))
:dbg-call :dbg-call
(fn [x ...] (fn [x ...]
`(do `(do

View file

@ -10,9 +10,8 @@
(defn plugin-installed? [name] (defn plugin-installed? [name]
(~= nil (. packer_plugins name))) (~= nil (. packer_plugins name)))
(defn dbg [x] (defn all [f xs]
(a.println (fennel.view x)) (not (a.some (not (f $1)))))
x)
(defn single-to-list [x] (defn single-to-list [x]
"Returns the list given to it. If given a single value, wraps it in a list" "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] (defn without-keys [keys t]
(filter-table #(not (contains? keys $1)) t)) (filter-table #(not (contains? keys $1)) t))
(defn keymap [modes from to ?opts] (defn keymap [modes from to ?opts]
"Set a mapping in the given modes, and some optional parameters, defaulting to {:noremap true :silent true}. "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" If :buffer is set, uses buf_set_keymap rather than set_keymap"
@ -68,6 +66,10 @@
(use (a.assoc opts 1 name))))))) (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] (defn surround-if-present [a mid b]
(if mid (if mid
(.. a mid b) (.. a mid b)