Skip to content

Commit 26ac312

Browse files
committed
Merge pull request #1046 from cichli/delay-error-buffer-creation
Delay creation of error buffer until the error can be rendered
2 parents 8814c41 + c5661d7 commit 26ac312

File tree

2 files changed

+69
-34
lines changed

2 files changed

+69
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ when in buffer that's not visiting a file (e.g. a REPL buffer).
7272
* Tunneled ssh connection now deals correctly with the ssh password request.
7373
* [#1026](https://github.com/clojure-emacs/cider/issues/1026): The full `(ns ...)` form for the current buffer is now sent with all source-tracking eval requests, to fix ClojureScript compatibility.
7474
* [#1033](https://github.com/clojure-emacs/cider/issues/1033): Removed erroneous underlining from stacktrace frames and disabled frame filters in the error buffer.
75+
* The error buffer no longer pops up when there is no error to display.
7576

7677
## 0.8.2 / 2014-12-21
7778

cider-interaction.el

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,21 +1124,68 @@ They exist for compatibility with `next-error'."
11241124
(goto-next-note-boundary))
11251125
(goto-next-note-boundary)))
11261126

1127-
(defun cider-default-err-eval-handler (buffer session)
1128-
"Display in BUFFER the last SESSION exception, without middleware support."
1129-
(nrepl-request:eval
1130-
"(clojure.stacktrace/print-cause-trace *e)"
1131-
(lambda (response)
1132-
(nrepl-dbind-response response (out)
1133-
(when out
1134-
(with-current-buffer buffer
1135-
(cider-emit-into-color-buffer buffer out)
1136-
(compilation-minor-mode +1)))))
1137-
nil
1138-
session))
1127+
(defun cider--show-error-buffer-p ()
1128+
"Return non-nil if the error buffer must be shown on error.
11391129
1140-
(defun cider-default-err-op-handler (buffer session)
1141-
"Display in BUFFER the last SESSION exception, with middleware support."
1130+
Takes into account both the value of `cider-show-error-buffer' and the
1131+
currently selected buffer."
1132+
(let* ((selected-buffer (window-buffer (selected-window)))
1133+
(replp (with-current-buffer selected-buffer (derived-mode-p 'cider-repl-mode))))
1134+
(memq cider-show-error-buffer
1135+
(if replp
1136+
'(t always only-in-repl)
1137+
'(t always except-in-repl)))))
1138+
1139+
(defun cider-new-error-buffer ()
1140+
"Return an empty error buffer, possibly displaying and/or selecting it.
1141+
1142+
When deciding whether to display the buffer, takes into account both the
1143+
value of `cider-show-error-buffer' and the currently selected buffer.
1144+
1145+
When deciding whether to select the buffer, takes into account the value of
1146+
`cider-auto-select-error-buffer'."
1147+
(if (cider--show-error-buffer-p)
1148+
(cider-popup-buffer cider-error-buffer cider-auto-select-error-buffer)
1149+
(cider-make-popup-buffer cider-error-buffer)))
1150+
1151+
(defun cider--handle-err-eval-response (response)
1152+
"Render eval RESPONSE into a new error buffer.
1153+
1154+
Uses the value of the `out' slot in RESPONSE."
1155+
(nrepl-dbind-response response (out)
1156+
(when out
1157+
(let ((error-buffer (cider-new-error-buffer)))
1158+
(cider-emit-into-color-buffer error-buffer out)
1159+
(with-current-buffer error-buffer
1160+
(compilation-minor-mode +1))))))
1161+
1162+
(defun cider-default-err-eval-handler (session)
1163+
"Display the last exception for SESSION, without middleware support."
1164+
(cider--handle-err-eval-response
1165+
(nrepl-sync-request:eval
1166+
"(clojure.stacktrace/print-cause-trace *e)"
1167+
nil
1168+
session)))
1169+
1170+
(defun cider--render-stacktrace-causes (causes)
1171+
"If CAUSES is non-nil, render its contents into a new error buffer."
1172+
(when causes
1173+
(let ((error-buffer (cider-new-error-buffer)))
1174+
(cider-stacktrace-render error-buffer (reverse causes)))))
1175+
1176+
(defun cider--handle-stacktrace-response (response causes)
1177+
"Handle stacktrace op RESPONSE, aggregating the result into CAUSES.
1178+
1179+
If RESPONSE contains a cause, cons it onto CAUSES and return that. If
1180+
RESPONSE is the final message (i.e. it contains a status), render CAUSES
1181+
into a new error buffer."
1182+
(nrepl-dbind-response response (class status)
1183+
(cond (class (cons response causes))
1184+
(status (cider--render-stacktrace-causes causes)))))
1185+
1186+
(defun cider-default-err-op-handler (session)
1187+
"Display the last exception for SESSION, with middleware support."
1188+
;; Causes are returned as a series of messages, which we aggregate in `causes'
11421189
(let (causes)
11431190
(nrepl-send-request
11441191
(append
@@ -1148,31 +1195,18 @@ They exist for compatibility with `next-error'."
11481195
(when cider-stacktrace-print-level
11491196
(list "print-level" cider-stacktrace-print-level)))
11501197
(lambda (response)
1151-
(nrepl-dbind-response response (class status)
1152-
(cond (class (setq causes (cons response causes)))
1153-
(status (when causes
1154-
(cider-stacktrace-render buffer (reverse causes))))))))))
1155-
1156-
(defun cider--show-error-buffer-p (buffer)
1157-
"Return non-nil if stacktrace buffer must be shown on error.
1158-
Takes into account the current BUFFER and the value of `cider-show-error-buffer'."
1159-
(let ((replp (with-current-buffer buffer (derived-mode-p 'cider-repl-mode))))
1160-
(memq cider-show-error-buffer
1161-
(if replp
1162-
'(t always only-in-repl)
1163-
'(t always except-in-repl)))))
1198+
;; While the return value of `cider--handle-stacktrace-response' is not
1199+
;; meaningful for the last message, we do not need the value of `causes'
1200+
;; after it has been handled, so it's fine to set it unconditionally here
1201+
(setq causes (cider--handle-stacktrace-response response causes))))))
11641202

11651203
(defun cider-default-err-handler (buffer ex root-ex session)
11661204
"Make an error handler for BUFFER, EX, ROOT-EX and SESSION.
11671205
This function determines how the error buffer is shown, and then delegates
11681206
the actual error content to the eval or op handler."
1169-
(let* ((error-buffer (if (cider--show-error-buffer-p buffer)
1170-
(cider-popup-buffer cider-error-buffer
1171-
cider-auto-select-error-buffer)
1172-
(cider-make-popup-buffer cider-error-buffer))))
1173-
(if (nrepl-op-supported-p "stacktrace")
1174-
(cider-default-err-op-handler error-buffer session)
1175-
(cider-default-err-eval-handler error-buffer session))))
1207+
(if (nrepl-op-supported-p "stacktrace")
1208+
(cider-default-err-op-handler session)
1209+
(cider-default-err-eval-handler session)))
11761210

11771211
(defvar cider-compilation-regexp
11781212
'("\\(?:.*\\(warning, \\)\\|.*?\\(, compiling\\):(\\)\\([^:]*\\):\\([[:digit:]]+\\)\\(?::\\([[:digit:]]+\\)\\)?\\(\\(?: - \\(.*\\)\\)\\|)\\)" 3 4 5 (1))

0 commit comments

Comments
 (0)