Skip to content

Commit 6a35a93

Browse files
author
Shahaf Arad
committed
Show plugins' description and search in them
1 parent 0b28e33 commit 6a35a93

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

autoload/vundle/scripts.vim

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ func! vundle#scripts#all(bang, ...)
1111
let info = ['"Keymap: i - Install plugin; c - Cleanup; s - Search; R - Reload list']
1212
let matches = s:load_scripts(a:bang)
1313
if !empty(a:1)
14-
let matches = filter(matches, 'v:val =~? "'.escape(a:1,'"').'"')
14+
let escapedSearch = escape(a:1,'"')
15+
" Search both name and description of a plugin
16+
" for matches
17+
let matches = filter(matches,
18+
\ 'v:val.n =~? "'.escapedSearch.'" ||
19+
\ v:val.s =~? "'.escapedSearch.'"')
1520
let info += ['"Search results for: '.a:1]
16-
" TODO: highlight matches
1721
let b:match = a:1
1822
endif
19-
call vundle#scripts#view('search',info, vundle#scripts#bundle_names(reverse(matches)))
23+
call vundle#scripts#view('search',info, vundle#scripts#bundle_search_data(matches))
24+
25+
if exists('escapedSearch')
26+
exec 'match Search /\v\c' . escapedSearch . '/'
27+
endif
28+
2029
redraw
2130
echo len(matches).' plugins found'
2231
endf
@@ -115,9 +124,18 @@ endf
115124
" return -- a list of 'Plugin ...' lines suitable to be written to a buffer
116125
" ---------------------------------------------------------------------------
117126
func! vundle#scripts#bundle_names(names)
118-
return map(copy(a:names), ' printf("Plugin ' ."'%s'".'", v:val) ')
127+
return map(copy(a:names), ' printf("Plugin ''%s''", v:val ')
119128
endf
120129

130+
" ---------------------------------------------------------------------------
131+
" Create a list of 'Plugin ...' lines from a list of bundle search data.
132+
"
133+
" names -- a list of data (dictionaries) of plugins
134+
" return -- a list of 'Plugin ...' lines suitable to be written to a buffer
135+
" ---------------------------------------------------------------------------
136+
func! vundle#scripts#bundle_search_data(data)
137+
return map(copy(a:data), ' printf("Plugin ''%s'' \" %s", v:val.n, v:val.s) ')
138+
endf
121139

122140
" ---------------------------------------------------------------------------
123141
" Open a buffer to display information to the user. Several special commands
@@ -158,6 +176,9 @@ func! vundle#scripts#view(title, headers, results)
158176
syn keyword vimCommand Bundle
159177
syn keyword vimCommand Helptags
160178

179+
" Without this, highlighting breaks when description contains double quotes
180+
syn match vimComment '\v".*$'
181+
161182
com! -buffer -bang -nargs=1 DeletePlugin
162183
\ call vundle#installer#run('vundle#installer#delete', split(<q-args>,',')[0], ['!' == '<bang>', <args>])
163184

@@ -175,13 +196,13 @@ func! vundle#scripts#view(title, headers, results)
175196
com! -buffer -nargs=0 VundleChangelog call s:view_changelog()
176197

177198
nnoremap <buffer> q :silent bd!<CR>
178-
nnoremap <buffer> D :exec 'Delete'.getline('.')<CR>
199+
nnoremap <buffer> D :exec 'Delete'.<SID>get_plugin_line()<CR>
179200
180-
nnoremap <buffer> add :exec 'Install'.getline('.')<CR>
181-
nnoremap <buffer> add! :exec 'Install'.substitute(getline('.'), '^Plugin ', 'Plugin! ', '')<CR>
201+
nnoremap <buffer> add :exec 'Install'.<SID>get_plugin_line()<CR>
202+
nnoremap <buffer> add! :exec 'Install'.substitute(<SID>get_plugin_line(), '^Plugin ', 'Plugin! ', '')<CR>
182203
183-
nnoremap <buffer> i :exec 'InstallAndRequire'.getline('.')<CR>
184-
nnoremap <buffer> I :exec 'InstallAndRequire'.substitute(getline('.'), '^Plugin ', 'Plugin! ', '')<CR>
204+
nnoremap <buffer> i :exec 'InstallAndRequire'.<SID>get_plugin_line()<CR>
205+
nnoremap <buffer> I :exec 'InstallAndRequire'.substitute(<SID>get_plugin_line(), '^Plugin ', 'Plugin! ', '')<CR>
185206
186207
nnoremap <buffer> l :VundleLog<CR>
187208
nnoremap <buffer> u :VundleChangelog<CR>
@@ -199,6 +220,14 @@ func! vundle#scripts#view(title, headers, results)
199220
endf
200221

201222

223+
" ---------------------------------------------------------------------------
224+
" Remove description from plugin line to prevent current
225+
" implementation from breaking.
226+
" ---------------------------------------------------------------------------
227+
func! s:get_plugin_line()
228+
return matchstr(getline('.'), '\vPlugin\s''.{-}''')
229+
endf
230+
202231
" ---------------------------------------------------------------------------
203232
" Load the plugin database from vim-scripts.org .
204233
"
@@ -211,7 +240,7 @@ func! s:fetch_scripts(to)
211240
call mkdir(scripts_dir, "p")
212241
endif
213242

214-
let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json'
243+
let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts_recent.json'
215244
if executable("curl")
216245
let cmd = 'curl --fail -s -o '.vundle#installer#shellesc(a:to).' '.l:vim_scripts_json
217246
elseif executable("wget")

0 commit comments

Comments
 (0)