Anonymous avatar Anonymous committed 21bb0b3

Only activating local keys in python mode

Comments (0)

Files changed (3)

  ropemacs, rope in emacs
 =========================
 
-For using rope in emacs.  You should install `rope`_ library before
-using ropemacs.
+Ropemacs is an emacs mode that uses rope_ library to provide features
+like refactorings and code-assists.  You should install rope_ library
+and Pymacs before using ropemacs.
 
 .. _`rope`: http://rope.sf.net/
 
 TODO
 ====
 
-
 > Public Release 1.0
 
-* only activating keybinding in python files
 * previewing changes
 * showing refactoring progress
 * adding a menu
+* including pymacs in ropemacs?
 * change pymacs to accept unicode strings
 
 > Public Release 0.2
 * specifying refactoring options
 * new file/directory/module/package; C-x p n [fdmp]
 * showing proposal type in code-assist
-* including pymacs in rope?
 * an option for saving files before refactorings without asking

ropemacs/__init__.py

     @lispfunction
     def init(self):
         """Initialize rope mode"""
-        lisp.add_hook(lisp.before_save_hook,
-                      lisp.rope_before_save_actions)
-        lisp.add_hook(lisp.after_save_hook,
-                      lisp.rope_after_save_actions)
-        lisp.add_hook(lisp.kill_emacs_hook,
-                      lisp.rope_exiting_actions)
+        lisp.add_hook(lisp.before_save_hook, lisp.rope_before_save_actions)
+        lisp.add_hook(lisp.after_save_hook, lisp.rope_after_save_actions)
+        lisp.add_hook(lisp.kill_emacs_hook, lisp.rope_exiting_actions)
+        lisp.add_hook(lisp.python_mode_hook, lisp.rope_register_local_keys)
 
-        actions = [
+        self.global_keys = [
             ('C-x p o', lisp.rope_open_project),
             ('C-x p k', lisp.rope_close_project),
             ('C-x p u', lisp.rope_undo_refactoring),
             ('C-x p r', lisp.rope_redo_refactoring),
-            ('C-x p f', lisp.rope_find_file),
+            ('C-x p f', lisp.rope_find_file)]
 
+        self.local_keys = [
             ('C-c r r', lisp.rope_rename),
             ('C-c r l', lisp.rope_extract_variable),
             ('C-c r m', lisp.rope_extract_method),
             ('C-c n m', lisp.rope_generate_module),
             ('C-c n p', lisp.rope_generate_package)]
 
-        for key, callback in actions:
+        for key, callback in self.global_keys:
             lisp.global_set_key(self._key_sequence(key), callback)
 
     def _key_sequence(self, sequence):
             self.old_content = None
 
     @lispfunction
+    def register_local_keys(self):
+        for key, callback in self.local_keys:
+            lisp.local_set_key(self._key_sequence(key), callback)
+
+    @lispfunction
     def exiting_actions(self):
         if self.project is not None:
             self.close_project()
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.