QuickFix window: only sort if from cscope search, restore title, always auto open
dblume

dblume commited on 2022-03-11 16:54:29
Showing 1 changed files, with 9 additions and 2 deletions.

... ...
@@ -320,10 +320,17 @@ endif
320 320
 " :grep -r term path/
321 321
 " :cw
322 322
 " :ccl (or C-w,q)
323
-autocmd! QuickfixCmdPost * call SortQuickfix('QfStrCmp')
323
+autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
324 324
 
325
-function! SortQuickfix(fn)
325
+function! MaybeSortQuickfix(fn)
326
+"    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
327
+    let t = getqflist({'title': 1}).title
328
+    " Only sort the files if cscope generated the list, not for "make" commands.
329
+    if stridx(t, "cs ") == 0
326 330
         call setqflist(sort(getqflist(), a:fn), 'r')
331
+        call setqflist([], 'r', {'title': t})
332
+    endif
333
+    cwindow
327 334
 endfunction
328 335
 
329 336
 function! QfStrCmp(e1, e2)
330 337