Skip to content

Commit

Permalink
Fix bad seems_like_end_point impl
Browse files Browse the repository at this point in the history
  • Loading branch information
eerohele committed Feb 26, 2024
1 parent 80eab54 commit d0dfe4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
44 changes: 16 additions & 28 deletions src/sexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,28 +326,12 @@ def crude_find_open(view, point):
point = begin - 1


def next_non_whitespace_character_at_first_column(view, point):
max_point = view.size()

while point < max_point:
ch = view.substr(point)

if view.rowcol(point)[1] == 0 and not ch.isspace():
return ch

point += 1

return "\x00"


end_point_candidates = set(OPEN.keys()).union({"\x00"})


def seems_like_end_point(view, point):
return (
view.match_selector(point - 1, END_SELECTORS)
and next_non_whitespace_character_at_first_column(view, point)
in end_point_candidates
return view.match_selector(point - 1, "punctuation.section.parens.end") and (
view.substr(Region(point, point + 2)) == "\n("
or view.substr(Region(point, point + 3)) == "\n\n("
or view.substr(Region(point, point + 4)) == "\n\n\n("
or view.substr(point + 1) == "\x00"
)


Expand Down Expand Up @@ -378,13 +362,17 @@ def crude_outermost(view, point):
Only finds S-expressions surrounded by parentheses, not brackets or braces."""
begin = crude_find_open(view, point)
end = crude_find_close(view, point)

if begin is not None and end is not None:
begin_delim = Delimiter(
"punctuation.section.parens.begin", Region(begin, begin + 1)
)
if begin is not None:
end = crude_find_close(view, point)

end_delim = Delimiter("punctuation.section.parens.end", Region(end - 1, end))
if end is not None:
begin_delim = Delimiter(
"punctuation.section.parens.begin", Region(begin, begin + 1)
)

end_delim = Delimiter(
"punctuation.section.parens.end", Region(end - 1, end)
)

return make_sexp(view, begin_delim, end_delim)
return make_sexp(view, begin_delim, end_delim)
6 changes: 6 additions & 0 deletions tests/test_sexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,9 @@ def test_crude_outermost(self):
for n in range(0, 16):
outermost = sexp.crude_outermost(self.view, n)
self.assertEquals(outermost, None)

form = "(ns x (:require []\n [c.d]))\n(defn f [y] y)"
self.set_view_content(form)

outermost = sexp.crude_outermost(self.view, 17)
self.assertEquals(outermost.extent(), Region(0, 28))

0 comments on commit d0dfe4f

Please sign in to comment.