chadtree icon indicating copy to clipboard operation
chadtree copied to clipboard

[Feature request] CHADIsOpen

Open distek opened this issue 4 years ago • 3 comments

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?

distek avatar Feb 06 '21 06:02 distek

+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 :)

Diegovsky avatar Jul 23 '21 15:07 Diegovsky

@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

da-moon avatar Sep 03 '21 18:09 da-moon

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

mrubli avatar Oct 22 '21 13:10 mrubli