Anonymous avatar Anonymous committed 709035c

Separating indenting and correcting indentation

Comments (0)

Files changed (6)

-- Enhancing editor and indentation
+- Separating indenting and correcting indentation : May 7, 2006
+
+
+- Enhancing editor and indentation : May 4, 2006
   - Pressing backspace should deindent
   - Clearing undo list when opening a file; undoSeparator when saving
 
 * Writing ASTs @ 4
 
 
+* Better multi-sequence key event handling @ 2
+
+
 * Auto-complete variable names @ 3
 
 
-* Show searching status in the status bar @ 1
-
-
 * Adding TextIterator or LineOriented to the Editor class @ 1
 
 
   * Showing modified file status
 
 
+> Public release 0.2pre : May 20, 2006
+
+
+* Show searching status in the status bar @ 1
+
+
 * Making ASTs @ 4
 
 
 ? Separate domain and presentation everywhere
 * Make tests less dependant
 ? Changing used graphical interface
-* Make a new Project; Seperate opening and creating projects
-* Add removing resources to Core
 ? Project resource consistency; What if it is deleted after being created.

docs/workingon.txt

-* Extract NormalIndenter class
+--- Separating indenting and correcting indentation @ 1 ---
 
-
-- Back space does not work for normal files when deindenting
 ? SF repository; Subversion or CVS? Synchronizing local SVN with SF?
-? Adding selection list class
-? Separation of acceptance and unit tests
-? GUI Testing Problems? again!
-? Possible base UI classes: completion lists, dialogs, named fields
-? Use Dialogs instead
-? Better multi-sequence key event handling
-? Consider using Tix or Pmw or idlelib
+? Functional tests
 ? Should workingon.txt be under version control?
-? Separating domain and presentation in Core
             self.prevPage()
             return 'break'
         self.text.bind('<Alt-v>', goPrevPage)
+        def indent_line(event):
+            self.indenter.correct_indentation(self.get_insert())
+            return 'break'
         def doInsertTab(event):
             self.insertTab()
             return 'break'
-        def indent_line(event):
-            self.indenter.indent_line(self.get_insert())
-            return 'break'
         self.text.bind('<Control-i>', indent_line)
         self.text.bind('<Tab>', doInsertTab)
         def return_handler(event):
                 self.searcher.end_searching()
                 return 'break'
             self.text.insert(INSERT, '\n')
-            self.indenter.indent_line(self.get_insert())
+            self.indenter.correct_indentation(self.get_insert())
             self.text.see(INSERT)
             return 'break'
         def backspace(event):
     def prevPage(self):
         self.text.event_generate('<Prior>')
 
-    def insertTab(self, textIndex = None):
-        index = INSERT
-        if textIndex is not None:
-            index = textIndex._getIndex()
-        self.text.insert(INSERT, ' ' * 4)
+    def insertTab(self, text_index = None):
+        if text_index is None:
+            text_index = self.get_insert()
+        self.indenter.indent(text_index)
 
     def set_highlighting(self, highlighting):
         self.highlighting = highlighting
     def __init__(self, editor):
         self.editor = editor
 
-    def indent_line(self, index):
+    def correct_indentation(self, index):
         '''Correct the indentation of the line containing the given index'''
 
     def deindent(self, index):
         '''Deindent the line containing the given index'''
+        start = self._get_line_start(index)
+        current_indents = self._count_line_indents(start)
+        new_indents = max(0, current_indents - 4)
+        self._set_line_indents(start, 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)
+        new_indents = current_indents + 4
+        self._set_line_indents(start, new_indents)
 
     def _get_prev_line_start(self, line_start):
         return self._get_line_start(self.editor.get_relative(line_start, -1))
     def __init__(self, editor):
         super(NormalIndenter, self).__init__(editor)
 
-    def indent_line(self, index):
-        start = self._get_line_start(index)
-        current_indents = self._count_line_indents(start)
-        new_indents = current_indents + 4
-        self._set_line_indents(start, new_indents)
+    def correct_indentation(self, index):
+        pass
         
-    def deindent(self, index):
-        start = self._get_line_start(index)
-        current_indents = self._count_line_indents(start)
-        new_indents = max(0, current_indents - 4)
-        self._set_line_indents(start, new_indents)
-
 
 class PythonCodeIndenter(TextIndenter):
     def __init__(self, editor):
             new_indent -= 4
         return new_indent
 
-    def indent_line(self, index):
+    def correct_indentation(self, index):
         '''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))
 
-    def deindent(self, index):
-        '''Deindent the line containing the given index'''
-        start = self._get_line_start(index)
-        indents = self._count_line_indents(start)
-        new_indents = max(0, indents - 4)
-        self._set_line_indents(start, new_indents)

ropetest/indentertest.py

 
     def test_python_indenter(self):
         self.editor.set_text('print "hello"\n')
-        self.indenter.indent_line(self.editor.get_start())
+        self.indenter.correct_indentation(self.editor.get_start())
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -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.indent_line(self.editor.get_index(10))
+        self.indenter.correct_indentation(self.editor.get_index(10))
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -2))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -2))
         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.indent_line(self.editor.get_start())
+        self.indenter.correct_indentation(self.editor.get_start())
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -1))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -1))
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -1))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -1))
         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.indent_line(self.editor.get_relative(self.editor.get_end(), -1))
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), -1))
         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.indent_line(self.editor.get_end())
-        self.indenter.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         self.assertEquals('def f():\n    ', self.editor.get_text())
 
     def test_implicit_continuation(self):
         self.editor.set_text('def f(a,\nb):')
-        self.indenter.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_relative(self.editor.get_end(), - 5))
-        self.indenter.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_relative(self.editor.get_end(), - 5))
+        self.indenter.correct_indentation(self.editor.get_end())
         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.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         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,\n3)\na = 10')
-        self.indenter.indent_line(self.editor.get_end())
+        self.indenter.correct_indentation(self.editor.get_end())
         self.assertEquals('def f():\n    return (2,\n            3)\na = 10', self.editor.get_text())
 
     def test_deindenting_empty_lines(self):
     def test_normal_indenter_indenting(self):
         self.editor.set_text('a sample text')
         indenter = NormalIndenter(self.editor)
-        indenter.indent_line(self.editor.get_start())
+        indenter.indent(self.editor.get_start())
         self.assertEquals('    a sample text', self.editor.get_text())
 
     def test_normal_indenter_deindenting(self):
         indenter.deindent(self.editor.get_end())
         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.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())
+        self.assertEquals('a sample \ntext', self.editor.get_text())
+
 
 if __name__ == '__main__':
     unittest.main()
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.