Skip to content

Commit

Permalink
Introduce cider-shorten-error-overlays customization option (#3531)
Browse files Browse the repository at this point in the history
Fixes #3525
  • Loading branch information
vemv authored Oct 17, 2023
1 parent ac38d36 commit 27ed547
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [#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`.
- If specified, only errors will result in an overlay being shown.
- [#3527](https://github.com/clojure-emacs/cider/issues/3527): Preserve the font size as one navigates through the CIDER inspector.
- [#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.

## 1.8.2 (2023-10-15)

Expand Down
27 changes: 21 additions & 6 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,26 @@ REPL buffer. This is controlled via
conn)))
(nrepl-dict-get result "phase"))))))

(defcustom cider-inline-error-message-function #'cider--shorten-error-message
"A function that will shorten a given error message,
as shown in overlays / the minibuffer (per `cider-use-overlays').
The function takes a single arg. You may want to use `identity',
for leaving the message as-is."
:type 'boolean
:group 'cider
:package-version '(cider . "1.19.0"))

(defun cider--shorten-error-message (err)
"Removes from ERR the prefix matched by `cider-clojure-compilation-regexp',
and the suffix matched by `cider-module-info-regexp'."
(thread-last err
(replace-regexp-in-string cider-clojure-compilation-regexp
"")
(replace-regexp-in-string cider-module-info-regexp
"")
(string-trim)))

(declare-function cider-inspect-last-result "cider-inspector")
(defun cider-interactive-eval-handler (&optional buffer place)
"Make an interactive eval handler for BUFFER.
Expand Down Expand Up @@ -856,12 +876,7 @@ when `cider-auto-inspect-after-eval' is non-nil."
(member phase cider-clojure-compilation-error-phases)))
;; Display errors as temporary overlays
(let ((cider-result-use-clojure-font-lock nil)
(trimmed-err (thread-last err
(replace-regexp-in-string cider-clojure-compilation-regexp
"")
(replace-regexp-in-string cider-module-info-regexp
"")
(string-trim))))
(trimmed-err (funcall cider-inline-error-message-function err)))
(cider--display-interactive-eval-result
trimmed-err
'error
Expand Down
13 changes: 11 additions & 2 deletions doc/modules/ROOT/pages/usage/code_evaluation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ bottom) with the `cider-use-overlays` variable:
(setq cider-use-overlays nil)
----

Overlays that indicate errors are by default trimmed of file/line/phase information.

(Example: the entire `Syntax error compiling at (src/ns.clj:227:3).` preamble)

You can prevent any trimming by customizing instead:

[source,lisp]
----
(setq cider-inline-error-message-function #'identity)
----

By default, result overlays are displayed at the end of the line. You can set
the variable `cider-result-overlay-position` to display results at the end of
their respective forms instead.
Expand All @@ -217,7 +228,6 @@ Note that this also affects the position of debugger overlays.
(setq cider-result-overlay-position 'at-point)
----


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

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


[source,lisp]
----
(setq cider-eval-result-duration 5.0)
Expand Down

0 comments on commit 27ed547

Please sign in to comment.