1 ;;; pcmpl-gnu.el --- completions for GNU project tools
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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 (pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps
"\\|")))
109 (defun pcmpl-gnu-make-rule-names ()
110 "Return a list of possible make rule names in MAKEFILE."
111 (let* ((minus-f (member "-f" pcomplete-args
))
112 (makefile (or (cadr minus-f
)
113 (if (file-exists-p "GNUmakefile")
117 (if (not (file-readable-p makefile
))
118 (unless minus-f
(list "-f"))
120 (insert-file-contents-literally makefile
)
121 (while (re-search-forward
122 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t
)
123 (setq rules
(append (split-string (match-string 1)) rules
))))
124 (pcomplete-uniqify-list rules
))))
126 (defcustom pcmpl-gnu-tarfile-regexp
127 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
128 "A regexp which matches any tar archive."
132 (defvar pcmpl-gnu-tar-buffer nil
)
134 ;; Only used in tar-mode buffers.
135 (defvar tar-parse-info
)
136 (declare-function tar-header-name
"tar-mode" t t
)
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