Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on empty location list #8

Open
goodboy opened this issue Jan 4, 2017 · 1 comment
Open

Warn on empty location list #8

goodboy opened this issue Jan 4, 2017 · 1 comment

Comments

@goodboy
Copy link

goodboy commented Jan 4, 2017

I was using this plug I found some time ago until finding your lovely alternative:

function! toggle#GetBufferList()
  redir =>buflist
  silent! ls
  redir END
  return buflist
endfunction

function! toggle#ToggleList(bufname, pfx)
  let buflist = toggle#GetBufferList()
  for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
    if bufwinnr(bufnum) != -1
      exec(a:pfx.'close')
      return
    endif
  endfor
  if a:pfx == 'l' && len(getloclist(0)) == 0
    echohl ErrorMsg
    echo "Location List is Empty."
    return
  endif
  let winnr = winnr()
  exec(a:pfx.'open')
  if winnr() != winnr
    wincmd p
  endif
endfunction

The thing I miss is the error message that alerts you that the list is empty.
Not sure if you'd be cool with adding something like that or not?

@ghost
Copy link

ghost commented Mar 27, 2017

@tgoodlet You can check my fork ListToggle.vim. I added this error handling and I'm using the <Plug> special key. This allows for lazy loading in a plugin manager like vim-plug or dein.
Example:

Plug 'fszymanski/ListToggle.vim', {
      \ 'on': ['<Plug>ListToggleQuickfixListToggle',
      \        '<Plug>ListToggleLocationListToggle']
      \ }

let g:listtoggle_no_maps = 1

nmap <Leader>q <Plug>ListToggleQuickfixListToggle
nmap <Leader>l <Plug>ListToggleLocationListToggle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant