Anonymous avatar Anonymous committed 95a5db1

Adding LineOriented class

Comments (0)

Files changed (9)

+- Proposing templates in code-assist proposals : May 26, 2006
+
+
 - Auto-complete from-import imported objects : May 25, 2006
 
 
 * Better multi-sequence key event handling @ 2
 
 
-* Adding TextIterator or LineOriented to the Editor class @ 1
-
-
 * Enhancing editor @ 1
   * Clearing selection if something happens
   * Unifying builtin and emacs-style selections; if selection
   * Showing modified file status
 
 
+* Show quick outline; C-o @ 2
+
+
 * Auto-completing function parameter names when calling @ 2
 
 
   * Auto-completing "self."s
 
 
-* Proposing templates in auto-completion proposals @ 1
-
-
 --- Remaining Stories ---
 ? Change program goals and description; principles.html
   ? Go toward refactoring and ... library rather than an IDE

docs/workingon.txt

-*** Proposing templates in code-assist proposals @ 1 ***
+*** Ignoring string contents while indenting @ 1 ***
 
-- Show the type of the completion in the codeassist dialog
-- Showing templates in completion dialog
-- main, test
-- Not asking for variables if there is none
+- Adding LineOriented to the Editor class
 
-? Builtin templates
-?? Ignoring string contents while indenting
-?? Next/prev word should stop consider underline and capitals as spaces
-?? Better change editor
-?? GUI testing redux
+
+
+--- Before 0.2 Release ---
+* Next/prev word should consider underline and capitals as spaces; make it configurable
+* GUI testing redux
+* Better editor changing dialog; use uihelpers module
+* More builtin templates
+
+
+
+--- Remaining Stories ---
+
 ? From-import might cache module global variables
 ? Directories should contain __init__.py to be packages in codeassist
 ? Auto-completion on relative imports

rope/codeassist.py

 
 
 class TemplateProposal(CodeAssistProposal):
-    """A template proposal"""
+    """A template proposal
+
+    The template attribute is a Template object.
+    """
 
     def __init__(self, name, template):
         super(TemplateProposal, self).__init__(name)
 
 
 class Template(object):
+    """Templates reported by CodeAssist
+    
+    Variables in templates are in the format ${variable}. To put
+    a dollar sign in the template put $$. To set the place of the
+    cursor use ${cursor}.
+    """
 
     def __init__(self, template):
         self.template = template
         
 
 class ICodeAssist(object):
+
     def assist(self, source, offset):
         pass
 
+    def add_template(self, name, template):
+        pass
+
 
 class NoAssist(ICodeAssist):
+
     def assist(self, source_code, offset):
         return Proposals()
 
     def undo_separator(self):
         pass
 
+    def line_editor(self):
+        pass
+
+
 class TextIndex(object):
     '''A class for pointing to a position in a text'''
 
 
+class LineEditor(object):
+    '''An interface for working line oriented with editors'''
+    
+    def get_line(self, line_number):
+        pass
+    
+    def set_line(self, line_number, string):
+        pass
+
+
+class GraphicalLineEditor(LineEditor):
+    def __init__(self, editor):
+        self.editor = editor
+
+    def get_line(self, line_number):
+        return self.editor.text.get('%d.0' % line_number, '%d.0 lineend' % line_number)
+
+    def set_line(self, line_number, contents):
+        old_contents = self.get_line(line_number)
+        if old_contents == contents:
+            return
+        if old_contents.endswith(contents):
+            self.editor.text.delete('%d.0' % line_number,
+                                    '%d.%d' % (line_number, len(old_contents) - len(contents)))
+            return
+        if contents.endswith(old_contents):
+            self.editor.text.insert('%d.0' % line_number, contents[0:len(contents) - len(old_contents)])
+            return
+        self.editor.text.delete('%d.0' % line_number, '%d.0 lineend' % line_number)
+        self.editor.text.insert('%d.0' % line_number, contents)
+
+
 class GraphicalEditor(TextEditor):
     def __init__(self, parent):
         font = None
             return 'break'
         self.text.bind('<Alt-v>', go_prev_page)
         def indent_line(event):
-            self.indenter.correct_indentation(self.get_insert())
+            lineno = self.get_current_line_number()
+            cols_from_end = len(self.text.get(INSERT, 'insert lineend'))
+            self.indenter.correct_indentation(lineno)
+            new_insert = '%d.end -%dc' % (lineno, cols_from_end)
+            self.text.mark_set(INSERT, new_insert)
             while self.text.get(INSERT) == ' ':
                 self.text.mark_set(INSERT, 'insert +1c')
             return 'break'
             current_char = self.text.get(INSERT)
             if line_starting.isspace() and (not current_char.isspace() 
                                             or current_char == '' or current_char == '\n'):
-                self.indenter.deindent(self.get_insert())
+                self.indenter.deindent(self.get_current_line_number())
                 return 'break'
         self.text.bind('<Return>', return_handler)
         self.text.event_add('<<ForwardSearch>>', '<Control-s>')
                              string)
             offset = template.get_cursor_location(mapping)
             self.text.mark_set(INSERT, '0.0 +%dc' % (result.start_offset + offset))
+            self.text.see(INSERT)
 
         if not template.variables():
             apply_template({})
     def set_status_bar_manager(self, manager):
         self.status_bar_manager = manager
 
+    def line_editor(self):
+        return GraphicalLineEditor(self)
+
 
 class GraphicalTextIndex(TextIndex):
     '''An immutable class for pointing to a position in a text'''
 
     def __init__(self, editor):
         self.editor = editor
+        self.line_editor = editor.line_editor()
 
-    def correct_indentation(self, index):
-        '''Correct the indentation of the line containing the given index'''
+    def correct_indentation(self, lineno):
+        '''Correct the indentation of a line'''
 
-    def deindent(self, index):
-        '''Deindent the line containing the given index'''
-        start = self._get_line_start(index)
-        current_indents = self._count_line_indents(start)
+    def deindent(self, lineno):
+        '''Deindent the a line'''
+        current_indents = self._count_line_indents(lineno)
         new_indents = max(0, current_indents - 4)
-        self._set_line_indents(start, new_indents)
+        self._set_line_indents(lineno, new_indents)
 
-    def indent(self, index):
-        '''Indents the line containing the given index'''
-        start = self._get_line_start(index)
-        current_indents = self._count_line_indents(start)
+    def indent(self, lineno):
+        '''Indents a line'''
+        current_indents = self._count_line_indents(lineno)
         new_indents = current_indents + 4
-        self._set_line_indents(start, new_indents)
+        self._set_line_indents(lineno, new_indents)
 
     def insert_tab(self, index):
         '''Inserts a tab in the given index'''
         self.editor.insert(index, ' ' * 4)
 
-    def _get_prev_line_start(self, line_start):
-        return self._get_line_start(self.editor.get_relative(line_start, -1))
-
-    def _get_line_end(self, index):
-        while index != self.editor.get_end():
-            if self.editor.get(index) == '\n':
-                return index
-            index = self.editor.get_relative(index, +1)
-        return self.editor.get_end()
-
-    def _get_line_contents(self, line_start):
-        end = self._get_line_end(line_start)
-        return self.editor.get(line_start, end)
-
-    def _set_line_indents(self, line_start, indents):
-        old_indents = self._count_line_indents(line_start)
+    def _set_line_indents(self, lineno, indents):
+        old_indents = self._count_line_indents(lineno)
         indent_diffs = indents - old_indents
         if indent_diffs == 0:
             return
+        old_line = self.line_editor.get_line(lineno)
+        new_line = ''
         if indent_diffs > 0:
-            self.editor.insert(line_start, ' ' * indent_diffs)
+            new_line = ' ' * indent_diffs + old_line
         else:
-            self.editor.delete(line_start, 
-                               self.editor.get_relative(line_start, -indent_diffs))
+            new_line = old_line[-indent_diffs:]
+        self.line_editor.set_line(lineno, new_line)
 
