Skip to content

Commit

Permalink
[Fix #1197] Display some indication that we're waiting for a result f…
Browse files Browse the repository at this point in the history
…or long-running evaluations
  • Loading branch information
Anatoly Smolyaninov committed Aug 15, 2015
1 parent cfbe137 commit d19ad85
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
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

* [#1197](https://github.com/clojure-emacs/cider/issues/1197): Display some indication that we're waiting for a result for long-running evaluations.
* [#1127](https://github.com/clojure-emacs/cider/issues/1127): Make it possible to associate a buffer with a connection (via `cider-assoc-buffer-with-connection`).
* [#1217](https://github.com/clojure-emacs/cider/issues/1217): Add new command `cider-assoc-project-with-connection` to associate a project directory with a connection.
* [#1248](https://github.com/clojure-emacs/cider/pull/1248): Add <kbd>TAB</kbd> and <kbd>RET</kbd> keys to the test-report buffer.
Expand Down
43 changes: 42 additions & 1 deletion cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,27 @@ namespace-qualified function of zero arity."
:group 'cider
:package-version '(cider . "0.7.0"))

(defcustom cider-eval-spinner-type 'progress-bar
"Appearance of the evaluation spinner.
Value is a symbol. The possible values are the symbols in the
`spinner-types' variable."
:type 'symbol
:group 'cider
:package-version '(cider . "0.10.0"))

(defcustom cider-show-eval-spinner t
"When true, show the evaluation spinner in the mode line."
:type 'boolean
:group 'cider
:package-version '(cider . "0.10.0"))

(defcustom cider-eval-spinner-delay 1
"Amount of time, in seconds, after which the evaluation spinner will be shown."
:type 'integer
:group 'cider
:package-version '(cider . "0.10.0"))

(defface cider-error-highlight-face
'((((supports :underline (:style wave)))
(:underline (:style wave :color "red") :inherit unspecified))
Expand Down Expand Up @@ -1728,6 +1749,19 @@ Clears any compilation highlights and kills the error window."
(defvar-local cider-interactive-eval-override nil
"Function to call instead of `cider-interactive-eval'.")

(defun cider-eval-spinner-handler (eval-buffer original-callback)
"Return a response handler that stops the spinner and calls ORIGINAL-CALLBACK.
EVAL-BUFFER is the buffer where the spinner was started."
(lambda (response)
;; buffer still exists and
;; we've got status "done" from nrepl
;; stop the spinner
(when (and (buffer-live-p eval-buffer)
(member "done" (nrepl-dict-get response "status")))
(with-current-buffer eval-buffer
(spinner-stop)))
(funcall original-callback response)))

(defun cider-interactive-eval (form &optional callback bounds)
"Evaluate FORM and dispatch the response to CALLBACK.
This function is the main entry point in CIDER's interactive evaluation
Expand All @@ -1745,9 +1779,16 @@ arguments and only proceed with evaluation if it returns nil."
(functionp cider-interactive-eval-override)
(funcall cider-interactive-eval-override form callback bounds))
(cider--prep-interactive-eval form)
(when cider-show-eval-spinner
(spinner-start cider-eval-spinner-type nil
cider-eval-spinner-delay))
(nrepl-request:eval
form
(or callback (cider-interactive-eval-handler nil end))
(if cider-eval-progress-bar-show
(cider-eval-spinner-handler
(current-buffer)
(or callback (cider-interactive-eval-handler nil end)))
(or callback (cider-interactive-eval-handler nil end)))
;; always eval ns forms in the user namespace
;; otherwise trying to eval ns form for the first time will produce an error
(if (cider-ns-form-p form) "user" (cider-current-ns))
Expand Down
11 changes: 9 additions & 2 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -586,17 +586,24 @@ If NEWLINE is true then add a newline at the end of the input."
(goto-char (point-max))
(cider-repl--mark-input-start)
(cider-repl--mark-output-start)
(when cider-show-eval-spinner
(spinner-start cider-eval-spinner-type nil
cider-eval-spinner-delay))
(if (and (not (string-match-p "\\`[ \t\r\n]*\\'" input))
cider-repl-use-pretty-printing)
(nrepl-request:pprint-eval
input
(cider-repl-handler (current-buffer))
(cider-eval-spinner-handler
(current-buffer)
(cider-repl-handler (current-buffer)))
(cider-current-ns)
nil
(1- (window-width)))
(nrepl-request:eval
input
(cider-repl-handler (current-buffer))
(cider-eval-spinner-handler
(current-buffer)
(cider-repl-handler (current-buffer)))
(cider-current-ns)))))

(defun cider-repl-return (&optional end-of-input)
Expand Down
2 changes: 1 addition & 1 deletion cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
;; Maintainer: Bozhidar Batsov <[email protected]>
;; URL: http://www.github.com/clojure-emacs/cider
;; Version: 0.10.0-cvs
;; Package-Requires: ((clojure-mode "4.2.0") (dash "2.4.1") (pkg-info "0.4") (emacs "24.3") (queue "0.1.1"))
;; Package-Requires: ((clojure-mode "4.2.0") (dash "2.4.1") (pkg-info "0.4") (emacs "24.3") (queue "0.1.1") (spinner "1.4"))
;; Keywords: languages, clojure, cider

;; This program is free software: you can redistribute it and/or modify
Expand Down

0 comments on commit d19ad85

Please sign in to comment.