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