Skip to content

Commit

Permalink
Add cider-jump-to-always-use-same-window
Browse files Browse the repository at this point in the history
Provide a means to control what window to use when jumping to a definition with
`cider-jump-to`.

By default, always use current window.

Provide an option to use existing buffer in current frame when there is one that
is showing the target buffer. (This is the old behaviour, but note that it does
not work well with `cider-pop-back` (M-,).

This fixes #2499
  • Loading branch information
simon-katz committed Nov 25, 2019
1 parent dd74ddd commit 0edf098
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#2757](https://github.com/clojure-emacs/cider/pull/2757): Add `cider-jump-to-always-use-same-window`
* [#2738](https://github.com/clojure-emacs/cider/pull/2738): Add ability to lookup a function symbol when cursor is at the opening paren.
* [#2735](https://github.com/clojure-emacs/cider/pull/2735): New debugger command `P` to inspect an arbitrary expression, it was previously bound to `p` which now inspects the current value.
* [#2729](https://github.com/clojure-emacs/cider/pull/2729): New cider inspector command `cider-inspector-def-current-val` lets you define a var with the current inspector value.
Expand Down
14 changes: 12 additions & 2 deletions cider-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ On failure, read a symbol name using PROMPT and call CALLBACK with that."

(declare-function cider-mode "cider-mode")

(defcustom cider-jump-to-always-use-same-window t
"Determines what window `cider-jump-to` uses.
If non-nil, always use current window.
If nil: if target buffer is being displayed in the current frame use its
window, otherwise use the current window."
:type 'boolean
:group 'cider)

(defun cider-jump-to (buffer &optional pos other-window)
"Push current point onto marker ring, and jump to BUFFER and POS.
POS can be either a number, a cons, or a symbol.
Expand All @@ -139,8 +147,10 @@ If OTHER-WINDOW is non-nil don't reuse current window."
(ring-insert find-tag-marker-ring (point-marker)))
(if other-window
(pop-to-buffer buffer 'display-buffer-pop-up-window)
;; like switch-to-buffer, but reuse existing window if BUFFER is visible
(pop-to-buffer buffer '((display-buffer-reuse-window display-buffer-same-window))))
(pop-to-buffer buffer (if cider-jump-to-always-use-same-window
'((display-buffer-same-window))
'((display-buffer-reuse-window
display-buffer-same-window)))))
(with-current-buffer buffer
(widen)
(goto-char (point-min))
Expand Down
12 changes: 12 additions & 0 deletions doc/modules/ROOT/pages/repl/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,15 @@ can set:
----
(setq cider-repl-require-ns-on-set t)
----

== Control what window to use when jumping to a definition

By default M-. and other commands that jump to a definition use the current
window to show the definition. An alternative is to use an existing buffer in
the current frame when there is one that is showing the target buffer. If you
want this alternative behaviour, set:

[source,lisp]
----
(setq cider-jump-to-always-use-same-window nil)
----

0 comments on commit 0edf098

Please sign in to comment.