Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cider--goto-expression-start: Do not throw if bop #3309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,10 @@ until we find a delimiters that's not inside a string."
(if (and (looking-back "[])}]" (line-beginning-position))
(null (nth 3 (syntax-ppss))))
(backward-sexp)
(while (or (not (looking-at-p "[({[]"))
(nth 3 (syntax-ppss)))
(while (and (not (bobp))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking a bit more about the issue it seems to me the right place for this check is not the while loop, but rather the first if or even an other if. E.g. if you're at the beginning of the buffer there's no point to look for the start of an expression as you're already there.

(or
(not (looking-at-p "[({[]"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder why this check didn't get triggered in your example with (insert foo). At the beginning of the expression the code should not try to go backward looking for the beginning of the expression.

Copy link
Contributor Author

@benjamin-asdf benjamin-asdf Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It short circuits to backward-sexp if we are are behind a closing paren. In the example there is only "foo" so no parens.

(nth 3 (syntax-ppss))))
(backward-char))))

(defun cider--find-last-error-location (message)
Expand Down
19 changes: 19 additions & 0 deletions test/cider-eval-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,23 @@
(insert "🍻"))
(expect (cider-provide-file filename) :to-equal "8J+Nuw=="))))

(describe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to add a few tests that also cover the normal behavior of this function.

"cider--goto-expression-start"
(it "Does not throw an error, when file does not contain a list"
(expect
(with-temp-buffer
(insert "foo")
;; After evaling, message:
;; "Syntax error compiling at (foo.clj:0:0).
;; Unable to resolve symbol: foo in this context
;; "
;; cider--find-last-error-location goes to location
;; 0:0 and calls cider--goto-expression-start
(goto-char (point-min))
;; no error
(cider--goto-expression-start)
'ok)
:to-equal 'ok)))


(provide 'cider-eval-tests)