7from rope.base
import codeanalyze
12 """A class for formatting texts"""
20 """Correct the indentation of a line"""
23 """Deindent the a line"""
24 current_indents = self._count_line_indents(lineno)
25 new_indents = max(0, current_indents - self.indents)
26 self._set_line_indents(lineno, new_indents)
31 new_indents = current_indents + self.
indents
37 Uses `correct_indentation` and last line indents
42 if last_line.strip() ==
'':
48 """Inserts a tab in the given index"""
53 indent_diffs = indents - old_indents
72 super(NormalIndenter, self).
__init__(editor)
84 super(PythonCodeIndenter, self).
__init__(editor, indents)
87 current_line = lineno - 1
88 while current_line != 1
and \
100 if prev_lineno == lineno
or prev_line.strip() ==
'':
109 start = range_finder.get_statement_start()
110 if not range_finder.is_line_continued():
114 if range_finder.last_open_parens():
115 open_parens = range_finder.last_open_parens()
117 if parens_line[open_parens[1] + 1:].strip() ==
'':
118 if len(range_finder.open_parens) > 1:
119 return range_finder.open_parens[-2][1] + 1
122 return range_finder.last_open_parens()[1] + 1
125 if start == lineno - 1:
127 equals_index = start_line.index(
' = ') + 1
128 if start_line[equals_index + 1:].strip() ==
'\\':
130 return equals_index + 2
132 match = re.search(
r'(\b )|(\.)', start_line)
134 return match.start() + 1
136 return len(start_line) + 1
144 if self.
_strip(last_line).endswith(
':'):
146 if self.
_startswith(first_line, (
'return',
'raise',
'pass',
147 'break',
'continue')):
154 if line == token
or line.startswith(token +
' '):
159 numsign = line.rindex(
'#')
160 comment = line[numsign:]
161 if '\'' not in comment
and '\"' not in comment:
162 line = line[:numsign]
169 if self.
_strip(current_line) ==
'else:':
171 if self.
_strip(current_line) ==
'finally:':
175 if self.
_startswith(current_line, (
'except',))
and \
176 self.
_strip(current_line).endswith(
':'):
181 """Correct the indentation of the line containing the given index"""
187 """A method object for finding the range of a statement"""
199 current_line = self.
lines.get_line(lineno)
200 for i, char
in enumerate(current_line):
204 if char * 3 == current_line[i:i + 3]:
207 not (i > 0
and current_line[i - 1] ==
'\\' and
208 not (i > 1
and current_line[i - 2:i] ==
'\\\\')):
221 if current_line
and char !=
'#' and current_line.endswith(
'\\'):
228 block_start = codeanalyze.get_block_start(self.
lines, self.
lineno)
229 for current_line_number
in range(block_start, self.
lineno + 1):
232 last_statement = current_line_number
248 return self._count_line_indents(self.
lines.get_line(line_number))
correct_indentation(self, lineno)
_last_non_blank(self, lineno)
_get_correct_indentation(self, lineno)
__init__(self, editor, indents=4)
_indents_caused_by_current_stmt(self, current_line)
_indents_caused_by_prev_stmt(self, stmt_range)
_get_base_indentation(self, lineno)
correct_indentation(self, lineno)
_startswith(self, line, tokens)
entering_new_line(self, lineno)
_set_line_indents(self, lineno, indents)
_count_line_indents(self, lineno)
correct_indentation(self, lineno)
__init__(self, editor, indents=4)
__init__(self, lines, lineno)
get_line_indents(self, line_number)
get_statement_start(self)
_analyze_line(self, lineno)