emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 6853290 031/399: counsel-switch-buffer: Add support for iv


From: Oleh Krehel
Subject: [elpa] master 6853290 031/399: counsel-switch-buffer: Add support for ivy-use-virtual-buffers.
Date: Sat, 20 Jul 2019 14:56:42 -0400 (EDT)

branch: master
commit 685329069c2690a531e203e571bfc0e42dc9fd0e
Author: Nathan Moreau <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel-switch-buffer: Add support for ivy-use-virtual-buffers.
    
    This will open virtual buffers for preview, and kill them.
    
    counsel.el (counsel--switch-buffer-temporary-buffers): new variable.
    (counsel--switch-buffer-unwind): new function.
    (counsel--switch-buffer-update-fn): try to find files.
    (counsel-switch-buffer): add unwind.
    
    Fixes #1897
---
 counsel.el | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/counsel.el b/counsel.el
index 93dcb2f..fa214c4 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5016,14 +5016,28 @@ When ARG is non-nil, ignore NoDisplay property in 
*.desktop files."
               :action #'counsel-wmctrl-action
               :caller 'counsel-wmctrl)))
 
+(defvar counsel--switch-buffer-temporary-buffers nil
+  "Internal.")
+
+(defun counsel--switch-buffer-unwind ()
+  "Clear temporary file buffers.
+The buffers are those opened during a session of `counsel-switch-buffer'."
+  (while counsel--switch-buffer-temporary-buffers
+    (let ((buf (pop counsel--switch-buffer-temporary-buffers)))
+      (kill-buffer buf))))
+
 (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))))))
+      (if (and ivy-use-virtual-buffers (file-exists-p current))
+          (let ((buf (find-file-noselect current)))
+            (push buf counsel--switch-buffer-temporary-buffers)
+            (ivy-call))
+        (with-ivy-window
+          (switch-to-buffer (ivy-state-buffer ivy-last)))))))
 
 ;;;###autoload
 (defun counsel-switch-buffer ()
@@ -5036,6 +5050,7 @@ in the current window."
             :action #'ivy--switch-buffer-action
             :matcher #'ivy--switch-buffer-matcher
             :caller 'counsel-switch-buffer
+            :unwind #'counsel--switch-buffer-unwind
             :update-fn 'counsel--switch-buffer-update-fn))
 
 ;;* `counsel-mode'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]