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/>.
30 (defgroup pcmpl-gnu nil
31 "Completions for GNU project tools."
36 (defcustom pcmpl-gnu-makefile-regexps
37 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
38 "A list of regexps that will match Makefile names."
39 :type
'(repeat regexp
)
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
52 (let ((args pcomplete-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."
64 (when (and (file-readable-p entry
)
65 (file-regular-p entry
))
66 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
68 (or (and unzip-p zipped
)
69 (and (not unzip-p
) (not zipped
)))))))))
72 (defun pcomplete/bzip2
()
73 "Completion for `bzip2'."
74 (pcomplete-opt "hdzkftcqvLVs123456789")
75 (while (pcomplete-here
76 (pcmpl-gnu-bzipped-files
78 (let ((args pcomplete-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."
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
)))))))))
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
))
108 (nconc names
(pcomplete-entries (car reg
)))
109 (setq reg
(cdr reg
)))
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")
120 (if (not (file-readable-p makefile
))
121 (unless minus-f
(list "-f"))
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."
135 (defvar pcmpl-gnu-tar-buffer nil
)
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)
145 (if (pcomplete-match "^--" 0)
146 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
176 "--ignore-failed-read"
184 "--listed-incremental"
186 "--modification-time"
188 "--new-volume-script="
201 "--preserve-permissions"
202 "--read-full-records"
220 "--use-compress-program="
225 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
227 ((pcomplete-match "\\`--after-date=" 0)
229 ((pcomplete-match "\\`--backup=" 0)
231 ((pcomplete-match "\\`--blocking-factor=" 0)
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)
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)
257 ((pcomplete-match "\\`--mode=" 0)
259 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
260 (pcomplete-here* (pcomplete-entries)
261 (pcomplete-match-string 1 0)))
262 ((pcomplete-match "\\`--newer=" 0)
264 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
265 (pcomplete-here* (pcmpl-unix-user-names)
266 (pcomplete-match-string 1 0)))
267 ((pcomplete-match "\\`--record-size=" 0)
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)
277 ((pcomplete-match "\\`--tape-length=" 0)
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
))
288 (mapcar 'char-to-string
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
297 (with-current-buffer pcmpl-gnu-tar-buffer
301 (tar-header-name (cdr entry
))))
307 (defalias 'pcomplete
/gdb
'pcomplete
/xargs
)
309 ;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183
310 ;;; pcmpl-gnu.el ends here