(calendar-location-name, calendar-latitude)
[emacs.git] / lisp / pcmpl-gnu.el
blob4db911f0499fce34296e032504c8d8671632e5bb
1 ;;; pcmpl-gnu.el --- completions for GNU project tools
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
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.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;;; Commentary:
25 ;;; Code:
27 (provide 'pcmpl-gnu)
29 (require 'pcomplete)
30 (require 'pcmpl-unix)
32 (defgroup pcmpl-gnu nil
33 "Completions for GNU project tools."
34 :group 'pcomplete)
36 ;; User Variables:
38 (defcustom pcmpl-gnu-makefile-regexps
39 '("\\`GNUmakefile" "\\`Makefile" "\\.mak\\'")
40 "*A list of regexps that will match Makefile names."
41 :type '(repeat regexp)
42 :group 'pcmpl-gnu)
44 ;; Functions:
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))))))))))
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)))))))))
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)))))))))
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)))))))))
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))))
105 (defun pcmpl-gnu-makefile-names ()
106 "Return a list of possible makefile names."
107 (let ((names (list t))
108 (reg pcmpl-gnu-makefile-regexps))
109 (while reg
110 (nconc names (pcomplete-entries (car reg)))
111 (setq reg (cdr reg)))
112 (cdr names)))
114 (defun pcmpl-gnu-make-rule-names ()
115 "Return a list of possible make rule names in MAKEFILE."
116 (let* ((minus-f (member "-f" pcomplete-args))
117 (makefile (or (cadr minus-f)
118 (if (file-exists-p "GNUmakefile")
119 "GNUmakefile"
120 "Makefile")))
121 rules)
122 (if (not (file-readable-p makefile))
123 (unless minus-f (list "-f"))
124 (with-temp-buffer
125 (insert-file-contents-literally makefile)
126 (while (re-search-forward
127 (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t)
128 (setq rules (append (split-string (match-string 1)) rules))))
129 (pcomplete-uniqify-list rules))))
131 (defcustom pcmpl-gnu-tarfile-regexp
132 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
133 "*A regexp which matches any tar archive."
134 :type 'regexp
135 :group 'pcmpl-gnu)
137 (defvar pcmpl-gnu-tar-buffer nil)
139 ;;;###autoload
140 (defun pcomplete/tar ()
141 "Completion for the GNU tar utility."
142 ;; options that end in an equal sign will want further completion...
143 (let (saw-option complete-within)
144 (setq pcomplete-suffix-list (cons ?= pcomplete-suffix-list))
145 (while (pcomplete-match "^-" 0)
146 (setq saw-option t)
147 (if (pcomplete-match "^--" 0)
148 (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0)
149 (pcomplete-here*
150 '("--absolute-names"
151 "--after-date="
152 "--append"
153 "--atime-preserve"
154 "--backup"
155 "--block-number"
156 "--blocking-factor="
157 "--catenate"
158 "--checkpoint"
159 "--compare"
160 "--compress"
161 "--concatenate"
162 "--confirmation"
163 "--create"
164 "--delete"
165 "--dereference"
166 "--diff"
167 "--directory="
168 "--exclude="
169 "--exclude-from="
170 "--extract"
171 "--file="
172 "--files-from="
173 "--force-local"
174 "--get"
175 "--group="
176 "--gzip"
177 "--help"
178 "--ignore-failed-read"
179 "--ignore-zeros"
180 "--incremental"
181 "--info-script="
182 "--interactive"
183 "--keep-old-files"
184 "--label="
185 "--list"
186 "--listed-incremental"
187 "--mode="
188 "--modification-time"
189 "--multi-volume"
190 "--new-volume-script="
191 "--newer="
192 "--newer-mtime"
193 "--no-recursion"
194 "--null"
195 "--numeric-owner"
196 "--old-archive"
197 "--one-file-system"
198 "--owner="
199 "--portability"
200 "--posix"
201 "--preserve"
202 "--preserve-order"
203 "--preserve-permissions"
204 "--read-full-records"
205 "--record-size="
206 "--recursive-unlink"
207 "--remove-files"
208 "--rsh-command="
209 "--same-order"
210 "--same-owner"
211 "--same-permissions"
212 "--sparse"
213 "--starting-file="
214 "--suffix="
215 "--tape-length="
216 "--to-stdout"
217 "--totals"
218 "--uncompress"
219 "--ungzip"
220 "--unlink-first"
221 "--update"
222 "--use-compress-program="
223 "--verbose"
224 "--verify"
225 "--version"
226 "--volno-file=")))
227 (pcomplete-opt "01234567ABCFGKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz"))
228 (cond
229 ((pcomplete-match "\\`--after-date=" 0)
230 (pcomplete-here*))
231 ((pcomplete-match "\\`--backup=" 0)
232 (pcomplete-here*))
233 ((pcomplete-match "\\`--blocking-factor=" 0)
234 (pcomplete-here*))
235 ((pcomplete-match "\\`--directory=\\(.*\\)" 0)
236 (pcomplete-here* (pcomplete-dirs)
237 (pcomplete-match-string 1 0)))
238 ((pcomplete-match "\\`--exclude-from=\\(.*\\)" 0)
239 (pcomplete-here* (pcomplete-entries)
240 (pcomplete-match-string 1 0)))
241 ((pcomplete-match "\\`--exclude=" 0)
242 (pcomplete-here*))
243 ((pcomplete-match "\\`--\\(extract\\|list\\)\\'" 0)
244 (setq complete-within t))
245 ((pcomplete-match "\\`--file=\\(.*\\)" 0)
246 (pcomplete-here* (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)
247 (pcomplete-match-string 1 0)))
248 ((pcomplete-match "\\`--files-from=\\(.*\\)" 0)
249 (pcomplete-here* (pcomplete-entries)
250 (pcomplete-match-string 1 0)))
251 ((pcomplete-match "\\`--group=\\(.*\\)" 0)
252 (pcomplete-here* (pcmpl-unix-group-names)
253 (pcomplete-match-string 1 0)))
254 ((pcomplete-match "\\`--info-script=\\(.*\\)" 0)
255 (pcomplete-here* (pcomplete-entries)
256 (pcomplete-match-string 1 0)))
257 ((pcomplete-match "\\`--label=" 0)
258 (pcomplete-here*))
259 ((pcomplete-match "\\`--mode=" 0)
260 (pcomplete-here*))
261 ((pcomplete-match "\\`--new-volume-script=\\(.*\\)" 0)
262 (pcomplete-here* (pcomplete-entries)
263 (pcomplete-match-string 1 0)))
264 ((pcomplete-match "\\`--newer=" 0)
265 (pcomplete-here*))
266 ((pcomplete-match "\\`--owner=\\(.*\\)" 0)
267 (pcomplete-here* (pcmpl-unix-user-names)
268 (pcomplete-match-string 1 0)))
269 ((pcomplete-match "\\`--record-size=" 0)
270 (pcomplete-here*))
271 ((pcomplete-match "\\`--rsh-command=\\(.*\\)" 0)
272 (pcomplete-here* (funcall pcomplete-command-completion-function)
273 (pcomplete-match-string 1 0)))
274 ((pcomplete-match "\\`--starting-file=\\(.*\\)" 0)
275 (pcomplete-here* (pcomplete-entries)
276 (pcomplete-match-string 1 0)))
277 ((pcomplete-match "\\`--suffix=" 0)
278 (pcomplete-here*))
279 ((pcomplete-match "\\`--tape-length=" 0)
280 (pcomplete-here*))
281 ((pcomplete-match "\\`--use-compress-program=\\(.*\\)" 0)
282 (pcomplete-here* (funcall pcomplete-command-completion-function)
283 (pcomplete-match-string 1 0)))
284 ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0)
285 (pcomplete-here* (pcomplete-entries)
286 (pcomplete-match-string 1 0)))))
287 (setq pcomplete-suffix-list (cdr pcomplete-suffix-list))
288 (unless saw-option
289 (pcomplete-here
290 (mapcar 'char-to-string
291 (string-to-list
292 "01234567ABCFGIKLMNOPRSTUVWXZbcdfghiklmoprstuvwxz")))
293 (if (pcomplete-match "[xt]" 'first 1)
294 (setq complete-within t)))
295 (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp))
296 (setq pcmpl-gnu-tar-buffer (find-file-noselect (pcomplete-arg 1)))
297 (while (pcomplete-here
298 (if complete-within
299 (with-current-buffer pcmpl-gnu-tar-buffer
300 (mapcar
301 (function
302 (lambda (entry)
303 (tar-header-name (cdr entry))))
304 tar-parse-info))
305 (pcomplete-entries))
306 nil 'identity))))
308 ;;;###autoload
309 (defalias 'pcomplete/gdb 'pcomplete/xargs)
311 ;;; arch-tag: 06d2b429-dcb1-4a57-84e1-f70d87781183
312 ;;; pcmpl-gnu.el ends here