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

Conversation

SophieBosio
Copy link
Contributor

This PR expands on the work of #682.

The problem is that when running cider-find-def with point inside the following function,

(defn- foo [x] x)

it would not recognize defn- as the first symbol. Instead it would output ("defn" "-"). I would expect it to output ("defn-" "foo").

This stems from the regex for declarations in clojure-def-type-and-name-regex:

"\\(def\\(?:\\sw\\|\\s_\\)*\\)\\>"

It recognizes def followed by an entry from the word class w or from the symbol class _, but it also states that the end must be from the "comment end" class >. The hyphen is not included in this class and therefore can't be the final character in the recognized expression.

My suggested fix is to recognize an optional hyphen at the end.

It still recognizes def-n and now also def-n-

I added a few test cases to the ones added by @frwdrik.

Emacs version:
GNU Emacs 30.0.92 (build 2, aarch64-apple-darwin24.1.0, NS appkit-2575.20 Version 15.1 (Build 24B83)) of 2024-11-01

clojure-mode version:
clojure-mode (version 5.20.0-snapshot)


Before submitting a PR mark the checkboxes for the items you've done (if you
think a checkbox does not apply, then leave it unchecked):

  • The commits are consistent with our contribution guidelines.
  • You've added tests (if possible) to cover your change(s). Bugfix, indentation, and font-lock tests are extremely important!
  • You've run M-x checkdoc and fixed any warnings in the code you've written.
  • You've updated the changelog (if adding/changing user-visible functionality).
  • You've updated the readme (if adding/changing user-visible functionality).

Thanks!

@@ -374,7 +374,25 @@
"(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-"
Copy link
Member

Choose a reason for hiding this comment

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

Probably you should also add a couple of tests showing that anything like defxyz- will be accepted, so it's clearer that the - will work for every definition form.

"(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.

@bbatsov
Copy link
Member

bbatsov commented Dec 9, 2024

Thanks for the detailed description of the problem and the proposed solution!

Outside of my small remark about adding some extra tests - your proposed changes look good to me. Also - please mention your fix in the changelog.

P.S. It's always nice to see a first-time contributor to the project!

@SophieBosio
Copy link
Contributor Author

Thanks for the detailed description of the problem and the proposed solution!

Outside of my small remark about adding some extra tests - your proposed changes look good to me. Also - please mention your fix in the changelog.

P.S. It's always nice to see a first-time contributor to the project!

My pleasure! It's my first-ever open source contribution, so thank you for the feedback and for the helpful contribution guide!

Please let this newbie know if there's anything else I can improve 😊

@bbatsov
Copy link
Member

bbatsov commented Dec 11, 2024

Everything looks great now! Just rebase your branch on top of master to address the conflict in the changelog.

My pleasure! It's my first-ever open source contribution, so thank you for the feedback and for the helpful contribution guide!

Hopefully the first of many! 🚀

@SophieBosio
Copy link
Contributor Author

Everything looks great now! Just rebase your branch on top of master to address the conflict in the changelog.

My pleasure! It's my first-ever open source contribution, so thank you for the feedback and for the helpful contribution guide!

Hopefully the first of many! 🚀

Glad to hear it! ❤ Thanks to you and to @frwdrik!

@bbatsov bbatsov merged commit eabe29b into clojure-emacs:master Dec 11, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants