<commit_before>" Quickfix {{{
augroup Quickfix
 autocmd!
 autocmd BufWinEnter quickfix let g:quickfixwin = bufnr("$")
 autocmd BufWinLeave * if exists("g:quickfixwin") && expand("<abuf>") == g:quickfixwin | unlet! g:quickfixwin | endif
augroup END

" Execute a quickfix list command (preceded by 'c') if it exists (even if not
" visible), else execute a location list command (preceded by 'l').
function! QuickfixOrLocationExists(cmd)
  silent! exec(len(getqflist()) > 0 ? 'c'.a:cmd : 'l'.a:cmd)
endfunction
" Execute a quickfix list command if it exists and is visible, else execute a
" location list command (preceded by 'l').
function! QuickfixOrLocationIsOpen(cmd)
  silent! exec(exists("g:quickfixwin") > 0 ? 'c'.a:cmd : 'l'.a:cmd)
endfunction
" Execute a quickfix list command if it exists and is visible, or focus the
" quickfix list if it has only one item. If the Quickfix List does not exist
" or is not visible, execute a location list command or focus it.
function! QuickfixOrLocationMove(cmd)
  let qflist = getqflist()
  let loclist = getloclist(0)

  if (exists("g:quickfixwin") && len(qflist) > 0)
    silent! exec(len(qflist) > 1 ? 'c'.a:cmd : 'cc')
  elseif (len(loclist) > 0)
    silent! exec(len(loclist) > 1 ? 'l'.a:cmd : 'll')
  endif
endfunction

command! Lopen  call QuickfixOrLocationExists('open')
command! Lclose call QuickfixOrLocationIsOpen('close')
command! Lwin   call QuickfixOrLocationIsOpen('win')
command! Lnext  call QuickfixOrLocationMove('next')
command! Lprev  call QuickfixOrLocationMove('prev')

" Perform a vimgrep search, open the quickfix list and jump to the first match.
command! -nargs=+ -complete=file_in_path -bar Vim vim <args> | cw | cfirst
" Perform a vimgrep search over files of same extension under the current
" directory (recursively).
command! -nargs=+ -complete=user -bar Vims execute "Vim /\\<<args>\\>/g **/*" . (expand("%:e") == "" ? "" : ".".expand("%:e")) | silent! g/<args>/
" }}}
<commit_msg>Fix quickfix and location list handling after Vim8 updates<commit_after>function! QuickfixIsOpen()
  " " The command below used to work before Vim8...
  " return len(filter(range(1, winnr('$')), 'getbufvar(winbufnr(v:val), "&buftype") == "quickfix"')) > 0

  " Now the only reliable way to detect whether a quickfix window is opened is
  " by using ls.
  silent! exec 'redir @a | ls | redir END'
  return match(@a,'"\[Quickfix List\]"') >= 0
endfunction

" Execute a quickfix list command (preceded by 'c') if it exists (even if not
" visible), else execute a location list command (preceded by 'l').
function! QuickfixOrLocationExists(cmd, ...)
  let cmdl = a:0 == 0 ? a:cmd : a:1
  silent! exec(len(getqflist()) > 0 ? 'c'.a:cmd : 'l'.cmdl)
endfunction

" Execute a quickfix list command if it exists and is visible, else execute a
" location list command (preceded by 'l').
function! QuickfixOrLocationIsOpen(cmd, ...)
  let cmdl = a:0 < 1 ? a:cmd : a:1
  echo QuickfixIsOpen()
  exec(QuickfixIsOpen() ? 'c'.a:cmd : 'l'.cmdl)
endfunction

" Execute a quickfix list command if it exists and is visible, or focus the
" quickfix list if it has only one item. If the Quickfix List does not exist
" or is not visible, execute a location list command or focus it.
function! QuickfixOrLocationMove(cmd)
  let qflist = getqflist()
  let loclist = getloclist(0)

  if (QuickfixIsOpen() && len(qflist) > 0)
    silent! exec(len(qflist) > 1 ? 'c'.a:cmd : 'cc')
  elseif (len(loclist) > 0)
    silent! exec(len(loclist) > 1 ? 'l'.a:cmd : 'll')
  endif
endfunction

command! Lopen  call QuickfixOrLocationExists('open')
command! Lclose call QuickfixOrLocationIsOpen('close')
command! Lwin   call QuickfixOrLocationExists('win')
command! Llist  call QuickfixOrLocationIsOpen('c', 'l')
command! Lnext  call QuickfixOrLocationMove('next')
command! Lprev  call QuickfixOrLocationMove('prev')

" Perform a vimgrep search, open the quickfix list and jump to the first match.
command! -nargs=+ -complete=file_in_path -bar Vim vim <args> | cw | cfirst
" Perform a vimgrep search over files of same extension under the current
" directory (recursively).
command! -nargs=+ -complete=user -bar Vims execute "Vim /\\<<args>\\>/g **/*" . (expand("%:e") == "" ? "" : ".".expand("%:e")) | silent! g/<args>/
" }}}

{'fraction_non_alphanumeric': 0.13733804475853945, 'fraction_numerical': 0.005653710247349823, 'mean_word_length': 4.6537949400798935, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4508140', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1417, 'n_words': 487}