Skip to content

Commit f556d30

Browse files
authored
Add option to remove result overlays after buffer change (clojure-emacs#3149)
1 parent f3309c3 commit f556d30

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [#3127](https://github.com/clojure-emacs/cider/pull/3040): Strip all exec-opts flags (`-A` `-M` `-T` `-X`) if they exist in `cider-clojure-cli-aliases`. Also addresses a duplicate `:` in the generated `clj` command.
88
* Enable `cider-enrich-classpath` by default.
99
* [#3148](https://github.com/clojure-emacs/cider/pull/3148): Display error messages in multiline comment eval results, and in result overlays when `cider-show-error-buffer` is set to nil.
10+
* [#3149](https://github.com/clojure-emacs/cider/pull/3149): Add option `'change` to `cider-eval-result-duration`, allowing multiple eval result overlays to persist until the next change to the buffer.
1011

1112
### Bugs fixed
1213

Diff for: cider-eval.el

+5-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,11 @@ arguments and only proceed with evaluation if it returns nil."
902902
(start (car-safe bounds))
903903
(end (car-safe (cdr-safe bounds))))
904904
(when (and start end)
905-
(remove-overlays start end 'cider-temporary t))
905+
;; NOTE: don't use `remove-overlays' as it splits and leaves behind
906+
;; partial overlays, leading to duplicate eval results in some situations.
907+
(dolist (ov (overlays-in start end))
908+
(when (eq (overlay-get ov 'cider-temporary) t)
909+
(delete-overlay ov))))
906910
(unless (and cider-interactive-eval-override
907911
(functionp cider-interactive-eval-override)
908912
(funcall cider-interactive-eval-override form callback bounds))

Diff for: cider-overlays.el

+18-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ applied with lower priority than the syntax highlighting."
4444

4545
(defface cider-error-overlay-face
4646
'((((class color) (background light))
47-
:background "orange red")
47+
:background "orange red"
48+
:extend t)
4849
(((class color) (background dark))
49-
:background "firebrick"))
50+
:background "firebrick"
51+
:extend t))
5052
"Like `cider-result-overlay-face', but for evaluation errors."
5153
:group 'cider
5254
:package-version '(cider "0.25.0"))
@@ -98,9 +100,11 @@ If 'at-point, display at the end of the respective sexp."
98100
"Duration, in seconds, of CIDER's eval-result overlays.
99101
If nil, overlays last indefinitely.
100102
If the symbol `command', they're erased after the next command.
103+
If the symbol `change', they last until the next change to the buffer.
101104
Also see `cider-use-overlays'."
102105
:type '(choice (integer :tag "Duration in seconds")
103106
(const :tag "Until next command" command)
107+
(const :tag "Until next buffer change" change)
104108
(const :tag "Last indefinitely" nil))
105109
:group 'cider
106110
:package-version '(cider . "0.10.0"))
@@ -125,10 +129,14 @@ PROPS is a plist of properties and values to add to the overlay."
125129
(push #'cider--delete-overlay (overlay-get o 'modification-hooks))
126130
o))
127131

128-
(defun cider--remove-result-overlay ()
132+
(defun cider--remove-result-overlay (&rest _)
129133
"Remove result overlay from current buffer.
130-
This function also removes itself from `post-command-hook'."
131-
(remove-hook 'post-command-hook #'cider--remove-result-overlay 'local)
134+
This function also removes itself from `post-command-hook' and
135+
`after-change-functions'."
136+
(let ((hook (pcase cider-eval-result-duration
137+
(`command 'post-command-hook)
138+
(`change 'after-change-functions))))
139+
(remove-hook hook #'cider--remove-result-overlay 'local))
132140
(remove-overlays nil nil 'category 'result))
133141

134142
(defun cider--remove-result-overlay-after-command ()
@@ -258,7 +266,11 @@ overlay."
258266
(add-hook 'post-command-hook
259267
#'cider--remove-result-overlay-after-command
260268
nil 'local)
261-
(cider--remove-result-overlay-after-command))))
269+
(cider--remove-result-overlay-after-command)))
270+
(`change
271+
(add-hook 'after-change-functions
272+
#'cider--remove-result-overlay
273+
nil 'local)))
262274
(when-let* ((win (get-buffer-window buffer)))
263275
;; Left edge is visible.
264276
(when (and (<= (window-start win) (point) (window-end win))

Diff for: doc/modules/ROOT/pages/usage/code_evaluation.adoc

+18
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@ Note that this also affects the position of debugger overlays.
207207
(setq cider-result-overlay-position 'at-point)
208208
----
209209

210+
211+
You can also customize how overlays are persisted using the variable
212+
`cider-eval-result-duration`.
213+
214+
By default, its value is `'command`, meaning that result overlays disappear
215+
after the next user-executed command, such as moving the point or scrolling.
216+
217+
Setting the variable to a number represents the duration in seconds until
218+
overlays are removed, while setting it to `'change' persists overlays until the
219+
next change to the buffer contents.
220+
221+
222+
[source,lisp]
223+
----
224+
(setq cider-eval-result-duration 5.0)
225+
(setq cider-eval-result-duration 'change)
226+
----
227+
210228
=== Auto-Save Clojure Buffers on Load
211229

212230
Normally, CIDER prompts you to save a modified Clojure buffer when you

0 commit comments

Comments
 (0)