Tidy up +ivy-buffer-preview functionality

Let-binding `ivy-use-virtual-buffers` is neater and more robust than the
previous solution using some copy-pasta.  Calling the unwind routine
will become important once counsel is patched to restore buffer-list.
This commit is contained in:
Andrew Whatson 2019-03-08 16:08:36 +10:00
parent 4a1a359c21
commit 0f0b0d720b

View file

@ -35,10 +35,11 @@ temporary/special buffers in `font-lock-comment-face'."
;; Library ;; Library
(defun +ivy--switch-buffer-preview () (defun +ivy--switch-buffer-preview ()
(if (get-buffer (ivy-state-current ivy-last)) (let (ivy-use-virtual-buffers)
(ivy-call) (counsel--switch-buffer-update-fn)))
(with-ivy-window
(switch-to-buffer (ivy-state-buffer ivy-last))))) (defalias '+ivy--switch-buffer-preview-all #'counsel--switch-buffer-update-fn)
(defalias '+ivy--switch-buffer-unwind #'counsel--switch-buffer-unwind)
(defun +ivy--switch-buffer (workspace other) (defun +ivy--switch-buffer (workspace other)
(let ((current (not other)) (let ((current (not other))
@ -60,10 +61,11 @@ temporary/special buffers in `font-lock-comment-face'."
(when +ivy-buffer-preview (when +ivy-buffer-preview
(cond ((not (and ivy-use-virtual-buffers (cond ((not (and ivy-use-virtual-buffers
(eq +ivy-buffer-preview 'everything))) (eq +ivy-buffer-preview 'everything)))
(setq update #'+ivy--switch-buffer-preview)) (setq update #'+ivy--switch-buffer-preview
unwind #'+ivy--switch-buffer-unwind))
(t (t
(setq update #'counsel--switch-buffer-update-fn (setq update #'+ivy--switch-buffer-preview-all
unwind #'counsel--switch-buffer-unwind)))) unwind #'+ivy--switch-buffer-unwind))))
(ivy-read prompt 'internal-complete-buffer (ivy-read prompt 'internal-complete-buffer
:action action :action action
:predicate filter :predicate filter