]> oss.titaniummirror.com Git - vim-mkbuild.git/commitdiff
Unite! integration for file selection
authorR. Steve McKown <rsmckown@gmail.com>
Sun, 17 Jan 2016 22:25:59 +0000 (15:25 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Sun, 17 Jan 2016 22:31:06 +0000 (15:31 -0700)
Provide the mkbfiles source for Unite!

autoload/unite/kinds/mkbfiles.vim [new file with mode: 0644]
autoload/unite/sources/mkbfiles.vim [new file with mode: 0644]
plugin/mkbuild.vim

diff --git a/autoload/unite/kinds/mkbfiles.vim b/autoload/unite/kinds/mkbfiles.vim
new file mode 100644 (file)
index 0000000..e7c2b4c
--- /dev/null
@@ -0,0 +1,19 @@
+let s:kind = {
+  \ 'name': 'mkbfiles',
+  \ 'default_action': 'execute',
+  \ 'action_table': {},
+  \ 'parents': [],
+  \ 'description': 'files used in mkbuild project'
+  \ }
+
+let s:kind.action_table.execute = { 'is_selectable': 1 }
+
+function! s:kind.action_table.execute.func(candidates)
+  if len(a:candidates) == 1
+    execute "e" a:candidates[0].word
+  endif
+endfunction
+
+function! unite#kinds#mkbfiles#define()
+  return s:kind
+endfunction
diff --git a/autoload/unite/sources/mkbfiles.vim b/autoload/unite/sources/mkbfiles.vim
new file mode 100644 (file)
index 0000000..d69f8e3
--- /dev/null
@@ -0,0 +1,27 @@
+" unite source: mkbuild filelist
+" Version: 0.0.1
+" Author : R. Steve McKown <rsmckown@gmail.com>
+" License: MIT License
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+let s:source = { 'name': 'mkbfiles' }
+
+function! s:source.gather_candidates(args, context)
+  let sourcecmd = 'find . -type f'
+  let filelist = split(mkbuild#filelist(), '\n')
+
+  return map(filelist, '{
+  \   "word": v:val,
+  \   "source": "mkbfiles",
+  \   "kind": "mkbfiles",
+  \ }')
+endfunction
+
+function! unite#sources#mkbfiles#define()
+  return s:source
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
index fd92caa28683d51da22f310305e029dd17fee78f..eb3fd2bd767cba259abe9a9ebbb991d4d82c3d48 100644 (file)
@@ -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)