branch: elpa/cider
commit e76cf6f9cbea5e7d44b87dbd5a711a74acf25de9
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    Disable the source-buffer eval keybindings in the REPL
    
    `C-x C-e' and `C-c C-v' ran the source-buffer eval path in the REPL - which
    dragged source-only machinery (fringe indicators and the like) into it - 
for a
    use case that was niche to begin with.  `C-x C-e' was added back in 2014 
mainly
    so it wouldn't error, and its author already called it "an odd use case".
    
    Leave `C-c C-v' unbound and shadow `C-x C-e' with `undefined' so it's an
    explicit no-op rather than falling through to Emacs's Emacs Lisp
    `eval-last-sexp'.  Evaluate at the prompt instead.  Macroexpansion
    (`C-c C-m'/`C-c M-m') and inspection (`C-c M-i') stay bound, since acting 
on a
    form you see in the REPL is a real thing.
---
 lisp/cider-repl.el       |  7 ++++---
 test/cider-repl-tests.el | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/lisp/cider-repl.el b/lisp/cider-repl.el
index 5dddf4f8f2..1e47f4f5be 100644
--- a/lisp/cider-repl.el
+++ b/lisp/cider-repl.el
@@ -2259,7 +2259,6 @@ in an unexpected place."
 (defvar cider-repl-mode-syntax-table
   (copy-syntax-table clojure-mode-syntax-table))
 
-(declare-function cider-eval-last-sexp "cider-eval")
 (declare-function cider-toggle-trace-ns "cider-tracing")
 (declare-function cider-toggle-trace-var "cider-tracing")
 (declare-function cider-find-resource "cider-find")
@@ -2318,9 +2317,11 @@ in an unexpected place."
     (define-key map (kbd "C-c M-p") #'cider-history)
     (define-key map (kbd "C-c M-t") #'cider-trace-menu)
     (define-key map (kbd "C-c C-x") #'cider-start-menu)
-    (define-key map (kbd "C-x C-e") #'cider-eval-last-sexp)
     (define-key map (kbd "C-c C-r") 'clojure-refactor-map)
-    (define-key map (kbd "C-c C-v") #'cider-eval-menu)
+    ;; Shadow the global `eval-last-sexp' (Emacs Lisp) so `C-x C-e' is an
+    ;; explicit no-op in the REPL rather than evaluating the Clojure text as
+    ;; Emacs Lisp.  Evaluate at the prompt instead.
+    (define-key map (kbd "C-x C-e") #'undefined)
     ;; Deprecated REPL-only aliases; the canonical bindings live in the
     ;; `C-c C-x' start map, shared with `cider-mode'.
     ;; Soft-deprecated since the `C-c C-x' start map landed in 0.18.0; now
diff --git a/test/cider-repl-tests.el b/test/cider-repl-tests.el
index 366c3587c7..bfc4ce5c7a 100644
--- a/test/cider-repl-tests.el
+++ b/test/cider-repl-tests.el
@@ -780,3 +780,17 @@ PROPERTY should be a symbol of either 'text, 'ansi-context 
or
               "image/svg+xml" "text/html"))
     (dolist (entry cider-repl-content-type-handler-alist)
       (expect (functionp (cdr entry)) :to-be-truthy))))
+
+(describe "cider-repl-mode-map"
+  ;; The plain-eval commands were removed from the REPL keymap: they ran
+  ;; source-buffer eval machinery (fringe indicators and the like) in the REPL
+  ;; for a use case that was niche to begin with.
+  (it "does not bind the source-buffer eval commands"
+    ;; `C-x C-e' is shadowed with `undefined' so it doesn't fall through to the
+    ;; global Emacs Lisp `eval-last-sexp'; `C-c C-v' is simply left unbound.
+    (expect (lookup-key cider-repl-mode-map (kbd "C-x C-e")) :to-be 'undefined)
+    (expect (lookup-key cider-repl-mode-map (kbd "C-c C-v")) :to-be nil))
+
+  (it "keeps the macroexpand and inspect commands"
+    (expect (lookup-key cider-repl-mode-map (kbd "C-c C-m")) :to-be 
'cider-macroexpand-1)
+    (expect (lookup-key cider-repl-mode-map (kbd "C-c M-i")) :to-be 
'cider-inspect)))

Reply via email to