X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=plugin%2Fmkbuild.vim;fp=plugin%2Fmkbuild.vim;h=eb3fd2bd767cba259abe9a9ebbb991d4d82c3d48;hb=efdf81b93665f15ea17ba7858e921663139e014c;hp=fd92caa28683d51da22f310305e029dd17fee78f;hpb=7ba078c7fb1c9a445c4f9db531f09b222f182dc9;p=vim-mkbuild.git diff --git a/plugin/mkbuild.vim b/plugin/mkbuild.vim index fd92caa..eb3fd2b 100644 --- a/plugin/mkbuild.vim +++ b/plugin/mkbuild.vim @@ -85,6 +85,61 @@ function! s:filels(filelist) return "(cat " . a:filelist . ")" endfunction +" Generate a command to generate a list of files. Return a dictionary +" containing two entries: +" source - The source of the files (generated by executing the sourcecmd) +" sourcecmd - The system command to use to generate the list of files +" +" The source command returned will output files from one of 4 locations, +" searched in priority order: +" 1. All filelist files found in the same directory(ies) vim looks for tags +" files. Files are extracted from the contents of these files. +" 2. Any tags files found in &tags. The file is parsed to get filenames. +" 3. The tracked files in the current git repository, and/or the tracked files +" in those valid git repositories named in the 'extrefs' file, if present. +" 4. Perform a 'find . -type f' in the current directory. +function! mkbuild#flcmd() + let files = s:filelists() + if empty(files) + let tags = s:tagfiles() + if empty(tags) + let gitdirs = s:gitdirs() + if empty(gitdirs) + let source = 'find' + let sourcecmd = 'find . -type f' + else " gitdirs + let source = 'git|extrefs' + let sourcecmd = '(true' + for g in gitdirs + let sourcecmd = sourcecmd . '; ' . s:gitls(g) + endfor + let sourcecmd = sourcecmd . ')' + endif + else " tags + let source = 'tags' + let sourcecmd = '(true' + for t in tags + let sourcecmd = sourcecmd . '; ' . s:tagls(t) + endfor + let sourcecmd = sourcecmd . ')' + endif + else " filelists + let source = 'filelists' + let sourcecmd = '(true' + for f in files + let sourcecmd = sourcecmd . '; ' . s:filels(f) + endfor + let sourcecmd = sourcecmd . ')' + endif + return { 'source': source, 'sourcecmd': sourcecmd } +endfunction + +" Generate a list of files using mkbuild#flcmd() +function! mkbuild#filelist() + let flcmdres = mkbuild#flcmd() + return s:chompsys(flcmdres['sourcecmd'] . ' | cat') +endfunction + " Use dmenu to select a file to execute with command 'cmd'. If no file is " selected, no action is taken. The list of files presented to dmenu comes " from one of four places, in the following priority order: @@ -98,38 +153,9 @@ function! mkbuild#DmenuOpen(cmd) if empty(system('which dmenu')) echo "Dmenu is not installed" else - let files = s:filelists() - if empty(files) - let tags = s:tagfiles() - if empty(tags) - let gitdirs = s:gitdirs() - if empty(gitdirs) - let source = 'find' - let sourcecmd = 'find . -type f' - else " gitdirs - let source = 'git|extrefs' - let sourcecmd = '(true' - for g in gitdirs - let sourcecmd = sourcecmd . '; ' . s:gitls(g) - endfor - let sourcecmd = sourcecmd . ')' - endif - else " tags - let source = 'tags' - let sourcecmd = '(true' - for t in tags - let sourcecmd = sourcecmd . '; ' . s:tagls(t) - endfor - let sourcecmd = sourcecmd . ')' - endif - else " filelists - let source = 'filelists' - let sourcecmd = '(true' - for f in files - let sourcecmd = sourcecmd . '; ' . s:filels(f) - endfor - let sourcecmd = sourcecmd . ')' - endif + let flcmdres = mkbuild#flcmd() + let source = flcmdres['source'] + let sourcecmd = flcmdres['sourcecmd'] let fname = s:chompsys(sourcecmd . ' | dmenu -i -l 20 -p "' . source . '(' . \ a:cmd . ')"') if empty(fname)