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 '("\\`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
) "Makefile"))
116 (if (not (file-readable-p makefile
))
117 (unless minus-f
(list "-f"))
119 (insert-file-contents-literally makefile
)
120 (while (re-search-forward
121 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t
)
122 (setq rules
(append (split-string (match-string 1)) rules
))))
123 (pcomplete-uniqify-list rules
))))
125 (defcustom pcmpl-gnu-tarfile-regexp
126 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
127 "*A regexp which matches any tar archive."
131 (defvar pcmpl-gnu-tar-buffer nil
)
134 (defun pcomplete/tar
()
135 "Completion for the GNU tar utility."
136 ;; options that end in an equal sign will want further completion...
137 (let (saw-option complete-within
)
138 (setq pcomplete-suffix-list
(cons ?
= pcomplete-suffix-list
))
139 (while (pcomplete-match "^-" 0)
141 (if (pcomplete-match "^--" 0)
142 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
172 "--ignore-failed-read"
180 "--listed-incremental"
182 "--modification-time"
184 "--new-volume-script="
197 "--preserve-permissions"
198 "--read-full-records"
216 "--use-compress-program="
221 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
223 ((pcomplete-match "\\`--after-date=" 0)
225 ((pcomplete-match "\\`--backup=" 0)
227 ((pcomplete-match "\\`--blocking-factor=" 0)
229 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
230 (pcomplete-here* (pcomplete-dirs)
231 (pcomplete-match-string 1 0)))
232 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
233 (pcomplete-here* (pcomplete-entries)
234 (pcomplete-match-string 1 0)))
235 ((pcomplete-match "\\`--exclude=" 0)
237 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
238 (setq complete-within t
))
239 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
240 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp
)
241 (pcomplete-match-string 1 0)))
242 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
243 (pcomplete-here* (pcomplete-entries)
244 (pcomplete-match-string 1 0)))
245 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
246 (pcomplete-here* (pcmpl-unix-group-names)
247 (pcomplete-match-string 1 0)))
248 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
249 (pcomplete-here* (pcomplete-entries)
250 (pcomplete-match-string 1 0)))
251 ((pcomplete-match "\\`--label=" 0)
253 ((pcomplete-match "\\`--mode=" 0)
255 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
256 (pcomplete-here* (pcomplete-entries)
257 (pcomplete-match-string 1 0)))
258 ((pcomplete-match "\\`--newer=" 0)
260 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
261 (pcomplete-here* (pcmpl-unix-user-names)
262 (pcomplete-match-string 1 0)))
263 ((pcomplete-match "\\`--record-size=" 0)
265 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
266 (pcomplete-here* (funcall pcomplete-command-completion-function
)
267 (pcomplete-match-string 1 0)))
268 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
269 (pcomplete-here* (pcomplete-entries)
270 (pcomplete-match-string 1 0)))
271 ((pcomplete-match "\\`--suffix=" 0)
273 ((pcomplete-match "\\`--tape-length=" 0)
275 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
276 (pcomplete-here* (funcall pcomplete-command-completion-function
)
277 (pcomplete-match-string 1 0)))
278 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
279 (pcomplete-here* (pcomplete-entries)
280 (pcomplete-match-string 1 0)))))
281 (setq pcomplete-suffix-list
(cdr pcomplete-suffix-list
))
284 (mapcar 'char-to-string
286 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
287 (if (pcomplete-match "[xt]" 'first
1)
288 (setq complete-within t
)))
289 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp
))
290 (setq pcmpl-gnu-tar-buffer
(find-file-noselect (pcomplete-arg 1)))
291 (while (pcomplete-here
293 (with-current-buffer pcmpl-gnu-tar-buffer
297 (tar-header-name (cdr entry
))))
303 (defalias 'pcomplete
/gdb
'pcomplete
/xargs
)
305 ;;; pcmpl-gnu.el ends here