Skip to content

Commit ee3fdfb

Browse files
author
Bozhidar Batsov
committed
[Fix #777] Honour lein's :init-ns on startup
1 parent ec96953 commit ee3fdfb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cider-repl.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,21 @@ PROJECT-DIR, PORT and HOST are as in `nrepl-make-buffer-name'."
182182
(clojure.core/map clojure.core/require clojure.main/repl-requires))"
183183
(lambda (response) nil)))
184184

185+
(defun cider-repl-set-initial-ns (buffer)
186+
"Set the REPL BUFFER's initial namespace (by altering `nrepl-buffer-ns').
187+
This is \"user\" by default but can be overridden in apps like lein (:init-ns)."
188+
;; we don't want to get a timeout during init
189+
(let ((nrepl-sync-request-timeout nil))
190+
(with-current-buffer buffer
191+
(let ((initial-ns (read (nrepl-dict-get (nrepl-sync-request:eval "(str *ns*)") "value"))))
192+
(when initial-ns
193+
(setq nrepl-buffer-ns initial-ns))))))
194+
185195
(defun cider-repl-init (buffer &optional no-banner)
186196
"Initialize the REPL in BUFFER.
187197
BUFFER must be a REPL buffer with `cider-repl-mode' and a running
188198
client process connection. Unless NO-BANNER is non-nil, insert a banner."
199+
(cider-repl-set-initial-ns buffer)
189200
(cider-repl-require-repl-utils)
190201
(unless no-banner
191202
(cider-repl--insert-banner-and-prompt buffer))

0 commit comments

Comments
 (0)