Skip to content

Warn on empty location list #8

@goodboy

Description

@goodboy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions