* keyboard.c (parse_modifiers_uncached, parse_modifiers):
[emacs.git] / lisp / pcmpl-rpm.el
blob475215b162257d5257a73f31b875f8f051d0808d
1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
5 ;; Package: pcomplete
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs 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.
14 ;; GNU Emacs 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.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; These functions provide completion rules for the `rpm' command.
26 ;;; Code:
28 (require 'pcomplete)
30 ;; Functions:
32 (defsubst pcmpl-rpm-packages ()
33 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
35 (defun pcmpl-rpm-all-query (flag)
36 (message "Querying all packages with `%s'..." flag)
37 (let ((pkgs (pcmpl-rpm-packages))
38 (provs (list t)))
39 (while pkgs
40 (nconc provs (split-string
41 (pcomplete-process-result
42 "rpm" "-q" (car pkgs) flag)))
43 (setq pkgs (cdr pkgs)))
44 (pcomplete-uniqify-list (cdr provs))))
46 (defsubst pcmpl-rpm-files ()
47 (pcomplete-dirs-or-entries "\\.rpm\\'"))
49 ;;;###autoload
50 (defun pcomplete/rpm ()
51 "Completion for the `rpm' command."
52 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
53 (let (mode)
54 (while (<= pcomplete-index pcomplete-last)
55 (unless mode
56 (if (pcomplete-match "^--\\(.*\\)" 0)
57 (pcomplete-here*
58 '("--addsign"
59 "--checksig"
60 "--erase"
61 "--help"
62 "--initdb"
63 "--install"
64 "--pipe"
65 "--querytags"
66 "--rebuild"
67 "--rebuilddb"
68 "--recompile"
69 "--resign"
70 "--rmsource"
71 "--setperms"
72 "--setugids"
73 "--upgrade"
74 "--verify"
75 "--version"))
76 (pcomplete-opt "vqVyiUebtK")))
77 ; -b<stage> <spec>
78 ; -t<stage> <tarball> - build package, where <stage> is one of:
79 ; p - prep (unpack sources and apply patches)
80 ; l - list check (do some cursory checks on %files)
81 ; c - compile (prep and compile)
82 ; i - install (prep, compile, install)
83 ; b - binary package (prep, compile, install, package)
84 ; a - bin/src package (prep, compile, install, package)
85 (cond
86 ((or (eq mode 'query)
87 (pcomplete-match "-[^-]*q"))
88 (setq mode 'query)
89 (if (pcomplete-match "^--\\(.*\\)" 0)
90 (progn
91 (pcomplete-here*
92 '("--changelog"
93 "--dbpath"
94 "--dump"
95 "--ftpport" ;nyi for the next four
96 "--ftpproxy"
97 "--httpport"
98 "--httpproxy"
99 "--provides"
100 "--queryformat"
101 "--rcfile"
102 "--requires"
103 "--root"
104 "--scripts"
105 "--triggeredby"
106 "--whatprovides"
107 "--whatrequires"))
108 (cond
109 ((pcomplete-test "--dbpath")
110 (pcomplete-here* (pcomplete-dirs)))
111 ((pcomplete-test "--queryformat")
112 (pcomplete-here*))
113 ((pcomplete-test "--rcfile")
114 (pcomplete-here* (pcomplete-entries)))
115 ((pcomplete-test "--root")
116 (pcomplete-here* (pcomplete-dirs)))
117 ((pcomplete-test "--scripts")
118 (if (pcomplete-match "^--\\(.*\\)" 0)
119 (pcomplete-here* '("--triggers"))))
120 ((pcomplete-test "--triggeredby")
121 (pcomplete-here* (pcmpl-rpm-packages)))
122 ((pcomplete-test "--whatprovides")
123 (pcomplete-here*
124 (pcmpl-rpm-all-query "--provides")))
125 ((pcomplete-test "--whatrequires")
126 (pcomplete-here*
127 (pcmpl-rpm-all-query "--requires")))))
128 (if (pcomplete-match "^-" 0)
129 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
130 (if (pcomplete-test "-[^-]*p" 'first 1)
131 (pcomplete-here (pcmpl-rpm-files))
132 (pcomplete-here (pcmpl-rpm-packages))))))
133 ((pcomplete-test "--pipe")
134 (pcomplete-here* (funcall pcomplete-command-completion-function)))
135 ((pcomplete-test "--rmsource")
136 (pcomplete-here* (pcomplete-entries))
137 (throw 'pcomplete-completions nil))
138 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
139 (pcomplete-here (pcmpl-rpm-files))
140 (throw 'pcomplete-completions nil))
141 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
142 (while (pcomplete-here (pcmpl-rpm-files))))
143 ((or (eq mode 'checksig)
144 (pcomplete-test "--checksig"))
145 (setq mode 'checksig)
146 (if (pcomplete-match "^--\\(.*\\)" 0)
147 (progn
148 (pcomplete-here*
149 '("--nopgp"
150 "--nogpg"
151 "--nomd5"
152 "--rcfile"))
153 (cond
154 ((pcomplete-test "--rcfile")
155 (pcomplete-here* (pcomplete-entries)))))
156 (if (pcomplete-match "^-" 0)
157 (pcomplete-opt "v")
158 (pcomplete-here (pcmpl-rpm-files)))))
159 ((or (eq mode 'rebuilddb)
160 (pcomplete-test "--rebuilddb"))
161 (setq mode 'rebuilddb)
162 (if (pcomplete-match "^--\\(.*\\)" 0)
163 (progn
164 (pcomplete-here*
165 '("--dbpath"
166 "--root"
167 "--rcfile"))
168 (cond
169 ((pcomplete-test "--dbpath")
170 (pcomplete-here* (pcomplete-dirs)))
171 ((pcomplete-test "--root")
172 (pcomplete-here* (pcomplete-dirs)))
173 ((pcomplete-test "--rcfile")
174 (pcomplete-here* (pcomplete-entries)))))
175 (if (pcomplete-match "^-" 0)
176 (pcomplete-opt "v")
177 (pcomplete-here))))
178 ((memq mode '(install upgrade))
179 (if (pcomplete-match "^--\\(.*\\)" 0)
180 (progn
181 (pcomplete-here*
182 (append
183 '("--allfiles"
184 "--badreloc"
185 "--dbpath"
186 "--excludedocs"
187 "--excludepath"
188 "--force"
189 "--hash"
190 "--ignorearch"
191 "--ignoreos"
192 "--ignoresize"
193 "--includedocs"
194 "--justdb"
195 "--nodeps"
196 "--noorder"
197 "--noscripts"
198 "--notriggers")
199 (if (eq mode 'upgrade)
200 '("--oldpackage"))
201 '("--percent"
202 "--prefix"
203 "--rcfile"
204 "--relocate"
205 "--replacefiles"
206 "--replacepkgs"
207 "--root")))
208 (cond
209 ((pcomplete-test "--dbpath")
210 (pcomplete-here* (pcomplete-dirs)))
211 ((pcomplete-test "--relocate")
212 (pcomplete-here*))
213 ((pcomplete-test "--rcfile")
214 (pcomplete-here* (pcomplete-entries)))
215 ((pcomplete-test "--excludepath")
216 (pcomplete-here* (pcomplete-entries)))
217 ((pcomplete-test "--root")
218 (pcomplete-here* (pcomplete-dirs)))
219 ((pcomplete-test "--prefix")
220 (pcomplete-here* (pcomplete-dirs)))))
221 (if (pcomplete-match "^-" 0)
222 (pcomplete-opt "vh")
223 (pcomplete-here (pcmpl-rpm-files)))))
224 ((or (pcomplete-test "--install")
225 (pcomplete-match "-[^-]*i"))
226 (setq mode 'install))
227 ((or (pcomplete-test "--upgrade")
228 (pcomplete-match "-[^-]*U"))
229 (setq mode 'upgrade))
230 ((or (eq mode 'erase)
231 (pcomplete-test "--erase")
232 (pcomplete-match "-[^-]*e"))
233 (setq mode 'erase)
234 (if (pcomplete-match "^--\\(.*\\)" 0)
235 (progn
236 (pcomplete-here*
237 '("--allmatches"
238 "--dbpath"
239 "--justdb"
240 "--nodeps"
241 "--noorder"
242 "--noscripts"
243 "--notriggers"
244 "--rcfile"
245 "--root"))
246 (cond
247 ((pcomplete-test "--dbpath")
248 (pcomplete-here* (pcomplete-dirs)))
249 ((pcomplete-test "--rcfile")
250 (pcomplete-here* (pcomplete-entries)))
251 ((pcomplete-test "--root")
252 (pcomplete-here* (pcomplete-dirs)))))
253 (if (pcomplete-match "^-" 0)
254 (pcomplete-opt "v")
255 (pcomplete-here (pcmpl-rpm-packages)))))
256 ((or (eq mode 'verify)
257 (pcomplete-test "--verify"))
258 (setq mode 'verify)
259 (if (pcomplete-match "^--\\(.*\\)" 0)
260 (progn
261 (pcomplete-here*
262 '("--dbpath"
263 "--nodeps"
264 "--nofiles"
265 "--nomd5"
266 "--rcfile"
267 "--root"
268 "--triggeredby"
269 "--whatprovides"
270 "--whatrequires"))
271 (cond
272 ((pcomplete-test "--dbpath")
273 (pcomplete-here* (pcomplete-dirs)))
274 ((pcomplete-test "--rcfile")
275 (pcomplete-here* (pcomplete-entries)))
276 ((pcomplete-test "--root")
277 (pcomplete-here* (pcomplete-dirs)))
278 ((pcomplete-test "--triggeredby")
279 (pcomplete-here* (pcmpl-rpm-packages)))
280 ((pcomplete-test "--whatprovides")
281 (pcomplete-here*
282 (pcmpl-rpm-all-query "--provides")))
283 ((pcomplete-test "--whatrequires")
284 (pcomplete-here*
285 (pcmpl-rpm-all-query "--requires")))))
286 (if (pcomplete-match "^-" 0)
287 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
288 (pcomplete-here (pcmpl-rpm-packages)))))
289 ((or (memq mode '(build test))
290 (pcomplete-match "\\`-[bt]"))
291 (setq mode (if (pcomplete-match "\\`-b")
292 'build
293 'test))
294 (if (pcomplete-match "^--\\(.*\\)" 0)
295 (progn
296 (pcomplete-here*
297 '("--buildroot"
298 "--clean"
299 "--nobuild"
300 "--rcfile"
301 "--rmsource"
302 "--short-circuit"
303 "--sign"
304 "--target"
305 "--timecheck"))
306 (cond
307 ((pcomplete-test "--buildroot")
308 (pcomplete-here* (pcomplete-dirs)))
309 ((pcomplete-test "--rcfile")
310 (pcomplete-here* (pcomplete-entries)))
311 ((pcomplete-test "--timecheck")
312 (pcomplete-here*))))
313 (if (pcomplete-match "^-" 0)
314 (pcomplete-opt "v")
315 (pcomplete-here
316 (if (eq mode 'test)
317 (pcomplete-dirs-or-entries "\\.tar\\'")
318 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
320 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
322 (provide 'pcmpl-rpm)
324 ;;; pcmpl-rpm.el ends here