Commits

Michael Hart committed dd4b329

Use a callback function to call out to another program/script
This provides the user the ability to rapidly navigate to a particular
directory then explore that with NERDTree or any other function for filesystem
manipulation etc.
let g:LycosaExplorerYankCallback = "g:my_function_name"
The function given must accept one argument, a directory name.

Comments (0)

Files changed (2)

         Explorer.__init__(self)
         self.prompt = FilesystemPrompt()
         self.memoized_dir_contents = {}
+        self._yank_callback = None
 
     def run(self):
         if self.running:
                 if self.prompt.at_dir():
                     path_str = self.prompt.input + e.label
                 else:
-                    path_str = os.path.join(self.prompt.dirname, e.label)
+                    path_str = os.path.join(self.prompt.dirname(), e.label)
 
                 if os.path.isfile(path_str):
                     self.load_file(path_str, self.CURRENT_TAB)
         elif i == 18:  # <C-r> refresh
             del self.memoized_dir_contents[self.view_path()]
             self._refresh(self.FULL)
+        elif i == 24:  # C-y yank to external function
+            if self._yank_callback is not None:
+                if self.prompt.at_dir():
+                    dirname = self.prompt.input
+                else:
+                    dirname = self.prompt.dirname()
+                self.cancel()
+                vim.eval("%s('%s')" % (self._yank_callback,
+                                       single_quote_escape(dirname)))
         else:
             Explorer.key_pressed(self)
 
             path = os.path.dirname(input_)
         return os.path.abspath(path)
 
+    def _create_explorer_window(self):
+        Explorer._create_explorer_window(self)
+        opt_name = "g:LycosaExplorerYankCallback"
+        if eval_bool("exists('%s') && %s != '0'" % (opt_name, opt_name)):
+            self._yank_callback = vim.eval("%s" % opt_name)
+            mapcmd = "noremap <silent> <buffer>"
+            key_binding_prefix = "Lycosa" + self.__class__.__name__
+            vim.command("%s %s    :call <SID>%sKeyPressed(%d)<CR>" % (
+                mapcmd, '<C-y>', key_binding_prefix, 24))
+
     def all_files_at_view(self):
         view = self.view_path()
 
 
             if abbrev == '.':
                 # Sort alphabetically, otherwise it just looks weird.
-                return sorted(matches, key=operator.attrgetter("label"))
+                order_fn = operator.attrgetter("label")
             else:
                 # Sort by score.
-                return sorted(matches, key=lambda x: -x.current_score)
+                order_fn = lambda x: -x.current_score
+            return sorted(matches, key=order_fn)
 
     def _open_entry(self, entry, open_mode):
         path = os.path.join(self.view_path(), entry.label)

plugin/lycosaexplorer.vim

 "  Maintainers: Michael Hart
 "
 " Release Date: January 16 2012
-"      Version: 0.8
+"      Version: 0.9
 "
 "        Usage:
 "                 <Leader>lf  - Opens the filesystem explorer.
 "                 <C-r>    [r]efresh directory contents
 "                 <C-a>    open [a]ll files in current tab
 "                 <C-e>    create new buffer with the given name and path
+"                 <C-y>    call callback, see install instructions below
 "
 " Filesystem Explorer:
 "
 " already provided. You can do this so like this (in .vimrc)
 "
 "   let g:LycosaExplorerDefaultMappings = 0
+"
+" You can set a callback to be run with the current directory name when C-y is
+" pressed in a filesystem explorer, for example:
+"
+"   function g:example_callback(dirname)
+"       echo a:dirname
+"   endfunction
+"
+"   let g:LycosaExplorerYankCallback = "g:example_callback"
 
 " Exit quickly when already loaded.
 if exists("g:loaded_lycosaexplorer")