@@ -2142,23 +2142,30 @@ DIRECTION is `forward' or `backward'."
21422142 (setq candidate (string-remove-prefix " '" (thing-at-point 'symbol ))))))))
21432143 candidate))
21442144
2145- (defun clojure-find-ns ()
2146- " Return the namespace of the current Clojure buffer.
2145+ (defun clojure-find-ns (&optional suppress-errors )
2146+ " Return the namespace of the current Clojure buffer, honor `SUPPRESS-ERRORS' .
21472147Return the namespace closest to point and above it. If there are
21482148no namespaces above point, return the first one in the buffer.
21492149
2150+ If `SUPPRESS-ERRORS' is t, errors during ns form parsing will be swallowed,
2151+ and nil will be returned instead of letting this function fail.
2152+
21502153The results will be cached if `clojure-cache-ns' is set to t."
21512154 (if (and clojure-cache-ns clojure-cached-ns)
21522155 clojure-cached-ns
2153- (let ((ns (save-excursion
2154- (save-restriction
2155- (widen )
2156-
2157- ; ; Move to top-level to avoid searching from inside ns
2158- (ignore-errors (while t (up-list nil t t )))
2159-
2160- (or (clojure--find-ns-in-direction 'backward )
2161- (clojure--find-ns-in-direction 'forward ))))))
2156+ (let* ((f (lambda (direction )
2157+ (if suppress-errors
2158+ (ignore-errors (clojure--find-ns-in-direction direction))
2159+ (clojure--find-ns-in-direction direction))))
2160+ (ns (save-excursion
2161+ (save-restriction
2162+ (widen )
2163+
2164+ ; ; Move to top-level to avoid searching from inside ns
2165+ (ignore-errors (while t (up-list nil t t )))
2166+
2167+ (or (funcall f 'backward )
2168+ (funcall f 'forward ))))))
21622169 (setq clojure-cached-ns ns)
21632170 ns)))
21642171
0 commit comments