Skip to content

Commit ae4dd40

Browse files
committed
Added pcomplete for drush.
Courtesy of Damon Haley.
1 parent 6dd8edc commit ae4dd40

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

drupal-mode.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ whitespace at the end."
118118
:group 'drupal-drush)
119119

120120

121+
;;;###autoload
121122
(defcustom drupal-drush-program (executable-find "drush")
122123
"Name of the Drush executable.
123124
Include path to the executable if it is not in your $PATH."
@@ -682,6 +683,8 @@ mode-hook."
682683
(eval-after-load 'ispell '(require 'drupal/ispell))
683684
(eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs))
684685
;;;###autoload
686+
(eval-after-load 'pcomplete '(require 'drupal/pcomplete))
687+
;;;###autoload
685688
(eval-after-load 'webjump '(require 'drupal/webjump))
686689

687690

drupal/pcomplete.el

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
;;; drupal/pcomplete.el --- Drush support for pcomplete.el
2+
3+
;; Copyright (C) 2013 Damon Haley
4+
5+
;; Author: Damon Haley <[email protected]>
6+
7+
;; This file is part of Drupal mode.
8+
9+
;; Drupal mode is free software: you can redistribute it and/or modify
10+
;; it under the terms of the GNU General Public License as published
11+
;; by the Free Software Foundation, either version 3 of the License,
12+
;; or (at your option) any later version.
13+
14+
;; Drupal mode is distributed in the hope that it will be useful, but
15+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
;; General Public License for more details.
18+
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with Drupal mode. If not, see <http://www.gnu.org/licenses/>.
21+
22+
;;; Commentary:
23+
24+
;; Enable drush support for pcomplete.el.
25+
26+
;;; Code:
27+
28+
(require 'pcomplete)
29+
30+
(defun drupal/pcomplete-drush-commands ()
31+
"Return the most common drush commands by parsing the drush output."
32+
(with-temp-buffer
33+
(call-process drupal-drush-program nil t nil
34+
"--early=includes/complete.inc")
35+
(goto-char 0)
36+
(let (commands)
37+
(while (re-search-forward
38+
"^[[:blank:]]*\\([@]?[[:word:]-.]+\\)"
39+
nil t)
40+
(push (match-string-no-properties 1) commands))
41+
(sort commands #'string<))))
42+
43+
(defvar drupal/pcomplete-drush-commands (drupal/pcomplete-drush-commands)
44+
"List of `drush' commands.")
45+
46+
(defun drupal/pcomplete-drush-completion ()
47+
"Completion for `drush'."
48+
;; Completion for the command argument.
49+
(pcomplete-here* drupal/pcomplete-drush-commands)
50+
(cond
51+
((pcomplete-match "help" 1)
52+
(pcomplete-here* drupal/pcomplete-drush-commands))
53+
(t
54+
(while (pcomplete-here (pcomplete-entries))))))
55+
56+
(defalias 'pcomplete/drush 'drupal/pcomplete-drush-completion)
57+
58+
59+
60+
(provide 'drupal/pcomplete)
61+
62+
;;; drupal/pcomplete.el ends here

0 commit comments

Comments
 (0)