-    def _get_line_start(self, index):
-        while index != self.editor.get_start():
-            index = self.editor.get_relative(index, -1)
-            if self.editor.get(index) == '\n':
-                return self.editor.get_relative(index, +1)
-        return self.editor.get_start()
-
-    def _count_line_indents(self, index):
-        contents = self._get_line_contents(index)
+    def _count_line_indents(self, lineno):
+        contents = self.line_editor.get_line(lineno)
         result = 0
         for x in contents:
             if x == ' ':
     def __init__(self, editor):
         super(NormalIndenter, self).__init__(editor)
 
-    def correct_indentation(self, index):
+    def correct_indentation(self, lineno):
         pass
         
 
     def __init__(self, editor):
         super(PythonCodeIndenter, self).__init__(editor)
 
-    def _get_last_non_empty_line(self, line_start):
-        current_line = self._get_prev_line_start(line_start)
-        while current_line != self.editor.get_start() and \
-                  self._get_line_contents(current_line).strip() == '':
-            current_line = self._get_prev_line_start(current_line)
+    def _get_last_non_empty_line(self, lineno):
+        current_line = lineno - 1
+        while current_line != 1 and \
+                  self.line_editor.get_line(current_line).strip() == '':
+            current_line -= 1
         return current_line
 
-    def _get_starting_backslash_line(self, line_start):
-        current = line_start
-        while current != self.editor.get_start():
-            new_line = self._get_prev_line_start(current)
-            if not self._get_line_contents(new_line).rstrip().endswith('\\'):
+    def _get_starting_backslash_line(self, lineno):
+        current = lineno
+        while current != 1:
+            new_line = current - 1
+            if not self.line_editor.get_line(new_line).rstrip().endswith('\\'):
                 return current
             current = new_line
-        return self.editor.get_start()
+        return 1
 
-    def _get_correct_indentation(self, line_start):
-        if line_start == self.editor.get_start():
+    def _get_correct_indentation(self, lineno):
+        if lineno == 1:
             return 0
-        new_indent = self._get_base_indentation(line_start)
+        new_indent = self._get_base_indentation(lineno)
 
-        prev_start = self._get_last_non_empty_line(line_start)
-        prev_line = self._get_line_contents(prev_start)
-        if prev_start == line_start or prev_line.strip() == '':
+        prev_lineno = self._get_last_non_empty_line(lineno)
+        prev_line = self.line_editor.get_line(prev_lineno)
+        if prev_lineno == lineno or prev_line.strip() == '':
             new_indent = 0
         else:
             new_indent += self._get_indentation_changes_caused_by_prev_line(prev_line)
-        current_line = self._get_line_contents(line_start)
+        current_line = self.line_editor.get_line(lineno)
         new_indent += self._get_indentation_changes_caused_by_current_line(current_line)
         return new_indent
-        
-    def _get_base_indentation(self, line_start):
-        current_start = self._get_last_non_empty_line(line_start)
-        current_line = self._get_line_contents(current_start)
+
+    def _get_base_indentation(self, lineno):
+        current_line = self.line_editor.get_line(lineno)
+        current_lineno = self._get_last_non_empty_line(lineno)
 
         openings = 0
         while True:
-            current_line = self._get_line_contents(current_start)
+            current_line = self.line_editor.get_line(current_lineno)
             current = len(current_line) - 1
             while current >= 0:
-                if current_line[current] in list('([{'):
+                if current_line[current] in '([{':
                     openings += 1
-                if current_line[current] in list(')]}'):
+                if current_line[current] in ')]}':
                     openings -= 1
                 if openings > 0:
                     return current + 1
                 current -= 1
             if openings == 0:
                 break
-            if current_start == self.editor.get_start():
+            if current_lineno == 1:
                 break
-            current_start = self._get_last_non_empty_line(current_start)
+            current_lineno -= 1
 
         if current_line.rstrip().endswith('\\'):
