]> git.eshelyaron.com Git - emacs.git/commitdiff
Add completion for command `ag'.
authorLeo Liu <sdl.web@gmail.com>
Thu, 21 Nov 2013 14:15:44 +0000 (22:15 +0800)
committerLeo Liu <sdl.web@gmail.com>
Thu, 21 Nov 2013 14:15:44 +0000 (22:15 +0800)
* pcmpl-x.el (pcomplete/ag, pcmpl-x-ag-options): New functions.
(pcmpl-x-ag-options): New variable.

lisp/ChangeLog
lisp/pcmpl-x.el

index ecec50e930dcf1eb1796b81f31cd1222b457a2b8..cc928f5c57f0aa144fa4eb1569f3fb2068275cc6 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-21  Leo Liu  <sdl.web@gmail.com>
+
+       Add completion for command `ag'.
+       * pcmpl-x.el (pcomplete/ag, pcmpl-x-ag-options): New functions.
+       (pcmpl-x-ag-options): New variable.
+
 2013-11-21  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * emacs-lisp/byte-run.el (eval-when-compile): Fix edebug spec
index 86d8dc652c367055d370760cd193bcbb4dbc20e2..b52a692a291fd61973b26e124ffcbc763983c401 100644 (file)
@@ -247,5 +247,35 @@ long options."
 ;;;###autoload
 (defalias 'pcomplete/ack-grep 'pcomplete/ack)
 
+
+;;;; the_silver_search - https://github.com/ggreer/the_silver_searcher
+
+(defvar pcmpl-x-ag-options nil)
+
+(defun pcmpl-x-ag-options ()
+  (or pcmpl-x-ag-options
+      (setq pcmpl-x-ag-options
+            (with-temp-buffer
+              (when (zerop (call-process "ag" nil t nil "--help"))
+                (let (so lo)
+                  (goto-char (point-min))
+                  (while (re-search-forward "^ +\\(-[a-zA-Z]\\) " nil t)
+                    (push (match-string 1) so))
+                  (goto-char (point-min))
+                  (while (re-search-forward
+                          "^ +\\(?:-[a-zA-Z] \\)?\\(--[^ \t\n]+\\) " nil t)
+                    (push (match-string 1) lo))
+                  (list (cons 'short (nreverse so))
+                        (cons 'long  (nreverse lo)))))))))
+
+;;;###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-x-ag-options))))
+      (pcomplete-here* (pcomplete-dirs-or-entries)))))
+
 (provide 'pcmpl-x)
 ;;; pcmpl-x.el ends here