[Top][All Lists]

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

[elpa] master 400d56f 319/399: counsel.el (counsel-open-buffer-file-exte

From: Oleh Krehel
Subject: [elpa] master 400d56f 319/399: counsel.el (counsel-open-buffer-file-externally): New function
Date: Sat, 20 Jul 2019 14:57:48 -0400 (EDT)

branch: master
commit 400d56f3caf7e747cbbb6789929ecbbf2a3380bd
Author: Damien Cassou <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-open-buffer-file-externally): New function
    Bind "x" when switching buffers to open associated file externally.
    Fixes #2108
 counsel.el | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/counsel.el b/counsel.el
index df0777d..d01bb5b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5305,6 +5305,22 @@ in the current window."
             :unwind #'counsel--switch-buffer-unwind
             :update-fn 'counsel--switch-buffer-update-fn))
+(defun counsel-open-buffer-file-externally (buffer)
+  "Open the file associated with BUFFER with an external program."
+  (when (zerop (length buffer))
+    (user-error "Can't open that"))
+  (let* ((virtual (assoc buffer ivy--virtual-buffers))
+         (filename (if virtual
+                       buffer
+                     (buffer-file-name (get-buffer buffer)))))
+    (unless filename
+      (user-error "Can't open `%s' externally" buffer))
+    (counsel-locate-action-extern (expand-file-name filename))))
+ 'ivy-switch-buffer
+ '(("x" counsel-open-buffer-file-externally "open externally")))
 ;;** `counsel-compile'
 (defvar counsel-compile-history nil
   "History for `counsel-compile'.

reply via email to

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