From: Leo Liu Date: Thu, 21 Nov 2013 14:15:44 +0000 (+0800) Subject: Add completion for command `ag'. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~761 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b6ffa04a65caa59f4f41234fc7b2edc0d0e68a82;p=emacs.git Add completion for command `ag'. * pcmpl-x.el (pcomplete/ag, pcmpl-x-ag-options): New functions. (pcmpl-x-ag-options): New variable. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ecec50e930d..cc928f5c57f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-11-21 Leo Liu + + 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 * emacs-lisp/byte-run.el (eval-when-compile): Fix edebug spec diff --git a/lisp/pcmpl-x.el b/lisp/pcmpl-x.el index 86d8dc652c3..b52a692a291 100644 --- a/lisp/pcmpl-x.el +++ b/lisp/pcmpl-x.el @@ -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