chadtree
chadtree copied to clipboard
[Feature request] CHADIsOpen
Hey!
Thanks for the work on this!
I'm not sure if there's current a way to do this, but it'd be sweet if there was a way to get the current state of chadtree.
Main reason I want this is I'd like to create a function that exits vim if, in this case, chadtree is the last window open.
I'm basing this off of how nerdtree worked, if it was the only window open, vim would just close.
Any possibility for this to be an option?
+1 on that one. CHADtree breaks a little when I invoke it using <cmd>CHADopen $path<cr>
because it does not toggle, so having a way of knowing if it is open would help a lot with that :)
@distek I think if you add this to your init.vim
file, it should do the trick
autocmd bufenter * if (winnr("$") == 1 && &buftype == "nofile" && &filetype == "CHADTree") | q! | endif
I came across this because I was looking for a :CHADclose
command. I ended up using this here:
function! CloseChadTree()
let l:bufs = filter(range(1, bufnr('$')), 'getbufvar(v:val, "&filetype") == "CHADTree"')
for l:buf in l:bufs
:execute "bdelete " . l:buf
endfor
endfunction
A function to check if CHADTree is open might then look like this:
function! IsChadTreeOpen()
let l:bufs = filter(range(1, bufnr('$')), 'getbufvar(v:val, "&filetype") == "CHADTree" && bufwinnr(v:val) > 0')
return len(l:bufs) > 0
endfunction