Commits

Anonymous committed 869d39a

Adding indent_size project config

Comments (0)

Files changed (12)

docs/dev/done.txt

 ===========
 
 
+- Using a better object textual form : April 4, 2007
+
+
 - Spell-Checker : April 3, 2007
 
 

docs/dev/issues.txt

 to disk.
 
 
-Fixing Small Changes
---------------------
-
-We don't want small changes in source files to invalidate all
-information.  For example if a blank line is inserted at the top of a
-file we don't want the information held for all the methods contained
-in that module to be lost.
-
-Using hierarchies::
-
-  class A(object):
-      def f(self):
-          pass
-
-  def g():
-      pass
-
-* f -> ('defined', path, 'A.f')
-* g -> ('defined', path, 'f')
-* A -> ('defined', path, 'A')
-
-Maybe we can use multiple forms for textuals:
-
-* ``key.isdigit()`` -> uses *lineno* form
-* ``key.isalnum()`` -> uses *name* form
-* ``'.' in key`` -> uses *hierarchical* form
-* ``':' in key `` -> uses *lineno/name* form
-
-But the main problem with having multiple representations is that it
-makes comparison harder.  We can no more match expected args using a
-simple dictionary lookup.
-
-Because of its resistance to changes, hierarchical form will be added
-although there are problems for DOI.  Possible Implementations:
-
-* Performing two lookups
-* Merging textual forms whenever possible
-* Transforming DOI data to hierarchical form
-
-
 Saving Data On Disk
 -------------------
 
 * Not analyzing everytime?
 * ``automatic_soi`` project config
 
+Unfortunately performing SOI whenever a buffer is saved is not
+cpu and memory efficient.
+
+
+Memory Management
+=================
+
+These are the places in which rope spends most of the memory it
+consumes:
+
+* PyCore: for storing PyModules
+* ObjectInfo: for storing object information
+* History: for storing changes
+
+We should measure the amount of memory each of them uses to make
+decisions.
+
+
+Refactoring `Progress`
+======================
+
+Currently refactorings cannot be stopped.  I propose to add an object
+for stopping and showing the progress of a time consuming task::
+
+  class TaskHandle(object):
+
+      def stop(self):
+          pass
+
+      def is_stopped(self):
+          pass
+
+It requires adding an argument to all refactorings and other time
+consuming tasks and changing them to use this object.
+
 
 Better Concluded Data
 =====================
 In order to simplify problems a bit, rope makes some assumptions about
 the source code.  In futures some of this restrictions might be removed.
 
-* All of the modules should use 4 spaces for indenting and no hard tabs.
 * All files that end with ``.py`` are considered to be python files and
   all others not.
 * Either all files should be under version control or none.

docs/dev/stories.txt

 
 
 > Public Release 0.5m5 : April 15, 2007
-
-
-* Using a better object textual form

docs/dev/workingon.txt

-New Hierarchical Textual Form
-=============================
+Small Stories
+=============
 
-- Using a new textual form
+- Adding ``indentation_size`` config
 
-* Adding ``indentation_size`` config
+* Renaming normal files, folder, modules, and packages in project tree view
 * Adding configs for specifying long imports?
 * ``match_when_unsure`` project config?
 * Spell checking on python source

rope/base/project.py

 
     # Possible values are 'memory' and 'shelve' for now.  The default
     # is 'memory'.  If 'shelve', object information is saved to disk
-    # for future sessions.
+    # so that it can be used in future sessions.
     prefs['objectdb_type'] = 'shelve'
 
     # Shows whether to save history across sessions.  Defaults to
     # `True`.
     prefs['validate_objectdb'] = True
 
+    # If `True`, rope will analyze each module after it is saved.
     prefs['automatic_soi'] = True
 
+    # Set the number spaces used for indenting.
+    prefs['indent_size'] = 4
+
 
 def project_opened(project):
     """This function is called after the project is opened"""

