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, or (at your option)
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; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
32 (defgroup pcmpl-gnu nil
33 "Completions for GNU project tools."
38 (defcustom pcmpl-gnu-makefile-regexps
39 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
40 "*A list of regexps that will match Makefile names."
41 :type
'(repeat regexp
)
47 (defun pcomplete/gzip
()
48 "Completion for `gzip'."
49 (let ((pcomplete-help "(gzip)"))
50 (pcomplete-opt "cdfhlLnNqrStvV123456789")
51 (while (pcomplete-here
52 (pcmpl-gnu-zipped-files
54 (let ((args pcomplete-args
))
56 (if (string-match "\\`-.*[dt]" (car args
))
57 (throw 'has-d-flag t
))
58 (setq args
(cdr args
))))))))))
60 (defun pcmpl-gnu-zipped-files (unzip-p)
61 "Find all zipped or unzipped files: the inverse of UNZIP-P."
66 (when (and (file-readable-p entry
)
67 (file-regular-p entry
))
68 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
70 (or (and unzip-p zipped
)
71 (and (not unzip-p
) (not zipped
)))))))))
74 (defun pcomplete/bzip2
()
75 "Completion for `bzip2'."
76 (pcomplete-opt "hdzkftcqvLVs123456789")
77 (while (pcomplete-here
78 (pcmpl-gnu-bzipped-files
80 (let ((args pcomplete-args
))
82 (if (string-match "\\`-.*[dt]" (car args
))
83 (throw 'has-d-flag t
))
84 (setq args
(cdr args
)))))))))
86 (defun pcmpl-gnu-bzipped-files (unzip-p)
87 "Find all zipped or unzipped files: the inverse of UNZIP-P."
92 (when (and (file-readable-p entry
)
93 (file-regular-p entry
))
94 (let ((zipped (string-match "\\.\\(t?z2\\|bz2\\)\\'" entry
)))
95 (or (and unzip-p zipped
)
96 (and (not unzip-p
) (not zipped
)))))))))
99 (defun pcomplete/make
()
100 "Completion for GNU `make'."
101 (let ((pcomplete-help "(make)Top"))
102 (pcomplete-opt "bmC/def(pcmpl-gnu-makefile-names)hiI/j?kl?no.pqrsStvwW.")
103 (while (pcomplete-here (pcmpl-gnu-make-rule-names) nil
'identity
))))
105 (defun pcmpl-gnu-makefile-names ()
106 "Return a list of possible makefile names."
107 (let ((names (list t
))
108 (reg pcmpl-gnu-makefile-regexps
))
110 (nconc names
(pcomplete-entries (car reg
)))
111 (setq reg
(cdr reg
)))
114 (defun pcmpl-gnu-make-rule-names ()
115 "Return a list of possible make rule names in MAKEFILE."
116 (let* ((minus-f (member "-f" pcomplete-args
))
117 (makefile (or (cadr minus-f
)
118 (if (file-exists-p "GNUmakefile")
122 (if (not (file-readable-p makefile
))
123 (unless minus-f
(list "-f"))
125 (insert-file-contents-literally makefile
)
126 (while (re-search-forward
127 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t
)
128 (setq rules
(append (split-string (match-string 1)) rules
))))
129 (pcomplete-uniqify-list rules
))))
131 (defcustom pcmpl-gnu-tarfile-regexp
132 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
133 "*A regexp which matches any tar archive."
137 (defvar pcmpl-gnu-tar-buffer nil
)
140 (defun pcomplete/tar
()
141 "Completion for the GNU tar utility."
142 ;; options that end in an equal sign will want further completion...
143 (let (saw-option complete-within
)
144 (setq pcomplete-suffix-list
(cons ?
= pcomplete-suffix-list
))
145 (while (pcomplete-match "^-" 0)
147 (if (pcomplete-match "^--" 0)
148 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
178 "--ignore-failed-read"
186 "--listed-incremental"
188 "--modification-time"
190 "--new-volume-script="
203 "--preserve-permissions"
204 "--read-full-records"
222 "--use-compress-program="
227 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
229 ((pcomplete-match "\\`--after-date=" 0)
231 ((pcomplete-match "\\`--backup=" 0)
233 ((pcomplete-match "\\`--blocking-factor=" 0)
235 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
236 (pcomplete-here* (pcomplete-dirs)
237 (pcomplete-match-string 1 0)))
238 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
239 (pcomplete-here* (pcomplete-entries)
240 (pcomplete-match-string 1 0)))
241 ((pcomplete-match "\\`--exclude=" 0)
243 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
244 (setq complete-within t
))
245 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
246 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp
)
247 (pcomplete-match-string 1 0)))
248 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
249 (pcomplete-here* (pcomplete-entries)
250 (pcomplete-match-string 1 0)))
251 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
252 (pcomplete-here* (pcmpl-unix-group-names)
253 (pcomplete-match-string 1 0)))
254 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
255 (pcomplete-here* (pcomplete-entries)
256 (pcomplete-match-string 1 0)))
257 ((pcomplete-match "\\`--label=" 0)
259 ((pcomplete-match "\\`--mode=" 0)
261 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
262 (pcomplete-here* (pcomplete-entries)
263 (pcomplete-match-string 1 0)))
264 ((pcomplete-match "\\`--newer=" 0)
266 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
267 (pcomplete-here* (pcmpl-unix-user-names)
268 (pcomplete-match-string 1 0)))
269 ((pcomplete-match "\\`--record-size=" 0)
271 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
272 (pcomplete-here* (funcall pcomplete-command-completion-function
)
273 (pcomplete-match-string 1 0)))
274 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
275 (pcomplete-here* (pcomplete-entries)
276 (pcomplete-match-string 1 0)))
277 ((pcomplete-match "\\`--suffix=" 0)
279 ((pcomplete-match "\\`--tape-length=" 0)
281 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
282 (pcomplete-here* (funcall pcomplete-command-completion-function
)
283 (pcomplete-match-string 1 0)))
284 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
285 (pcomplete-here* (pcomplete-entries)
286 (pcomplete-match-string 1 0)))))
287 (setq pcomplete-suffix-list
(cdr pcomplete-suffix-list
))
290 (mapcar 'char-to-string
292 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
293 (if (pcomplete-match "[xt]" 'first
1)
294 (setq complete-within t
)))
295 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp
))
296 (setq pcmpl-gnu-tar-buffer
(find-file-noselect (pcomplete-arg 1)))
297 (while (pcomplete-here
299 (with-current-buffer pcmpl-gnu-tar-buffer
303 (tar-header-name (cdr entry
))))
309 (defalias 'pcomplete
/gdb
'pcomplete
/xargs
)
311 ;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183
312 ;;; pcmpl-gnu.el ends here