From 5276adba8bb95e89d6573aa47d9e82ee62d139ae Mon Sep 17 00:00:00 2001 From: cskksc Date: Sun, 24 Jul 2016 14:53:55 +0530 Subject: [PATCH] [#1804] Remember cursor position between cider-inspector-* operations --- CHANGELOG.md | 1 + cider-inspector.el | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc12b8e57..567b993fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * [#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 .`). * [#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. * [#1783](https://github.com/clojure-emacs/cider/issues/1783): Put eval commands onto single map bound to `C-c C-v`. +* [#1804](https://github.com/clojure-emacs/cider/issues/1804): Remember cursor position between `cider-inspector-*` operations. ### Changes diff --git a/cider-inspector.el b/cider-inspector.el index 3af61966c..c8d07f86a 100644 --- a/cider-inspector.el +++ b/cider-inspector.el @@ -114,11 +114,41 @@ With a second prefix argument it prompts for an expression to eval and inspect." (4 (cider-inspect-defun-at-point)) (16 (call-interactively #'cider-inspect-expr)))) +(defvar cider-inspector-location-stack nil + "A stack used to save point locations in inspector buffers. +These locations are used to emulate save-excursion between +`cider-inspector-push' and `cider-inspector-pop' operations.") + +(defvar cider-inspector-page-location-stack nil + "A stack used to save point locations in inspector buffers. +These locations are used to emulate save-excursion between +`cider-inspector-next-page' and `cider-inspector-prev-page' operations.") + +(defvar cider-inspector-last-command nil + "Contains the value of the most recently used `cider-inspector-*' command. +This is used as an alternative to the built-in `last-command'. Whenever we +invoke any command through M-x and its variants, the value of `last-command' +is not set to the command it invokes.") + ;; Operations (defun cider-inspector--value-handler (_buffer value) (cider-make-popup-buffer cider-inspector-buffer 'cider-inspector-mode) (cider-inspector-render cider-inspector-buffer value) - (cider-popup-buffer-display cider-inspector-buffer t)) + (cider-popup-buffer-display cider-inspector-buffer t) + (with-current-buffer cider-inspector-buffer + (when (eq cider-inspector-last-command 'cider-inspector-pop) + (setq cider-inspector-last-command nil) + ;; Prevents error message being displayed when we try to pop + ;; from the top-level of a data struture + (when cider-inspector-location-stack + (goto-char (pop cider-inspector-location-stack)))) + + (when (eq cider-inspector-last-command 'cider-inspector-prev-page) + (setq cider-inspector-last-command nil) + ;; Prevents error message being displayed when we try to + ;; go to a prev-page from the first page + (when cider-inspector-page-location-stack + (goto-char (pop cider-inspector-page-location-stack)))))) (defun cider-inspector--out-handler (_buffer value) (cider-emit-interactive-eval-output value)) @@ -157,12 +187,14 @@ current buffer's namespace." (defun cider-inspector-pop () (interactive) + (setq cider-inspector-last-command 'cider-inspector-pop) (cider-nrepl-send-request (list "op" "inspect-pop" "session" (cider-current-session)) (cider-inspector-response-handler (current-buffer)))) (defun cider-inspector-push (idx) + (push (point) cider-inspector-location-stack) (cider-nrepl-send-request (list "op" "inspect-push" "idx" idx @@ -181,6 +213,7 @@ current buffer's namespace." Does nothing if already on the last page." (interactive) + (push (point) cider-inspector-page-location-stack) (cider-nrepl-send-request (list "op" "inspect-next-page" "session" (cider-current-session)) @@ -191,6 +224,7 @@ Does nothing if already on the last page." Does nothing if already on the first page." (interactive) + (setq cider-inspector-last-command 'cider-inspector-prev-page) (cider-nrepl-send-request (list "op" "inspect-prev-page" "session" (cider-current-session))