Skip to content

Commit

Permalink
cider--sesman-friendly-session-p: avoid semi-recursive edge case (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv authored Aug 25, 2023
1 parent 3d0c841 commit 253c22f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,19 @@ Useful for special buffers (e.g. REPL, doc buffers) that have to keep track
of a namespace. This should never be set in Clojure buffers, as there the
namespace should be extracted from the buffer's ns form.")

(defun cider-current-ns (&optional no-default)
(defun cider-current-ns (&optional no-default no-repl-check)
"Return the current ns.
The ns is extracted from the ns form for Clojure buffers and from
`cider-buffer-ns' for all other buffers. If it's missing, use the current
REPL's ns, otherwise fall back to \"user\". When NO-DEFAULT is non-nil, it
will return nil instead of \"user\"."
REPL's ns, otherwise fall back to \"user\".
When NO-DEFAULT is non-nil, it will return nil instead of \"user\".
When NO-REPL-CHECK is non-nil, `cider-current-repl' will not be queried,
improving performance (at the possible cost of accuracy)."
(or cider-buffer-ns
(cider-get-ns-name)
(when-let* ((repl (cider-current-repl)))
(buffer-local-value 'cider-buffer-ns repl))
(unless no-repl-check
(when-let* ((repl (cider-current-repl)))
(buffer-local-value 'cider-buffer-ns repl)))
(if no-default nil "user")))

(defun cider-path-to-ns (relpath)
Expand Down
5 changes: 4 additions & 1 deletion cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,10 @@ The checking is done as follows:
classpath-roots)))
translated))
(when-let ((ns (condition-case nil
(substring-no-properties (cider-current-ns :no-default))
(substring-no-properties (cider-current-ns :no-default
;; important - don't query the repl,
;; avoiding a recursive invocation of `cider--sesman-friendly-session-p`:
:no-repl-check))
(error nil))))
;; if the ns form matches with a ns of all runtime namespaces, we can consider the buffer to match
;; (this is a bit lax, but also quite useful)
Expand Down

0 comments on commit 253c22f

Please sign in to comment.