Skip to content

Commit

Permalink
refactor(sexp): use loop instead of try catch
Browse files Browse the repository at this point in the history
We can know how deep we are in a list with the syntax-ppss function,
with this we can use a simple loop instead of going up until something explodes
  • Loading branch information
martini97 committed Jun 29, 2023
1 parent 5cd767f commit a5086f5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions testrun-sexp.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
;;; Code:

(require 'seq)
(require 'syntax)
(require 'thingatpt)

(defun testrun-sexp--beginning-of-thing-at-point-p (thing)
Expand All @@ -49,6 +50,10 @@
(thing-at-point 'list))
(thing-at-point 'list))))

(defun testrun-sexp--current-depth ()
"Get current point depth in parentheses, counting from 0."
(car (syntax-ppss)))

(defun testrun-sexp--parents ()
"Return a list with all the parent sexps of the current point.
Expand All @@ -57,11 +62,9 @@ If point is at the beginning of a list then it will also be included."
(list (testrun-sexp--read-list-at-point))
'())))
(save-excursion
(condition-case _err
(while t
(backward-up-list)
(push (testrun-sexp--read-list-at-point) parents))
(scan-error nil)))
(cl-loop for i from 0 below (testrun-sexp--current-depth) do
(backward-up-list)
(push (testrun-sexp--read-list-at-point) parents)))
parents))

(defun testrun-sexp--filter-car-memq (lists wanted)
Expand Down

0 comments on commit a5086f5

Please sign in to comment.