Skip to content

Commit 8c0f219

Browse files
cskkscbbatsov
authored andcommitted
[Fix #1804] Remember cursor position between cider-inspector-* operations (#1807)
1 parent 736be3c commit 8c0f219

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* [#1767](https://github.com/clojure-emacs/cider/issues/1767): Add a command `cider-read-and-eval-defun-at-point` to insert the defun at point into the minibuffer for evaluation (bound to `C-c C-v .`).
2424
* [#1646](https://github.com/clojure-emacs/cider/issues/1646): Add an option `cider-apropos-actions` to control the list of actions to be applied on the symbol found by an apropos search.
2525
* [#1783](https://github.com/clojure-emacs/cider/issues/1783): Put eval commands onto single map bound to `C-c C-v`.
26+
* [#1804](https://github.com/clojure-emacs/cider/issues/1804): Remember cursor position between `cider-inspector-*` operations.
2627

2728
### Changes
2829

cider-inspector.el

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,41 @@ With a second prefix argument it prompts for an expression to eval and inspect."
114114
(4 (cider-inspect-defun-at-point))
115115
(16 (call-interactively #'cider-inspect-expr))))
116116

117+
(defvar cider-inspector-location-stack nil
118+
"A stack used to save point locations in inspector buffers.
119+
These locations are used to emulate save-excursion between
120+
`cider-inspector-push' and `cider-inspector-pop' operations.")
121+
122+
(defvar cider-inspector-page-location-stack nil
123+
"A stack used to save point locations in inspector buffers.
124+
These locations are used to emulate save-excursion between
125+
`cider-inspector-next-page' and `cider-inspector-prev-page' operations.")
126+
127+
(defvar cider-inspector-last-command nil
128+
"Contains the value of the most recently used `cider-inspector-*' command.
129+
This is used as an alternative to the built-in `last-command'. Whenever we
130+
invoke any command through M-x and its variants, the value of `last-command'
131+
is not set to the command it invokes.")
132+
117133
;; Operations
118134
(defun cider-inspector--value-handler (_buffer value)
119135
(cider-make-popup-buffer cider-inspector-buffer 'cider-inspector-mode)
120136
(cider-inspector-render cider-inspector-buffer value)
121-
(cider-popup-buffer-display cider-inspector-buffer t))
137+
(cider-popup-buffer-display cider-inspector-buffer t)
138+
(with-current-buffer cider-inspector-buffer
139+
(when (eq cider-inspector-last-command 'cider-inspector-pop)
140+
(setq cider-inspector-last-command nil)
141+
;; Prevents error message being displayed when we try to pop
142+
;; from the top-level of a data struture
143+
(when cider-inspector-location-stack
144+
(goto-char (pop cider-inspector-location-stack))))
145+
146+
(when (eq cider-inspector-last-command 'cider-inspector-prev-page)
147+
(setq cider-inspector-last-command nil)
148+
;; Prevents error message being displayed when we try to
149+
;; go to a prev-page from the first page
150+
(when cider-inspector-page-location-stack
151+
(goto-char (pop cider-inspector-page-location-stack))))))
122152

123153
(defun cider-inspector--out-handler (_buffer value)
124154
(cider-emit-interactive-eval-output value))
@@ -157,12 +187,14 @@ current buffer's namespace."
157187

158188
(defun cider-inspector-pop ()
159189
(interactive)
190+
(setq cider-inspector-last-command 'cider-inspector-pop)
160191
(cider-nrepl-send-request
161192
(list "op" "inspect-pop"
162193
"session" (cider-current-session))
163194
(cider-inspector-response-handler (current-buffer))))
164195

165196
(defun cider-inspector-push (idx)
197+
(push (point) cider-inspector-location-stack)
166198
(cider-nrepl-send-request
167199
(list "op" "inspect-push"
168200
"idx" idx
@@ -181,6 +213,7 @@ current buffer's namespace."
181213
182214
Does nothing if already on the last page."
183215
(interactive)
216+
(push (point) cider-inspector-page-location-stack)
184217
(cider-nrepl-send-request
185218
(list "op" "inspect-next-page"
186219
"session" (cider-current-session))
@@ -191,6 +224,7 @@ Does nothing if already on the last page."
191224
192225
Does nothing if already on the first page."
193226
(interactive)
227+
(setq cider-inspector-last-command 'cider-inspector-prev-page)
194228
(cider-nrepl-send-request
195229
(list "op" "inspect-prev-page"
196230
"session" (cider-current-session))

0 commit comments

Comments
 (0)