]> code.delx.au - gnu-emacs-elpa/blob - packages/ack/pcmpl-ack.el
Add ack
[gnu-emacs-elpa] / packages / ack / pcmpl-ack.el
1 ;;; pcmpl-ack.el --- completion for ack tool
2
3 ;; Copyright (C) 2012 Leo Liu
4
5 ;; Author: Leo Liu <sdl.web@gmail.com>
6 ;; Keywords: tools, processes, convenience
7 ;; Created: 2012-09-26
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;; Provide pcompletion support for the cli tool `ack' which can be
25 ;; downloaded from http://betterthangrep.com.
26 ;;
27 ;; Install:
28 ;; (autoload 'pcomplete/ack "pcmpl-ack")
29 ;;
30 ;; Usage:
31 ;; - To complete short options type '-' first
32 ;; - To complete long options type '--' first
33 ;; - Color name completion is also supported following
34 ;; --color-filename=, --color-match= and --color-lineno=.
35
36 ;;; Code:
37
38 (require 'pcomplete)
39
40 (defvar pcmpl-ack-short-options
41 (mapconcat (lambda (o) (substring o 1))
42 '("-a" "-A" "-B" "-C" "-c" "-f" "-G" "-g"
43 "-H" "-h" "-i" "-l" "-L" "-m" "-n"
44 "-o" "-Q" "-r" "-R"
45 "-u" "-v" "-w" "-1")
46 "")
47 "Short options for the `ack' command.")
48
49 (defvar pcmpl-ack-long-options
50 '("--after-context="
51 "--all-types"
52 "--before-context="
53 "--break"
54 "--nobreak"
55 "--color"
56 "--nocolor"
57 "--colour"
58 "--nocolour"
59 "--color-filename="
60 "--color-match="
61 "--color-lineno="
62 "--column"
63 "--context="
64 "--count"
65 "--env"
66 "--noenv"
67 "--files-with-matches"
68 "--files-without-matches"
69 "--flush"
70 "--follow"
71 "--nofollow"
72 "--group"
73 "--nogroup"
74 "--heading"
75 "--noheading"
76 "--ignore-case"
77 "--ignore-dir="
78 "--noignore-dir="
79 "--invert-match"
80 "--line="
81 "--literal"
82 "--match"
83 "--max-count="
84 "--no-filename"
85 "--output="
86 "--pager="
87 "--nopager"
88 "--passthru"
89 "--print0"
90 "--recurse"
91 "--norecurse"
92 "--smart-case"
93 "--nosmart-case"
94 "--sort-files"
95 "--type="
96 "--type-add"
97 "--type-set"
98 "--unrestricted"
99 "--with-filename"
100 "--word-regexp"
101 "--help"
102 "--help-types"
103 "--man"
104 "--thpppt"
105 "--version")
106 "Long options for the `ack' command.")
107
108 (defvar pcmpl-ack-color-options
109 '("clear"
110 "reset"
111 "dark"
112 "bold"
113 "underline"
114 "underscore"
115 "blink"
116 "reverse"
117 "concealed"
118 "black"
119 "red"
120 "green"
121 "yellow"
122 "blue"
123 "magenta"
124 "on_black"
125 "on_red"
126 "on_green"
127 "on_yellow"
128 "on_blue"
129 "on_magenta"
130 "on_cyan"
131 "on_white")
132 "Color names for the `ack' command.")
133
134 ;;;###autoload
135 (defun pcomplete/ack ()
136 "Completion for the `ack' command.
137 Start an argument with '-' to complete short options and '--' for
138 long options."
139 ;; No space after =
140 (add-to-list 'pcomplete-suffix-list ?=)
141 (while t
142 (if (pcomplete-match "^-" 0)
143 (cond
144 ((pcomplete-match "^--color-\\w+=\\(\\S-*\\)" 0)
145 (pcomplete-here* pcmpl-ack-color-options
146 (pcomplete-match-string 1 0) t))
147 ((pcomplete-match "^--\\(?:no\\)?ignore-dir=\\(\\S-*\\)" 0)
148 (pcomplete-here* (pcomplete-dirs)
149 (pcomplete-match-string 1 0) t))
150 ((pcomplete-match "^--" 0)
151 (pcomplete-here* pcmpl-ack-long-options))
152 (t (pcomplete-opt pcmpl-ack-short-options)))
153 (pcomplete-here* (pcomplete-dirs-or-entries)))))
154
155 ;;;###autoload
156 (defalias 'pcomplete/ack-grep 'pcomplete/ack)
157
158 (provide 'pcmpl-ack)
159 ;;; pcmpl-ack.el ends here