Commits

Anonymous committed f16b422

indent /deindent feature

Comments (0)

Files changed (2)

ropeide/editactions.py

         else:
             return elements.prev(offset)
 
+def indent_block(context):
+    if context.get_active_editor():
+        context.editor.indent_block()
+
+def deindent_block(context):
+    if context.get_active_editor():
+        context.editor.deindent_block()
+
 
 core = ropeide.core.Core.get_core()
 core.add_menu_cascade(MenuAddress(['Edit'], 'e'), ['all', 'none'])
 others = MenuAddress(['Edit', 'Others'], 'o', 0)
 core.add_menu_cascade(others, ['all'])
 
+actions.append(SimpleAction('indent_block', indent_block, 'C-x i',
+                            MenuAddress(['Edit', 'Indent Block'], 'i',4), ['all','none']))
+
+actions.append(SimpleAction('deindent_block', deindent_block, 'C-x d',
+                            MenuAddress(['Edit', 'De-indent Block'], 'd',4), ['all','none']))
+
+
+
 actions.append(SimpleAction('next_word', next_word, 'M-f',
                             others.child('Next Word'), ['all']))
 actions.append(SimpleAction('prev_word', prev_word, 'M-b',

ropeide/editor.py

         self.text.bind('<<Modified>>', self._editor_modified)
         self.text.edit_modified(False)
 
+
+    def indent_block(self):
+        start, end = self._get_region_index()
+        start_line = self._get_line_from_index(start)
+        end_line = self._get_line_from_index(end)
+        for curr_line in xrange (start_line, end_line):
+            self.indenter.indent(curr_line)
+
+    def deindent_block(self):
+        start, end = self._get_region_index()
+        start_line = self._get_line_from_index(start)
+        end_line = self._get_line_from_index(end)
+        for curr_line in xrange (start_line, end_line):
+            self.indenter.deindent(curr_line)
+
+
     def _text_changed(self):
         if not self.change_inspector.is_changed():
             return