1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 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/>.
23 ;; These functions provide completion rules for RedHat's `rpm' tool.
31 (defgroup pcmpl-rpm nil
32 "Functions for dealing with CVS completions."
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))
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\\'"))
55 (defun pcomplete/rpm
()
56 "Completion for RedHat's `rpm' command.
57 These rules were taken from the output of `rpm --help' on a RedHat 6.1
58 system. They follow my interpretation of what followed, but since I'm
59 not a major rpm user/builder, please send me any corrections you find.
60 You can use \\[report-emacs-bug] to do so."
62 (while (<= pcomplete-index pcomplete-last
)
64 (if (pcomplete-match "^--\\(.*\\)" 0)
84 (pcomplete-opt "vqVyiUebtK")))
86 ; -t<stage> <tarball> - build package, where <stage> is one of:
87 ; p - prep (unpack sources and apply patches)
88 ; l - list check (do some cursory checks on %files)
89 ; c - compile (prep and compile)
90 ; i - install (prep, compile, install)
91 ; b - binary package (prep, compile, install, package)
92 ; a - bin/src package (prep, compile, install, package)
95 (pcomplete-match "-[^-]*q"))
97 (if (pcomplete-match "^--\\(.*\\)" 0)
103 "--ftpport" ;nyi for the next four
117 ((pcomplete-test "--dbpath")
118 (pcomplete-here* (pcomplete-dirs)))
119 ((pcomplete-test "--queryformat")
121 ((pcomplete-test "--rcfile")
122 (pcomplete-here* (pcomplete-entries)))
123 ((pcomplete-test "--root")
124 (pcomplete-here* (pcomplete-dirs)))
125 ((pcomplete-test "--scripts")
126 (if (pcomplete-match "^--\\(.*\\)" 0)
127 (pcomplete-here* '("--triggers"))))
128 ((pcomplete-test "--triggeredby")
129 (pcomplete-here* (pcmpl-rpm-packages)))
130 ((pcomplete-test "--whatprovides")
132 (pcmpl-rpm-all-query "--provides")))
133 ((pcomplete-test "--whatrequires")
135 (pcmpl-rpm-all-query "--requires")))))
136 (if (pcomplete-match "^-" 0)
137 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
138 (if (pcomplete-test "-[^-]*p" 'first
1)
139 (pcomplete-here (pcmpl-rpm-files))
140 (pcomplete-here (pcmpl-rpm-packages))))))
141 ((pcomplete-test "--pipe")
142 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
143 ((pcomplete-test "--rmsource")
144 (pcomplete-here* (pcomplete-entries))
145 (throw 'pcomplete-completions nil
))
146 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
147 (pcomplete-here (pcmpl-rpm-files))
148 (throw 'pcomplete-completions nil
))
149 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
150 (while (pcomplete-here (pcmpl-rpm-files))))
151 ((or (eq mode
'checksig
)
152 (pcomplete-test "--checksig"))
153 (setq mode
'checksig
)
154 (if (pcomplete-match "^--\\(.*\\)" 0)
162 ((pcomplete-test "--rcfile")
163 (pcomplete-here* (pcomplete-entries)))))
164 (if (pcomplete-match "^-" 0)
166 (pcomplete-here (pcmpl-rpm-files)))))
167 ((or (eq mode
'rebuilddb
)
168 (pcomplete-test "--rebuilddb"))
169 (setq mode
'rebuilddb
)
170 (if (pcomplete-match "^--\\(.*\\)" 0)
177 ((pcomplete-test "--dbpath")
178 (pcomplete-here* (pcomplete-dirs)))
179 ((pcomplete-test "--root")
180 (pcomplete-here* (pcomplete-dirs)))
181 ((pcomplete-test "--rcfile")
182 (pcomplete-here* (pcomplete-entries)))))
183 (if (pcomplete-match "^-" 0)
186 ((memq mode
'(install upgrade
))
187 (if (pcomplete-match "^--\\(.*\\)" 0)
207 (if (eq mode
'upgrade
)
217 ((pcomplete-test "--dbpath")
218 (pcomplete-here* (pcomplete-dirs)))
219 ((pcomplete-test "--relocate")
221 ((pcomplete-test "--rcfile")
222 (pcomplete-here* (pcomplete-entries)))
223 ((pcomplete-test "--excludepath")
224 (pcomplete-here* (pcomplete-entries)))
225 ((pcomplete-test "--root")
226 (pcomplete-here* (pcomplete-dirs)))
227 ((pcomplete-test "--prefix")
228 (pcomplete-here* (pcomplete-dirs)))))
229 (if (pcomplete-match "^-" 0)
231 (pcomplete-here (pcmpl-rpm-files)))))
232 ((or (pcomplete-test "--install")
233 (pcomplete-match "-[^-]*i"))
234 (setq mode
'install
))
235 ((or (pcomplete-test "--upgrade")
236 (pcomplete-match "-[^-]*U"))
237 (setq mode
'upgrade
))
238 ((or (eq mode
'erase
)
239 (pcomplete-test "--erase")
240 (pcomplete-match "-[^-]*e"))
242 (if (pcomplete-match "^--\\(.*\\)" 0)
255 ((pcomplete-test "--dbpath")
256 (pcomplete-here* (pcomplete-dirs)))
257 ((pcomplete-test "--rcfile")
258 (pcomplete-here* (pcomplete-entries)))
259 ((pcomplete-test "--root")
260 (pcomplete-here* (pcomplete-dirs)))))
261 (if (pcomplete-match "^-" 0)
263 (pcomplete-here (pcmpl-rpm-packages)))))
264 ((or (eq mode
'verify
)
265 (pcomplete-test "--verify"))
267 (if (pcomplete-match "^--\\(.*\\)" 0)
280 ((pcomplete-test "--dbpath")
281 (pcomplete-here* (pcomplete-dirs)))
282 ((pcomplete-test "--rcfile")
283 (pcomplete-here* (pcomplete-entries)))
284 ((pcomplete-test "--root")
285 (pcomplete-here* (pcomplete-dirs)))
286 ((pcomplete-test "--triggeredby")
287 (pcomplete-here* (pcmpl-rpm-packages)))
288 ((pcomplete-test "--whatprovides")
290 (pcmpl-rpm-all-query "--provides")))
291 ((pcomplete-test "--whatrequires")
293 (pcmpl-rpm-all-query "--requires")))))
294 (if (pcomplete-match "^-" 0)
295 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
296 (pcomplete-here (pcmpl-rpm-packages)))))
297 ((or (memq mode
'(build test
))
298 (pcomplete-match "\\`-[bt]"))
299 (setq mode
(if (pcomplete-match "\\`-b")
302 (if (pcomplete-match "^--\\(.*\\)" 0)
315 ((pcomplete-test "--buildroot")
316 (pcomplete-here* (pcomplete-dirs)))
317 ((pcomplete-test "--rcfile")
318 (pcomplete-here* (pcomplete-entries)))
319 ((pcomplete-test "--timecheck")
321 (if (pcomplete-match "^-" 0)
325 (pcomplete-dirs-or-entries "\\.tar\\'")
326 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
328 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
330 ;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
331 ;;; pcmpl-rpm.el ends here