Anonymous avatar Anonymous committed daa31b9

added hooks

Comments (0)

Files changed (1)

         self._add_command(name, callback, key, prefix, prekey='<F12>p')
 
     def add_hook(self, name, callback, hook):
-        pass
+        mapping = {'before_save': 'FileWritePre,BufWritePre',
+                   'after_save': 'FileWritePost,BufWritePost',
+                   'exit': 'VimLeave'}
+        self._add_function(name, callback)
+        vim.command('autocmd %s *.py call %s()' %
+                    (mapping[hook], _vim_name(name)))
 
     def _add_command(self, name, callback, key, prefix, prekey):
+        self._add_function(name, callback, prefix)
+        if key is not None:
+            key = prekey + key.replace(' ', '')
+            vim.command('map %s :call %s()' % (key, _vim_name(name)))
+
+    def _add_function(self, name, callback, prefix=False):
         globals()[name] = callback
         arg = '0' if prefix else ''
         vim.command('function! %s()\n' % _vim_name(name) +
                     'python ropevim.%s(%s)\n' % (name, arg) +
                     'endfunction\n')
-        if key is not None:
-            key = prekey + key.replace(' ', '')
-            vim.command('map %s :call %s()' % (key, _vim_name(name)))
 
 
 def _vim_name(name):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.