Skip to content

[#1804] Remember location after cider-inspector-pop #1807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 35 additions & 1 deletion cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this should be a buffer-local variable.

"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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is preventing us from creating a buffer-local var. It clears out all the state when creating a new buffer. I guess our this method could use an optional param which controls this behavior. But it would involve changes in a lot of places. Let's handle this in a separate PR ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I forgot about this. Yeah, guess we can revisit this later. I'll merge the PR in its current state.

(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))
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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))
Expand Down