diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e78866c..b4645400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/clojure-mode.el b/clojure-mode.el index e6f7e185..a70ad39c 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -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 diff --git a/test/clojure-mode-util-test.el b/test/clojure-mode-util-test.el index f1895b67..d905fc70 100644 --- a/test/clojure-mode-util-test.el +++ b/test/clojure-mode-util-test.el @@ -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 + "(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)