29959
|
1 ;;; pcmpl-gnu --- completions for GNU project tools
|
|
2
|
|
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
|
|
4
|
|
5 ;; This file is part of GNU Emacs.
|
|
6
|
|
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)
|
|
10 ;; any later version.
|
|
11
|
|
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.
|
|
16
|
|
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.
|
|
21
|
|
22 ;;; Code:
|
|
23
|
|
24 (provide 'pcmpl-gnu)
|
|
25
|
|
26 (require 'pcomplete)
|
|
27 (require 'pcmpl-unix)
|
|
28
|
|
29 (defgroup pcmpl-gnu nil
|
|
30 "Completions for GNU project tools."
|
|
31 :group 'pcomplete)
|
|
32
|
|
33 ;; User Variables:
|
|
34
|
|
35 (defcustom pcmpl-gnu-makefile-regexps
|
|
36 '("\\`Makefile\\." "\\.mak\\'")
|
|
37 "*A list of regexps that will match Makefile names."
|
|
38 :type '(repeat regexp)
|
|
39 :group 'pcmpl-gnu)
|
|
40
|
|
41 ;; Functions:
|
|
42
|
|
43 ;;;###autoload
|
|
44 (defun pcomplete/gzip ()
|
|
45 "Completion for `gzip'."
|
|
46 (let ((pcomplete-help "(gzip)"))
|
|
47 (pcomplete-opt "cdfhlLnNqrStvV123456789")
|
|
48 (while (pcomplete-here
|
|
49 (pcmpl-gnu-zipped-files
|
|
50 (catch 'has-d-flag
|
|
51 (let ((args pcomplete-args))
|
|
52 (while args
|
|
53 (if (string-match "\\`-.*[dt]" (car args))
|
|
54 (throw 'has-d-flag t))
|
|
55 (setq args (cdr args))))))))))
|
|
56
|
|
57 (defun pcmpl-gnu-zipped-files (unzip-p)
|
|
58 "Find all zipped or unzipped files: the inverse of UNZIP-P."
|
|
59 (pcomplete-entries
|
|
60 nil
|
|
61 (function
|
|
62 (lambda (entry)
|
|
63 (when (and (file-readable-p entry)
|
|
64 (file-regular-p entry))
|
|
65 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'"
|
|
66 entry)))
|
|
67 (or (and unzip-p zipped)
|
|
68 (and (not unzip-p) (not zipped)))))))))
|
|
69
|
|
70 ;;;###autoload
|
|
71 (defun pcomplete/bzip2 ()
|
|
72 "Completion for `bzip2'."
|
|
73 (pcomplete-opt "hdzkftcqvLVs123456789")
|
|
74 (while (pcomplete-here
|
|
75 (pcmpl-gnu-bzipped-files
|
|
76 (catch 'has-d-flag
|
|
77 (let ((args pcomplete-args))
|
|
78 (while args
|
|
79 (if (string-match "\\`-.*[dt]" (car args))
|
|
80 (throw 'has-d-flag t))
|
|
81 (setq args (cdr args)))))))))
|
|
82
|
|
83 (defun pcmpl-gnu-bzipped-files (unzip-p)
|
|
84 "Find all zipped or unzipped files: the inverse of UNZIP-P."
|
|
85 (pcomplete-entries
|
|
86 nil
|
|
87 (function
|
|
88 (lambda (entry)
|
|
89 (when (and (file-readable-p entry)
|
|
90 (file-regular-p entry))
|
|
91 (let ((zipped (string-match "\\.\\(t?z2\\|bz2\\)\\'" entry)))
|
|
92 (or (and unzip-p zipped)
|
|
93 (and (not unzip-p) (not zipped)))))))))
|
|
94
|
|
95 ;;;###autoload
|
|
96 (defun pcomplete/make ()
|
|
97 "Completion for GNU `make'."
|
|
98 (let ((pcomplete-help "(make)Top"))
|
|
99 (pcomplete-opt "bmC/def(pcmpl-gnu-makefile-names)hiI/j?kl?no.pqrsStvwW.")
|
|
100 (while (pcomplete-here (pcmpl-gnu-make-rule-names) nil 'identity))))
|
|
101
|
|
102 (defun pcmpl-gnu-makefile-names ()
|
|
103 "Return a list of possible makefile names."
|
|
104 (let ((names (list t))
|
|
105 (reg pcmpl-gnu-makefile-regexps))
|
|
106 (while reg
|
|
107 (nconc names (pcomplete-entries (car reg)))
|
|
108 (setq reg (cdr reg)))
|
|
109 (cdr names)))
|
|
110
|
|
111 (defun pcmpl-gnu-make-rule-names ()
|
|
112 "Return a list of possible make rule names in MAKEFILE."
|
|
113 (let* ((minus-f (member "-f" pcomplete-args))
|
|
114 (makefile (or (cadr minus-f) "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))))
|
|
124
|
|
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)
|
|
130
|
|
131 (defvar pcmpl-gnu-tar-buffer nil)
|
|
132
|
|
133 ;;;###autoload
|
|
134 (defun pcomplete/tar ()
|
|
135 "Completion for the GNU tar utility."
|
|
136 ;; options that end in an equal sign will want further completion...
|
|
137 (let (saw-option complete-within)
|
|
138 (setq pcomplete-suffix-list (cons ?= pcomplete-suffix-list))
|
|
139 (while (pcomplete-match "^-" 0)
|
|
140 (setq saw-option t)
|
|
141 (if (pcomplete-match "^--" 0)
|
|
142 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
|
|
143 (pcomplete-here*
|
|
144 '("--absolute-names"
|
|
145 "--after-date="
|
|
146 "--append"
|
|
147 "--atime-preserve"
|
|
148 "--backup"
|
|
149 "--block-number"
|
|
150 "--blocking-factor="
|
|
151 "--catenate"
|
|
152 "--checkpoint"
|
|
153 "--compare"
|
|
154 "--compress"
|
|
155 "--concatenate"
|
|
156 "--confirmation"
|
|
157 "--create"
|
|
158 "--delete"
|
|
159 "--dereference"
|
|
160 "--diff"
|
|
161 "--directory="
|
|
162 "--exclude="
|
|
163 "--exclude-from="
|
|
164 "--extract"
|
|
165 "--file="
|
|
166 "--files-from="
|
|
167 "--force-local"
|
|
168 "--get"
|
|
169 "--group="
|
|
170 "--gzip"
|
|
171 "--help"
|
|
172 "--ignore-failed-read"
|
|
173 "--ignore-zeros"
|
|
174 "--incremental"
|
|
175 "--info-script="
|
|
176 "--interactive"
|
|
177 "--keep-old-files"
|
|
178 "--label="
|
|
179 "--list"
|
|
180 "--listed-incremental"
|
|
181 "--mode="
|
|
182 "--modification-time"
|
|
183 "--multi-volume"
|
|
184 "--new-volume-script="
|
|
185 "--newer="
|
|
186 "--newer-mtime"
|
|
187 "--no-recursion"
|
|
188 "--null"
|
|
189 "--numeric-owner"
|
|
190 "--old-archive"
|
|
191 "--one-file-system"
|
|
192 "--owner="
|
|
193 "--portability"
|
|
194 "--posix"
|
|
195 "--preserve"
|
|
196 "--preserve-order"
|
|
197 "--preserve-permissions"
|
|
198 "--read-full-records"
|
|
199 "--record-size="
|
|
200 "--recursive-unlink"
|
|
201 "--remove-files"
|
|
202 "--rsh-command="
|
|
203 "--same-order"
|
|
204 "--same-owner"
|
|
205 "--same-permissions"
|
|
206 "--sparse"
|
|
207 "--starting-file="
|
|
208 "--suffix="
|
|
209 "--tape-length="
|
|
210 "--to-stdout"
|
|
211 "--totals"
|
|
212 "--uncompress"
|
|
213 "--ungzip"
|
|
214 "--unlink-first"
|
|
215 "--update"
|
|
216 "--use-compress-program="
|
|
217 "--verbose"
|
|
218 "--verify"
|
|
219 "--version"
|
|
220 "--volno-file=")))
|
|
221 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
|
|
222 (cond
|
|
223 ((pcomplete-match "\\`--after-date=" 0)
|
|
224 (pcomplete-here*))
|
|
225 ((pcomplete-match "\\`--backup=" 0)
|
|
226 (pcomplete-here*))
|
|
227 ((pcomplete-match "\\`--blocking-factor=" 0)
|
|
228 (pcomplete-here*))
|
|
229 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
|
|
230 (pcomplete-here* (pcomplete-dirs)
|
|
231 (pcomplete-match-string 1 0)))
|
|
232 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
|
|
233 (pcomplete-here* (pcomplete-entries)
|
|
234 (pcomplete-match-string 1 0)))
|
|
235 ((pcomplete-match "\\`--exclude=" 0)
|
|
236 (pcomplete-here*))
|
|
237 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
|
|
238 (setq complete-within t))
|
|
239 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
|
|
240 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)
|
|
241 (pcomplete-match-string 1 0)))
|
|
242 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
|
|
243 (pcomplete-here* (pcomplete-entries)
|
|
244 (pcomplete-match-string 1 0)))
|
|
245 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
|
|
246 (pcomplete-here* (pcmpl-unix-group-names)
|
|
247 (pcomplete-match-string 1 0)))
|
|
248 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
|
|
249 (pcomplete-here* (pcomplete-entries)
|
|
250 (pcomplete-match-string 1 0)))
|
|
251 ((pcomplete-match "\\`--label=" 0)
|
|
252 (pcomplete-here*))
|
|
253 ((pcomplete-match "\\`--mode=" 0)
|
|
254 (pcomplete-here*))
|
|
255 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
|
|
256 (pcomplete-here* (pcomplete-entries)
|
|
257 (pcomplete-match-string 1 0)))
|
|
258 ((pcomplete-match "\\`--newer=" 0)
|
|
259 (pcomplete-here*))
|
|
260 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
|
|
261 (pcomplete-here* (pcmpl-unix-user-names)
|
|
262 (pcomplete-match-string 1 0)))
|
|
263 ((pcomplete-match "\\`--record-size=" 0)
|
|
264 (pcomplete-here*))
|
|
265 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
|
|
266 (pcomplete-here* (funcall pcomplete-command-completion-function)
|
|
267 (pcomplete-match-string 1 0)))
|
|
268 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
|
|
269 (pcomplete-here* (pcomplete-entries)
|
|
270 (pcomplete-match-string 1 0)))
|
|
271 ((pcomplete-match "\\`--suffix=" 0)
|
|
272 (pcomplete-here*))
|
|
273 ((pcomplete-match "\\`--tape-length=" 0)
|
|
274 (pcomplete-here*))
|
|
275 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
|
|
276 (pcomplete-here* (funcall pcomplete-command-completion-function)
|
|
277 (pcomplete-match-string 1 0)))
|
|
278 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
|
|
279 (pcomplete-here* (pcomplete-entries)
|
|
280 (pcomplete-match-string 1 0)))))
|
|
281 (setq pcomplete-suffix-list (cdr pcomplete-suffix-list))
|
|
282 (unless saw-option
|
|
283 (pcomplete-here
|
|
284 (mapcar 'char-to-string
|
|
285 (string-to-list
|
|
286 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
|
|
287 (if (pcomplete-match "[xt]" 'first 1)
|
|
288 (setq complete-within t)))
|
|
289 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp))
|
|
290 (setq pcmpl-gnu-tar-buffer (find-file-noselect (pcomplete-arg 1)))
|
|
291 (while (pcomplete-here
|
|
292 (if complete-within
|
|
293 (with-current-buffer pcmpl-gnu-tar-buffer
|
|
294 (mapcar
|
|
295 (function
|
|
296 (lambda (entry)
|
|
297 (tar-header-name (cdr entry))))
|
|
298 tar-parse-info))
|
|
299 (pcomplete-entries))
|
|
300 nil 'identity))))
|
|
301
|
|
302 ;;;###autoload
|
|
303 (defalias 'pcomplete/gdb 'pcomplete/xargs)
|
|
304
|
|
305 ;;; pcmpl-gnu.el ends here
|