-
-
Notifications
You must be signed in to change notification settings - Fork 339
ivy.el (ivy-call): Restore previous buffer #1607
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
Running your recipe from Swiper version: 7df7ab6
|
Oops! Let me look into this further. I know something is wrong, but I think I probably misidentified the problem in this pull request :( |
Or perhaps the recipe above just doesn't showcase the problem? |
I think that it does showcase the problem, but the problem only exists due to some other package or configuration that was active when I did the testing. |
Welp, I did a lot of bisecting, and here's a new recipe that works from (with-current-buffer "*scratch*"
(set-buffer "*Messages*")
(ivy-read "Select one: " (list "X") :action (lambda (x) x))
(pcase (buffer-name)
("*scratch*" (message "Buffer was not restored correctly."))
("*Messages*" (message "Buffer was restored correctly."))
(_ (message "Something unexpected has happened.")))) Note the explicit Line 1219 in 7df7ab6
In case you were wondering, the reason the original recipe was working for me was because I was using |
In cases where `set-buffer' was called before `ivy-read', the correct window was restored but the effects of `set-buffer' were lost. Restoring the buffer explicitly fixes the problem. Evaluate the following code to check if the bug is fixed: (with-current-buffer "*scratch*" (set-buffer "*Messages*") (ivy-read "Select one: " (list "X") :action (lambda (x) x)) (pcase (buffer-name) ("*scratch*" (message "Buffer was not restored correctly.")) ("*Messages*" (message "Buffer was restored correctly.")) (_ (message "Something unexpected has happened."))))
6b515ee
to
6a7aeac
Compare
Nice.
Not sure what the purpose of that is, but even if there is a valid one, it can nevertheless be simplified: diff --git a/ivy.el b/ivy.el
index f8aceb2..83c46dd 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1216,8 +1216,8 @@ ivy-call
ivy-text)
(t
(ivy-state-current ivy-last)))))
- (if (eq action 'identity)
- (funcall action x)
+ (if (eq action #'identity)
+ x
(select-window (ivy--get-window ivy-last))
(prog1 (with-current-buffer (ivy-state-buffer ivy-last)
(unwind-protect (funcall action x) |
I like the fix proposed by @basil-conto more. @raxod502 does it solve your problem? In case it does I suggest we close this PR and apply the fix by @basil-conto instead. |
@abo-abo My patch (#1607 (comment)) is not a solution to @raxod502's issue; it was just a suggestion for a truly trivial additional simplification. |
Thanks. |
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
In cases where
set-buffer
was called beforeivy-read
, the correct window was restored but the effects ofset-buffer
were lost. Restoring the buffer explicitly fixes the problem.Example code to reproduce the issue: