-
-
Notifications
You must be signed in to change notification settings - Fork 649
[#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
Conversation
@@ -157,12 +166,16 @@ current buffer's namespace." | |||
|
|||
(defun cider-inspector-pop () | |||
(interactive) | |||
;; We cannot pop anything if we're at the top level | |||
(when cider-inspector-location-stack | |||
(push 'pop cider-inspector-location-stack)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this is necessary. Can't we just (goto-char (pop cider-inspector-location-stack))
in the cider-inspector--value-handler
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only have to goto-char
if this handler is called by the pop
operation. I just pushed a patch where we check this through the last-command
. This was certainly not the best way to do this :-)
I'm not quite certain what you mean by this. |
I think it might make sense to have it, but it would probably complicate the feature a lot (as the two trackings would interfere with each other), so maybe it's best to leave it like this. |
@bbatsov This PR, in its current state would only preserve cursor location across @Malabarba You're right. It would complicate tracking method calls in the handler. But lets keep this PR open for another day. I'll try this today, and if I'm able to get it to work and if we're happy with the added complexity vs usefulness of the feature, then lets merge it. Otherwise lets stick to only preserving cursor location across |
So, what's the verdict here - are we extending this or merging it as it is? |
@@ -114,11 +114,18 @@ 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 |
There was a problem hiding this comment.
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.
I'm sorry I forgot to post an update :-) I have gotten it to work. We can just use 2 stacks to track the position. But I ran into something else. When I invoke any I am AFK for the last two days. I will definitely finish this tomorrow :-) |
Yes, that's just how last-command works. The same happens if you invoke the command with regular M-x |
Probably we shouldn't rely on |
It is surprising I guess. I expected it to get the value of the command selected through M-x.
Yep. It seems so. We're gonna have to track this via our own var I guess. Or through the stack like in the previous patch. I'll try and see we could get it done any other way. On a side note, I have a doubt about this. Why have we used callback's here ? All the actions seem synchronous with the middleware response. What I guessed is that its because we have a good abstraction of the form |
We don't really need it. In the early days of the project we were trying to use callbacks everywhere as nREPL doesn't natively support sync evaluations and our emulation of those was poor. This code hasn't be updated in quite a while. Async handlers have a ton of room for improvement, this has been discussed in some older open tickets - unfortunately no one has had to the time to tackle them in years... |
The discussions about callbacks is here #1099 |
@bbatsov Ah ok. It makes sense now. Thanks! I'll read those tickets and we can start working on it next. I have some free time now :-) For now, we can track this through our own global |
The solution looks good. Just use |
@@ -136,6 +166,7 @@ displayed. | |||
|
|||
Used for all inspector nREPL ops." | |||
(nrepl-make-response-handler buffer | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've added this blank line by accident.
That'd be great. This refactoring is way way overdue... Many of the older tickets are some essential changes that got stale mostly due to lack of time to work on them (comint is another such example). |
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) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
Ill start reading the code and let's break the refactoring tasks down into smaller tickets we could handle. I'll start working on this from tomorrow 🔨 :-) |
We push our current location in the buffer i.e
(point)
, onto a stack, before everycider-inspector-push
operation. Then when we're navigation back usingcider-inspector-pop
,we just
goto-char
to that location.I've not used this feature of CIDER much. But does it make sense to do something like this for
next-page
andprev-page
too ?/cc @mallt
make test
)M-x checkdoc
warnings