@@ -205,17 +205,6 @@ With a second prefix argument it prompts for an expression to eval and inspect."
205205These locations are used to emulate `save-excursion' between
206206`cider-inspector-push' and `cider-inspector-pop' operations." )
207207
208- (defvar cider-inspector-page-location-stack nil
209- " A stack used to save point locations in inspector buffers.
210- These locations are used to emulate `save-excursion' between
211- `cider-inspector-next-page' and `cider-inspector-prev-page' operations." )
212-
213- (defvar cider-inspector-last-command nil
214- " Contains the value of the most recently used `cider-inspector-*' command.
215- This is used as an alternative to the built-in `last-command' . Whenever we
216- invoke any command through \\ [execute-extended-command] and its variants,
217- the value of `last-command' is not set to the command it invokes." )
218-
219208; ; Operations
220209;;;### autoload
221210(defun cider-inspect-expr (expr ns )
@@ -226,7 +215,8 @@ current buffer's namespace."
226215 (cider-current-ns)))
227216 (let ((result (cider-sync-request:inspect-expr expr ns)))
228217 (when (nrepl-dict-get result " value" )
229- (cider-inspector--render-value result))))
218+ (setq cider-inspector-location-stack nil )
219+ (cider-inspector--render-value result :next-inspectable ))))
230220
231221(defun cider-inspect-expr-from-inspector ()
232222 " Performs `cider-inspect-expr' in a way that is suitable from the Inspector itself.
@@ -242,10 +232,9 @@ In particular, it does not read `cider-sexp-at-point'."
242232 " Pop the last value off the inspector stack and render it.
243233See `cider-sync-request:inspect-pop' and `cider-inspector--render-value' ."
244234 (interactive )
245- (setq cider-inspector-last-command 'cider-inspector-pop )
246235 (let ((result (cider-sync-request:inspect-pop)))
247236 (when (nrepl-dict-get result " value" )
248- (cider-inspector--render-value result))))
237+ (cider-inspector--render-value result :pop ))))
249238
250239(defun cider-inspector-push (idx )
251240 " Inspect the value at IDX in the inspector stack and render it.
@@ -254,38 +243,32 @@ See `cider-sync-request:inspect-push' and `cider-inspector--render-value'"
254243 (let ((result (cider-sync-request:inspect-push idx)))
255244 (when (nrepl-dict-get result " value" )
256245 (push (point ) cider-inspector-location-stack)
257- (cider-inspector--render-value result)
258- (cider-inspector-next-inspectable-object 1 ))))
246+ (cider-inspector--render-value result :next-inspectable ))))
259247
260248(defun cider-inspector-inspect-last-exception (index )
261249 " Inspects the exception in the cause stack identified by INDEX."
262250 (interactive )
263251 (cl-assert (numberp index))
264252 (let ((result (cider-sync-request:inspect-last-exception index)))
265253 (when (nrepl-dict-get result " value" )
266- (push (point ) cider-inspector-location-stack)
267- (cider-inspector--render-value result)
268- (cider-inspector-next-inspectable-object 1 ))))
254+ (setq cider-inspector-location-stack nil )
255+ (cider-inspector--render-value result :next-inspectable ))))
269256
270257(defun cider-inspector-previous-sibling ()
271258 " Inspect the previous sibling value within a sequential parent.
272259See `cider-sync-request:inspect-previous-sibling' and `cider-inspector--render-value' "
273260 (interactive )
274261 (let ((result (cider-sync-request:inspect-previous-sibling)))
275262 (when (nrepl-dict-get result " value" )
276- (push (point ) cider-inspector-location-stack)
277- (cider-inspector--render-value result)
278- (cider-inspector-next-inspectable-object 1 ))))
263+ (cider-inspector--render-value result))))
279264
280265(defun cider-inspector-next-sibling ()
281266 " Inspect the next sibling value within a sequential parent.
282267See `cider-sync-request:inspect-next-sibling' and `cider-inspector--render-value' "
283268 (interactive )
284269 (let ((result (cider-sync-request:inspect-next-sibling)))
285270 (when (nrepl-dict-get result " value" )
286- (push (point ) cider-inspector-location-stack)
287- (cider-inspector--render-value result)
288- (cider-inspector-next-inspectable-object 1 ))))
271+ (cider-inspector--render-value result))))
289272
290273(defun cider-inspector--refresh-with-opts (&rest opts )
291274 " Invokes `inspect-refresh' op with supplied extra OPTS.
@@ -305,7 +288,6 @@ Re-renders the currently inspected value."
305288
306289Does nothing if already on the last page."
307290 (interactive )
308- (push (point ) cider-inspector-page-location-stack)
309291 (let ((result (cider-sync-request:inspect-next-page)))
310292 (when (nrepl-dict-get result " value" )
311293 (cider-inspector--render-value result))))
@@ -315,7 +297,6 @@ Does nothing if already on the last page."
315297
316298Does nothing if already on the first page."
317299 (interactive )
318- (setq cider-inspector-last-command 'cider-inspector-prev-page )
319300 (let ((result (cider-sync-request:inspect-prev-page)))
320301 (when (nrepl-dict-get result " value" )
321302 (cider-inspector--render-value result))))
@@ -350,7 +331,7 @@ MAX-NESTED-DEPTH is the new value."
350331 (let ((result (cider-nrepl-send-sync-request `(" op" " inspect-toggle-view-mode" )
351332 (cider-current-repl))))
352333 (when (nrepl-dict-get result " value" )
353- (cider-inspector--render-value result))))
334+ (cider-inspector--render-value result :next-inspectable ))))
354335
355336(defcustom cider-inspector-preferred-var-names nil
356337 " The preferred var names to be suggested by `cider-inspector-def-current-val' .
@@ -515,10 +496,12 @@ MAX-COLL-SIZE if non nil."
515496(declare-function cider-set-buffer-ns " cider-mode" )
516497
517498; ; Render Inspector from Structured Values
518- (defun cider-inspector--render-value (dict-or-value )
499+ (defun cider-inspector--render-value (dict-or-value &optional point-action )
519500 " Render DICT-OR-VALUE.
520501It can either be a value directly or a inspector response that contains
521- `value' field."
502+ `value' field.
503+ POINT-ACTION can either be nil (leave point where it is now), `:pop' (pop point
504+ from stack), `:next-inspectable' (move point to next inspectable object)."
522505 (let* ((value (if (nrepl-dict-p dict-or-value)
523506 (nrepl-dict-get dict-or-value " value" )
524507 dict-or-value))
@@ -535,31 +518,24 @@ It can either be a value directly or a inspector response that contains
535518 (truncate-lines-p (when-let* ((b (get-buffer cider-inspector-buffer))
536519 (continue truncate-lines-defined))
537520 (buffer-local-value 'truncate-lines b)))
538- (repl (cider-current-repl)))
521+ (repl (cider-current-repl))
522+ (current-point (point )))
539523 (cider-make-popup-buffer cider-inspector-buffer 'cider-inspector-mode 'ancillary )
540524 (cider-inspector-render cider-inspector-buffer value
541525 :font-size font-size
542526 :truncate-lines-defined truncate-lines-defined
543527 :truncate-lines-p truncate-lines-p)
544528 (cider-popup-buffer-display cider-inspector-buffer cider-inspector-auto-select-buffer)
545529 (when cider-inspector-fill-frame (delete-other-windows ))
546- (ignore-errors (cider-inspector-next-inspectable-object 1 ))
547530 (with-current-buffer cider-inspector-buffer
548531 (setq cider--ancillary-buffer-repl repl)
549532 (cider-set-buffer-ns ns)
550- (when (eq cider-inspector-last-command 'cider-inspector-pop )
551- (setq cider-inspector-last-command nil )
552- ; ; Prevents error message being displayed when we try to pop
553- ; ; from the top-level of a data structure
554- (when cider-inspector-location-stack
555- (goto-char (pop cider-inspector-location-stack))))
556-
557- (when (eq cider-inspector-last-command 'cider-inspector-prev-page )
558- (setq cider-inspector-last-command nil )
559- ; ; Prevents error message being displayed when we try to
560- ; ; go to a prev-page from the first page
561- (when cider-inspector-page-location-stack
562- (goto-char (pop cider-inspector-page-location-stack)))))))
533+ (cond ((eq point-action nil ) (goto-char current-point))
534+ ((eq point-action :next-inspectable ) (ignore-errors (cider-inspector-next-inspectable-object 1 )))
535+ ((eq point-action :pop )
536+ (goto-char (or (when cider-inspector-location-stack
537+ (pop cider-inspector-location-stack))
538+ current-point)))))))
563539
564540(cl-defun cider-inspector-render (buffer str &key font-size truncate-lines-defined truncate-lines-p )
565541 " Render STR in BUFFER."
0 commit comments