Skip to content

Commit 1c63258

Browse files
committed
Simplify insert-startup-commands call
1 parent 92da68c commit 1c63258

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

cider-repl.el

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ fully initialized."
319319
((pred identity) (pop-to-buffer buffer)))
320320
(with-current-buffer buffer
321321
(cider-repl--insert-banner)
322-
(cider-repl--insert-param-values `((:cljs-repl-type "cljs repl type" ,#'symbol-name)
323-
(:repl-init-form "cljs repl startup command")))
322+
(cider-repl--insert-startup-commands)
324323
(when-let* ((window (get-buffer-window buffer t)))
325324
(with-selected-window window
326325
(recenter (- -1 scroll-margin))))
@@ -335,7 +334,7 @@ fully initialized."
335334
(insert-before-markers
336335
(propertize (cider-repl--help-banner) 'font-lock-face 'font-lock-comment-face))))
337336

338-
(defun cider-repl--insert-param-values (param-tuples)
337+
(defun cider-repl--insert-startup-commands ()
339338
"Insert the values from params specified in PARAM-TUPLES.
340339
PARAM-TUPLES are tuples of (param-key description) or (param-key
341340
description transform) where transform is called with the param-value if
@@ -347,18 +346,18 @@ present."
347346
(propertize
348347
(if (string-blank-p contents) ";;\n" (concat ";; " contents "\n"))
349348
'font-lock-face 'font-lock-comment-face))))
350-
(let ((present-values (thread-last param-tuples
351-
(seq-map (lambda (tuple)
352-
(cl-destructuring-bind (param-key desc &optional transform) tuple
353-
(when-let ((value (plist-get cider-saved-params param-key)))
354-
(list desc (funcall (or transform #'identity) value))))))
355-
(seq-filter #'identity))))
356-
(when present-values
349+
(let ((jack-in-command (plist-get cider-saved-params :jack-in-cmd))
350+
(cljs-repl-type (plist-get cider-saved-params :cljs-repl-type))
351+
(cljs-init-form (plist-get cider-saved-params :repl-init-form)))
352+
(when jack-in-command
353+
;; spaces to align with the banner
354+
(emit-comment (concat " Startup: " jack-in-command)))
355+
(when (or cljs-repl-type cljs-init-form)
357356
(emit-comment "")
358-
(mapc (lambda (desc-and-value)
359-
(cl-destructuring-bind (desc value) desc-and-value
360-
(emit-comment (concat desc ": " value))))
361-
present-values)
357+
(when cljs-repl-type
358+
(emit-comment (concat "cljs repl type: " (symbol-name cljs-repl-type))))
359+
(when cljs-init-form
360+
(emit-comment (concat "cljs repl startup command: " cljs-init-form)))
362361
(emit-comment "")))))
363362

364363
(defun cider-repl--banner ()
@@ -372,15 +371,13 @@ present."
372371
;; Javadoc: (javadoc java-object-or-class)
373372
;; Exit: <C-c C-q>
374373
;; Results: Stored in vars *1, *2, *3, an exception in *e;
375-
;; Startup: %s
376374
"
377375
(plist-get nrepl-endpoint :host)
378376
(plist-get nrepl-endpoint :port)
379377
(cider--version)
380378
(cider--nrepl-version)
381379
(cider--clojure-version)
382-
(cider--java-version)
383-
(plist-get cider-saved-params :jack-in-cmd)))
380+
(cider--java-version)))
384381

385382
(defun cider-repl--help-banner ()
386383
"Generate the help banner."

test/cider-repl-tests.el

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,24 @@
3737
(spy-on 'insert-before-markers
3838
:and-call-fake (lambda (arg)
3939
(setq output (format "%s%s" output (substring-no-properties arg)))))
40-
(cider-repl--insert-param-values `((:cljs-repl-type "cljs repl type" ,#'symbol-name)
41-
(:repl-init-form "cljs repl startup command")))
40+
(cider-repl--insert-startup-commands)
4241
(expect output :to-be "")))
42+
(it "puts jack-in-command in same style as banner"
43+
(let ((output "")
44+
(cider-saved-params '(:jack-in-cmd "lein command")))
45+
(spy-on 'insert-before-markers
46+
:and-call-fake (lambda (arg)
47+
(setq output (format "%s%s" output (substring-no-properties arg)))))
48+
(cider-repl--insert-startup-commands)
49+
(expect output :to-equal
50+
";; Startup: lein command\n")))
4351
(it "formats output if present"
4452
(let ((output "")
4553
(cider-saved-params '(:cljs-repl-type shadow :repl-init-form "(do)")))
4654
(spy-on 'insert-before-markers
4755
:and-call-fake (lambda (arg)
4856
(setq output (format "%s%s" output (substring-no-properties arg)))))
49-
(cider-repl--insert-param-values `((:cljs-repl-type "cljs repl type" ,#'symbol-name)
50-
(:repl-init-form "cljs repl startup command")))
57+
(cider-repl--insert-startup-commands)
5158
(expect output :to-equal
5259
";;
5360
;; cljs repl type: shadow
@@ -79,7 +86,6 @@
7986
;; Javadoc: (javadoc java-object-or-class)
8087
;; Exit: <C-c C-q>
8188
;; Results: Stored in vars *1, *2, *3, an exception in *e;
82-
;; Startup: startup command
8389
")))
8490

8591
(describe "when the cider package version information is not available"
@@ -95,7 +101,6 @@
95101
;; Javadoc: (javadoc java-object-or-class)
96102
;; Exit: <C-c C-q>
97103
;; Results: Stored in vars *1, *2, *3, an exception in *e;
98-
;; Startup: startup command
99104
"))))
100105

101106
(defvar cider-testing-ansi-colors-vector

0 commit comments

Comments
 (0)