Skip to content

Instantly share code, notes, and snippets.

@poc7667
Created November 18, 2013 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poc7667/7523230 to your computer and use it in GitHub Desktop.
Save poc7667/7523230 to your computer and use it in GitHub Desktop.
How to refractoring this code
def get_exception_region(self, except_region, max_lines_in_exception=100):
'''
# get current line number
row, _ = self.view.rowcol(except_region.a)
# get next line's starting point
next_row_starting = self.view.text_point(row + 1, 0)
# get the whole next line
next_row_region = self.view.full_line(next_row_starting)
print(self.view.substr(next_row_region))
'''
# Init first setting
try:
row, _ = self.view.rowcol(except_region.a)
next_line_text, next_line_region = self.get_next_line__text_and_region(row)
prev_line_text, prev_line_region = next_line_text, next_line_region
beginning_spaces = self.count_the_beginning_spaces(next_line_text)
start_row, start_beginning_spaces = row, beginning_spaces
print "=================Start================="
print row, beginning_spaces, next_line_text.strip()
while True and (beginning_spaces - start_beginning_spaces) < max_lines_in_exception :
row = row + 1
next_line_text , next_line_region = self.get_next_line__text_and_region(row)
beginning_spaces = self.count_the_beginning_spaces(next_line_text)
print row, beginning_spaces, next_line_text.strip()
if beginning_spaces > 1 and beginning_spaces != start_beginning_spaces:
print "=================Exit================="
break
prev_line_text, prev_line_region = next_line_text, next_line_region
return row, prev_line_text, prev_line_region
pass
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print("[Error]\n", exc_type, fname, exc_tb.tb_lineno)
raise e
sys.exit(e)
#EndOfExcept
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment