diff --git a/helpers.py b/helpers.py index 7658251..47b24b4 100644 --- a/helpers.py +++ b/helpers.py @@ -4,12 +4,15 @@ import sublime_plugin -class BaseBlockCommand(sublime_plugin.TextCommand): +class LineIndexError(Exception): + pass + +class BaseBlockCommand(sublime_plugin.TextCommand): def _get_row_text(self, row): if row < 0 or row > self.view.rowcol(self.view.size())[0]: - raise RuntimeError('Cannot find table bounds.') + raise LineIndexError('Cannot find table bounds.') point = self.view.text_point(row, 0) region = self.view.line(point) @@ -28,9 +31,7 @@ def get_block_bounds(self): try: while self._get_row_text(upper - 1).strip(): upper -= 1 - - except Exception as e: - print(e) + except LineIndexError: pass else: upper += 1 @@ -38,8 +39,7 @@ def get_block_bounds(self): try: while self._get_row_text(lower + 1).strip(): lower += 1 - except Exception as e: - print(e) + except LineIndexError: pass else: lower -= 1 @@ -47,5 +47,9 @@ def get_block_bounds(self): block_region = Region(self.view.text_point(upper - 1, 0), self.view.text_point(lower + 2, 0)) lines = [self.view.substr(region) for region in self.view.lines(block_region)] - indent = re.match('^(\s*).*$', self._get_row_text(upper - 1)).group(1) + try: + row_text = self._get_row_text(upper - 1) + except LineIndexError: + row_text = '' + indent = re.match('^(\s*).*$', row_text).group(1) return block_region, lines, indent