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