Skip to content

Commit

Permalink
cider-eval: Introduce new `cider-auto-inspect-after-eval-select-win…
Browse files Browse the repository at this point in the history
…dow` defcustom

It allows one to have the `*cider-inspect*` buffer rendered without switching to it.
  • Loading branch information
vemv committed Mar 14, 2024
1 parent 7826a2d commit e140417
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

### Changes

- `cider-eval`: Introduce new `cider-auto-inspect-after-eval-select-window` defcustom.
- It allows one to have the `*cider-inspect*` buffer rendered without switching to it.
- [#3626](https://github.com/clojure-emacs/cider/issues/3626): `cider-ns-refresh`: jump to the relevant file/line on errors.
- [#3628](https://github.com/clojure-emacs/cider/issues/3628): `cider-ns-refresh`: summarize errors as an overlay.
- Bump the injected nREPL to [1.1.1](https://github.com/nrepl/nrepl/blob/v1.1.1/CHANGELOG.md#111-2024-02-20).
Expand Down
7 changes: 4 additions & 3 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -993,17 +993,18 @@ when `cider-auto-inspect-after-eval' is non-nil."
;; and needs no jumping:
phase)))
;; done handler:
(lambda (buffer)
(lambda (_buffer)
(if beg
(unless fringed
(cider--make-fringe-overlays-for-region beg end)
(setq fringed t))
(cider--make-fringe-overlay end))
(when (and cider-auto-inspect-after-eval
(boundp 'cider-inspector-buffer)
(windowp (get-buffer-window cider-inspector-buffer 'visible)))
(windowp (cider--get-inspector-window)))
(cider-inspect-last-result)
(select-window (get-buffer-window buffer)))
(when cider-auto-inspect-after-eval-select-window
(select-window (cider--get-inspector-window))))
(when cider-eval-register
(set-register cider-eval-register res))))))

Expand Down
3 changes: 1 addition & 2 deletions cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
(require 'easymenu)
(require 'seq)
(require 'cider-eval)
(require 'cider-util)

;; ===================================
;; Inspector Key Map and Derived Mode
;; ===================================

(defconst cider-inspector-buffer "*cider-inspect*")

;;; Customization
(defgroup cider-inspector nil
"Presentation and behavior of the CIDER value inspector."
Expand Down
24 changes: 24 additions & 0 deletions cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,30 @@ KIND can be the symbols `ns', `var', `emph', `fn', or a face name."
(t x)))
menu-list))

;; Defined here to avoid circular dependencies
(defconst cider-inspector-buffer "*cider-inspect*")

(defcustom cider-auto-inspect-after-eval-select-window t
"When t (and `cider-auto-inspect-after-eval' is also t),
the inspector window will be selected after eval.
When nil, while the underlying *cider-inspect* buffer will be re-rendered,
its window won't be selected.
You may want the nil value if you like having *cider-inspect* in a background frame."
:type 'boolean
:group 'cider
:package-version '(cider . "1.14.0"))

(defun cider--get-inspector-window ()
"Returns a window showing the *cider-inspect* buffer,
honoring the `cider-auto-inspect-after-eval-select-window' preference.
May return nil."
(get-buffer-window cider-inspector-buffer (if cider-auto-inspect-after-eval-select-window
'visible
t)))

(provide 'cider-util)

;;; cider-util.el ends here
3 changes: 2 additions & 1 deletion doc/modules/ROOT/pages/debugging/inspector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Alternatively, after a regular eval command, you can inspect the last
evaluated value using `cider-inspect-last-result`. When an inspector
buffer is visible in the background, it is automatically updated with
the last result. This behavior can be controlled with the variable
`cider-auto-inspect-after-eval`.
`cider-auto-inspect-after-eval` (and `cider-auto-inspect-after-eval-select-window`,
`cider-inspector-auto-select-buffer` for even more fine-grained control over the UX).

TIP: The inspector can also be invoked in the middle of a debugging
session, see xref:debugging/debugger.adoc[here] for more details.
Expand Down

0 comments on commit e140417

Please sign in to comment.