Skip to content

Commit

Permalink
Simplify insert-startup-commands call
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsutton committed Nov 28, 2019
1 parent 92da68c commit 1c63258
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
31 changes: 14 additions & 17 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ fully initialized."
((pred identity) (pop-to-buffer buffer)))
(with-current-buffer buffer
(cider-repl--insert-banner)
(cider-repl--insert-param-values `((:cljs-repl-type "cljs repl type" ,#'symbol-name)
(:repl-init-form "cljs repl startup command")))
(cider-repl--insert-startup-commands)
(when-let* ((window (get-buffer-window buffer t)))
(with-selected-window window
(recenter (- -1 scroll-margin))))
Expand All @@ -335,7 +334,7 @@ fully initialized."
(insert-before-markers
(propertize (cider-repl--help-banner) 'font-lock-face 'font-lock-comment-face))))

(defun cider-repl--insert-param-values (param-tuples)
(defun cider-repl--insert-startup-commands ()
"Insert the values from params specified in PARAM-TUPLES.
PARAM-TUPLES are tuples of (param-key description) or (param-key
description transform) where transform is called with the param-value if
Expand All @@ -347,18 +346,18 @@ present."
(propertize
(if (string-blank-p contents) ";;\n" (concat ";; " contents "\n"))
'font-lock-face 'font-lock-comment-face))))
(let ((present-values (thread-last param-tuples
(seq-map (lambda (tuple)
(cl-destructuring-bind (param-key desc &optional transform) tuple
(when-let ((value (plist-get cider-saved-params param-key)))
(list desc (funcall (or transform #'identity) value))))))
(seq-filter #'identity))))
(when present-values
(let ((jack-in-command (plist-get cider-saved-params :jack-in-cmd))
(cljs-repl-type (plist-get cider-saved-params :cljs-repl-type))
(cljs-init-form (plist-get cider-saved-params :repl-init-form)))
(when jack-in-command
;; spaces to align with the banner
(emit-comment (concat " Startup: " jack-in-command)))
(when (or cljs-repl-type cljs-init-form)
(emit-comment "")
(mapc (lambda (desc-and-value)
(cl-destructuring-bind (desc value) desc-and-value
(emit-comment (concat desc ": " value))))
present-values)
(when cljs-repl-type
(emit-comment (concat "cljs repl type: " (symbol-name cljs-repl-type))))
(when cljs-init-form
(emit-comment (concat "cljs repl startup command: " cljs-init-form)))
(emit-comment "")))))

(defun cider-repl--banner ()
Expand All @@ -372,15 +371,13 @@ present."
;; Javadoc: (javadoc java-object-or-class)
;; Exit: <C-c C-q>
;; Results: Stored in vars *1, *2, *3, an exception in *e;
;; Startup: %s
"
(plist-get nrepl-endpoint :host)
(plist-get nrepl-endpoint :port)
(cider--version)
(cider--nrepl-version)
(cider--clojure-version)
(cider--java-version)
(plist-get cider-saved-params :jack-in-cmd)))
(cider--java-version)))

(defun cider-repl--help-banner ()
"Generate the help banner."
Expand Down
17 changes: 11 additions & 6 deletions test/cider-repl-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,24 @@
(spy-on 'insert-before-markers
:and-call-fake (lambda (arg)
(setq output (format "%s%s" output (substring-no-properties arg)))))
(cider-repl--insert-param-values `((:cljs-repl-type "cljs repl type" ,#'symbol-name)
(:repl-init-form "cljs repl startup command")))
(cider-repl--insert-startup-commands)
(expect output :to-be "")))
(it "puts jack-in-command in same style as banner"
(let ((output "")
(cider-saved-params '(:jack-in-cmd "lein command")))
(spy-on 'insert-before-markers
:and-call-fake (lambda (arg)
(setq output (format "%s%s" output (substring-no-properties arg)))))
(cider-repl--insert-startup-commands)
(expect output :to-equal
";; Startup: lein command\n")))
(it "formats output if present"
(let ((output "")
(cider-saved-params '(:cljs-repl-type shadow :repl-init-form "(do)")))
(spy-on 'insert-before-markers
:and-call-fake (lambda (arg)
(setq output (format "%s%s" output (substring-no-properties arg)))))
(cider-repl--insert-param-values `((:cljs-repl-type "cljs repl type" ,#'symbol-name)
(:repl-init-form "cljs repl startup command")))
(cider-repl--insert-startup-commands)
(expect output :to-equal
";;
;; cljs repl type: shadow
Expand Down Expand Up @@ -79,7 +86,6 @@
;; Javadoc: (javadoc java-object-or-class)
;; Exit: <C-c C-q>
;; Results: Stored in vars *1, *2, *3, an exception in *e;
;; Startup: startup command
")))

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

(defvar cider-testing-ansi-colors-vector
Expand Down

0 comments on commit 1c63258

Please sign in to comment.