Skip to content

Recognize defn- in clojure-find-def for declarations #683

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 7 commits into from
Dec 11, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* [cider#3758](https://github.com/clojure-emacs/cider/issues/3758): Improve regexp for clojure-find-def to recognize more complex metadata on vars
* [#684](https://github.com/clojure-emacs/clojure-mode/issues/684): Restore `outline-regexp` pattern to permit outline handling of top-level forms.
* Improve regexp for clojure-find-def to recognize `defn-` and other declarations on the form `def...-`.

## 5.19.0 (2024-05-26)

Expand Down
2 changes: 1 addition & 1 deletion clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ renaming a namespace."
(defconst clojure-def-type-and-name-regex
(concat "(\\(?:\\(?:\\sw\\|\\s_\\)+/\\)?"
;; Declaration
"\\(def\\(?:\\sw\\|\\s_\\)*\\)\\>"
"\\(def\\(?:\\sw\\|\\s_\\)*\\(?:-\\|\\>\\)\\)"
;; Any whitespace
"[ \r\n\t]*"
;; Possibly type or metadata
Expand Down
55 changes: 54 additions & 1 deletion test/clojure-mode-util-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,60 @@
"(deftest ^{:a 1} simple-metadata)
(deftest ^{:a {}} complex-metadata)
(deftest |no-metadata)"
(expect (clojure-find-def) :to-equal '("deftest" "no-metadata")))))
(expect (clojure-find-def) :to-equal '("deftest" "no-metadata"))))
(it "should recognize defn-, with or without metadata"
(with-clojure-buffer-point
"(def foo 1)
(defn- bar |[x y z] z)
(def bar 2)"
(expect (clojure-find-def) :to-equal '("defn-" "bar")))
(with-clojure-buffer-point
"(def foo 1)
(defn- ^:private bar |[x y z] z)"
(expect (clojure-find-def) :to-equal '("defn-" "bar")))
(with-clojure-buffer-point
"(defn- |^{:doc \"A function\"} foo [] 1)
(defn- ^:private bar 2)"
(expect (clojure-find-def) :to-equal '("defn-" "foo")))
(with-clojure-buffer-point
Copy link
Member

Choose a reason for hiding this comment

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

I think this test should be under a different it group.

"(def foo 1)
(defn- ^{:|a {}} complex-metadata |[x y z] z)
(def bar 2)"
(expect (clojure-find-def) :to-equal '("defn-" "complex-metadata"))))
(it "should recognize def...-, with or without metadata"
(with-clojure-buffer-point
"(def foo 1)
(def- bar| 5)
(def baz 2)"
(expect (clojure-find-def) :to-equal '("def-" "bar")))
(with-clojure-buffer-point
"(def foo 1)
(deftest- bar |[x y z] z)
(def baz 2)"
(expect (clojure-find-def) :to-equal '("deftest-" "bar")))
(with-clojure-buffer-point
"(def foo 1)
(defxyz- bar| 5)
(def baz 2)"
(expect (clojure-find-def) :to-equal '("defxyz-" "bar")))
(with-clojure-buffer-point
"(def foo 1)
(defn-n- bar| [x y z] z)
(def baz 2)"
(expect (clojure-find-def) :to-equal '("defn-n-" "bar")))
(with-clojure-buffer-point
"(def foo 1)
(defn-n- ^:private bar |[x y z] z)"
(expect (clojure-find-def) :to-equal '("defn-n-" "bar")))
(with-clojure-buffer-point
"(def-n- |^{:doc \"A function\"} foo [] 1)
(def- ^:private bar 2)"
(expect (clojure-find-def) :to-equal '("def-n-" "foo")))
(with-clojure-buffer-point
"(def foo 1)
(defn-n- ^{:|a {}} complex-metadata |[x y z] z)
(def bar 2)"
(expect (clojure-find-def) :to-equal '("defn-n-" "complex-metadata")))))

(provide 'clojure-mode-util-test)

Expand Down