-            real_start = self._get_starting_backslash_line(current_start)
-            if (real_start == current_start):
+            real_lineno = self._get_starting_backslash_line(current_lineno)
+            if (real_lineno == current_lineno):
                 try:
                     return current_line.index(' = ') + 3
                 except ValueError:
                     else:
                         return len(current_line) + 1
         else:
-            second_prev_start = self._get_prev_line_start(current_start)
-            if second_prev_start != current_start and \
-                   self._get_line_contents(second_prev_start).rstrip().endswith('\\'):
-                real_start = self._get_starting_backslash_line(second_prev_start)
-                return self._count_line_indents(real_start)
-        return self._count_line_indents(current_start)
+            second_prev_lineno = current_lineno - 1
+            if second_prev_lineno >= 1 and \
+               self.line_editor.get_line(second_prev_lineno).rstrip().endswith('\\'):
+                real_lineno = self._get_starting_backslash_line(second_prev_lineno)
+                return self._count_line_indents(real_lineno)
+        return self._count_line_indents(current_lineno)
 
 
     def _is_line_continued(self, line_contents):
         if prev_line.strip() == 'continue':
             new_indent -= 4
         return new_indent
-        
+
     def _get_indentation_changes_caused_by_current_line(self, current_line):
         new_indent = 0
         if current_line.strip() == 'else:':
             new_indent -= 4
         return new_indent
 
-    def correct_indentation(self, index):
+    def correct_indentation(self, lineno):
         '''Correct the indentation of the line containing the given index'''
-        start = self._get_line_start(index)
-        self._set_line_indents(start, self._get_correct_indentation(start))
+        self._set_line_indents(lineno, self._get_correct_indentation(lineno))
 

ropetest/indentertest.py

 
     def test_python_indenter(self):
         self.editor.set_text('print "hello"\n')
-        self.indenter.correct_indentation(self.editor.get_start())
+        self.indenter.correct_indentation(0)
         self.assertEquals('print "hello"\n', self.editor.get_text())
 
     def test_indenting_lines_with_indented_previous_line(self):
         self.editor.set_text('def f():\n    g()\nh()\n')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    g()\n    h()\n', self.editor.get_text())
 
     def test_indenting_lines_with_indented_previous_line(self):
         self.editor.set_text('def f():\n    g()\nh()\n')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    g()\n    h()\n', self.editor.get_text())
 
     def test_indenting_lines_when_prev_line_ends_with_a_colon(self):
         self.editor.set_text('def f():\ng()')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(2)
         self.assertEquals('def f():\n    g()', self.editor.get_text())
 
     def test_empty_prev_line(self):
         self.editor.set_text('    \nprint "hello"\n')
-        self.indenter.correct_indentation(self.editor.get_index(10))
+        self.indenter.correct_indentation(2)
         self.assertEquals('    \nprint "hello"\n', self.editor.get_text())
 
     def test_indenting_lines_with_indented_previous_line_with_empty_line(self):
         self.editor.set_text('def f():\n    g()\n\nh()\n')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(4)
         self.assertEquals('def f():\n    g()\n\n    h()\n', self.editor.get_text())
 
     def test_indenting_lines_when_prev_line_ends_with_a_colon_with_empty_line(self):
         self.editor.set_text('def f():\n\ng()')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n\n    g()', self.editor.get_text())
 
     def test_indenting_lines_at_start(self):
         self.editor.set_text('    g()\n')
-        self.indenter.correct_indentation(self.editor.get_start())
+        self.indenter.correct_indentation(1)
         self.assertEquals('g()\n', self.editor.get_text())
 
     def test_indenting_lines_with_start_previous_line(self):
         self.editor.set_text('\n    g()\n')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -1))
