branch: master commit 97189623c5b36d5b153c43ad1676799553237b9e Author: Gergely Risko <er...@nilcons.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Add a simple initial counsel-switch-buffer This first implementation already provides the interactive element of functionality: in the current window the user can preview her buffer selection. Fixes #1895 --- counsel.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/counsel.el b/counsel.el index 73f2b76..93dcb2f 100644 --- a/counsel.el +++ b/counsel.el @@ -5016,6 +5016,28 @@ When ARG is non-nil, ignore NoDisplay property in *.desktop files." :action #'counsel-wmctrl-action :caller 'counsel-wmctrl))) +(defun counsel--switch-buffer-update-fn () + (let ((current (ivy-state-current ivy-last))) + ;; This check is necessary, otherwise typing into the completion + ;; would create empty buffers. + (if (get-buffer current) + (ivy-call) + (with-ivy-window + (switch-to-buffer (ivy-state-buffer ivy-last)))))) + +;;;###autoload +(defun counsel-switch-buffer () + "Switch to another buffer. +Display a preview of the selected ivy completion candidate buffer +in the current window." + (interactive) + (ivy-read "Switch to buffer: " 'internal-complete-buffer + :preselect (buffer-name (other-buffer (current-buffer))) + :action #'ivy--switch-buffer-action + :matcher #'ivy--switch-buffer-matcher + :caller 'counsel-switch-buffer + :update-fn 'counsel--switch-buffer-update-fn)) + ;;* `counsel-mode' (defvar counsel-mode-map (let ((map (make-sparse-keymap)))