branch: elpa/cider
commit 412ed1086c0a012c2e7769cf95d2911c1f4cbc71
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Don't place eval fringe indicators in the REPL
`cider-eval-last-sexp' is bound to `C-x C-e' in the REPL, so evaluating
there
went through the interactive-eval handler and left a fringe indicator in the
REPL buffer. Those indicators track a source form's load/eval state, which
is
meaningless in the REPL. Guard `cider--make-fringe-overlay' - the single
point
where every eval fringe overlay is created - to Clojure source buffers, the
same guard the namespace load-state indicators already use.
---
lisp/cider-overlays.el | 43 ++++++++++++++++++++++++-------------------
test/cider-overlay-tests.el | 27 +++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 19 deletions(-)
diff --git a/lisp/cider-overlays.el b/lisp/cider-overlays.el
index 150094fe90..70db631641 100644
--- a/lisp/cider-overlays.el
+++ b/lisp/cider-overlays.el
@@ -255,25 +255,30 @@ END is the position where the sexp ends, and defaults to
point."
(with-current-buffer (if (markerp end)
(marker-buffer end)
(current-buffer))
- (save-excursion
- (if end
- (goto-char end)
- (setq end (point)))
- (clojure-forward-logical-sexp -1)
- ;; Drop any prior indicator on this form (e.g. a stale one) so a
- ;; re-evaluation replaces it with a fresh in-sync indicator.
- (remove-overlays (point) end 'category 'cider-fringe-indicator)
- ;; Create the green-circle overlay.
- (let ((ov (cider--make-overlay (point) end 'cider-fringe-indicator
- 'before-string
cider--fringe-overlay-good)))
- (when cider-mark-stale-after-edit
- ;; `cider--make-overlay' installs a delete-on-edit hook; swap just
- ;; that one out for mark-stale, leaving any other hooks intact.
- (overlay-put ov 'modification-hooks
- (cons #'cider--fringe-overlay-mark-stale
- (remq #'cider--delete-overlay
- (overlay-get ov 'modification-hooks)))))
- ov)))))
+ ;; The fringe indicators track a source form's load/eval state, which is
+ ;; meaningless in the REPL (and other non-source buffers), so only place
+ ;; them in Clojure source buffers. `cider-eval-last-sexp' is bound in
the
+ ;; REPL, so without this guard `C-x C-e' there would leave a marker.
+ (when (derived-mode-p 'clojure-mode 'clojure-ts-mode)
+ (save-excursion
+ (if end
+ (goto-char end)
+ (setq end (point)))
+ (clojure-forward-logical-sexp -1)
+ ;; Drop any prior indicator on this form (e.g. a stale one) so a
+ ;; re-evaluation replaces it with a fresh in-sync indicator.
+ (remove-overlays (point) end 'category 'cider-fringe-indicator)
+ ;; Create the green-circle overlay.
+ (let ((ov (cider--make-overlay (point) end 'cider-fringe-indicator
+ 'before-string
cider--fringe-overlay-good)))
+ (when cider-mark-stale-after-edit
+ ;; `cider--make-overlay' installs a delete-on-edit hook; swap
just
+ ;; that one out for mark-stale, leaving any other hooks intact.
+ (overlay-put ov 'modification-hooks
+ (cons #'cider--fringe-overlay-mark-stale
+ (remq #'cider--delete-overlay
+ (overlay-get ov 'modification-hooks)))))
+ ov))))))
(cl-defun cider--make-result-overlay (value &rest props &key where duration
(type 'result)
(format (concat " "
cider-eval-result-prefix "%s "))
diff --git a/test/cider-overlay-tests.el b/test/cider-overlay-tests.el
index 3c59f96a9b..6f35e47f67 100644
--- a/test/cider-overlay-tests.el
+++ b/test/cider-overlay-tests.el
@@ -22,6 +22,8 @@
(require 'cl-lib)
(require 'cider-overlays)
+(require 'clojure-mode)
+(require 'cider-repl)
;; Please, for each `describe', ensure there's an `it' block, so that its
execution is visible in CI.
@@ -238,6 +240,31 @@ being set that way"
(expect (cider--use-fringe-indicators-p 'eval) :to-be-truthy)
(expect (cider--use-fringe-indicators-p 'test) :to-be-truthy))))
+(describe "cider--make-fringe-overlay"
+ (it "places an eval indicator in a Clojure source buffer"
+ (with-temp-buffer
+ (clojure-mode)
+ (insert "(+ 1 2)")
+ (let ((cider-fringe-indicators t))
+ (cider--make-fringe-overlay (point)))
+ (expect (seq-filter (lambda (o) (eq (overlay-get o 'category)
'cider-fringe-indicator))
+ (overlays-in (point-min) (point-max)))
+ :not :to-be nil)))
+
+ ;; Regression: `cider-eval-last-sexp' is bound to `C-x C-e' in the REPL, and
+ ;; the fringe indicators track source-form state, so they must not appear
+ ;; there. `cider-repl-mode' is `fundamental-mode'-derived, so the
+ ;; source-buffer guard excludes it.
+ (it "does not place an indicator in the REPL buffer"
+ (with-temp-buffer
+ (setq major-mode 'cider-repl-mode)
+ (insert "(+ 1 2)")
+ (let ((cider-fringe-indicators t))
+ (cider--make-fringe-overlay (point)))
+ (expect (seq-filter (lambda (o) (eq (overlay-get o 'category)
'cider-fringe-indicator))
+ (overlays-in (point-min) (point-max)))
+ :to-be nil))))
+
(describe "cider--eval-result-display"
(it "passes the canonical values through unchanged"
(dolist (mode '(overlay echo both errors-only))