Skip to content

Fix clojure-find-ns #661

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 5 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Improve support for multiple forms in the same line by replacing `beginning-of-defun` fn.

### Bugs fixed

* [#593](https://github.com/clojure-emacs/clojure-mode/issues/593): Fix clojure-find-ns when ns form is preceded by whitespace or inside comment form.

## 5.16.2 (2023-08-23)

### Changes
Expand Down
6 changes: 3 additions & 3 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ content) are considered part of the preceding sexp."
(make-obsolete-variable 'clojure-namespace-name-regex 'clojure-namespace-regexp "5.12.0")

(defconst clojure-namespace-regexp
(rx line-start "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end))
(rx line-start (zero-or-more whitespace) "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end))

(defcustom clojure-cache-ns nil
"Whether to cache the results of `clojure-find-ns'.
Expand Down Expand Up @@ -2153,7 +2153,7 @@ DIRECTION is `forward' or `backward'."
(save-match-data
(goto-char end)
(clojure-forward-logical-sexp)
(unless (or (clojure--in-string-p) (clojure--in-comment-p))
(unless (or (clojure--in-string-p) (clojure--in-comment-p) (clojure-top-level-form-p "comment"))
(setq candidate (string-remove-prefix "'" (thing-at-point 'symbol))))))))
candidate))

Expand Down Expand Up @@ -3224,7 +3224,7 @@ With universal argument \\[universal-argument], act on the \"top-level\" form."
(beginning-of-defun-raw)
(clojure--toggle-ignore-next-sexp)))


;;; ClojureScript
(defconst clojurescript-font-lock-keywords
(eval-when-compile
Expand Down
15 changes: 15 additions & 0 deletions test/clojure-mode-util-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@
(expect (clojure-find-ns) :to-equal "foo"))
(with-clojure-buffer "(ns ^:bar ^:baz foo)"
(expect (clojure-find-ns) :to-equal "foo")))
(it "should find namespaces with spaces before ns form"
(with-clojure-buffer " (ns foo)"
(expect (clojure-find-ns) :to-equal "foo")))
(it "should skip namespaces within any comment forms"
(with-clojure-buffer " (ns foo)
(comment
(ns bar))"
(expect (clojure-find-ns) :to-equal "foo"))
(with-clojure-buffer " (comment
(ns foo))
(ns bar)
(comment
(ns baz))"
(expect (clojure-find-ns) :to-equal "bar"))
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(expect (clojure-find-ns) :to-equal "bar"))
)
(expect (clojure-find-ns) :to-equal "bar")))

(it "should find namespace declarations with nested metadata and docstrings"
(with-clojure-buffer "(ns ^{:bar true} foo)"
(expect (clojure-find-ns) :to-equal "foo"))
Expand Down