Skip to content

Commit

Permalink
Fix clojure-find-ns for ns forms preceded by whitespace (#661)
Browse files Browse the repository at this point in the history
Closes #593
  • Loading branch information
p4v4n authored and vemv committed Sep 7, 2023
1 parent a6a688d commit 1dc343f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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
17 changes: 17 additions & 0 deletions test/clojure-mode-util-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@
(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 "(comment
(ns foo))"
(expect (clojure-find-ns) :to-equal nil))
(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")))
(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

0 comments on commit 1dc343f

Please sign in to comment.