1 ;;; pcmpl-gnu --- completions for GNU project tools
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
29 (defgroup pcmpl-gnu nil
30 "Completions for GNU project tools."
35 (defcustom pcmpl-gnu-makefile-regexps
36 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
37 "*A list of regexps that will match Makefile names."
38 :type '(repeat regexp)
44 (defun pcomplete/gzip ()
45 "Completion for `gzip'."
46 (let ((pcomplete-help "(gzip)"))
47 (pcomplete-opt "cdfhlLnNqrStvV123456789")
48 (while (pcomplete-here
49 (pcmpl-gnu-zipped-files
51 (let ((args pcomplete-args))
53 (if (string-match "\\`-.*[dt]" (car args))
54 (throw 'has-d-flag t))
55 (setq args (cdr args))))))))))
57 (defun pcmpl-gnu-zipped-files (unzip-p)
58 "Find all zipped or unzipped files: the inverse of UNZIP-P."
63 (when (and (file-readable-p entry)
64 (file-regular-p entry))
65 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
67 (or (and unzip-p zipped)
68 (and (not unzip-p) (not zipped)))))))))
71 (defun pcomplete/bzip2 ()
72 "Completion for `bzip2'."
73 (pcomplete-opt "hdzkftcqvLVs123456789")
74 (while (pcomplete-here
75 (pcmpl-gnu-bzipped-files
77 (let ((args pcomplete-args))
79 (if (string-match "\\`-.*[dt]" (car args))
80 (throw 'has-d-flag t))
81 (setq args (cdr args)))))))))
83 (defun pcmpl-gnu-bzipped-files (unzip-p)
84 "Find all zipped or unzipped files: the inverse of UNZIP-P."
89 (when (and (file-readable-p entry)
90 (file-regular-p entry))
91 (let ((zipped (string-match "\\.\\(t?z2\\|bz2\\)\\'" entry)))
92 (or (and unzip-p zipped)
93 (and (not unzip-p) (not zipped)))))))))
96 (defun pcomplete/make ()
97 "Completion for GNU `make'."
98 (let ((pcomplete-help "(make)Top"))
99 (pcomplete-opt "bmC/def(pcmpl-gnu-makefile-names)hiI/j?kl?no.pqrsStvwW.")
100 (while (pcomplete-here (pcmpl-gnu-make-rule-names) nil 'identity))))
102 (defun pcmpl-gnu-makefile-names ()
103 "Return a list of possible makefile names."
104 (let ((names (list t))
105 (reg pcmpl-gnu-makefile-regexps))
107 (nconc names (pcomplete-entries (car reg)))
108 (setq reg (cdr reg)))
111 (defun pcmpl-gnu-make-rule-names ()
112 "Return a list of possible make rule names in MAKEFILE."
113 (let* ((minus-f (member "-f" pcomplete-args))
114 (makefile (or (cadr minus-f)
115 (if (file-exists-p "GNUmakefile")
119 (if (not (file-readable-p makefile))
120 (unless minus-f (list "-f"))
122 (insert-file-contents-literally makefile)
123 (while (re-search-forward
124 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t)
125 (setq rules (append (split-string (match-string 1)) rules))))
126 (pcomplete-uniqify-list rules))))
128 (defcustom pcmpl-gnu-tarfile-regexp
129 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
130 "*A regexp which matches any tar archive."
134 (defvar pcmpl-gnu-tar-buffer nil)
137 (defun pcomplete/tar ()
138 "Completion for the GNU tar utility."
139 ;; options that end in an equal sign will want further completion...
140 (let (saw-option complete-within)
141 (setq pcomplete-suffix-list (cons ?= pcomplete-suffix-list))
142 (while (pcomplete-match "^-" 0)
144 (if (pcomplete-match "^--" 0)
145 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
175 "--ignore-failed-read"
183 "--listed-incremental"
185 "--modification-time"
187 "--new-volume-script="
200 "--preserve-permissions"
201 "--read-full-records"
219 "--use-compress-program="
224 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
226 ((pcomplete-match "\\`--after-date=" 0)
228 ((pcomplete-match "\\`--backup=" 0)
230 ((pcomplete-match "\\`--blocking-factor=" 0)
232 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
233 (pcomplete-here* (pcomplete-dirs)
234 (pcomplete-match-string 1 0)))
235 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
236 (pcomplete-here* (pcomplete-entries)
237 (pcomplete-match-string 1 0)))
238 ((pcomplete-match "\\`--exclude=" 0)
240 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
241 (setq complete-within t))
242 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
243 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)
244 (pcomplete-match-string 1 0)))
245 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
246 (pcomplete-here* (pcomplete-entries)
247 (pcomplete-match-string 1 0)))
248 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
249 (pcomplete-here* (pcmpl-unix-group-names)
250 (pcomplete-match-string 1 0)))
251 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
252 (pcomplete-here* (pcomplete-entries)
253 (pcomplete-match-string 1 0)))
254 ((pcomplete-match "\\`--label=" 0)
256 ((pcomplete-match "\\`--mode=" 0)
258 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
259 (pcomplete-here* (pcomplete-entries)
260 (pcomplete-match-string 1 0)))
261 ((pcomplete-match "\\`--newer=" 0)
263 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
264 (pcomplete-here* (pcmpl-unix-user-names)
265 (pcomplete-match-string 1 0)))
266 ((pcomplete-match "\\`--record-size=" 0)
268 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
269 (pcomplete-here* (funcall pcomplete-command-completion-function)
270 (pcomplete-match-string 1 0)))
271 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
272 (pcomplete-here* (pcomplete-entries)
273 (pcomplete-match-string 1 0)))
274 ((pcomplete-match "\\`--suffix=" 0)
276 ((pcomplete-match "\\`--tape-length=" 0)
278 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
279 (pcomplete-here* (funcall pcomplete-command-completion-function)
280 (pcomplete-match-string 1 0)))
281 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
282 (pcomplete-here* (pcomplete-entries)
283 (pcomplete-match-string 1 0)))))
284 (setq pcomplete-suffix-list (cdr pcomplete-suffix-list))
287 (mapcar 'char-to-string
289 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
290 (if (pcomplete-match "[xt]" 'first 1)
291 (setq complete-within t)))
292 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp))
293 (setq pcmpl-gnu-tar-buffer (find-file-noselect (pcomplete-arg 1)))
294 (while (pcomplete-here
296 (with-current-buffer pcmpl-gnu-tar-buffer
300 (tar-header-name (cdr entry))))
306 (defalias 'pcomplete/gdb 'pcomplete/xargs)
308 ;;; pcmpl-gnu.el ends here