@@ -1124,21 +1124,68 @@ They exist for compatibility with `next-error'."
1124
1124
(goto-next-note-boundary))
1125
1125
(goto-next-note-boundary)))
1126
1126
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.
1139
1129
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'
1142
1189
(let (causes)
1143
1190
(nrepl-send-request
1144
1191
(append
@@ -1148,31 +1195,18 @@ They exist for compatibility with `next-error'."
1148
1195
(when cider-stacktrace-print-level
1149
1196
(list " print-level" cider-stacktrace-print-level)))
1150
1197
(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))))))
1164
1202
1165
1203
(defun cider-default-err-handler (buffer ex root-ex session )
1166
1204
" Make an error handler for BUFFER, EX, ROOT-EX and SESSION.
1167
1205
This function determines how the error buffer is shown, and then delegates
1168
1206
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)))
1176
1210
1177
1211
(defvar cider-compilation-regexp
1178
1212
'(" \\ (?:.*\\ (warning, \\ )\\ |.*?\\ (, compiling\\ ):(\\ )\\ ([^:]*\\ ):\\ ([[:digit:]]+\\ )\\ (?::\\ ([[:digit:]]+\\ )\\ )?\\ (\\ (?: - \\ (.*\\ )\\ )\\ |)\\ )" 3 4 5 (1 ))
0 commit comments