]> git.rmz.io Git - dotfiles.git/blobdiff - vim/after/plugin/togglelist.vim
lazyvim: absorb icons into rmz.util.ui
[dotfiles.git] / vim / after / plugin / togglelist.vim
index 8eb7b2b6050d1271c9a3adf437895bc125c4599d..278362c8392ef0e0e150e6076118480930808203 100644 (file)
@@ -2,47 +2,32 @@
 if exists("g:loaded_toggle_list")
   finish
 endif
-
 let g:loaded_toggle_list = 1
 
-function! s:GetBufferList()
-  redir =>buflist
-  silent! ls
-  redir END
-  return buflist
-endfunction
-
+" Inspired by
+" https://github.com/drmingdrmer/vim-toggle-quickfix/blob/master/autoload/togglequickfix.vim
 function! s:ToggleLocationList()
-  for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~# "Location List"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
-      lclose
-      return
-  endfor
-
   let last = winnr('$')
-
+  let cur = winnr()
   try
-    Errors
-  catch
-    try
-      lopen
-    catch /E776/
-    endtry
-  endtry
-  if last == winnr('$')
+    lwindow 10
+  catch /E776/
     echohl WarningMsg | echon 'No Location List' | echohl None
+  endtry
+  if winnr('$') == last
+    lclose
+  elseif winnr() != cur
+    wincmd p
   endif
 endfunction
 
 function! s:ToggleQuickfixList()
-  for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~ "Quickfix List"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
-    if bufwinnr(bufnum) != -1
-      cclose
-      return
-    endif
-  endfor
-  let winnr = winnr()
-  copen 10
-  if winnr() != winnr
+  let last = winnr('$')
+  let cur = winnr()
+  cwindow 10
+  if winnr('$') == last
+    cclose
+  elseif winnr() != cur
     wincmd p
   endif
 endfunction
@@ -59,9 +44,10 @@ function! s:ToggleUnite()
   UniteResume
 endfunction
 
-nmap <silent> [oq :copen<cr>
-nmap <silent> ]oq :cclose<cr>
-nmap <silent> coq :call <SID>ToggleQuickfixList()<CR>
-nmap <silent> [ol :lopen<cr>
-nmap <silent> ]ol :lclose<cr>
-nmap <silent> col :call <SID>ToggleLocationList()<CR>
+nnoremap <silent> [oq :copen<cr>
+nnoremap <silent> ]oq :cclose<cr>
+nnoremap <silent> coq :call <SID>ToggleQuickfixList()<CR>
+nnoremap <silent> [ol :lopen<cr>
+nnoremap <silent> ]ol :lclose<cr>
+nnoremap <silent> col :call <SID>ToggleLocationList()<CR>
+nnoremap <silent> cop :pclose<CR>