]> git.rmz.io Git - dotfiles.git/commitdiff
vim: update togglelist to also work in nvim
authorSamir Benmendil <me@rmz.io>
Wed, 12 Apr 2023 13:44:43 +0000 (14:44 +0100)
committerSamir Benmendil <me@rmz.io>
Tue, 31 Oct 2023 23:08:51 +0000 (23:08 +0000)
I think the Quickfix window has been renamed which caused this to stop
working. The approach of using [cl]window seems better.

vim/after/plugin/togglelist.vim

index dbb06f1ec74dfa8ee2e11ad4739f7b152a07b86a..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