Return a list of block line tuples and the 'last' indent. The tuple fields are (linenum, indent, text, opener). The list represents header lines from new_topvisible back to stopline with successively shorter indents > stopindent. The list is returned ordered by line
(self, new_topvisible, stopline=1, stopindent=0)
| 147 | return "break" |
| 148 | |
| 149 | def get_context(self, new_topvisible, stopline=1, stopindent=0): |
| 150 | """Return a list of block line tuples and the 'last' indent. |
| 151 | |
| 152 | The tuple fields are (linenum, indent, text, opener). |
| 153 | The list represents header lines from new_topvisible back to |
| 154 | stopline with successively shorter indents > stopindent. |
| 155 | The list is returned ordered by line number. |
| 156 | Last indent returned is the smallest indent observed. |
| 157 | """ |
| 158 | assert stopline > 0 |
| 159 | lines = [] |
| 160 | # The indentation level we are currently in. |
| 161 | lastindent = INFINITY |
| 162 | # For a line to be interesting, it must begin with a block opening |
| 163 | # keyword, and have less indentation than lastindent. |
| 164 | for linenum in range(new_topvisible, stopline-1, -1): |
| 165 | codeline = self.text.get(f'{linenum}.0', f'{linenum}.end') |
| 166 | indent, text, opener = get_line_info(codeline) |
| 167 | if indent < lastindent: |
| 168 | lastindent = indent |
| 169 | if opener in ("else", "elif"): |
| 170 | # Also show the if statement. |
| 171 | lastindent += 1 |
| 172 | if opener and linenum < new_topvisible and indent >= stopindent: |
| 173 | lines.append((linenum, indent, text, opener)) |
| 174 | if lastindent <= stopindent: |
| 175 | break |
| 176 | lines.reverse() |
| 177 | return lines, lastindent |
| 178 | |
| 179 | def update_code_context(self): |
| 180 | """Update context information and lines visible in the context pane. |