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

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

[elpa] master 069315e 1/4: Add shell completion support for the_silver_s


From: Leo Liu
Subject: [elpa] master 069315e 1/4: Add shell completion support for the_silver_search
Date: Sat, 12 Sep 2015 12:40:52 +0000

branch: master
commit 069315e8374472ffbbe00115a1850a988da1ae65
Author: Leo Liu <address@hidden>
Commit: Leo Liu <address@hidden>

    Add shell completion support for the_silver_search
---
 pcmpl-ack.el |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/pcmpl-ack.el b/pcmpl-ack.el
index 3029367..ca906ab 100644
--- a/pcmpl-ack.el
+++ b/pcmpl-ack.el
@@ -1,4 +1,4 @@
-;;; pcmpl-ack.el --- completion for ack    -*- lexical-binding: t; -*-
+;;; pcmpl-ack.el --- completion for ack and ag       -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2012-2013  Free Software Foundation, Inc.
 
@@ -27,6 +27,7 @@
 ;;
 ;; Install:
 ;;   (autoload 'pcomplete/ack "pcmpl-ack")
+;;   (autoload 'pcomplete/ag "pcmpl-ack")
 ;;
 ;; Usage:
 ;;   - To complete short options type '-' first
@@ -137,5 +138,39 @@ long options."
 ;;;###autoload
 (defalias 'pcomplete/ack-grep 'pcomplete/ack)
 
+(defvar pcmpl-ack-ag-options nil)
+
+(defun pcmpl-ack-ag-options ()
+  (or pcmpl-ack-ag-options
+      (setq pcmpl-ack-ag-options
+            (with-temp-buffer
+              (when (zerop (call-process "ag" nil t nil "--help"))
+                (let (short long)
+                  (goto-char (point-min))
+                  (while (re-search-forward "^ +\\(-[a-zA-Z]\\) " nil t)
+                    (push (match-string 1) short))
+                  (goto-char (point-min))
+                  (while (re-search-forward
+                          "^ +\\(?:-[a-zA-Z] \\)?\\(--\\(\\[no\\]\\)?[^ 
\t\n]+\\) "
+                          nil t)
+                    (if (match-string 2)
+                        (progn
+                          (replace-match "" nil nil nil 2)
+                          (push (match-string 1) long)
+                          (replace-match "no" nil nil nil 2)
+                          (push (match-string 1) long))
+                      (push (match-string 1) long)))
+                  (list (cons 'short (nreverse short))
+                        (cons 'long  (nreverse long)))))))))
+
+;;;###autoload
+(defun pcomplete/ag ()
+  "Completion for the `ag' command."
+  (while t
+    (if (pcomplete-match "^-" 0)
+        (pcomplete-here* (cdr (assq (if (pcomplete-match "^--" 0) 'long 'short)
+                                    (pcmpl-ack-ag-options))))
+      (pcomplete-here* (pcomplete-dirs-or-entries)))))
+
 (provide 'pcmpl-ack)
 ;;; pcmpl-ack.el ends here



reply via email to

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