Skip to content

Commit 27ed547

Browse files
authored
Introduce cider-shorten-error-overlays customization option (#3531)
Fixes #3525
1 parent ac38d36 commit 27ed547

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [#3522](https://github.com/clojure-emacs/cider/issues/3522): Introduce a new possible value for [`cider-use-overlays`](https://docs.cider.mx/cider/usage/code_evaluation.html#overlays): `errors-only`.
1111
- If specified, only errors will result in an overlay being shown.
1212
- [#3527](https://github.com/clojure-emacs/cider/issues/3527): Preserve the font size as one navigates through the CIDER inspector.
13+
- [#3525](https://github.com/clojure-emacs/cider/issues/3525): Introduce [`cider-inline-error-message-function`](https://docs.cider.mx/cider/usage/code_evaluation.html#overlays) customization option.
1314

1415
## 1.8.2 (2023-10-15)
1516

cider-eval.el

+21-6
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,26 @@ REPL buffer. This is controlled via
821821
conn)))
822822
(nrepl-dict-get result "phase"))))))
823823

824+
(defcustom cider-inline-error-message-function #'cider--shorten-error-message
825+
"A function that will shorten a given error message,
826+
as shown in overlays / the minibuffer (per `cider-use-overlays').
827+
828+
The function takes a single arg. You may want to use `identity',
829+
for leaving the message as-is."
830+
:type 'boolean
831+
:group 'cider
832+
:package-version '(cider . "1.19.0"))
833+
834+
(defun cider--shorten-error-message (err)
835+
"Removes from ERR the prefix matched by `cider-clojure-compilation-regexp',
836+
and the suffix matched by `cider-module-info-regexp'."
837+
(thread-last err
838+
(replace-regexp-in-string cider-clojure-compilation-regexp
839+
"")
840+
(replace-regexp-in-string cider-module-info-regexp
841+
"")
842+
(string-trim)))
843+
824844
(declare-function cider-inspect-last-result "cider-inspector")
825845
(defun cider-interactive-eval-handler (&optional buffer place)
826846
"Make an interactive eval handler for BUFFER.
@@ -856,12 +876,7 @@ when `cider-auto-inspect-after-eval' is non-nil."
856876
(member phase cider-clojure-compilation-error-phases)))
857877
;; Display errors as temporary overlays
858878
(let ((cider-result-use-clojure-font-lock nil)
859-
(trimmed-err (thread-last err
860-
(replace-regexp-in-string cider-clojure-compilation-regexp
861-
"")
862-
(replace-regexp-in-string cider-module-info-regexp
863-
"")
864-
(string-trim))))
879+
(trimmed-err (funcall cider-inline-error-message-function err)))
865880
(cider--display-interactive-eval-result
866881
trimmed-err
867882
'error

doc/modules/ROOT/pages/usage/code_evaluation.adoc

+11-2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ bottom) with the `cider-use-overlays` variable:
207207
(setq cider-use-overlays nil)
208208
----
209209

210+
Overlays that indicate errors are by default trimmed of file/line/phase information.
211+
212+
(Example: the entire `Syntax error compiling at (src/ns.clj:227:3).` preamble)
213+
214+
You can prevent any trimming by customizing instead:
215+
216+
[source,lisp]
217+
----
218+
(setq cider-inline-error-message-function #'identity)
219+
----
220+
210221
By default, result overlays are displayed at the end of the line. You can set
211222
the variable `cider-result-overlay-position` to display results at the end of
212223
their respective forms instead.
@@ -217,7 +228,6 @@ Note that this also affects the position of debugger overlays.
217228
(setq cider-result-overlay-position 'at-point)
218229
----
219230

220-
221231
You can also customize how overlays are persisted using the variable
222232
`cider-eval-result-duration`.
223233

@@ -228,7 +238,6 @@ Setting the variable to a number represents the duration in seconds until
228238
overlays are removed, while setting it to `'change' persists overlays until the
229239
next change to the buffer contents.
230240

231-
232241
[source,lisp]
233242
----
234243
(setq cider-eval-result-duration 5.0)

0 commit comments

Comments
 (0)