1 ;;; pcmpl-gnu.el --- 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.
31 (defgroup pcmpl-gnu nil
32 "Completions for GNU project tools."
37 (defcustom pcmpl-gnu-makefile-regexps
38 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
39 "*A list of regexps that will match Makefile names."
40 :type
'(repeat regexp
)
46 (defun pcomplete/gzip
()
47 "Completion for `gzip'."
48 (let ((pcomplete-help "(gzip)"))
49 (pcomplete-opt "cdfhlLnNqrStvV123456789")
50 (while (pcomplete-here
51 (pcmpl-gnu-zipped-files
53 (let ((args pcomplete-args
))
55 (if (string-match "\\`-.*[dt]" (car args
))
56 (throw 'has-d-flag t
))
57 (setq args
(cdr args
))))))))))
59 (defun pcmpl-gnu-zipped-files (unzip-p)
60 "Find all zipped or unzipped files: the inverse of UNZIP-P."
65 (when (and (file-readable-p entry
)
66 (file-regular-p entry
))
67 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
69 (or (and unzip-p zipped
)
70 (and (not unzip-p
) (not zipped
)))))))))
73 (defun pcomplete/bzip2
()
74 "Completion for `bzip2'."
75 (pcomplete-opt "hdzkftcqvLVs123456789")
76 (while (pcomplete-here
77 (pcmpl-gnu-bzipped-files
79 (let ((args pcomplete-args
))
81 (if (string-match "\\`-.*[dt]" (car args
))
82 (throw 'has-d-flag t
))
83 (setq args
(cdr args
)))))))))
85 (defun pcmpl-gnu-bzipped-files (unzip-p)
86 "Find all zipped or unzipped files: the inverse of UNZIP-P."
91 (when (and (file-readable-p entry
)
92 (file-regular-p entry
))
93 (let ((zipped (string-match "\\.\\(t?z2\\|bz2\\)\\'" entry
)))
94 (or (and unzip-p zipped
)
95 (and (not unzip-p
) (not zipped
)))))))))
98 (defun pcomplete/make
()
99 "Completion for GNU `make'."
100 (let ((pcomplete-help "(make)Top"))
101 (pcomplete-opt "bmC/def(pcmpl-gnu-makefile-names)hiI/j?kl?no.pqrsStvwW.")
102 (while (pcomplete-here (pcmpl-gnu-make-rule-names) nil
'identity
))))
104 (defun pcmpl-gnu-makefile-names ()
105 "Return a list of possible makefile names."
106 (let ((names (list t
))
107 (reg pcmpl-gnu-makefile-regexps
))
109 (nconc names
(pcomplete-entries (car reg
)))
110 (setq reg
(cdr reg
)))
113 (defun pcmpl-gnu-make-rule-names ()
114 "Return a list of possible make rule names in MAKEFILE."
115 (let* ((minus-f (member "-f" pcomplete-args
))
116 (makefile (or (cadr minus-f
)
117 (if (file-exists-p "GNUmakefile")
121 (if (not (file-readable-p makefile
))
122 (unless minus-f
(list "-f"))
124 (insert-file-contents-literally makefile
)
125 (while (re-search-forward
126 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t
)
127 (setq rules
(append (split-string (match-string 1)) rules
))))
128 (pcomplete-uniqify-list rules
))))
130 (defcustom pcmpl-gnu-tarfile-regexp
131 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
132 "*A regexp which matches any tar archive."
136 (defvar pcmpl-gnu-tar-buffer nil
)
139 (defun pcomplete/tar
()
140 "Completion for the GNU tar utility."
141 ;; options that end in an equal sign will want further completion...
142 (let (saw-option complete-within
)
143 (setq pcomplete-suffix-list
(cons ?
= pcomplete-suffix-list
))
144 (while (pcomplete-match "^-" 0)
146 (if (pcomplete-match "^--" 0)
147 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
177 "--ignore-failed-read"
185 "--listed-incremental"
187 "--modification-time"
189 "--new-volume-script="
202 "--preserve-permissions"
203 "--read-full-records"
221 "--use-compress-program="
226 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
228 ((pcomplete-match "\\`--after-date=" 0)
230 ((pcomplete-match "\\`--backup=" 0)
232 ((pcomplete-match "\\`--blocking-factor=" 0)
234 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
235 (pcomplete-here* (pcomplete-dirs)
236 (pcomplete-match-string 1 0)))
237 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
238 (pcomplete-here* (pcomplete-entries)
239 (pcomplete-match-string 1 0)))
240 ((pcomplete-match "\\`--exclude=" 0)
242 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
243 (setq complete-within t
))
244 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
245 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp
)
246 (pcomplete-match-string 1 0)))
247 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
248 (pcomplete-here* (pcomplete-entries)
249 (pcomplete-match-string 1 0)))
250 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
251 (pcomplete-here* (pcmpl-unix-group-names)
252 (pcomplete-match-string 1 0)))
253 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
254 (pcomplete-here* (pcomplete-entries)
255 (pcomplete-match-string 1 0)))
256 ((pcomplete-match "\\`--label=" 0)
258 ((pcomplete-match "\\`--mode=" 0)
260 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
261 (pcomplete-here* (pcomplete-entries)
262 (pcomplete-match-string 1 0)))
263 ((pcomplete-match "\\`--newer=" 0)
265 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
266 (pcomplete-here* (pcmpl-unix-user-names)
267 (pcomplete-match-string 1 0)))
268 ((pcomplete-match "\\`--record-size=" 0)
270 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
271 (pcomplete-here* (funcall pcomplete-command-completion-function
)
272 (pcomplete-match-string 1 0)))
273 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
274 (pcomplete-here* (pcomplete-entries)
275 (pcomplete-match-string 1 0)))
276 ((pcomplete-match "\\`--suffix=" 0)
278 ((pcomplete-match "\\`--tape-length=" 0)
280 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
281 (pcomplete-here* (funcall pcomplete-command-completion-function
)
282 (pcomplete-match-string 1 0)))
283 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
284 (pcomplete-here* (pcomplete-entries)
285 (pcomplete-match-string 1 0)))))
286 (setq pcomplete-suffix-list
(cdr pcomplete-suffix-list
))
289 (mapcar 'char-to-string
291 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
292 (if (pcomplete-match "[xt]" 'first
1)
293 (setq complete-within t
)))
294 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp
))
295 (setq pcmpl-gnu-tar-buffer
(find-file-noselect (pcomplete-arg 1)))
296 (while (pcomplete-here
298 (with-current-buffer pcmpl-gnu-tar-buffer
302 (tar-header-name (cdr entry
))))
308 (defalias 'pcomplete
/gdb
'pcomplete
/xargs
)
310 ;;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183
311 ;;; pcmpl-gnu.el ends here