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

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

[elpa] master 871f78c 168/272: Add optional exit-code table to counsel--


From: Oleh Krehel
Subject: [elpa] master 871f78c 168/272: Add optional exit-code table to counsel--async-cmd
Date: Mon, 25 Apr 2016 10:13:23 +0000

branch: master
commit 871f78cc9fea6c2c86e0d68a89df0a9dc9aad8b5
Author: justbur <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add optional exit-code table to counsel--async-cmd
    
    This argument can be used to associate exit codes with the underlying
    reason. Used in counsel-ag-function to signal that an exit code of 1
    means that no matches were found.
    
    Fixes #421
---
 counsel.el |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/counsel.el b/counsel.el
index 2c6c54c..2ea12d6 100644
--- a/counsel.el
+++ b/counsel.el
@@ -66,6 +66,18 @@
   "Store the time when a new process was started.
 Or the time of the last minibuffer update.")
 
+(defvar counsel--async-exit-code-plist nil
+  "Associates exit codes with reasons.")
+
+(defun counsel-set-async-exit-code (cmd number str)
+  "For CMD, associate NUMBER exit code with STR."
+  (let ((plist (plist-get counsel--async-exit-code-plist cmd)))
+    (setq counsel--async-exit-code-plist
+          (plist-put
+           counsel--async-exit-code-plist
+           cmd
+           (plist-put plist number str)))))
+
 (defvar counsel-async-split-string-re "\n"
   "Store the regexp for splitting shell command output.")
 
@@ -111,8 +123,14 @@ Or the time of the last minibuffer update.")
             (ivy--insert-minibuffer "")
           (ivy--exhibit)))
     (if (string-match "exited abnormally with code \\([0-9]+\\)\n" event)
-        (progn
-          (setq ivy--all-candidates (list (format "error code %s" 
(match-string 1 event))))
+        (let* ((exit-code-plist (plist-get counsel--async-exit-code-plist
+                                           (ivy-state-caller ivy-last)))
+               (exit-num (read (match-string 1 event)))
+               (exit-code (plist-get exit-code-plist exit-num)))
+          (setq ivy--all-candidates
+                (list
+                 (or exit-code
+                     (format "error code %d" exit-num))))
           (setq ivy--old-cands ivy--all-candidates)
           (ivy--exhibit)))))
 
@@ -1139,6 +1157,8 @@ string - the full shell command to run."
  '(("x" counsel-locate-action-extern "xdg-open")
    ("d" counsel-locate-action-dired "dired")))
 
+(counsel-set-async-exit-code 'counsel-locate 1 "Nothing found")
+
 (defvar counsel-locate-history nil
   "History for `counsel-locate'.")
 
@@ -1205,6 +1225,8 @@ command. %S will be replaced by the regex string. The 
default is
   :type 'string
   :group 'ivy)
 
+(counsel-set-async-exit-code 'counsel-ag 1 "No matches found")
+
 (defun counsel-ag-function (string)
   "Grep in the current directory for STRING."
   (if (< (length string) 3)



reply via email to

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