Skip to content
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

ivy-switch-buffer: calling current-buffer soon afterward returns old buffer #1766

Closed
mehw opened this issue Sep 26, 2018 · 5 comments
Closed

ivy-switch-buffer: calling current-buffer soon afterward returns old buffer #1766

mehw opened this issue Sep 26, 2018 · 5 comments

Comments

@mehw
Copy link

@mehw mehw commented Sep 26, 2018

Hello.

Could someone confirm the following, please?

Description

Switching buffer from A to B via ivy-switch-buffer changes the buffer to B as expected, but calling current-buffer soon afterward returns A not B!

Versions affected

How to replicate

Register the command testme-ivy-switch-buffer below, then run it via M-x testme-ivy-switch-buffer. Then, try to switch to a different buffer and take note of the printed message.

(defun testme-ivy-switch-buffer ()
  (interactive)
  (ivy-switch-buffer)
  ;; NOTE: Delay `message' with `run-with-timer' to get proper results,
  ;; i.e. (run-with-timer 0.5 nil (lambda () (message ...))).  On my
  ;; system just 0.00005 seconds are enough to get proper results.
  (message "(current-buffer): %s | (window-buffer (selected-window)): %s"
           (current-buffer) (window-buffer (selected-window))))

Expected odd results:

  • (current-buffer) returns the old buffer.
  • (window-buffer (selected-window)) returns the buffer switched to.

Implementation notes

There's a sort of oddity in ivy-call:

(with-current-buffer (ivy-state-buffer ivy-last)
  (unwind-protect (funcall action x)
    (ivy-recursive-restore)))

When action is ivy--switch-buffer-action, it switches buffer to x, but the wrapping with-current-buffer set it back to ivy-last's registered :buffer... the old buffer.

Proposed solution

Excuse me for not opening a PR... my bad...

I pushed a commit on a new branch and there should be a referenced solution right here.

@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Sep 26, 2018

Ccing @raxod502 who had some insights on related code in #1607.

basil-conto added a commit to basil-conto/swiper that referenced this issue Sep 26, 2018
The call to with-current-buffer was made redundant by the preceding
set-buffer added in abo-abo#1607, and incorrectly restores ivy-state-buffer
after calling action.

(ivy-call): Remove call to with-current-buffer.

Closes abo-abo#1766
@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Sep 26, 2018

@mehw Can you please review #1767?

@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Sep 26, 2018

the wrapping with-current-buffer set it back to ivy-last's registered :buffer... the old buffer.

Which is why I think this with-current-buffer can/should be removed, though I'm not 100% sure.

@mehw
Copy link
Author

@mehw mehw commented Sep 26, 2018

Ccing @raxod502 who had some insights on related code in #1607.

Please, also see @ericdanan 717#issuecomment-321920963.

@mehw Can you please review #1767?

It seems to work. Thanks!

Which is why I think this with-current-buffer can/should be removed, though I'm not 100% sure.

Peer reviews will be helpful... Please, kindly review #1767.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Sep 26, 2018

Thanks, all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants