Issues with displaying previews #855
Replies: 5 comments 15 replies
-
Hi @mpedramfar! It is a known issue that fine-grained display-buffer-alists don't play well together with Consult preview. And as you found, vertico-buffer doesn't simplify the situation. I don't have a solution ready for this, but there were experiments at some point (#670, #671, which only worked on 28 and newer). I would be happy to consider patches improving the status quo. Adding buffer exclusion lists would be one solution, but not a really satisfactory one. We better restore windows as you propose. This is not easily to do since almost anything can happen, so one would need to save the full window configuration every time. The problem gets even worse if one adds frames to the equations. |
Beta Was this translation helpful? Give feedback.
-
On 11/11/23 19:07, mpedramfar wrote:
This seems to solve all the issues, though it probably needs more testing.
I've done some tests with the examples I've written above and also with
|display-buffer-pop-up-frame|, with and without |vertico-buffer-mode|.
Thanks. This is quite an increase in complexity. I am not sure if I want
to go that way, if we need a custom set-frame-configuration function.
Also there is some Vertico-specific code.
By the way, in the docstring of |consult--with-preview|, it says "The
state function is always executed with the original window selected".
This doesn't seem to be always true.
When does this happen in your tests? The state function is normally
executed in the window selected before the minibuffer was selected. The
only scenario where this does not happen is if the window has been
closed in the meantime.
|
Beta Was this translation helpful? Give feedback.
-
We could also use `set-window-configuration` with DONT-SET-MINIWINDOW=t
on Emacs 28 and newer as I had done in the earlier patch. On older Emacs
versions, we simply retain the current solution.
|
Beta Was this translation helpful? Give feedback.
-
Complexity is not the only issue with the code I sent above! I'll message here when I have a properly working code.
I may have used
(add-to-list 'display-buffer-alist
'("popup-frame.txt" display-buffer-pop-up-frame))
(setq minibuffer-follows-selected-frame t)
Actually, it's good that |
Beta Was this translation helpful? Give feedback.
-
Here is a better version: (defun my-set-frame-configuration (configuration)
(dolist (frame (visible-frame-list))
(if-let ((parameters (assq frame (cdr configuration))))
(set-window-configuration (nth 2 parameters) 'no-frame 'no-miniwindow)
(delete-frame frame))))
(setq my-consult-exclude nil)
(defun consult--buffer-preview ()
"Buffer preview function."
(let (fc)
(lambda (action cand)
(when (eq action 'preview)
(when fc
(my-set-frame-configuration fc)
(setq fc nil))
(when (and cand (get-buffer cand)
(not (seq-some (lambda (x) (buffer-match-p x cand))
my-consult-exclude)))
(let* ((frame (selected-frame))
(buf (window-buffer (minibuffer-window)))
(semi-mini-windows (delq (minibuffer-window) ;; windows other than the minibuffer-window that are showing the minibuffer in the current frame
(get-buffer-window-list buf))))
(setq fc (current-frame-configuration))
(consult--buffer-action cand 'norecord)
(select-window (minibuffer-window) 'norecord)
(when (and semi-mini-windows
(not (cl-subsetp semi-mini-windows
(get-buffer-window-list buf nil frame))))
(my-set-frame-configuration fc)
(setq fc nil)))))))) It does have a bit of code that might be vertico specific, or it might also be useful for some other completion frameworks as well ( The function
Here we might need use a custom version to change the first 2 things that it does. |
Beta Was this translation helpful? Give feedback.
-
I'll explain the issues with an example.
Create a new folder, create a file named
test.el
in it with the following content and runeval-buffer
:Issue 1:
Run
consult-buffer
. As you go over different buffers, the previous previews are not closed, instead they pile up:Possible solution:
Some kind of
save-window-excursion
that would make consult show at most a single preview at a time.Issue 2:
Activate
vertico-bufffer-mode
, then runconsult-buffer
. Not only preview buffers pile up, but the bufferbottom-side.txt
hides the vertico buffer:Note that the vertico buffer is active and current. We can move up and down and select buffers.
Possible solution:
This specific example can be be solved by modifying
consult-preview-excluded-files
, but this is not a general solution.For example, it could be
vterm
instead ofbottom-side.txt
. A better solution would be to have a variableconsult-preview-exclude
which is a list, where each item in the list is like a condition ofdisplay-buffer-alist
, i.e. each item can be a condition that can be passed tobuffer-match-p
.Beta Was this translation helpful? Give feedback.
All reactions