Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#2744](https://github.com/clojure-emacs/cider/pull/2744): Add startup commands to repl banner.
* [#2499](https://github.com/clojure-emacs/cider/issues/2499): Add `cider-jump-to-pop-to-buffer-actions`.
* [#2738](https://github.com/clojure-emacs/cider/pull/2738): Add ability to lookup a function symbol when cursor is at the opening paren.
* [#2735](https://github.com/clojure-emacs/cider/pull/2735): New debugger command `P` to inspect an arbitrary expression, it was previously bound to `p` which now inspects the current value.
Expand Down
4 changes: 3 additions & 1 deletion cider-connection.el
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ PARAMS is a plist as received by `cider-repl-create'."
(declare-function cider-repl-reset-markers "cider-repl")
(defvar-local cider-session-name nil)
(defvar-local cider-repl-init-function nil)
(defvar-local cider-launch-params nil)
(defun cider-repl-create (params)
"Create new repl buffer.
PARAMS is a plist which contains :repl-type, :host, :port, :project-dir,
Expand Down Expand Up @@ -727,7 +728,8 @@ function with the repl buffer set as current."
;; REPLs start with clj and then "upgrade" to a different type
cider-repl-type (plist-get params :repl-type)
;; ran at the end of cider--connected-handler
cider-repl-init-function (plist-get params :repl-init-function))
cider-repl-init-function (plist-get params :repl-init-function)
cider-launch-params params)
(cider-repl-reset-markers)
(add-hook 'nrepl-response-handler-functions #'cider-repl--state-handler nil 'local)
(add-hook 'nrepl-connected-hook #'cider--connected-handler nil 'local)
Expand Down
27 changes: 27 additions & 0 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ fully initialized."
((pred identity) (pop-to-buffer buffer)))
(with-current-buffer buffer
(cider-repl--insert-banner)
(cider-repl--insert-startup-commands)
(when-let* ((window (get-buffer-window buffer t)))
(with-selected-window window
(recenter (- -1 scroll-margin))))
Expand All @@ -333,6 +334,32 @@ fully initialized."
(insert-before-markers
(propertize (cider-repl--help-banner) 'font-lock-face 'font-lock-comment-face))))

(defun cider-repl--insert-startup-commands ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought a bit more about this and I'd prefer to split this in two - the jack-in command that gets displayed in the REPL banner if present and the ClojureScript details which can be placed/displayed as you've suggested. I just feel that the jack-in command is more fundamental than the ClojureScript form, that's why it should be listed more prominently. Potentially we can add there some info about the build system down the road - e.g. Leiningen 2.9, etc.

"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
present."
(cl-labels
((emit-comment
(contents)
(insert-before-markers
(propertize
(if (string-blank-p contents) ";;\n" (concat ";; " contents "\n"))
'font-lock-face 'font-lock-comment-face))))
(let ((jack-in-command (plist-get cider-launch-params :jack-in-cmd))
(cljs-repl-type (plist-get cider-launch-params :cljs-repl-type))
(cljs-init-form (plist-get cider-launch-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 "")
(when cljs-repl-type
(emit-comment (concat "ClojureScript REPL type: " (symbol-name cljs-repl-type))))
(when cljs-init-form
(emit-comment (concat "ClojureScript REPL init form: " cljs-init-form)))
(emit-comment "")))))

(defun cider-repl--banner ()
"Generate the welcome REPL buffer banner."
(format ";; Connected to nREPL server - nrepl://%s:%s
Expand Down
31 changes: 17 additions & 14 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -1283,20 +1283,23 @@ non-nil, don't start if ClojureScript requirements are not met."
"Update PARAMS :repl-init-function for cljs connections."
(with-current-buffer (or (plist-get params :--context-buffer)
(current-buffer))
(let ((cljs-type (plist-get params :cljs-repl-type)))
(plist-put params :repl-init-function
(lambda ()
(cider--check-cljs cljs-type)
;; FIXME: ideally this should be done in the state handler
(setq-local cider-cljs-repl-type cljs-type)
(cider-nrepl-send-request
(list "op" "eval"
"ns" (cider-current-ns)
"code" (cider-cljs-repl-form cljs-type))
(cider-repl-handler (current-buffer)))
(when (and (buffer-live-p nrepl-server-buffer)
cider-offer-to-open-cljs-app-in-browser)
(cider--offer-to-open-app-in-browser nrepl-server-buffer)))))))
(let* ((cljs-type (plist-get params :cljs-repl-type))
(repl-init-form (cider-cljs-repl-form cljs-type)))
(thread-first params
(plist-put :repl-init-function
(lambda ()
(cider--check-cljs cljs-type)
;; FIXME: ideally this should be done in the state handler
(setq-local cider-cljs-repl-type cljs-type)
(cider-nrepl-send-request
(list "op" "eval"
"ns" (cider-current-ns)
"code" repl-init-form)
(cider-repl-handler (current-buffer)))
(when (and (buffer-live-p nrepl-server-buffer)
cider-offer-to-open-cljs-app-in-browser)
(cider--offer-to-open-app-in-browser nrepl-server-buffer))))
(plist-put :repl-init-form repl-init-form)))))

(defun cider--check-existing-session (params)
"Ask for confirmation if a session with similar PARAMS already exists.
Expand Down
32 changes: 32 additions & 0 deletions test/cider-repl-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@
(require 'buttercup)
(require 'cider-repl)

(describe "cider-repl--insert-param-values"
(it "doesn't output anything when the params aren't present"
(let ((output "")
(cider-launch-params '()))
(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-be "")))
(it "puts jack-in-command in same style as banner"
(let ((output "")
(cider-launch-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-launch-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-startup-commands)
(expect output :to-equal
";;
;; ClojureScript REPL type: shadow
;; ClojureScript REPL init form: (do)
;;
"))))

(describe "cider-repl--banner"
:var (cider-version cider-codename)
(before-all
Expand Down