Skip to content

Commit 1732c6c

Browse files
committed
Improve title of quick-fix windows with search results
1 parent edcbac0 commit 1732c6c

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

autoload/xolox/notes.vim

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.17.4'
9+
let g:xolox#notes#version = '0.17.5'
1010
let s:scriptdir = expand('<sfile>:p:h')
1111

1212
call xolox#misc#compat#check('notes', 1)
@@ -398,16 +398,13 @@ function! xolox#notes#search(bang, input) " {{{1
398398
endif
399399
if input =~ '^/.\+/$'
400400
call s:internal_search(a:bang, input, '', '')
401-
if &buftype == 'quickfix'
402-
let w:quickfix_title = 'Notes matching the pattern ' . input
403-
endif
401+
call s:set_quickfix_title([], input)
404402
else
405403
let keywords = split(input)
406404
let all_keywords = s:match_all_keywords(keywords)
407405
let any_keyword = s:match_any_keyword(keywords)
408406
call s:internal_search(a:bang, all_keywords, input, any_keyword)
409407
if &buftype == 'quickfix'
410-
call map(keywords, '"`" . v:val . "''"')
411408
" Enable line wrapping in the quick-fix window.
412409
setlocal wrap
413410
" Resize the quick-fix window to 1/3 of the screen height.
@@ -418,8 +415,7 @@ function! xolox#notes#search(bang, input) " {{{1
418415
let preferred_height = winline()
419416
execute 'resize' min([max_height, preferred_height])
420417
normal gg
421-
let w:quickfix_title = printf('Notes containing the word%s %s', len(keywords) == 1 ? '' : 's',
422-
\ len(keywords) > 1 ? (join(keywords[0:-2], ', ') . ' and ' . keywords[-1]) : keywords[0])
418+
call s:set_quickfix_title(keywords, '')
423419
endif
424420
endif
425421
call xolox#misc#timer#stop("notes.vim %s: Searched notes in %s.", g:xolox#notes#version, starttime)
@@ -450,6 +446,24 @@ function! s:match_any_keyword(keywords) " {{{2
450446
return '/' . escape(join(results, '\|'), '/') . '/'
451447
endfunction
452448

449+
function! s:set_quickfix_title(keywords, pattern) " {{{2
450+
" Set the title of the quick-fix window.
451+
if &buftype == 'quickfix'
452+
let num_notes = len(xolox#misc#list#unique(map(getqflist(), 'v:val["bufnr"]')))
453+
if len(a:keywords) > 0
454+
let keywords = map(copy(a:keywords), '"`" . v:val . "''"')
455+
let w:quickfix_title = printf('Found %i note%s containing the word%s %s',
456+
\ num_notes, num_notes == 1 ? '' : 's',
457+
\ len(keywords) == 1 ? '' : 's',
458+
\ len(keywords) > 1 ? (join(keywords[0:-2], ', ') . ' and ' . keywords[-1]) : keywords[0])
459+
else
460+
let w:quickfix_title = printf('Found %i note%s containing the pattern %s',
461+
\ num_notes, num_notes == 1 ? '' : 's',
462+
\ a:pattern)
463+
endif
464+
endif
465+
endfunction
466+
453467
function! xolox#notes#related(bang) " {{{1
454468
" Find all notes related to the current note or file.
455469
let starttime = xolox#misc#timer#start()

0 commit comments

Comments
 (0)