diff --git a/clojure-mode.el b/clojure-mode.el index 2f68a0db..517f8803 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -2110,7 +2110,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 "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end)) (defcustom clojure-cache-ns nil "Whether to cache the results of `clojure-find-ns'. diff --git a/test/clojure-mode-util-test.el b/test/clojure-mode-util-test.el index a35babbe..ba9bfeea 100644 --- a/test/clojure-mode-util-test.el +++ b/test/clojure-mode-util-test.el @@ -125,6 +125,23 @@ (with-clojure-buffer "(ns foo) (ns-unmap *ns* 'map) (ns.misleading 1 2 3)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should skip leading garbage" + (with-clojure-buffer " (ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "1(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "1 (ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "1 +(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "[1] +(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "[1] (ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "[1](ns foo)" (expect (clojure-find-ns) :to-equal "foo")))) (describe "clojure-sort-ns" @@ -154,7 +171,7 @@ ;;[comment2] ))"))) (it "should sort requires in ns with copyright disclamer and comments" - (with-clojure-buffer ";; Copyright (c) John Doe. All rights reserved. + (with-clojure-buffer ";; Copyright (c) John Doe. All rights reserved. ;; The use and distribution terms for this software are covered by the ;; Eclipse Public License 1.0 (https://opensource.org/license/epl-1-0/) (ns clojure.core