86 indent_width = editor.getEditorConfig('IndentWidth') |
86 indent_width = editor.getEditorConfig('IndentWidth') |
87 |
87 |
88 lead_spaces = editor.indentation(line) |
88 lead_spaces = editor.indentation(line) |
89 |
89 |
90 pline = line - 1 |
90 pline = line - 1 |
91 while pline >= 0 and re.match('^\s*(#.*)?$', editor.text(pline)): |
91 while pline >= 0 and re.match(r'^\s*(#.*)?$', editor.text(pline)): |
92 pline -= 1 |
92 pline -= 1 |
93 |
93 |
94 if pline < 0: |
94 if pline < 0: |
95 last = 0 |
95 last = 0 |
96 else: |
96 else: |
97 previous_lead_spaces = editor.indentation(pline) |
97 previous_lead_spaces = editor.indentation(pline) |
98 # trailing spaces |
98 # trailing spaces |
99 m = re.search(':\s*(#.*)?$', editor.text(pline)) |
99 m = re.search(r':\s*(#.*)?$', editor.text(pline)) |
100 last = previous_lead_spaces |
100 last = previous_lead_spaces |
101 if m: |
101 if m: |
102 last += indent_width |
102 last += indent_width |
103 else: |
103 else: |
104 # special cases, like pass (unindent) or return (also unindent) |
104 # special cases, like pass (unindent) or return (also unindent) |
105 m = re.search('(pass\s*(#.*)?$)|(^[^#]return)', |
105 m = re.search(r'(pass\s*(#.*)?$)|(^[^#]return)', |
106 editor.text(pline)) |
106 editor.text(pline)) |
107 if m: |
107 if m: |
108 last -= indent_width |
108 last -= indent_width |
109 |
109 |
110 if lead_spaces % indent_width != 0 or lead_spaces == 0 \ |
110 if lead_spaces % indent_width != 0 or lead_spaces == 0 \ |