weirongxu / coc-explorer

📁 Explorer for coc.nvim
MIT License
1.14k stars 45 forks source link

check if coc-explorer window is open #259

Closed pirey closed 4 years ago

pirey commented 4 years ago

is there a way to know if there is current coc-explorer window buffer opened?

right now i'm using this method:

let g:coc_explorer_open = 0

function! s:coc_explorer_is_open() abort
    return get(g:, 'coc_explorer_open', 0)
endfunction

function! s:coc_explorer_state(s) abort
    echom 'state ' . a:s
    let g:coc_explorer_open = a:s
endfunction

autocmd BufEnter *coc-explorer* call s:coc_explorer_state(1)
autocmd BufHidden *coc-explorer* call s:coc_explorer_state(0)

but it rather hacky.

i'm just wondering if it has already this feature built-in to coc-explorer

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.76. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

weirongxu commented 4 years ago

You can use let opened = CocAction('runCommand', 'explorer.getNodeInfo', 'closest') is v:null, more information see this https://github.com/weirongxu/coc-explorer/wiki/Vim-API

pirey commented 4 years ago

i got this error on initial load neovim

image

the error only happen on initial load. the code works after that.

it seems that my code is running before runComman is ready, i'm not really sure. is there a way to check if runCommand is ready? what do you think?

i'm calling this function in lightline component, which i suppose is called everytime lightline is updated.

here's an excerpt.

let g:lightline = {
" ...
\   'tabline': {
\     'left': [['explorer_pad', 'buffers']]
\   }
\   'component_function': {
\     'explorer_pad': 'LightlineCocExplorerLeftpad',
" ...
\   },
" ...
\}

function! LightlineCocExplorerLeftpad() abort
    if &co < 86
        return ''
    endif

    if CocAction('runCommand', 'explorer.getNodeInfo', 'closest') isnot# v:null
        return printf('%-29s', '') . '⎟'
    endif

    return ''
endfunction
weirongxu commented 4 years ago

:help CocNvimInit

pirey commented 4 years ago

Ok. so there is no direct means to check if coc has already started.

for anyone looking at similar issue later, what i do is to set custom variable to indicate coc has initialized.

function! s:on_coc_init()
    let g:coc_ready = 1
endfunction

autocmd User CocNvimInit call s:on_coc_init()

then i can use it in lightline function

    if get(g:, 'coc_ready', 0)
        if CocAction('runCommand', 'explorer.getNodeInfo', 'closest') isnot# v:null
            return printf('%-29s', '') . '⎟'
        endif
    endif

thanks @weirongxu

alps2006 commented 3 days ago

It is not working when having multiple windows by explorer.getNodeInfo.

I use the code below.

    let l:winnrs = filter(range(1, winnr('$')), 'getwinvar(v:val, "&ft") == "coc-explorer"')
    let l:opened  = len(l:winnrs) > 0
    if l:opened
        ......
    else
        ......
    endif