File tree 3 files changed +26
-15
lines changed
3 files changed +26
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## master (unreleased)
4
4
5
+ ### Changes
6
+
7
+ * ` clojure-find-ns ` : never raise errors, returning nil instead on unparseable ns forms.
8
+
5
9
## 5.16.1 (2023-06-26)
6
10
7
11
### Changes
Original file line number Diff line number Diff line change @@ -2127,20 +2127,21 @@ the cached value will be updated automatically."
2127
2127
(defun clojure--find-ns-in-direction (direction )
2128
2128
" Return the nearest namespace in a specific DIRECTION.
2129
2129
DIRECTION is `forward' or `backward' ."
2130
- (let ((candidate)
2131
- (fn (if (eq direction 'forward )
2132
- #'search-forward-regexp
2133
- #'search-backward-regexp )))
2134
- (while (and (not candidate)
2135
- (funcall fn clojure-namespace-regexp nil t ))
2136
- (let ((end (match-end 0 )))
2137
- (save-excursion
2138
- (save-match-data
2139
- (goto-char end)
2140
- (clojure-forward-logical-sexp)
2141
- (unless (or (clojure--in-string-p) (clojure--in-comment-p))
2142
- (setq candidate (string-remove-prefix " '" (thing-at-point 'symbol ))))))))
2143
- candidate))
2130
+ (ignore-errors
2131
+ (let ((candidate)
2132
+ (fn (if (eq direction 'forward )
2133
+ #'search-forward-regexp
2134
+ #'search-backward-regexp )))
2135
+ (while (and (not candidate)
2136
+ (funcall fn clojure-namespace-regexp nil t ))
2137
+ (let ((end (match-end 0 )))
2138
+ (save-excursion
2139
+ (save-match-data
2140
+ (goto-char end)
2141
+ (clojure-forward-logical-sexp)
2142
+ (unless (or (clojure--in-string-p) (clojure--in-comment-p))
2143
+ (setq candidate (string-remove-prefix " '" (thing-at-point 'symbol ))))))))
2144
+ candidate)))
2144
2145
2145
2146
(defun clojure-find-ns ()
2146
2147
" Return the namespace of the current Clojure buffer.
Original file line number Diff line number Diff line change 167
167
(expect (clojure-find-ns) :to-equal expected)
168
168
; ; After both namespaces
169
169
(goto-char (point-max ))
170
- (expect (clojure-find-ns) :to-equal expected)))))))
170
+ (expect (clojure-find-ns) :to-equal expected))))))
171
+
172
+ (it " should return nil for an invalid ns form"
173
+ ; ; we should not cache the results of `clojure-find-ns' here
174
+ (let ((clojure-cache-ns nil ))
175
+ (with-clojure-buffer " (ns )"
176
+ (expect (equal nil (clojure-find-ns)))))))
171
177
172
178
(describe " clojure-sexp-starts-until-position"
173
179
(it " should return starting points for forms after POINT until POSITION"
You can’t perform that action at this time.
0 commit comments