Mercurial > emacs
annotate lisp/pcmpl-gnu.el @ 110971:80846b446563
lisp/subr.el (last): Use `safe-length' instead of `length' (bug#7206).
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 01:15:03 +0200 |
parents | 280c8ae2476d |
children | 417b1e4d63cd |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
31241
diff
changeset
|
1 ;;; pcmpl-gnu.el --- completions for GNU project tools |
29959 | 2 |
74442 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
106815 | 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
29959 | 5 |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
6 ;; Package: pcomplete |
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
7 |
29959 | 8 ;; This file is part of GNU Emacs. |
9 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29959 | 11 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
29959 | 14 |
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. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29959 | 22 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
31241
diff
changeset
|
23 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
31241
diff
changeset
|
24 |
29959 | 25 ;;; Code: |
26 | |
27 (provide 'pcmpl-gnu) | |
28 | |
29 (require 'pcomplete) | |
30 (require 'pcmpl-unix) | |
31 | |
32 (defgroup pcmpl-gnu nil | |
33 "Completions for GNU project tools." | |
34 :group 'pcomplete) | |
35 | |
36 ;; User Variables: | |
37 | |
38 (defcustom pcmpl-gnu-makefile-regexps | |
31241 | 39 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'") |
100171 | 40 "A list of regexps that will match Makefile names." |
29959 | 41 :type '(repeat regexp) |
42 :group 'pcmpl-gnu) | |
43 | |
44 ;; Functions: | |
45 | |
46 ;;;###autoload | |
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 | |
53 (catch 'has-d-flag | |
54 (let ((args pcomplete-args)) | |
55 (while args | |
56 (if (string-match "\\`-.*[dt]" (car args)) | |
57 (throw 'has-d-flag t)) | |
58 (setq args (cdr args)))))))))) | |
59 | |
60 (defun pcmpl-gnu-zipped-files (unzip-p) | |
61 "Find all zipped or unzipped files: the inverse of UNZIP-P." | |
62 (pcomplete-entries | |
63 nil | |
64 (function | |
65 (lambda (entry) | |
66 (when (and (file-readable-p entry) | |
67 (file-regular-p entry)) | |
68 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'" | |
69 entry))) | |
70 (or (and unzip-p zipped) | |
71 (and (not unzip-p) (not zipped))))))))) | |
72 | |
73 ;;;###autoload | |
74 (defun pcomplete/bzip2 () | |
75 "Completion for `bzip2'." | |
76 (pcomplete-opt "hdzkftcqvLVs123456789") | |
77 (while (pcomplete-here | |
78 (pcmpl-gnu-bzipped-files | |
79 (catch 'has-d-flag | |
80 (let ((args pcomplete-args)) | |
81 (while args | |
82 (if (string-match "\\`-.*[dt]" (car args)) | |
83 (throw 'has-d-flag t)) | |
84 (setq args (cdr args))))))))) | |
85 | |
86 (defun pcmpl-gnu-bzipped-files (unzip-p) | |
87 "Find all zipped or unzipped files: the inverse of UNZIP-P." | |
88 (pcomplete-entries | |
89 nil | |
90 (function | |
91 (lambda (entry) | |
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))))))))) | |
97 | |
98 ;;;###autoload | |
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)))) | |
104 | |
105 (defun pcmpl-gnu-makefile-names () | |
106 "Return a list of possible makefile names." | |
105704
4d03be3df4fe
(pcmpl-gnu-makefile-names): Use a single call to pcomplete-entries.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
107 (pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|"))) |
29959 | 108 |
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)) | |
31241 | 112 (makefile (or (cadr minus-f) |
113 (if (file-exists-p "GNUmakefile") | |
114 "GNUmakefile" | |
115 "Makefile"))) | |
29959 | 116 rules) |
117 (if (not (file-readable-p makefile)) | |
118 (unless minus-f (list "-f")) | |
119 (with-temp-buffer | |
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)))) | |
125 | |
126 (defcustom pcmpl-gnu-tarfile-regexp | |
127 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'" | |
100171 | 128 "A regexp which matches any tar archive." |
29959 | 129 :type 'regexp |
130 :group 'pcmpl-gnu) | |
131 | |
132 (defvar pcmpl-gnu-tar-buffer nil) | |
133 | |
105809
27deb58e021f
(tar-parse-info, tar-header-name): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
105704
diff
changeset
|
134 ;; Only used in tar-mode buffers. |
27deb58e021f
(tar-parse-info, tar-header-name): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
105704
diff
changeset
|
135 (defvar tar-parse-info) |
27deb58e021f
(tar-parse-info, tar-header-name): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
105704
diff
changeset
|
136 (declare-function tar-header-name "tar-mode" t t) |
27deb58e021f
(tar-parse-info, tar-header-name): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
105704
diff
changeset
|
137 |
29959 | 138 ;;;###autoload |
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) | |
145 (setq saw-option t) | |
146 (if (pcomplete-match "^--" 0) | |
147 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0) | |
148 (pcomplete-here* | |
149 '("--absolute-names" | |
150 "--after-date=" | |
151 "--append" | |
152 "--atime-preserve" | |
153 "--backup" | |
154 "--block-number" | |
155 "--blocking-factor=" | |
156 "--catenate" | |
157 "--checkpoint" | |
158 "--compare" | |
159 "--compress" | |
160 "--concatenate" | |
161 "--confirmation" | |
162 "--create" | |
163 "--delete" | |
164 "--dereference" | |
165 "--diff" | |
166 "--directory=" | |
167 "--exclude=" | |
168 "--exclude-from=" | |
169 "--extract" | |
170 "--file=" | |
171 "--files-from=" | |
172 "--force-local" | |
173 "--get" | |
174 "--group=" | |
175 "--gzip" | |
176 "--help" | |
177 "--ignore-failed-read" | |
178 "--ignore-zeros" | |
179 "--incremental" | |
180 "--info-script=" | |
181 "--interactive" | |
182 "--keep-old-files" | |
183 "--label=" | |
184 "--list" | |
185 "--listed-incremental" | |
186 "--mode=" | |
187 "--modification-time" | |
188 "--multi-volume" | |
189 "--new-volume-script=" | |
190 "--newer=" | |
191 "--newer-mtime" | |
192 "--no-recursion" | |
193 "--null" | |
194 "--numeric-owner" | |
195 "--old-archive" | |
196 "--one-file-system" | |
197 "--owner=" | |
198 "--portability" | |
199 "--posix" | |
200 "--preserve" | |
201 "--preserve-order" | |
202 "--preserve-permissions" | |
203 "--read-full-records" | |
204 "--record-size=" | |
205 "--recursive-unlink" | |
206 "--remove-files" | |
207 "--rsh-command=" | |
208 "--same-order" | |
209 "--same-owner" | |
210 "--same-permissions" | |
211 "--sparse" | |
212 "--starting-file=" | |
213 "--suffix=" | |
214 "--tape-length=" | |
215 "--to-stdout" | |
216 "--totals" | |
217 "--uncompress" | |
218 "--ungzip" | |
219 "--unlink-first" | |
220 "--update" | |
221 "--use-compress-program=" | |
222 "--verbose" | |
223 "--verify" | |
224 "--version" | |
225 "--volno-file="))) | |
226 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")) | |
227 (cond | |
228 ((pcomplete-match "\\`--after-date=" 0) | |
229 (pcomplete-here*)) | |
230 ((pcomplete-match "\\`--backup=" 0) | |
231 (pcomplete-here*)) | |
232 ((pcomplete-match "\\`--blocking-factor=" 0) | |
233 (pcomplete-here*)) | |
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) | |
241 (pcomplete-here*)) | |
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) | |
257 (pcomplete-here*)) | |
258 ((pcomplete-match "\\`--mode=" 0) | |
259 (pcomplete-here*)) | |
260 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0) | |
261 (pcomplete-here* (pcomplete-entries) | |
262 (pcomplete-match-string 1 0))) | |
263 ((pcomplete-match "\\`--newer=" 0) | |
264 (pcomplete-here*)) | |
265 ((pcomplete-match "\\`--owner=\\(.*\\)" 0) | |
266 (pcomplete-here* (pcmpl-unix-user-names) | |
267 (pcomplete-match-string 1 0))) | |
268 ((pcomplete-match "\\`--record-size=" 0) | |
269 (pcomplete-here*)) | |
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) | |
277 (pcomplete-here*)) | |
278 ((pcomplete-match "\\`--tape-length=" 0) | |
279 (pcomplete-here*)) | |
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)) | |
287 (unless saw-option | |
288 (pcomplete-here | |
289 (mapcar 'char-to-string | |
290 (string-to-list | |
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 | |
297 (if complete-within | |
298 (with-current-buffer pcmpl-gnu-tar-buffer | |
299 (mapcar | |
300 (function | |
301 (lambda (entry) | |
302 (tar-header-name (cdr entry)))) | |
303 tar-parse-info)) | |
304 (pcomplete-entries)) | |
305 nil 'identity)))) | |
306 | |
307 ;;;###autoload | |
308 (defalias 'pcomplete/gdb 'pcomplete/xargs) | |
309 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
310 ;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183 |
29959 | 311 ;;; pcmpl-gnu.el ends here |