Mercurial > emacs
annotate lisp/pcmpl-gnu.el @ 107522:2ba213d1dc9a
NEWS: Re-organize Lisp changes for Emacs 23.2.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 21 Mar 2010 11:09:29 -0400 |
parents | 1d1d5d9bd884 |
children | 280c8ae2476d 376148b31b5e |
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 |
6 ;; This file is part of GNU Emacs. | |
7 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
8 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29959 | 9 ;; 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
|
10 ;; 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
|
11 ;; (at your option) any later version. |
29959 | 12 |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; 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
|
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29959 | 20 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
31241
diff
changeset
|
21 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
31241
diff
changeset
|
22 |
29959 | 23 ;;; Code: |
24 | |
25 (provide 'pcmpl-gnu) | |
26 | |
27 (require 'pcomplete) | |
28 (require 'pcmpl-unix) | |
29 | |
30 (defgroup pcmpl-gnu nil | |
31 "Completions for GNU project tools." | |
32 :group 'pcomplete) | |
33 | |
34 ;; User Variables: | |
35 | |
36 (defcustom pcmpl-gnu-makefile-regexps | |
31241 | 37 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'") |
100171 | 38 "A list of regexps that will match Makefile names." |
29959 | 39 :type '(repeat regexp) |
40 :group 'pcmpl-gnu) | |
41 | |
42 ;; Functions: | |
43 | |
44 ;;;###autoload | |
45 (defun pcomplete/gzip () | |
46 "Completion for `gzip'." | |
47 (let ((pcomplete-help "(gzip)")) | |
48 (pcomplete-opt "cdfhlLnNqrStvV123456789") | |
49 (while (pcomplete-here | |
50 (pcmpl-gnu-zipped-files | |
51 (catch 'has-d-flag | |
52 (let ((args pcomplete-args)) | |
53 (while args | |
54 (if (string-match "\\`-.*[dt]" (car args)) | |
55 (throw 'has-d-flag t)) | |
56 (setq args (cdr args)))))))))) | |
57 | |
58 (defun pcmpl-gnu-zipped-files (unzip-p) | |
59 "Find all zipped or unzipped files: the inverse of UNZIP-P." | |
60 (pcomplete-entries | |
61 nil | |
62 (function | |
63 (lambda (entry) | |
64 (when (and (file-readable-p entry) | |
65 (file-regular-p entry)) | |
66 (let ((zipped (string-match "\\.\\(t?gz\\|\\(ta\\)?Z\\)\\'" | |
67 entry))) | |
68 (or (and unzip-p zipped) | |
69 (and (not unzip-p) (not zipped))))))))) | |
70 | |
71 ;;;###autoload | |
72 (defun pcomplete/bzip2 () | |
73 "Completion for `bzip2'." | |
74 (pcomplete-opt "hdzkftcqvLVs123456789") | |
75 (while (pcomplete-here | |
76 (pcmpl-gnu-bzipped-files | |
77 (catch 'has-d-flag | |
78 (let ((args pcomplete-args)) | |
79 (while args | |
80 (if (string-match "\\`-.*[dt]" (car args)) | |
81 (throw 'has-d-flag t)) | |
82 (setq args (cdr args))))))))) | |
83 | |
84 (defun pcmpl-gnu-bzipped-files (unzip-p) | |
85 "Find all zipped or unzipped files: the inverse of UNZIP-P." | |
86 (pcomplete-entries | |
87 nil | |
88 (function | |
89 (lambda (entry) | |
90 (when (and (file-readable-p entry) | |
91 (file-regular-p entry)) | |
92 (let ((zipped (string-match "\\.\\(t?z2\\|bz2\\)\\'" entry))) | |
93 (or (and unzip-p zipped) | |
94 (and (not unzip-p) (not zipped))))))))) | |
95 | |
96 ;;;###autoload | |
97 (defun pcomplete/make () | |
98 "Completion for GNU `make'." | |
99 (let ((pcomplete-help "(make)Top")) | |
100 (pcomplete-opt "bmC/def(pcmpl-gnu-makefile-names)hiI/j?kl?no.pqrsStvwW.") | |
101 (while (pcomplete-here (pcmpl-gnu-make-rule-names) nil 'identity)))) | |
102 | |
103 (defun pcmpl-gnu-makefile-names () | |
104 "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
|
105 (pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|"))) |
29959 | 106 |
107 (defun pcmpl-gnu-make-rule-names () | |
108 "Return a list of possible make rule names in MAKEFILE." | |
109 (let* ((minus-f (member "-f" pcomplete-args)) | |
31241 | 110 (makefile (or (cadr minus-f) |
111 (if (file-exists-p "GNUmakefile") | |
112 "GNUmakefile" | |
113 "Makefile"))) | |
29959 | 114 rules) |
115 (if (not (file-readable-p makefile)) | |
116 (unless minus-f (list "-f")) | |
117 (with-temp-buffer | |
118 (insert-file-contents-literally makefile) | |
119 (while (re-search-forward | |
120 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t) | |
121 (setq rules (append (split-string (match-string 1)) rules)))) | |
122 (pcomplete-uniqify-list rules)))) | |
123 | |
124 (defcustom pcmpl-gnu-tarfile-regexp | |
125 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'" | |
100171 | 126 "A regexp which matches any tar archive." |
29959 | 127 :type 'regexp |
128 :group 'pcmpl-gnu) | |
129 | |
130 (defvar pcmpl-gnu-tar-buffer nil) | |
131 | |
105809
27deb58e021f
(tar-parse-info, tar-header-name): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
105704
diff
changeset
|
132 ;; 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
|
133 (defvar tar-parse-info) |
27deb58e021f
(tar-parse-info, tar-header-name): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
105704
diff
changeset
|
134 (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
|
135 |
29959 | 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 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
308 ;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183 |
29959 | 309 ;;; pcmpl-gnu.el ends here |