branch: elpa/cider
commit eedbab26684cb1ce01a940b5b0da9ff78aeb4eac
Author: vemv <v...@users.noreply.github.com>
Commit: GitHub <nore...@github.com>

    `cider-eval`: never jump to spurious locations (#3382)
    
    Fixes #3331
---
 CHANGELOG.md  |  1 +
 cider-eval.el | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 098f033356..292131ae97 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
 - [#3362](https://github.com/clojure-emacs/cider/issues/3362): Fix 
`sesman-restart` regression issue.
 - [#3236](https://github.com/clojure-emacs/cider/issues/3236): 
`cider-repl-set-ns` no longer changes the repl session type from `cljs:shadow` 
to `clj`.
 - [#3383](https://github.com/clojure-emacs/cider/issues/3383): 
`cider-connect-clj&cljs`: don't render `"ClojureScript REPL type:" for JVM 
repls. 
+- [#3331](https://github.com/clojure-emacs/cider/issues/3331): `cider-eval`: 
never jump to spurious locations, as sometimes conveyed by nREPL.  
 
 ### Changes
 
diff --git a/cider-eval.el b/cider-eval.el
index 110505bd88..c5ac0c7c1f 100644
--- a/cider-eval.el
+++ b/cider-eval.el
@@ -626,11 +626,18 @@ If location could not be found, return nil."
                     (goto-char (point-min))
                     (forward-line (1- line))
                     (move-to-column (or col 0))
-                    (let ((begin (progn (if col (cider--goto-expression-start) 
(back-to-indentation))
-                                        (point)))
-                          (end (progn (if col (forward-list) (move-end-of-line 
nil))
-                                      (point))))
-                      (list begin end buffer))))))))))))
+                    ;; if this condition is false, it means that `col` was a 
spuriously large value,
+                    ;; therefore the whole calculation should be discarded:
+                    (when (or (not col) ;; if there's no col info, we cannot 
judge if it's spurious/not
+                              ;; (current-column) never goes past the last 
column in the actual line,
+                              ;; so if it's <, then the message had spurious 
info:
+                              (>= (1+ (current-column))
+                                  col))
+                      (let ((begin (progn (if col 
(cider--goto-expression-start) (back-to-indentation))
+                                          (point)))
+                            (end (progn (if col (forward-list) 
(move-end-of-line nil))
+                                        (point))))
+                        (list begin end buffer)))))))))))))
 
 (defun cider-handle-compilation-errors (message eval-buffer)
   "Highlight and jump to compilation error extracted from MESSAGE.

Reply via email to