+        self.indenter.correct_indentation(2)
         self.assertEquals('\ng()\n', self.editor.get_text())
 
     def test_deindenting_after_pass(self):
         self.editor.set_text('def f():\n    pass\n    f()')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    pass\nf()', self.editor.get_text())
         
     def test_explicit_line_continuation(self):
         self.editor.set_text('c = a + \\\nb')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('c = a + \\\n    b', self.editor.get_text())
 
     def test_returning_after_backslashes(self):
         self.editor.set_text('c = \\\n    b\\\n+ a')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('c = \\\n    b\\\n    + a', self.editor.get_text())
 
     def test_returning_after_backslashes(self):
         self.editor.set_text('c = \\\n    b\na')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('c = \\\n    b\na', self.editor.get_text())
 
     def test_backslash_should_indent_relative_to_the_first_word(self):
         self.editor.set_text('print a, \\\nb')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('print a, \\\n      b', self.editor.get_text())
 
     def test_backslash_indenting_on_indented_blocks(self):
         self.editor.set_text('def f():\n    c = a + \\\nb')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    c = a + \\\n        b', self.editor.get_text())
 
     def test_backslash_indenting_on_indented_blocks2(self):
         self.editor.set_text('def f():\n    print a, \\\nb')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    print a, \\\n          b', self.editor.get_text())
 
     def test_deindenting_when_encountering_else(self):
         self.editor.set_text('if True:\n    print "hello"\n    else:')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('if True:\n    print "hello"\nelse:', self.editor.get_text())
 
     def test_deindenting_when_encountering_except(self):
         self.editor.set_text('try:\n    print "hello"\n    except Exception:')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('try:\n    print "hello"\nexcept Exception:', self.editor.get_text())
     
     def test_deindenting_when_encountering_finally(self):
         self.editor.set_text('try:\n    print "hello"\n    finally:')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('try:\n    print "hello"\nfinally:', self.editor.get_text())
     
     def test_deindenting_after_return(self):
         self.editor.set_text('def f():\n    return "hello"\n    b\n')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -1))
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    return "hello"\nb\n', self.editor.get_text())
 
     def test_deindenting_after_raise(self):
         self.editor.set_text('def f():\n    raise Exception()\n    b\n')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -1))
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    raise Exception()\nb\n', self.editor.get_text())
 
     def test_multiple_indents(self):
         self.editor.set_text('def f():\n')
-        self.indenter.correct_indentation(self.editor.get_end())
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
+        self.indenter.correct_indentation(2)
         self.assertEquals('def f():\n    ', self.editor.get_text())
 
     def test_implicit_continuation(self):
         self.editor.set_text('def f(a,\nb):')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('def f(a,\n      b):', self.editor.get_text())
 
     def test_double_parens(self):
         self.editor.set_text('def f(a, (c, b),\ne):')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('def f(a, (c, b),\n      e):', self.editor.get_text())
 
     def test_double_parens(self):
         self.editor.set_text('def f(a, (c, \nb), e):')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('def f(a, (c, \n          b), e):', self.editor.get_text())
 
     def test_implicit_continuation2(self):
         self.editor.set_text('d = {"age" : 20, \n"name" : "Ali"}')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('d = {"age" : 20, \n     "name" : "Ali"}', self.editor.get_text())
 
     def test_deindents_after_implicit_continuation(self):
         self.editor.set_text('f(a,\n      b)\na = 10')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('f(a,\n      b)\na = 10', self.editor.get_text())
 
     def test_deindents_after_implicit_continuation_after_double_parens(self):
         self.editor.set_text('def f(a, (c, \nb), e):\na=b')
-        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), - 5))
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f(a, (c, \n          b), e):\n    a=b', self.editor.get_text())
 
     def test_implicit_continuation_after_return(self):
         self.editor.set_text('def f():\n    return (2,\n3)')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(3)
         self.assertEquals('def f():\n    return (2,\n            3)', self.editor.get_text())
 
     # TODO: handle this case
     def xxx_test_deindenting_after_implicit_continuation_after_return(self):
         self.editor.set_text('def f():\n    return (2,\n            3)\na = 10')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(4)
         self.assertEquals('def f():\n    return (2,\n            3)\na = 10',
                           self.editor.get_text())
 
     def test_deindenting_empty_lines(self):
         self.editor.set_text('\n')
