def next_paragraph_start(view, pt, count=1, skip_empty=True): if utils.row_at(view, pt) == utils.last_row(view): if not view.line(view.size()).empty(): return view.size() - 1 return view.size() # skip empty rows before moving for the first time current_row = utils.row_at(view, pt) if (view.line(view.text_point(current_row + 1, 0)).empty() and view.line(pt).empty()): pt, _ = _next_non_empty_row(view, pt) for i in range(count): pt, eof = _next_empty_row(view, pt) if eof: if view.line(pt).empty(): return pt return pt - 1 if skip_empty and (i != (count - 1)): pt, eof = _next_non_empty_row(view, pt) if eof: if not view.line(pt).empty(): return pt - 1 return pt return pt
def _next_non_empty_row(view, pt): r = utils.row_at(view, pt) while True: r += 1 reg = view.line(view.text_point(r, 0)) if r >= utils.last_row(view): return reg.a, True if not reg.empty(): return reg.a, False
def _next_empty_row(view, pt): r = utils.row_at(view, pt) while True: r += 1 pt = view.text_point(r, 0) if utils.row_at(view, pt) == utils.last_row(view): return pt, True if view.line(pt).empty(): return pt, False
def lines(view, s, count=1): """ Returns a region spanning @count full lines. Assumes we're operating in INTERNAL_NORMAL mode. @view Target view. @s Selection in @view taken as starting point. @count Number of lines to include in returned region. """ # assumes INTERNAL_NORMAL mode. a = view.line(s.b).a b = view.text_point(utils.row_at(view, s.b) + (count - 1), 0) # make sure we remove the last line if needed if ((utils.row_at(view, b) == utils.last_row(view)) and (view.substr(a - 1) == '\n')): a -= 1 return sublime.Region(a, view.full_line(b).b)