rope/refactor/extract.py

     """
 
     def __init__(self, pycore, resource, parts, extracted_name, extract_variable=False):
+        self.pycore = pycore
         self.source_code = source_code = resource.read()
         self.extracted_name = extracted_name
         self.extract_variable = extract_variable
                       (' ' * function_indents,
                        self._get_function_signature(args)))
         unindented_body = self._get_unindented_function_body(returns)
-        function_body = sourceutils.indent_lines(unindented_body, function_indents + 4)
+        indents = function_indents + sourceutils.get_indent(self.pycore)
+        function_body = sourceutils.indent_lines(unindented_body, indents)
         result.append(function_body)
         definition = ''.join(result)
 

rope/refactor/introduce_factory.py

         unindented_factory = ('@staticmethod\n' +
                               'def %s(*args, **kwds):\n' % factory_name +
                               '    return %s(*args, **kwds)\n' % self.old_name)
-        return '\n' + sourceutils.indent_lines(
-            unindented_factory, self._get_scope_indents(lines, class_scope) + 4)
+        indents = self._get_scope_indents(lines, class_scope) + \
+                  sourceutils.get_indent(self.pycore)
+        return '\n' + sourceutils.indent_lines(unindented_factory, indents)
 
     def _get_scope_indents(self, lines, scope):
         return sourceutils.get_indents(lines, scope.get_start())

rope/refactor/method_object.py

         self.resource = self.pymodule.get_resource()
 
     def get_new_class(self, name):
-        body = sourceutils.fix_indentation(self._get_body(), 8)
-        return 'class %s(object):\n\n%s    def __call__(self):\n%s' % \
-               (name, self._get_init(), body)
+        body = sourceutils.fix_indentation(
+            self._get_body(), sourceutils.get_indent(self.pycore) * 2)
+        return 'class %s(object):\n\n%s%sdef __call__(self):\n%s' % \
+               (name, self._get_init(),
+                ' ' * sourceutils.get_indent(self.pycore), body)
 
     def get_changes(self, new_class_name):
         collector = sourceutils.ChangeCollector(self.pymodule.source_code)
         start, end = sourceutils.get_body_region(self.pyfunction)
         indents = sourceutils.get_indents(
-            self.pymodule.lines, self.pyfunction.get_scope().get_start()) + 4
+            self.pymodule.lines, self.pyfunction.get_scope().get_start()) + \
+            sourceutils.get_indent(self.pycore)
         new_contents = ' ' * indents + 'return %s(%s)()\n' % \
                        (new_class_name, ', '.join(self._get_parameter_names()))
         collector.add_change(start, end, new_contents)
 
     def _get_init(self):
         params = self._get_parameter_names()
+        indents = ' ' * sourceutils.get_indent(self.pycore)
         if not params:
             return ''
-        header = '    def __init__(self'
+        header = indents + 'def __init__(self'
         body = ''
         for arg in params:
             new_name = arg
             if arg == 'self':
                 new_name = 'host'
             header += ', %s' % new_name
-            body += '        self.%s = %s\n' % (arg, new_name)
+            body += indents * 2 + 'self.%s = %s\n' % (arg, new_name)
         header += '):'
         return '%s\n%s\n' % (header, body)
 

rope/refactor/move.py

 
     def _get_changes_made_by_old_class(self, dest_attr, new_name):
         pymodule = self.pyfunction.get_module()
-        indents = sourceutils.get_indents(
-            pymodule.lines, self.pyfunction.get_scope().get_start())
+        indents = self._get_scope_indents(self.pyfunction)
         body = 'return self.%s.%s(%s)\n' % (dest_attr, new_name,
                                             self._get_passed_arguments_string())
         region = sourceutils.get_body_region(self.pyfunction)
         return (pymodule.get_resource(), region[0], region[1],
-                sourceutils.fix_indentation(body, indents + 4))
+                sourceutils.fix_indentation(body, indents))
+
+    def _get_scope_indents(self, pyobject):
+        pymodule = pyobject.get_module()
+        return sourceutils.get_indents(
+            pymodule.lines, pyobject.get_scope().get_start()) + \
+            sourceutils.get_indent(self.pycore)
 
     def _get_changes_made_by_new_class(self, dest_attr, new_name):
         old_pyclass = self.pyfunction.parent
         if pymodule.source_code[start:end].strip() != 'pass':
             pre_blanks = '\n\n'
             start = end
-        indents = sourceutils.get_indents(pymodule.lines,
-                                          pyclass.get_scope().get_start())
+        indents = self._get_scope_indents(pyclass)
         body = pre_blanks + sourceutils.fix_indentation(
-            self.get_new_method(new_name), indents + 4)
+            self.get_new_method(new_name), indents)
         return resource, start, end, body
 
     def get_new_method(self, name):
         return '%s\n%s' % (
             self._get_new_header(name),
-            sourceutils.fix_indentation(self._get_body(), 4))
+            sourceutils.fix_indentation(self._get_body(),
+                                        sourceutils.get_indent(self.pycore)))
 
     def _get_unchanged_body(self):
         return sourceutils.get_body(self.pyfunction)

rope/refactor/sourceutils.py

     insertion_offset = lines.get_line_end(insertion_line)
     methods = '\n\n' + '\n\n'.join(methods_sources)
     indented_methods = fix_indentation(
-        methods, get_indents(lines, class_scope.get_start()) + 4)
+        methods, get_indents(lines, class_scope.get_start()) + 
+        get_indent(pymodule.pycore))
     result = []
     result.append(source_code[:insertion_offset])
     result.append(indented_methods)
     end = min(lines.get_line_end(scope.get_end()) + 1,
               len(pymodule.source_code))
     return start, end
+
+
+def get_indent(pycore):
+    project = pycore.project
+    return project.get_prefs().get('indent_size', 4)

rope/ui/editingtools.py

 import rope.ide.codeassist
 import rope.ide.outline
 import rope.refactor
+import rope.refactor.sourceutils
 
 
 def get_editingtools_for_context(editing_context, project, prefs):
         self._outline = None
 
     def create_indenter(self, editor):
-        return rope.ui.indenter.PythonCodeIndenter(editor)
+        indents = rope.refactor.sourceutils.get_indent(self.project.get_pycore())
+        return rope.ui.indenter.PythonCodeIndenter(editor, indents=indents)
 
     def create_highlighting(self):
         return rope.ui.highlighter.PythonHighlighting()

rope/ui/indenter.py

 class TextIndenter(object):
     """A class for formatting texts"""
 
-    def __init__(self, editor):
+    def __init__(self, editor, indents=4):
         self.editor = editor
+        self.indents = indents
         self.line_editor = editor.line_editor()
 
     def correct_indentation(self, lineno):
     def deindent(self, lineno):
         """Deindent the a line"""
         current_indents = self._count_line_indents(lineno)
-        new_indents = max(0, current_indents - 4)
+        new_indents = max(0, current_indents - self.indents)
         self._set_line_indents(lineno, new_indents)
 
     def indent(self, lineno):
         """Indents a line"""
         current_indents = self._count_line_indents(lineno)
-        new_indents = current_indents + 4
+        new_indents = current_indents + self.indents
         self._set_line_indents(lineno, new_indents)
 
     def entering_new_line(self, lineno):
 
     def insert_tab(self, index):
         """Inserts a tab in the given index"""
-        self.editor.insert(index, ' ' * 4)
+        self.editor.insert(index, ' ' * self.indents)
 
     def _set_line_indents(self, lineno, indents):
         old_indents = self._count_line_indents(lineno)
 
 class PythonCodeIndenter(TextIndenter):
 
-    def __init__(self, editor):
-        super(PythonCodeIndenter, self).__init__(editor)
+    def __init__(self, editor, indents=4):
+        super(PythonCodeIndenter, self).__init__(editor, indents)
 
     def _get_last_non_empty_line(self, lineno):
         current_line = lineno - 1
                 if len(range_finder.open_parens) > 1:
                     return range_finder.open_parens[-2][1] + 1
                 else:
-                    return self._count_line_indents(start) + 4
+                    return self._count_line_indents(start) + self.indents
             return range_finder.last_open_parens()[1] + 1
 
         start_line = self.line_editor.get_line(start)
             try:
                 equals_index = start_line.index(' = ') + 1
                 if start_line[equals_index + 1:].strip() == '\\':
-                    return self._count_line_indents(start) + 4
+                    return self._count_line_indents(start) + self.indents
                 return equals_index + 2
             except ValueError:
                 match = re.search(r'(\b )|(\.)', start_line)
         last_line = self.line_editor.get_line(stmt_range[1])
         new_indent = 0
         if last_line.rstrip().endswith(':'):
-            new_indent += 4
+            new_indent += self.indents
         if last_line.strip() == 'pass':
-            new_indent -= 4
+            new_indent -= self.indents
         if first_line.lstrip().startswith('return ') or \
            first_line.lstrip().startswith('raise '):
-            new_indent -= 4
+            new_indent -= self.indents
         if first_line.strip() == 'break':
-            new_indent -= 4
+            new_indent -= self.indents
         if first_line.strip() == 'continue':
-            new_indent -= 4
+            new_indent -= self.indents
         return new_indent
 
     def _get_indentation_changes_caused_by_current_stmt(self, current_line):
         new_indent = 0
         if current_line.strip() == 'else:':
-            new_indent -= 4
+            new_indent -= self.indents
         if current_line.strip() == 'finally:':
-            new_indent -= 4
+            new_indent -= self.indents
         if current_line.strip().startswith('elif '):
-            new_indent -= 4
+            new_indent -= self.indents
         if current_line.lstrip().startswith('except ') and \
            current_line.rstrip().endswith(':'):
-            new_indent -= 4
+            new_indent -= self.indents
         return new_indent
 
     def correct_indentation(self, lineno):
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.