From 27ed54709944cf11e4050ba944855fcacdb2ed83 Mon Sep 17 00:00:00 2001 From: vemv Date: Tue, 17 Oct 2023 12:38:16 +0200 Subject: [PATCH] Introduce `cider-shorten-error-overlays` customization option (#3531) Fixes #3525 --- CHANGELOG.md | 1 + cider-eval.el | 27 ++++++++++++++----- .../ROOT/pages/usage/code_evaluation.adoc | 13 +++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9692c9f..c986919fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cider-eval.el b/cider-eval.el index 33fc97b60..73d914c55 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -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. @@ -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 diff --git a/doc/modules/ROOT/pages/usage/code_evaluation.adoc b/doc/modules/ROOT/pages/usage/code_evaluation.adoc index 612530b1b..ebc7cea0c 100644 --- a/doc/modules/ROOT/pages/usage/code_evaluation.adoc +++ b/doc/modules/ROOT/pages/usage/code_evaluation.adoc @@ -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. @@ -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`. @@ -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)