Skip to content

Commit 035ff00

Browse files
committed
Make the project-type a symbol
That's more in line with Emacs conventions. This commit also changes config values that used to be strings to symbols, but also preserves backward compatibility in cases so users changed the defaults.
1 parent 0e12ee2 commit 035ff00

File tree

1 file changed

+78
-72
lines changed

1 file changed

+78
-72
lines changed

cider.el

Lines changed: 78 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
(require 'cider-common)
8080
(require 'cider-compat)
8181
(require 'cider-debug)
82+
(require 'cider-util)
8283

8384
(require 'tramp-sh)
8485
(require 'subr-x)
@@ -214,42 +215,42 @@ By default we favor the project-specific shadow-cljs over the system-wide."
214215
:safe #'stringp
215216
:package-version '(cider . "0.10.0"))
216217

217-
(defcustom cider-jack-in-default (if (executable-find "clojure") "clojure-cli" "lein")
218+
(defcustom cider-jack-in-default (if (executable-find "clojure") 'clojure-cli 'lein)
218219
"The default tool to use when doing `cider-jack-in' outside a project.
219220
This value will only be consulted when no identifying file types, i.e.
220221
project.clj for leiningen or build.boot for boot, could be found.
221222
222223
As the Clojure CLI is bundled with Clojure itself, it's the default.
223224
In the absence of the Clojure CLI (e.g. on Windows), we fallback
224225
to Leiningen."
225-
:type '(choice (const "lein")
226-
(const "boot")
227-
(const "clojure-cli")
228-
(const "shadow-cljs")
229-
(const "gradle"))
226+
:type '(choice (const 'lein)
227+
(const 'boot)
228+
(const 'clojure-cli)
229+
(const 'shadow-cljs)
230+
(const 'gradle))
230231
:group 'cider
231-
:safe #'stringp
232+
:safe #'symbolp
232233
:package-version '(cider . "0.9.0"))
233234

234235
(define-obsolete-variable-alias 'cider-default-repl-command 'cider-jack-in-default)
235236

236237
(defcustom cider-preferred-build-tool
237238
nil
238239
"Allow choosing a build system when there are many.
239-
When there are artifacts from multiple build systems (\"lein\", \"boot\",
240-
\"gradle\") the user is prompted to select one of them. When non-nil, this
240+
When there are project markers from multiple build systems (e.g. lein and
241+
boot) the user is prompted to select one of them. When non-nil, this
241242
variable will suppress this behavior and will select whatever build system
242243
is indicated by the variable if present. Note, this is only when CIDER
243244
cannot decide which of many build systems to use and will never override a
244245
command when there is no ambiguity."
245-
:type '(choice (const "lein")
246-
(const "boot")
247-
(const "clojure-cli")
248-
(const "shadow-cljs")
249-
(const "gradle")
246+
:type '(choice (const 'lein)
247+
(const 'boot)
248+
(const 'clojure-cli)
249+
(const 'shadow-cljs)
250+
(const 'gradle)
250251
(const :tag "Always ask" nil))
251252
:group 'cider
252-
:safe #'stringp
253+
:safe #'symbolp
253254
:package-version '(cider . "0.13.0"))
254255

255256
(defcustom cider-allow-jack-in-without-project 'warn
@@ -320,54 +321,54 @@ Sub-match 1 must be the project path.")
320321
(defun cider-jack-in-command (project-type)
321322
"Determine the command `cider-jack-in' needs to invoke for the PROJECT-TYPE."
322323
(pcase project-type
323-
("lein" cider-lein-command)
324-
("boot" cider-boot-command)
325-
("clojure-cli" cider-clojure-cli-command)
326-
("shadow-cljs" cider-shadow-cljs-command)
327-
("gradle" cider-gradle-command)
328-
(_ (user-error "Unsupported project type `%s'" project-type))))
324+
('lein cider-lein-command)
325+
('boot cider-boot-command)
326+
('clojure-cli cider-clojure-cli-command)
327+
('shadow-cljs cider-shadow-cljs-command)
328+
('gradle cider-gradle-command)
329+
(_ (user-error "Unsupported project type `%S'" project-type))))
329330

330331
(defun cider-jack-in-resolve-command (project-type)
331332
"Determine the resolved file path to `cider-jack-in-command'.
332333
Throws an error if PROJECT-TYPE is unknown."
333334
(pcase project-type
334-
("lein" (cider--resolve-command cider-lein-command))
335-
("boot" (cider--resolve-command cider-boot-command))
336-
("clojure-cli" (cider--resolve-command cider-clojure-cli-command))
335+
('lein (cider--resolve-command cider-lein-command))
336+
('boot (cider--resolve-command cider-boot-command))
337+
('clojure-cli (cider--resolve-command cider-clojure-cli-command))
337338
;; here we have to account for the possibility that the command is either
338339
;; "npx shadow-cljs" or just "shadow-cljs"
339-
("shadow-cljs" (let ((parts (split-string cider-shadow-cljs-command)))
340+
('shadow-cljs (let ((parts (split-string cider-shadow-cljs-command)))
340341
(when-let* ((command (cider--resolve-command (car parts))))
341342
(mapconcat #'identity (cons command (cdr parts)) " "))))
342-
("gradle" (cider--resolve-command cider-gradle-command))
343-
(_ (user-error "Unsupported project type `%s'" project-type))))
343+
('gradle (cider--resolve-command cider-gradle-command))
344+
(_ (user-error "Unsupported project type `%S'" project-type))))
344345

345346
(defun cider-jack-in-global-options (project-type)
346347
"Determine the command line options for `cider-jack-in' for the PROJECT-TYPE."
347348
(pcase project-type
348-
("lein" cider-lein-global-options)
349-
("boot" cider-boot-global-options)
350-
("clojure-cli" cider-clojure-cli-global-options)
351-
("shadow-cljs" cider-shadow-cljs-global-options)
352-
("gradle" cider-gradle-global-options)
353-
(_ (user-error "Unsupported project type `%s'" project-type))))
349+
('lein cider-lein-global-options)
350+
('boot cider-boot-global-options)
351+
('clojure-cli cider-clojure-cli-global-options)
352+
('shadow-cljs cider-shadow-cljs-global-options)
353+
('gradle cider-gradle-global-options)
354+
(_ (user-error "Unsupported project type `%S'" project-type))))
354355

355356
(defun cider-jack-in-params (project-type)
356357
"Determine the commands params for `cider-jack-in' for the PROJECT-TYPE."
357358
(pcase project-type
358-
("lein" cider-lein-parameters)
359-
("boot" cider-boot-parameters)
360-
("clojure-cli" (format cider-clojure-cli-parameters
359+
('lein cider-lein-parameters)
360+
('boot cider-boot-parameters)
361+
('clojure-cli (format cider-clojure-cli-parameters
361362
(concat
362363
"["
363364
(mapconcat
364365
(apply-partially #'format "\"%s\"")
365366
(cider-jack-in-normalized-nrepl-middlewares)
366367
", ")
367368
"]")))
368-
("shadow-cljs" cider-shadow-cljs-parameters)
369-
("gradle" cider-gradle-parameters)
370-
(_ (user-error "Unsupported project type `%s'" project-type))))
369+
('shadow-cljs cider-shadow-cljs-parameters)
370+
('gradle cider-gradle-parameters)
371+
(_ (user-error "Unsupported project type `%S'" project-type))))
371372

372373

373374
;;; Jack-in dependencies injection
@@ -607,35 +608,35 @@ the used PROJECT-TYPE. Eliminates the need for hacking profiles.clj or the
607608
boot script for supporting cider with its nREPL middleware and
608609
dependencies."
609610
(pcase project-type
610-
("lein" (cider-lein-jack-in-dependencies
611-
global-opts
612-
params
613-
(cider-add-clojure-dependencies-maybe
614-
cider-jack-in-dependencies)
615-
cider-jack-in-dependencies-exclusions
616-
(cider-jack-in-normalized-lein-plugins)))
617-
("boot" (cider-boot-jack-in-dependencies
618-
global-opts
619-
params
620-
(cider-add-clojure-dependencies-maybe
621-
cider-jack-in-dependencies)
622-
(cider-jack-in-normalized-lein-plugins)
623-
(cider-jack-in-normalized-nrepl-middlewares)))
624-
("clojure-cli" (cider-clojure-cli-jack-in-dependencies
625-
global-opts
626-
params
627-
(cider-add-clojure-dependencies-maybe
628-
cider-jack-in-dependencies)))
629-
("shadow-cljs" (cider-shadow-cljs-jack-in-dependencies
630-
global-opts
631-
params
632-
(cider-add-clojure-dependencies-maybe
633-
cider-jack-in-dependencies)))
634-
("gradle" (concat
635-
global-opts
636-
(unless (seq-empty-p global-opts) " ")
637-
params))
638-
(_ (error "Unsupported project type `%s'" project-type))))
611+
('lein (cider-lein-jack-in-dependencies
612+
global-opts
613+
params
614+
(cider-add-clojure-dependencies-maybe
615+
cider-jack-in-dependencies)
616+
cider-jack-in-dependencies-exclusions
617+
(cider-jack-in-normalized-lein-plugins)))
618+
('boot (cider-boot-jack-in-dependencies
619+
global-opts
620+
params
621+
(cider-add-clojure-dependencies-maybe
622+
cider-jack-in-dependencies)
623+
(cider-jack-in-normalized-lein-plugins)
624+
(cider-jack-in-normalized-nrepl-middlewares)))
625+
('clojure-cli (cider-clojure-cli-jack-in-dependencies
626+
global-opts
627+
params
628+
(cider-add-clojure-dependencies-maybe
629+
cider-jack-in-dependencies)))
630+
('shadow-cljs (cider-shadow-cljs-jack-in-dependencies
631+
global-opts
632+
params
633+
(cider-add-clojure-dependencies-maybe
634+
cider-jack-in-dependencies)))
635+
('gradle (concat
636+
global-opts
637+
(unless (seq-empty-p global-opts) " ")
638+
params))
639+
(_ (error "Unsupported project type `%S'" project-type))))
639640

640641

641642
;;; ClojureScript REPL creation
@@ -1362,10 +1363,13 @@ tool in `cider-preferred-build-tool', otherwise prompt the user to choose.
13621363
PROJECT-DIR defaults to the current project."
13631364
(let* ((choices (cider--identify-buildtools-present project-dir))
13641365
(multiple-project-choices (> (length choices) 1))
1365-
(default (car choices)))
1366+
(default (car choices))
1367+
;; `cider-preferred-build-tool' used to be a string prior to CIDER
1368+
;; 0.18, therefore the need for `cider-maybe-intern'
1369+
(preferred-build-tool (cider-maybe-intern cider-preferred-build-tool)))
13661370
(cond ((and multiple-project-choices
1367-
(member cider-preferred-build-tool choices))
1368-
cider-preferred-build-tool)
1371+
(member preferred-build-tool choices))
1372+
preferred-build-tool)
13691373
(multiple-project-choices
13701374
(completing-read (format "Which command should be used (default %s): " default)
13711375
choices nil t nil nil default))
@@ -1374,7 +1378,9 @@ PROJECT-DIR defaults to the current project."
13741378
;; TODO: Move this fallback outside the project-type check
13751379
;; if we're outside a project we fallback to whatever tool
13761380
;; is specified in `cider-jack-in-default' (normally clojure-cli)
1377-
(t cider-jack-in-default))))
1381+
;; `cider-jack-in-default' used to be a string prior to CIDER
1382+
;; 0.18, therefore the need for `cider-maybe-intern'
1383+
(t (cider-maybe-intern cider-jack-in-default)))))
13781384

13791385

13801386
;; TODO: Implement a check for command presence over tramp

0 commit comments

Comments
 (0)