-        self.indenter.deindent(self.editor.get_end())
+        self.indenter.deindent(2)
         self.assertEquals('\n', self.editor.get_text())
 
     def test_deindenting_four_spaces(self):
         self.editor.set_text('    print "hello"\n')
-        self.indenter.deindent(self.editor.get_start())
+        self.indenter.deindent(1)
         self.assertEquals('print "hello"\n', self.editor.get_text())
 
     def test_deindenting(self):
         self.editor.set_text('def f()\n    print "hello"\n    def g():\n')
-        self.indenter.deindent(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.deindent(3)
         self.assertEquals('def f()\n    print "hello"\ndef g():\n', self.editor.get_text())
 
     def test_normal_indenter_indenting(self):
         self.editor.set_text('a sample text')
         indenter = NormalIndenter(self.editor)
-        indenter.indent(self.editor.get_start())
+        indenter.indent(1)
         self.assertEquals('    a sample text', self.editor.get_text())
 
     def test_normal_indenter_deindenting(self):
         self.editor.set_text('a sample \n        text')
         indenter = NormalIndenter(self.editor)
-        indenter.deindent(self.editor.get_end())
+        indenter.deindent(2)
         self.assertEquals('a sample \n    text', self.editor.get_text())
 
     def test_indenting(self):
         self.editor.set_text('print "a"')
-        self.indenter.indent(self.editor.get_start())
+        self.indenter.indent(1)
         self.assertEquals('    print "a"', self.editor.get_text())
 
     def test_not_doing_anything_in_noraml_indenters_correct_indentation(self):
         self.editor.set_text('a sample \ntext')
         indenter = NormalIndenter(self.editor)
-        indenter.correct_indentation(self.editor.get_end())
+        indenter.correct_indentation(2)
         self.assertEquals('a sample \ntext', self.editor.get_text())
 
     def test_inserting_tab(self):
     # ignoring strings while correcting indentations
     def xxx_test_ignoring_parens_in_strings(self):
         self.editor.set_text('print "("\na = 10')
-        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(2)
         self.assertEquals('print "("\na = 10', self.editor.get_text())
 
 

ropetest/mockeditor.py

-from rope.editor import TextEditor, TextIndex
+from rope.editor import TextEditor, TextIndex, LineEditor
+
+class MockLineEditor(LineEditor):
+    def __init__(self, editor):
+        self.editor = editor
+
+    def get_line(self, number):
+        return self.editor.get_text().split('\n')[number - 1]
+
+    def set_line(self, number, string):
+        lines = self.editor.get_text().split('\n')
+        lines[number - 1] = string
+        self.editor.set_text('\n'.join(lines))
+
 
 class MockEditor(TextEditor):
     '''A mock editor for testing editing commands'''
         except ValueError:
             return None
 
+    def line_editor(self):
+        return MockLineEditor(self)
+
+
 class MockTextIndex(TextIndex):
     def __init__(self, editor, index):
         self.editor = editor

ropetest/mockeditortest.py

         self.assertTrue(self.editor.search('aB', self.editor.get_insert()) is None)
         self.assertTrue(self.editor.search('aB', self.editor.get_insert(), case = False) is not None)
 
+    def test_simple_line_editor(self):
+        self.editor.set_text('line1')
+        line_editor = self.editor.line_editor()
+        self.assertEquals('line1', line_editor.get_line(1))
+
+    def test_line_editor_multiline(self):
+        self.editor.set_text('line1\nline2\nline3\n')
+        line_editor = self.editor.line_editor()
+        self.assertEquals('line1', line_editor.get_line(1))
+        self.assertEquals('line3', line_editor.get_line(3))
+        self.assertEquals('', line_editor.get_line(4))
+
+    def test_line_editor_setting(self):
+        self.editor.set_text('line1\nline2\nline3\n')
+        line_editor = self.editor.line_editor()
+        line_editor.set_line(2, 'second line')
+        self.assertEquals('second line', line_editor.get_line(2))
+        self.assertEquals('line1\nsecond line\nline3\n', self.editor.get_text())
+
 
 def suite():
     result = unittest.TestSuite()
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.