Commit | Line | Data |
---|---|---|
4fa9f636 GM |
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 | |
ca7aae91 | 36 | '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'") |
4fa9f636 GM |
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)) | |
ca7aae91 JW |
114 | (makefile (or (cadr minus-f) |
115 | (if (file-exists-p "GNUmakefile") | |
116 | "GNUmakefile" | |
117 | "Makefile"))) | |
4fa9f636 GM |
118 | rules) |
119 | (if (not (file-readable-p makefile)) | |
120 | (unless minus-f (list "-f")) | |
121 | (with-temp-buffer | |
122 | (insert-file-contents-literally makefile) | |
123 | (while (re-search-forward | |
124 | (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t) | |
125 | (setq rules (append (split-string (match-string 1)) rules)))) | |
126 | (pcomplete-uniqify-list rules)))) | |
127 | ||
128 | (defcustom pcmpl-gnu-tarfile-regexp | |
129 | "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'" | |
130 | "*A regexp which matches any tar archive." | |
131 | :type 'regexp | |
132 | :group 'pcmpl-gnu) | |
133 | ||
134 | (defvar pcmpl-gnu-tar-buffer nil) | |
135 | ||
136 | ;;;###autoload | |
137 | (defun pcomplete/tar () | |
138 | "Completion for the GNU tar utility." | |
139 | ;; options that end in an equal sign will want further completion... | |
140 | (let (saw-option complete-within) | |
141 | (setq pcomplete-suffix-list (cons ?= pcomplete-suffix-list)) | |
142 | (while (pcomplete-match "^-" 0) | |
143 | (setq saw-option t) | |
144 | (if (pcomplete-match "^--" 0) | |
145 | (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0) | |
146 | (pcomplete-here* | |
147 | '("--absolute-names" | |
148 | "--after-date=" | |
149 | "--append" | |
150 | "--atime-preserve" | |
151 | "--backup" | |
152 | "--block-number" | |
153 | "--blocking-factor=" | |
154 | "--catenate" | |
155 | "--checkpoint" | |
156 | "--compare" | |
157 | "--compress" | |
158 | "--concatenate" | |
159 | "--confirmation" | |
160 | "--create" | |
161 | "--delete" | |
162 | "--dereference" | |
163 | "--diff" | |
164 | "--directory=" | |
165 | "--exclude=" | |
166 | "--exclude-from=" | |
167 | "--extract" | |
168 | "--file=" | |
169 | "--files-from=" | |
170 | "--force-local" | |
171 | "--get" | |
172 | "--group=" | |
173 | "--gzip" | |
174 | "--help" | |
175 | "--ignore-failed-read" | |
176 | "--ignore-zeros" | |
177 | "--incremental" | |
178 | "--info-script=" | |
179 | "--interactive" | |
180 | "--keep-old-files" | |
181 | "--label=" | |
182 | "--list" | |
183 | "--listed-incremental" | |
184 | "--mode=" | |
185 | "--modification-time" | |
186 | "--multi-volume" | |
187 | "--new-volume-script=" | |
188 | "--newer=" | |
189 | "--newer-mtime" | |
190 | "--no-recursion" | |
191 | "--null" | |
192 | "--numeric-owner" | |
193 | "--old-archive" | |
194 | "--one-file-system" | |
195 | "--owner=" | |
196 | "--portability" | |
197 | "--posix" | |
198 | "--preserve" | |
199 | "--preserve-order" | |
200 | "--preserve-permissions" | |
201 | "--read-full-records" | |
202 | "--record-size=" | |
203 | "--recursive-unlink" | |
204 | "--remove-files" | |
205 | "--rsh-command=" | |
206 | "--same-order" | |
207 | "--same-owner" | |
208 | "--same-permissions" | |
209 | "--sparse" | |
210 | "--starting-file=" | |
211 | "--suffix=" | |
212 | "--tape-length=" | |
213 | "--to-stdout" | |
214 | "--totals" | |
215 | "--uncompress" | |
216 | "--ungzip" | |
217 | "--unlink-first" | |
218 | "--update" | |
219 | "--use-compress-program=" | |
220 | "--verbose" | |
221 | "--verify" | |
222 | "--version" | |
223 | "--volno-file="))) | |
224 | (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")) | |
225 | (cond | |
226 | ((pcomplete-match "\\`--after-date=" 0) | |
227 | (pcomplete-here*)) | |
228 | ((pcomplete-match "\\`--backup=" 0) | |
229 | (pcomplete-here*)) | |
230 | ((pcomplete-match "\\`--blocking-factor=" 0) | |
231 | (pcomplete-here*)) | |
232 | ((pcomplete-match "\\`--directory=\\(.*\\)" 0) | |
233 | (pcomplete-here* (pcomplete-dirs) | |
234 | (pcomplete-match-string 1 0))) | |
235 | ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0) | |
236 | (pcomplete-here* (pcomplete-entries) | |
237 | (pcomplete-match-string 1 0))) | |
238 | ((pcomplete-match "\\`--exclude=" 0) | |
239 | (pcomplete-here*)) | |
240 | ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0) | |
241 | (setq complete-within t)) | |
242 | ((pcomplete-match "\\`--file=\\(.*\\)" 0) | |
243 | (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp) | |
244 | (pcomplete-match-string 1 0))) | |
245 | ((pcomplete-match "\\`--files-from=\\(.*\\)" 0) | |
246 | (pcomplete-here* (pcomplete-entries) | |
247 | (pcomplete-match-string 1 0))) | |
248 | ((pcomplete-match "\\`--group=\\(.*\\)" 0) | |
249 | (pcomplete-here* (pcmpl-unix-group-names) | |
250 | (pcomplete-match-string 1 0))) | |
251 | ((pcomplete-match "\\`--info-script=\\(.*\\)" 0) | |
252 | (pcomplete-here* (pcomplete-entries) | |
253 | (pcomplete-match-string 1 0))) | |
254 | ((pcomplete-match "\\`--label=" 0) | |
255 | (pcomplete-here*)) | |
256 | ((pcomplete-match "\\`--mode=" 0) | |
257 | (pcomplete-here*)) | |
258 | ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0) | |
259 | (pcomplete-here* (pcomplete-entries) | |
260 | (pcomplete-match-string 1 0))) | |
261 | ((pcomplete-match "\\`--newer=" 0) | |
262 | (pcomplete-here*)) | |
263 | ((pcomplete-match "\\`--owner=\\(.*\\)" 0) | |
264 | (pcomplete-here* (pcmpl-unix-user-names) | |
265 | (pcomplete-match-string 1 0))) | |
266 | ((pcomplete-match "\\`--record-size=" 0) | |
267 | (pcomplete-here*)) | |
268 | ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0) | |
269 | (pcomplete-here* (funcall pcomplete-command-completion-function) | |
270 | (pcomplete-match-string 1 0))) | |
271 | ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0) | |
272 | (pcomplete-here* (pcomplete-entries) | |
273 | (pcomplete-match-string 1 0))) | |
274 | ((pcomplete-match "\\`--suffix=" 0) | |
275 | (pcomplete-here*)) | |
276 | ((pcomplete-match "\\`--tape-length=" 0) | |
277 | (pcomplete-here*)) | |
278 | ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0) | |
279 | (pcomplete-here* (funcall pcomplete-command-completion-function) | |
280 | (pcomplete-match-string 1 0))) | |
281 | ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0) | |
282 | (pcomplete-here* (pcomplete-entries) | |
283 | (pcomplete-match-string 1 0))))) | |
284 | (setq pcomplete-suffix-list (cdr pcomplete-suffix-list)) | |
285 | (unless saw-option | |
286 | (pcomplete-here | |
287 | (mapcar 'char-to-string | |
288 | (string-to-list | |
289 | "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))) | |
290 | (if (pcomplete-match "[xt]" 'first 1) | |
291 | (setq complete-within t))) | |
292 | (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)) | |
293 | (setq pcmpl-gnu-tar-buffer (find-file-noselect (pcomplete-arg 1))) | |
294 | (while (pcomplete-here | |
295 | (if complete-within | |
296 | (with-current-buffer pcmpl-gnu-tar-buffer | |
297 | (mapcar | |
298 | (function | |
299 | (lambda (entry) | |
300 | (tar-header-name (cdr entry)))) | |
301 | tar-parse-info)) | |
302 | (pcomplete-entries)) | |
303 | nil 'identity)))) | |
304 | ||
305 | ;;;###autoload | |
306 | (defalias 'pcomplete/gdb 'pcomplete/xargs) | |
307 | ||
308 | ;;; pcmpl-gnu.el ends here |