summaryrefslogtreecommitdiff
path: root/cider-inspector.el
diff options
context:
space:
mode:
authorChaitanya Koparkar <ckoparkar@live.in>2016-07-24 18:46:17 +0530
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2016-07-24 16:16:17 +0300
commit8c0f21914a91df1f9eb41c31817cfea39a2586df (patch)
tree95c688fc9fa1ac2a2156200787f29bbed197190a /cider-inspector.el
parent736be3c05076daa159f5aba937d697c1468e33e9 (diff)
[Fix #1804] Remember cursor position between cider-inspector-* operations (#1807)
Diffstat (limited to 'cider-inspector.el')
-rw-r--r--cider-inspector.el36
1 files changed, 35 insertions, 1 deletions
diff --git a/cider-inspector.el b/cider-inspector.el
index 3af61966..c8d07f86 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))