Skip to content

Commit 79369be

Browse files
committed
[Fix #2850] Ensure you're in the middle of a window after cider-jump-to
1 parent bdf4f86 commit 79369be

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* [#2617](https://github.com/clojure-emacs/cider/pull/2617): Add menu bar entry for `Insert last sexp in REPL`.
2222
* Removed support for the Nashorn ClojureScript REPL. (it was removed upstream in ClojureScript)
2323
* [#2825](https://github.com/clojure-emacs/cider/issues/2825): Disable support for displaying images in the REPL. (set `cider-repl-use-content-types` to re-enable it)
24+
* [#2850](https://github.com/clojure-emacs/cider/issues/2850): Ensure you're in the middle of a window after commands like `cider-find-var`.
2425

2526
### Bugs fixed
2627

cider-common.el

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,38 @@ If OTHER-WINDOW is non-nil don't reuse current window."
159159
(widen)
160160
(goto-char (point-min))
161161
(cider-mode +1)
162-
(cond
163-
;; Line-column specification.
164-
((consp pos)
165-
(forward-line (1- (or (car pos) 1)))
166-
(if (cdr pos)
167-
(move-to-column (cdr pos))
168-
(back-to-indentation)))
169-
;; Point specification.
170-
((numberp pos)
171-
(goto-char pos))
172-
;; Symbol or string.
173-
(pos
174-
;; Try to find (def full-name ...).
175-
(if (or (save-excursion
176-
(search-forward-regexp (format "(def.*\\s-\\(%s\\)" (regexp-quote pos))
177-
nil 'noerror))
178-
(let ((name (replace-regexp-in-string ".*/" "" pos)))
179-
;; Try to find (def name ...).
180-
(or (save-excursion
181-
(search-forward-regexp (format "(def.*\\s-\\(%s\\)" (regexp-quote name))
182-
nil 'noerror))
183-
;; Last resort, just find the first occurrence of `name'.
184-
(save-excursion
185-
(search-forward name nil 'noerror)))))
186-
(goto-char (match-beginning 0))
187-
(message "Can't find %s in %s" pos (buffer-file-name))))
188-
(t nil))))
162+
(let ((status
163+
(cond
164+
;; Line-column specification.
165+
((consp pos)
166+
(forward-line (1- (or (car pos) 1)))
167+
(if (cdr pos)
168+
(move-to-column (cdr pos))
169+
(back-to-indentation)))
170+
;; Point specification.
171+
((numberp pos)
172+
(goto-char pos))
173+
;; Symbol or string.
174+
(pos
175+
;; Try to find (def full-name ...).
176+
(if (or (save-excursion
177+
(search-forward-regexp (format "(def.*\\s-\\(%s\\)" (regexp-quote pos))
178+
nil 'noerror))
179+
(let ((name (replace-regexp-in-string ".*/" "" pos)))
180+
;; Try to find (def name ...).
181+
(or (save-excursion
182+
(search-forward-regexp (format "(def.*\\s-\\(%s\\)" (regexp-quote name))
183+
nil 'noerror))
184+
;; Last resort, just find the first occurrence of `name'.
185+
(save-excursion
186+
(search-forward name nil 'noerror)))))
187+
(goto-char (match-beginning 0))
188+
(message "Can't find %s in %s" pos (buffer-file-name))
189+
'not-found))
190+
(t 'not-found))))
191+
(unless (eq status 'not-found)
192+
;; Make sure the location we jump to is centered within the target window
193+
(recenter)))))
189194

190195
(defun cider--find-buffer-for-file (file)
191196
"Return a buffer visiting FILE.

0 commit comments

Comments
 (0)