1 ;;; pcmpl-gnu.el --- completions for GNU project tools
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009 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 (pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps
"\\|")))
107 (defun pcmpl-gnu-make-rule-names ()
108 "Return a list of possible make rule names in MAKEFILE."
109 (let* ((minus-f (member "-f" pcomplete-args
))
110 (makefile (or (cadr minus-f
)
111 (if (file-exists-p "GNUmakefile")
115 (if (not (file-readable-p makefile
))
116 (unless minus-f
(list "-f"))
118 (insert-file-contents-literally makefile
)
119 (while (re-search-forward
120 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t
)
121 (setq rules
(append (split-string (match-string 1)) rules
))))
122 (pcomplete-uniqify-list rules
))))
124 (defcustom pcmpl-gnu-tarfile-regexp
125 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
126 "A regexp which matches any tar archive."
130 (defvar pcmpl-gnu-tar-buffer nil
)
132 ;; Only used in tar-mode buffers.
133 (defvar tar-parse-info
)
134 (declare-function tar-header-name
"tar-mode" t t
)
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 ;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183
309 ;;; pcmpl-gnu.el ends here