@@ -1886,6 +1886,19 @@ the cached value will be updated automatically."
1886
1886
(defvar-local clojure-cached-ns nil
1887
1887
" A buffer ns cache used to speed up ns-related operations." )
1888
1888
1889
+ (defun clojure--find-ns-in-direction (direction )
1890
+ " Return the nearest namespace in a specific DIRECTION.
1891
+ DIRECTION is `forward' or `backward' ."
1892
+ (let ((candidate)
1893
+ (fn (if (eq direction 'forward )
1894
+ #'search-forward-regexp
1895
+ #'search-backward-regexp )))
1896
+ (while (and (not candidate)
1897
+ (funcall fn clojure-namespace-name-regex nil t ))
1898
+ (unless (or (clojure--in-string-p) (clojure--in-comment-p))
1899
+ (setq candidate (match-string-no-properties 4 ))))
1900
+ candidate))
1901
+
1889
1902
(defun clojure-find-ns ()
1890
1903
" Return the namespace of the current Clojure buffer.
1891
1904
Return the namespace closest to point and above it. If there are
@@ -1901,12 +1914,8 @@ The results will be cached if `clojure-cache-ns' is set to t."
1901
1914
; ; Move to top-level to avoid searching from inside ns
1902
1915
(ignore-errors (while t (up-list nil t t )))
1903
1916
1904
- ; ; The closest ns form above point.
1905
- (when (or (re-search-backward clojure-namespace-name-regex nil t )
1906
- ; ; Or any form at all.
1907
- (and (goto-char (point-min ))
1908
- (re-search-forward clojure-namespace-name-regex nil t )))
1909
- (match-string-no-properties 4 ))))))
1917
+ (or (clojure--find-ns-in-direction 'backward )
1918
+ (clojure--find-ns-in-direction 'forward ))))))
1910
1919
(setq clojure-cached-ns ns)
1911
1920
ns)))
1912
1921
@@ -2384,6 +2393,10 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-cycle-privacy"
2384
2393
" Check whether the point is currently in a string."
2385
2394
(nth 3 (syntax-ppss )))
2386
2395
2396
+ (defun clojure--in-comment-p ()
2397
+ " Check whether the point is currently in a comment."
2398
+ (nth 4 (syntax-ppss )))
2399
+
2387
2400
(defun clojure--goto-if ()
2388
2401
" Find the first surrounding if or if-not expression."
2389
2402
(when (clojure--in-string-p)
0 commit comments