Mark tiny change.
[emacs.git] / lisp / pcmpl-gnu.el
blob62f5fafe2c4cccf72674d415874da2ca428af18a
1 ;;; pcmpl-gnu.el --- completions for GNU project tools
3 ;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
5 ;; Package: pcomplete
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/>.
22 ;;; Commentary:
24 ;;; Code:
26 (provide 'pcmpl-gnu)
28 (require 'pcomplete)
29 (require 'pcmpl-unix)
31 (defgroup pcmpl-gnu nil
32 "Completions for GNU project tools."
33 :group 'pcomplete)
35 ;; User Variables:
37 (defcustom pcmpl-gnu-makefile-regexps
38 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
39 "A list of regexps that will match Makefile names."
40 :type '(repeat regexp)
41 :group 'pcmpl-gnu)
43 ;; Functions:
45 ;;;###autoload
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
52 (catch 'has-d-flag
53 (let ((args pcomplete-args))
54 (while 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."
61 (pcomplete-entries
62 nil
63 (function
64 (lambda (entry)
65 (when (and (file-readable-p entry)
66 (file-regular-p entry))
67 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
68 entry)))
69 (or (and unzip-p zipped)
70 (and (not unzip-p) (not zipped)))))))))
72 ;;;###autoload
73 (defun pcomplete/bzip2 ()
74 "Completion for `bzip2'."
75 (pcomplete-opt "hdzkftcqvLVs123456789")
76 (while (pcomplete-here
77 (pcmpl-gnu-bzipped-files
78 (catch 'has-d-flag
79 (let ((args pcomplete-args))
80 (while 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."
87 (pcomplete-entries
88 nil
89 (function
90 (lambda (entry)
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)))))))))
97 ;;;###autoload
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")
113 "GNUmakefile"
114 "Makefile")))
115 rules)
116 (if (not (file-readable-p makefile))
117 (unless minus-f (list "-f"))
118 (with-temp-buffer
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."
128 :type 'regexp
129 :group 'pcmpl-gnu)
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)
137 ;;;###autoload
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)
144 (setq saw-option t)
145 (if (pcomplete-match "^--" 0)
146 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
147 (pcomplete-here*
148 '("--absolute-names"
149 "--after-date="
150 "--append"
151 "--atime-preserve"
152 "--backup"
153 "--block-number"
154 "--blocking-factor="
155 "--catenate"
156 "--checkpoint"
157 "--compare"
158 "--compress"
159 "--concatenate"
160 "--confirmation"
161 "--create"
162 "--delete"
163 "--dereference"
164 "--diff"
165 "--directory="
166 "--exclude="
167 "--exclude-from="
168 "--extract"
169 "--file="
170 "--files-from="
171 "--force-local"
172 "--get"
173 "--group="
174 "--gzip"
175 "--help"
176 "--ignore-failed-read"
177 "--ignore-zeros"
178 "--incremental"
179 "--info-script="
180 "--interactive"
181 "--keep-old-files"
182 "--label="
183 "--list"
184 "--listed-incremental"
185 "--mode="
186 "--modification-time"
187 "--multi-volume"
188 "--new-volume-script="
189 "--newer="
190 "--newer-mtime"
191 "--no-recursion"
192 "--null"
193 "--numeric-owner"
194 "--old-archive"
195 "--one-file-system"
196 "--owner="
197 "--portability"
198 "--posix"
199 "--preserve"
200 "--preserve-order"
201 "--preserve-permissions"
202 "--read-full-records"
203 "--record-size="
204 "--recursive-unlink"
205 "--remove-files"
206 "--rsh-command="
207 "--same-order"
208 "--same-owner"
209 "--same-permissions"
210 "--sparse"
211 "--starting-file="
212 "--suffix="
213 "--tape-length="
214 "--to-stdout"
215 "--totals"
216 "--uncompress"
217 "--ungzip"
218 "--unlink-first"
219 "--update"
220 "--use-compress-program="
221 "--verbose"
222 "--verify"
223 "--version"
224 "--volno-file=")))
225 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
226 (cond
227 ((pcomplete-match "\\`--after-date=" 0)
228 (pcomplete-here*))
229 ((pcomplete-match "\\`--backup=" 0)
230 (pcomplete-here*))
231 ((pcomplete-match "\\`--blocking-factor=" 0)
232 (pcomplete-here*))
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)
240 (pcomplete-here*))
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)
256 (pcomplete-here*))
257 ((pcomplete-match "\\`--mode=" 0)
258 (pcomplete-here*))
259 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
260 (pcomplete-here* (pcomplete-entries)
261 (pcomplete-match-string 1 0)))
262 ((pcomplete-match "\\`--newer=" 0)
263 (pcomplete-here*))
264 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
265 (pcomplete-here* (pcmpl-unix-user-names)
266 (pcomplete-match-string 1 0)))
267 ((pcomplete-match "\\`--record-size=" 0)
268 (pcomplete-here*))
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)
276 (pcomplete-here*))
277 ((pcomplete-match "\\`--tape-length=" 0)
278 (pcomplete-here*))
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))
286 (unless saw-option
287 (pcomplete-here
288 (mapcar 'char-to-string
289 (string-to-list
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
296 (if complete-within
297 (with-current-buffer pcmpl-gnu-tar-buffer
298 (mapcar
299 (function
300 (lambda (entry)
301 (tar-header-name (cdr entry))))
302 tar-parse-info))
303 (pcomplete-entries))
304 nil 'identity))))
306 ;;;###autoload
307 (defalias 'pcomplete/gdb 'pcomplete/xargs)
309 ;;; pcmpl-gnu.el ends here