Anonymous avatar Anonymous committed c4f0eb3

Using y-or-n-p when confirming

Comments (0)

Files changed (2)

 * new file/directory/module/package; C-x p n [fdmp]
 * showing proposal type in code-assist
 * code assists when the buffer is changed causes problems
+* including pymacs in rope?
 * only saving python files before refactorings

ropemacs/__init__.py

 from rope.contrib import codeassist, generate
 
 
-class interactive(object):
-
-    def __init__(self, mode=''):
-        self.mode = mode
-
-    def __call__(self, func):
-        func.interaction = self.mode
-        return func
-
+def interactive(func):
+    func.interaction = ''
+    return func
 
 def lispfunction(func):
     func.lisp = None
         if self.project is not None:
             self.close_project()
 
-    @interactive('DRope Project Root Folder: ')
-    def open_project(self, root):
+    @interactive
+    def open_project(self):
+        root = lisp.read_directory_name('Rope project root folder: ')
         if self.project is not None:
             self.close_project()
         self.project = project.Project(root)
 
-    @interactive()
+    @interactive
     def close_project(self):
         if project is not None:
             self.project.close()
             self.project = None
             lisp.message('Project closed')
 
-    @interactive('cUndo refactoring might change many files; proceed? (y)')
-    def undo_refactoring(self, confirm):
-        if chr(confirm) in ('\r', '\n', 'y'):
+    @interactive
+    def undo_refactoring(self):
+        if lisp.y_or_n_p('Undo refactoring might change'
+                         ' many files; proceed? (y)'):
             self._check_project()
             for changes in self.project.history.undo():
                 self._reload_buffers(changes.get_changed_resources())
 
-    @interactive('cRedo refactoring might change many files; proceed? (y)')
-    def redo_refactoring(self, confirm):
-        if chr(confirm) in ('\r', '\n', 'y'):
+    @interactive
+    def redo_refactoring(self):
+        if lisp.y_or_n_p('Redo refactoring might change'
+                         ' many files; proceed? (y)'):
             self._check_project()
             for changes in self.project.history.redo():
                 self._reload_buffers(changes.get_changed_resources())
         changes = renamer.get_changes(newname, docs=True)
         self._perform(changes)
 
-    @interactive()
+    @interactive
     def rename(self):
         self.do_rename()
 
-    @interactive()
+    @interactive
     def rename_current_module(self):
         self.do_rename(module=True)
 
-    @interactive()
+    @interactive
     def move(self):
         mover = self._create_mover()
         if isinstance(mover, rope.refactor.move.MoveGlobal):
         destination = self.project.pycore.find_module(dest_package)
         self._perform(mover.get_changes(destination))
 
-    @interactive()
+    @interactive
     def move_current_module(self):
         mover = self._create_mover(module=True)
         dest_package = _ask('Destination Package: ')
         destination = self.project.pycore.find_module(dest_package)
         self._perform(mover.get_changes(destination))
 
-    @interactive()
+    @interactive
     def module_to_package(self):
         self._check_project()
         lisp.save_buffer()
         changes = extractor.get_changes(newname)
         self._perform(changes)
 
-    @interactive()
+    @interactive
     def extract_variable(self):
         self._do_extract(rope.refactor.extract.ExtractVariable,
                          'New Variable Name: ')
 
-    @interactive()
+    @interactive
     def extract_method(self):
         self._do_extract(rope.refactor.extract.ExtractMethod,
                          'New Method Name: ')
 
-    @interactive()
+    @interactive
     def inline(self):
         self._check_project()
         self._save_buffers()
             self.project, resource, offset)
         self._perform(inliner.get_changes())
 
-    @interactive()
+    @interactive
     def organize_imports(self):
         self._check_project()
         lisp.save_buffer()
     def _get_offset(self):
         return lisp.point() - 1
 
-    @interactive()
+    @interactive
     def goto_definition(self):
         self._check_project()
         resource, offset = self._get_location()
             self.project, lisp.buffer_string(), offset, resource)
         self._goto_location(definition)
 
-    @interactive()
+    @interactive
     def show_doc(self):
         self._check_project()
         resource, offset = self._get_location()
             lisp.insert(docs)
             lisp.display_buffer(pydoc_buffer)
 
-    @interactive()
+    @interactive
     def code_assist(self):
         self._check_project()
         resource, offset = self._get_location()
         lisp.delete_region(starting_offset + 1, offset + 1)
         lisp.insert(result)
 
-    @interactive()
+    @interactive
     def find_file(self):
         self._check_project()
         files = self.project.get_files()
         if location[1]:
             lisp.goto_line(location[1])
 
-    @interactive()
+    @interactive
     def generate_variable(self):
         self._generate_element('variable')
 
-    @interactive()
+    @interactive
     def generate_function(self):
         self._generate_element('function')
 
-    @interactive()
+    @interactive
     def generate_class(self):
         self._generate_element('class')
 
-    @interactive()
+    @interactive
     def generate_module(self):
         self._generate_element('module')
 
-    @interactive()
+    @interactive
     def generate_package(self):
         self._generate_element('package')
 
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.