diff --git a/autoload/projectionist.vim b/autoload/projectionist.vim index f5ba406..9aeeaad 100644 --- a/autoload/projectionist.vim +++ b/autoload/projectionist.vim @@ -239,6 +239,36 @@ function! s:match(file, pattern) abort return clean ==# match ? '' : clean endfunction +function! projectionist#list_project_files() abort + let found_files = {} + for [type, projection_variants] in items(projectionist#navigation_commands()) + let found_files[type] = projectionist#list_files_for_type(type) + endfor + return found_files +endfunction + +function! projectionist#list_files_for_type(type) abort + let nav_commands = projectionist#navigation_commands() + if !has_key(nav_commands, a:type) + return [] + endif + let projection_variants = nav_commands[a:type] + let projections = s:get_projections_from_variants(projection_variants) + return s:files_in_projections(projections) +endfunction + +function! s:files_in_projections(projections) abort + let files_in_projections = [] + for projection in a:projections + if projection !~# '\*' + continue + endif + let glob = s:sanitize_glob(projection) + let files_in_projections += map(split(glob(glob), "\n"), '[s:match(v:val, projection), v:val]') + endfor + return files_in_projections +endfunction + function! projectionist#query_raw(key, ...) abort let candidates = [] let file = a:0 ? a:1 : get(b:, 'projectionist_file', expand('%:p')) @@ -493,11 +523,7 @@ function! projectionist#navigation_commands() abort endfunction function! s:open_projection(cmd, variants, ...) abort - let formats = [] - for variant in a:variants - call add(formats, variant[0] . projectionist#slash() . (variant[1] =~# '\*\*' - \ ? variant[1] : substitute(variant[1], '\*', '**/*', ''))) - endfor + let formats = s:get_projections_from_variants(a:variants) if a:0 && a:1 ==# '&' let s:last_formats = formats return '' @@ -527,6 +553,20 @@ function! s:open_projection(cmd, variants, ...) abort \ fnameescape(fnamemodify(target, ':~:.')) endfunction +function! s:get_projection_from_variant(variant) abort + let projection = a:variant[0] . projectionist#slash() . (a:variant[1] =~# '\*\*' + \ ? a:variant[1] : substitute(a:variant[1], '\*', '**/*', '')) + return projection +endfunction + +function! s:get_projections_from_variants(variants) abort + let projections = [] + for variant in a:variants + call add(projections, s:get_projection_from_variant(variant)) + endfor + return projections +endfunction + function! s:projection_complete(lead, cmdline, _) abort execute matchstr(a:cmdline, '\a\@ + {'type1': [['file1', '/home/user/full/path/to/file1'], + \ ['file2', '/home/user/full/path/to/file2']], + \ 'type2': [['file1', '/home/user/full/path/to/file1'], + \ ['file2', '/home/user/full/path/to/file4']]} +< + The short versions of the filenames (`file1`, `file2` etc.) are + there for use with |projectionist-commands|. + For instance, `:Etype1 file1` would edit `file1`. + + + *projectionist#list_files_for_type()* +projectionist#list_files_for_type({type}) + Returns the list of files that belong to the current project and + are of type {type}. The list has the following form: +> + [['file1', '/home/user/full/path/to/file1'], + \ ['file2', '/home/user/full/path/to/file2']] +< + If {type} is not an existing projection type, an empty list is + returned. If {type} exists, calling this function is equivalent + to calling `projectionist#list_project_files()[{type}]`. + vim:tw=78:et:ft=help:norl: