branch: elpa/cider
commit 9994081a86cbbc2c7e7457f81a71359bc36114f4
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[Fix #4089] Let cider-macroexpand-undo work in the read-only buffer
`cider-macroexpand-undo' bound `inhibit-read-only' around the undo, but its
`(interactive "*P")' spec has a leading `*' that signals `buffer-read-only'
before the body runs - so undo failed in the (read-only) macroexpansion
buffer unless read-only mode was toggled off first. Drop the `*'; the
`inhibit-read-only' binding already handles the mutation.
---
lisp/cider-macroexpansion.el | 5 ++++-
test/cider-macroexpansion-tests.el | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/lisp/cider-macroexpansion.el b/lisp/cider-macroexpansion.el
index f93e015b2c..db0df93651 100644
--- a/lisp/cider-macroexpansion.el
+++ b/lisp/cider-macroexpansion.el
@@ -92,7 +92,10 @@ The default for DISPLAY-NAMESPACES is taken from
(defun cider-macroexpand-undo (&optional arg)
"Undo the last macroexpansion, using `undo-only'.
ARG is passed along to `undo-only'."
- (interactive "*P")
+ ;; No `*' in the spec: the macroexpansion buffer is read-only, and a leading
+ ;; `*' would signal `buffer-read-only' before the body could bind
+ ;; `inhibit-read-only' around the undo (clojure-emacs/cider#4089).
+ (interactive "P")
(let ((inhibit-read-only t))
(undo-only arg)))
diff --git a/test/cider-macroexpansion-tests.el
b/test/cider-macroexpansion-tests.el
index 04e02b1f7a..1a8a964c2a 100644
--- a/test/cider-macroexpansion-tests.el
+++ b/test/cider-macroexpansion-tests.el
@@ -168,6 +168,23 @@
cider-macroexpansion-print-metadata))))
(expect captured :to-equal '(tidy nil)))))
+(describe "cider-macroexpand-undo"
+ ;; Regression: the command used `(interactive "*P")', whose leading `*'
+ ;; signals `buffer-read-only' before the body can bind `inhibit-read-only',
+ ;; so undo failed in the read-only macroexpansion buffer (#4089).
+ (it "undoes in a read-only buffer without a `buffer-read-only' error"
+ (with-temp-buffer
+ (buffer-enable-undo)
+ (insert "(foo)")
+ (undo-boundary)
+ (let ((inhibit-read-only t)) (insert " (bar)"))
+ (setq buffer-read-only t)
+ ;; Invoked interactively, so the `*' check would fire if it were present.
+ (expect (call-interactively #'cider-macroexpand-undo)
+ :not :to-throw 'buffer-read-only)
+ ;; The undo actually took effect (the last change is gone).
+ (expect (buffer-string) :not :to-match "bar"))))
+
(provide 'cider-macroexpansion-tests)
;;; cider-macroexpansion-tests.el ends here