From 316564efbd15e5013eefbb2d2ccda955f1d5b533 Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Mon, 11 Oct 2021 10:00:58 +0200 Subject: [PATCH] Don't call `fundamental-mode` if we already are in `fundamental-mode` If the `" *nrepl-decoding*"` buffer already exists then it is likely already in the right mode. Not re-initializing the mode means we don't re-trigger hooks, which in this case in particular prevents an unfortunate interaction with evil-mode, where the cursor color gets updated even though it shouldn't. Fixes #3068 --- CHANGELOG.md | 1 + nrepl-client.el | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cec713e9..5cbb216b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * [#3044](https://github.com/clojure-emacs/cider/pull/3044): Dynamically upgrade nREPL connection * [#3047](https://github.com/clojure-emacs/cider/pull/3047): Fix info/lookup fallback: response has an extra level * [#2746](https://github.com/clojure-emacs/cider/issues/2746): Handle gracefully Clojure versions with non-standard qualifiers (e.g. `1.11.0-master-SNAPSHOT`). +* [#3069](https://github.com/clojure-emacs/cider/pull/3069): Fix cursor color changing when it shouldn't in evil-mode ## 1.1.1 (2021-05-24) diff --git a/nrepl-client.el b/nrepl-client.el index 20e1a2ee0..87691bdc4 100644 --- a/nrepl-client.el +++ b/nrepl-client.el @@ -362,6 +362,11 @@ STACK is as in `nrepl--bdecode-1'. Return a cons (INFO . STACK)." stack (cdr istack))) istack)) +(defun nrepl--ensure-fundamental-mode () + "Enable `fundamental-mode' if it is not enabled already." + (when (not (eq 'fundamental-mode major-mode)) + (fundamental-mode))) + (defun nrepl-bdecode (string-q &optional response-q) "Decode STRING-Q and place the results into RESPONSE-Q. STRING-Q is either a queue of strings or a string. RESPONSE-Q is a queue of @@ -374,7 +379,10 @@ decoded. RESPONSE-Q is the original queue with successfully decoded messages enqueued and with slot STUB containing a nested stack of an incompletely decoded message or nil if the strings were completely decoded." (with-current-buffer (get-buffer-create " *nrepl-decoding*") - (fundamental-mode) + ;; Don't needlessly call `fundamental-mode', to prevent needlessly firing + ;; hooks. This fixes an issue with evil-mode where the cursor loses its + ;; correct color. + (nrepl--ensure-fundamental-mode) (erase-buffer) (if (queue-p string-q) (while (queue-head string-q) @@ -1352,7 +1360,7 @@ The default buffer name is *nrepl-error*." (let ((buffer (get-buffer-create nrepl-error-buffer-name))) (with-current-buffer buffer (buffer-disable-undo) - (fundamental-mode) + (nrepl--ensure-fundamental-mode) buffer)))) (defun nrepl-log-error (msg)