Skip to content

Commit 061431d

Browse files
xiongtxbbatsov
authored andcommitted
Move to top-level before re-search-backward in clojure-find-ns
Moving to top level avoids improper matching behavior due to being in middle of match. Fix clojure-emacs/cider#2100
1 parent 05b6f05 commit 061431d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Bugs fixed
66

7+
* [#458](https://github.com/clojure-emacs/clojure-mode/pull/458): Get correct ns when in middle of ns form with `clojure-find-ns`
78
* [#447](https://github.com/clojure-emacs/clojure-mode/issues/241): When `electric-indent-mode` is on, force indentation from within docstrings.
89
* [#438](https://github.com/clojure-emacs/clojure-mode/issues/438): Filling within a doc-string doesn't affect surrounding code.
910
* Fix fill-paragraph in multi-line comments.

clojure-mode.el

+4
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,10 @@ no namespaces above point, return the first one in the buffer."
17631763
(save-excursion
17641764
(save-restriction
17651765
(widen)
1766+
1767+
;; Move to top-level to avoid searching from inside ns
1768+
(ignore-errors (while t (up-list nil t t)))
1769+
17661770
;; The closest ns form above point.
17671771
(when (or (re-search-backward clojure-namespace-name-regex nil t)
17681772
;; Or any form at all.

test/clojure-mode-sexp-test.el

+20
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@
7575
(insert "(+ 10")
7676
(newline-and-indent)))
7777

78+
(ert-deftest clojure-find-ns-test ()
79+
(with-temp-buffer
80+
(insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)")
81+
(newline)
82+
(newline)
83+
(insert "(in-ns 'baz-quux)")
84+
(clojure-mode)
85+
86+
;; From inside docstring of first ns
87+
(goto-char 18)
88+
(should (equal "foo-bar" (clojure-find-ns)))
89+
90+
;; From inside first ns's name, on its own line
91+
(goto-char 29)
92+
(should (equal "foo-bar" (clojure-find-ns)))
93+
94+
;; From inside second ns's name
95+
(goto-char 42)
96+
(should (equal "baz-quux" (clojure-find-ns)))))
97+
7898
(provide 'clojure-mode-sexp-test)
7999

80100
;;; clojure-mode-sexp-test.el ends here

0 commit comments

Comments
 (0)