Skip to content

Commit 35ae447

Browse files
committed
Warn when running cider-jack-in without a project
This makes it harder to accidentally jack-in from the wrong directory. The behaviour is configurable via `cider-allow-jack-in-without-project'.
1 parent bac53bd commit 35ae447

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ within the scope of your current Emacs session.
1919
### Changes
2020

2121
* [#1758](https://github.com/clojure-emacs/cider/issues/1758): Disable nREPL message logging by default due to its negative impact on performance.
22+
* Warn when running `cider-jack-in` without a Clojure project. This behaviour is controllable via `cider-allow-jack-in-without-project`.
2223

2324
### Bugs Fixed
2425

cider.el

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ command when there is no ambiguity."
161161
:group 'cider
162162
:package-version '(cider . "0.13.0"))
163163

164+
(defcustom cider-allow-jack-in-without-project 'warn
165+
"Controls what happens when doing `cider-jack-in' outside a project.
166+
When set to 'warn you'd prompted to confirm the command.
167+
When set to t `cider-jack-in' will quietly continue.
168+
When set to nil `cider-jack-in' will fail."
169+
:type '(choice (const :tag "always" t)
170+
(const 'warn)
171+
(const :tag "never" nil))
172+
:group 'cider
173+
:package-version '(cider . "0.14.0"))
174+
164175
(defcustom cider-known-endpoints nil
165176
"A list of connection endpoints where each endpoint is a list.
166177
For example: \\='((\"label\" \"host\" \"port\")).
@@ -513,12 +524,20 @@ own buffer."
513524
params))
514525

515526
(cmd (format "%s %s" command-resolved params)))
516-
(when-let ((repl-buff (cider-find-reusable-repl-buffer nil project-dir)))
517-
(let ((nrepl-create-client-buffer-function #'cider-repl-create)
518-
(nrepl-use-this-as-repl-buffer repl-buff))
519-
(nrepl-start-server-process
520-
project-dir cmd
521-
(when cljs-too #'cider-create-sibling-cljs-repl)))))
527+
(if (or project-dir cider-allow-jack-in-without-project)
528+
(progn
529+
(when (or project-dir
530+
(eq cider-allow-jack-in-without-project t)
531+
(and (null project-dir)
532+
(eq cider-allow-jack-in-without-project 'warn)
533+
(y-or-n-p "Are you sure you want to run `cider-jack-in' without a Clojure project? ")))
534+
(when-let ((repl-buff (cider-find-reusable-repl-buffer nil project-dir)))
535+
(let ((nrepl-create-client-buffer-function #'cider-repl-create)
536+
(nrepl-use-this-as-repl-buffer repl-buff))
537+
(nrepl-start-server-process
538+
project-dir cmd
539+
(when cljs-too #'cider-create-sibling-cljs-repl))))))
540+
(user-error "`cider-jack-in' is not allowed without a Clojure project")))
522541
(user-error "The %s executable isn't on your `exec-path'" command))))
523542

524543
;;;###autoload

0 commit comments

Comments
 (0)