Skip to content

Improve support for multiple forms in single lines by replacing beginning-of-defun fn #663

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

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions test/clojure-mode-refactor-threading-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@

(clojure-unwind '(4)))

(when-refactoring-it "should unwind correctly when multiple ->> are present on same line"
"(->> 1 inc) (->> [1 2 3 4 5]
(filter even?)
(map square))"

"(->> 1 inc) (->> (map square (filter even? [1 2 3 4 5])))"

(clojure-unwind)
(clojure-unwind))

(when-refactoring-it "should unwind with function name"
"(->> [1 2 3 4 5]
sum
Expand Down Expand Up @@ -299,8 +309,7 @@

(when-refactoring-it "should unwind some->>"
"(some->> :b
(find {:a 1})
val
(find {:a 1}) val
(+ 5))"

"(some->> (+ 5 (val (find {:a 1} :b))))"
Expand Down
21 changes: 14 additions & 7 deletions test/clojure-mode-sexp-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,37 @@
(wrong))"
;; make this use the native beginning of defun since this is used to
;; determine whether to use the comment aware version or not.
(expect (let ((beginning-of-defun-function nil))
(clojure-top-level-form-p "comment")))))
(it "should return true when multiple forms are present"
(with-clojure-buffer-point
"(+ 1 2) (comment
(wrong)
(rig|ht)
(wrong))"
(expect (let ((beginning-of-defun-function nil))
(clojure-top-level-form-p "comment"))))))

(describe "clojure-beginning-of-defun-function"
(it "should go to top level form"
(with-clojure-buffer-point
"(comment
" (comment
(wrong)
(wrong)
(rig|ht)
(wrong))"
(beginning-of-defun)
(clojure-beginning-of-defun-function)
(expect (looking-at-p "(comment"))))

(it "should eval top level forms inside comment forms when clojure-toplevel-inside-comment-form set to true"
(with-clojure-buffer-point
"(comment
(wrong)
"(+ inc 1) (comment
(wrong)
(rig|ht)
(wrong) (rig|ht)
(wrong))"
(let ((clojure-toplevel-inside-comment-form t))
(beginning-of-defun))
(expect (looking-at-p "[[:space:]]*(right)"))))
(clojure-beginning-of-defun-function))
(expect (looking-at-p "(right)"))))

(it "should go to beginning of previous top level form"
(with-clojure-buffer-point
Expand Down