|
| 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