Switch to recommended form of GPLv3 permissions notice.
[emacs.git] / lisp / pcmpl-gnu.el
blobd49624804f9adce47d9451e9a9d4f94da815e8a8
1 ;;; pcmpl-gnu.el --- completions for GNU project tools
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/>.
21 ;;; Commentary:
23 ;;; Code:
25 (provide 'pcmpl-gnu)
27 (require 'pcomplete)
28 (require 'pcmpl-unix)
30 (defgroup pcmpl-gnu nil
31 "Completions for GNU project tools."
32 :group 'pcomplete)
34 ;; User Variables:
36 (defcustom pcmpl-gnu-makefile-regexps
37 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
38 "*A list of regexps that will match Makefile names."
39 :type '(repeat regexp)
40 :group 'pcmpl-gnu)
42 ;; Functions:
44 ;;;###autoload
45 (defun pcomplete/gzip ()
46 "Completion for `gzip'."
47 (let ((pcomplete-help "(gzip)"))
48 (pcomplete-opt "cdfhlLnNqrStvV123456789")
49 (while (pcomplete-here
50 (pcmpl-gnu-zipped-files
51 (catch 'has-d-flag
52 (let ((args pcomplete-args))
53 (while args
54 (if (string-match "\\`-.*[dt]" (car args))
55 (throw 'has-d-flag t))
56 (setq args (cdr args))))))))))
58 (defun pcmpl-gnu-zipped-files (unzip-p)
59 "Find all zipped or unzipped files: the inverse of UNZIP-P."
60 (pcomplete-entries
61 nil
62 (function
63 (lambda (entry)
64 (when (and (file-readable-p entry)
65 (file-regular-p entry))
66 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
67 entry)))
68 (or (and unzip-p zipped)
69 (and (not unzip-p) (not zipped)))))))))
71 ;;;###autoload
72 (defun pcomplete/bzip2 ()
73 "Completion for `bzip2'."
74 (pcomplete-opt "hdzkftcqvLVs123456789")
75 (while (pcomplete-here
76 (pcmpl-gnu-bzipped-files
77 (catch 'has-d-flag
78 (let ((args pcomplete-args))
79 (while args
80 (if (string-match "\\`-.*[dt]" (car args))
81 (throw 'has-d-flag t))
82 (setq args (cdr args)))))))))
84 (defun pcmpl-gnu-bzipped-files (unzip-p)
85 "Find all zipped or unzipped files: the inverse of UNZIP-P."
86 (pcomplete-entries
87 nil
88 (function
89 (lambda (entry)
90 (when (and (file-readable-p entry)
91 (file-regular-p entry))
92 (let ((zipped (string-match "\\.\\(t?z2\\|bz2\\)\\'" entry)))
93 (or (and unzip-p zipped)
94 (and (not unzip-p) (not zipped)))))))))
96 ;;;###autoload
97 (defun pcomplete/make ()
98 "Completion for GNU `make'."
99 (let ((pcomplete-help "(make)Top"))
100 (pcomplete-opt "bmC/def(pcmpl-gnu-makefile-names)hiI/j?kl?no.pqrsStvwW.")
101 (while (pcomplete-here (pcmpl-gnu-make-rule-names) nil 'identity))))
103 (defun pcmpl-gnu-makefile-names ()
104 "Return a list of possible makefile names."
105 (let ((names (list t))
106 (reg pcmpl-gnu-makefile-regexps))
107 (while reg
108 (nconc names (pcomplete-entries (car reg)))
109 (setq reg (cdr reg)))
110 (cdr names)))
112 (defun pcmpl-gnu-make-rule-names ()
113 "Return a list of possible make rule names in MAKEFILE."
114 (let* ((minus-f (member "-f" pcomplete-args))
115 (makefile (or (cadr minus-f)
116 (if (file-exists-p "GNUmakefile")
117 "GNUmakefile"
118 "Makefile")))
119 rules)
120 (if (not (file-readable-p makefile))
121 (unless minus-f (list "-f"))
122 (with-temp-buffer
123 (insert-file-contents-literally makefile)
124 (while (re-search-forward
125 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t)
126 (setq rules (append (split-string (match-string 1)) rules))))
127 (pcomplete-uniqify-list rules))))
129 (defcustom pcmpl-gnu-tarfile-regexp
130 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
131 "*A regexp which matches any tar archive."
132 :type 'regexp
133 :group 'pcmpl-gnu)
135 (defvar pcmpl-gnu-tar-buffer nil)
137 ;;;###autoload
138 (defun pcomplete/tar ()
139 "Completion for the GNU tar utility."
140 ;; options that end in an equal sign will want further completion...
141 (let (saw-option complete-within)
142 (setq pcomplete-suffix-list (cons ?= pcomplete-suffix-list))
143 (while (pcomplete-match "^-" 0)
144 (setq saw-option t)
145 (if (pcomplete-match "^--" 0)
146 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
147 (pcomplete-here*
148 '("--absolute-names"
149 "--after-date="
150 "--append"
151 "--atime-preserve"
152 "--backup"
153 "--block-number"
154 "--blocking-factor="
155 "--catenate"
156 "--checkpoint"
157 "--compare"
158 "--compress"
159 "--concatenate"
160 "--confirmation"
161 "--create"
162 "--delete"
163 "--dereference"
164 "--diff"
165 "--directory="
166 "--exclude="
167 "--exclude-from="
168 "--extract"
169 "--file="
170 "--files-from="
171 "--force-local"
172 "--get"
173 "--group="
174 "--gzip"
175 "--help"
176 "--ignore-failed-read"
177 "--ignore-zeros"
178 "--incremental"
179 "--info-script="
180 "--interactive"
181 "--keep-old-files"
182 "--label="
183 "--list"
184 "--listed-incremental"
185 "--mode="
186 "--modification-time"
187 "--multi-volume"
188 "--new-volume-script="
189 "--newer="
190 "--newer-mtime"
191 "--no-recursion"
192 "--null"
193 "--numeric-owner"
194 "--old-archive"
195 "--one-file-system"
196 "--owner="
197 "--portability"
198 "--posix"
199 "--preserve"
200 "--preserve-order"
201 "--preserve-permissions"
202 "--read-full-records"
203 "--record-size="
204 "--recursive-unlink"
205 "--remove-files"
206 "--rsh-command="
207 "--same-order"
208 "--same-owner"
209 "--same-permissions"
210 "--sparse"
211 "--starting-file="
212 "--suffix="
213 "--tape-length="
214 "--to-stdout"
215 "--totals"
216 "--uncompress"
217 "--ungzip"
218 "--unlink-first"
219 "--update"
220 "--use-compress-program="
221 "--verbose"
222 "--verify"
223 "--version"
224 "--volno-file=")))
225 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
226 (cond
227 ((pcomplete-match "\\`--after-date=" 0)
228 (pcomplete-here*))
229 ((pcomplete-match "\\`--backup=" 0)
230 (pcomplete-here*))
231 ((pcomplete-match "\\`--blocking-factor=" 0)
232 (pcomplete-here*))
233 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
234 (pcomplete-here* (pcomplete-dirs)
235 (pcomplete-match-string 1 0)))
236 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
237 (pcomplete-here* (pcomplete-entries)
238 (pcomplete-match-string 1 0)))
239 ((pcomplete-match "\\`--exclude=" 0)
240 (pcomplete-here*))
241 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
242 (setq complete-within t))
243 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
244 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)
245 (pcomplete-match-string 1 0)))
246 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
247 (pcomplete-here* (pcomplete-entries)
248 (pcomplete-match-string 1 0)))
249 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
250 (pcomplete-here* (pcmpl-unix-group-names)
251 (pcomplete-match-string 1 0)))
252 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
253 (pcomplete-here* (pcomplete-entries)
254 (pcomplete-match-string 1 0)))
255 ((pcomplete-match "\\`--label=" 0)
256 (pcomplete-here*))
257 ((pcomplete-match "\\`--mode=" 0)
258 (pcomplete-here*))
259 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
260 (pcomplete-here* (pcomplete-entries)
261 (pcomplete-match-string 1 0)))
262 ((pcomplete-match "\\`--newer=" 0)
263 (pcomplete-here*))
264 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
265 (pcomplete-here* (pcmpl-unix-user-names)
266 (pcomplete-match-string 1 0)))
267 ((pcomplete-match "\\`--record-size=" 0)
268 (pcomplete-here*))
269 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
270 (pcomplete-here* (funcall pcomplete-command-completion-function)
271 (pcomplete-match-string 1 0)))
272 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
273 (pcomplete-here* (pcomplete-entries)
274 (pcomplete-match-string 1 0)))
275 ((pcomplete-match "\\`--suffix=" 0)
276 (pcomplete-here*))
277 ((pcomplete-match "\\`--tape-length=" 0)
278 (pcomplete-here*))
279 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
280 (pcomplete-here* (funcall pcomplete-command-completion-function)
281 (pcomplete-match-string 1 0)))
282 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
283 (pcomplete-here* (pcomplete-entries)
284 (pcomplete-match-string 1 0)))))
285 (setq pcomplete-suffix-list (cdr pcomplete-suffix-list))
286 (unless saw-option
287 (pcomplete-here
288 (mapcar 'char-to-string
289 (string-to-list
290 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
291 (if (pcomplete-match "[xt]" 'first 1)
292 (setq complete-within t)))
293 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp))
294 (setq pcmpl-gnu-tar-buffer (find-file-noselect (pcomplete-arg 1)))
295 (while (pcomplete-here
296 (if complete-within
297 (with-current-buffer pcmpl-gnu-tar-buffer
298 (mapcar
299 (function
300 (lambda (entry)
301 (tar-header-name (cdr entry))))
302 tar-parse-info))
303 (pcomplete-entries))
304 nil 'identity))))
306 ;;;###autoload
307 (defalias 'pcomplete/gdb 'pcomplete/xargs)
309 ;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183
310 ;;; pcmpl-gnu.el ends here