-
-
Notifications
You must be signed in to change notification settings - Fork 337
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 does not restore the correct environment for post-command-hook #1727
Comments
Looking at When I print |
WDYM by "correct"? Is this requirement documented somewhere? In other words, are these |
That's a good question. The expectation is simply stated as "run after executing each command". Thus, I would expect So strictly speaking, the current behavior isn't violating any explicitly documented constraints, but I think the current behavior is disingenuous. Edit: here's the manual page https://www.gnu.org/software/emacs/manual/html_node/elisp/Command-Overview.html |
Right, thanks for clarifying @darkfeline. |
I patched this locally by defining around advice like: ;; Macro for defining a func and adding as around advice.
(mir-nero--define ivy-switch-buffer (old)
"Fix bug https://github.com/abo-abo/swiper/issues/1727"
(funcall old)
(set-buffer (window-buffer (selected-window)))) After observing that after the |
https://www.gnu.org/software/emacs/manual/html_node/elisp/Current-Buffer.html |
@darkfeline Do you still get a problem with this version: (defun ivy--switch-buffer-action (buffer)
"Switch to BUFFER.
BUFFER may be a string or nil."
(if (zerop (length buffer))
(switch-to-buffer
ivy-text nil 'force-same-window)
(let ((virtual (assoc buffer ivy--virtual-buffers))
(view (assoc buffer ivy-views)))
(cond ((and virtual
(not (get-buffer buffer)))
(find-file (cdr virtual)))
(view
(delete-other-windows)
(let (
;; silence "Directory has changed on disk"
(inhibit-message t))
(ivy-set-view-recur (cadr view))))
(t
(switch-to-buffer
buffer nil 'force-same-window)))))) Please test with this version and your advice disabled and let me know. |
@abo-abo That doesn't fix the problem. |
@darkfeline Could you reformulate your advice as a patch to |
Unfortunately, I don't think it's possible to fix this in (mir-nero--define ivy-switch-buffer (old)
"Fix bug https://github.com/abo-abo/swiper/issues/1727"
(funcall old)
(let ((inhibit-message t))
(message "@@@@ Cbuffer %s" (current-buffer))
(message "@@@@ Cwindow %s" (window-buffer (selected-window)))))
(mir-nero--define ivy--switch-buffer-action (old buf)
"Fix bug https://github.com/abo-abo/swiper/issues/1727"
(funcall old buf)
(let ((inhibit-message t))
(message "@@@@ Abuffer %s" (current-buffer))
(message "@@@@ Awindow %s" (window-buffer (selected-window))))
(set-buffer (window-buffer (selected-window)))
(let ((inhibit-message t))
(message "@@@@ Bbuffer %s" (current-buffer))
(message "@@@@ Bwindow %s" (window-buffer (selected-window)))))
|
With the built-in
switch-to-buffer
, thecurrent-buffer
whilepost-command-hook
is running is the buffer that was switched to.With
ivy-switch-buffer
, thecurrent-buffer
whilepost-command-hook
is running is the buffer that was switchedfrom.
This neatly breaks all
post-command-hook
functions that rely oncurrent-buffer
being correct.ivy version is 20180809.1712
The text was updated successfully, but these errors were encountered: