1 ;;; pcmpl-cvs.el --- functions for dealing with cvs completions
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: John Wiegley <johnw@gnu.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; These functions provide completion rules for the `cvs' tool.
35 (defgroup pcmpl-cvs nil
36 "Functions for dealing with CVS completions."
41 (defcustom pcmpl-cvs-binary
(or (executable-find "cvs") "cvs")
42 "The full path of the 'cvs' binary."
49 (defun pcomplete/cvs
()
50 "Completion rules for the `cvs' command."
51 (let ((pcomplete-help "(cvs)Invoking CVS"))
52 (pcomplete-opt "HQqrwlntvfab/T/e*d/z?s")
53 (pcomplete-here* (pcmpl-cvs-commands))
54 (cond ((pcomplete-test "add")
55 (setq pcomplete-help
"(cvs)Adding files")
56 (pcomplete-opt "k?m?")
57 (while (pcomplete-here (pcmpl-cvs-entries '(??
)))))
58 ((pcomplete-test "remove")
59 (setq pcomplete-help
"(cvs)Removing files")
61 (while (pcomplete-here (pcmpl-cvs-entries '(?U
)))))
62 ((pcomplete-test "init")
63 (setq pcomplete-help
"(cvs)Creating a repository"))
64 ((pcomplete-test '("login" "logout"))
65 (setq pcomplete-help
"(cvs)Password authentication client"))
66 ((pcomplete-test "import")
67 (setq pcomplete-help
"(cvs)import")
68 (pcomplete-opt "dk?I(pcmpl-cvs-entries '(??))b?m?W?"))
69 ((pcomplete-test "checkout")
70 (setq pcomplete-help
"(cvs)checkout")
71 (pcomplete-opt "ANPRcflnpsr?D?d/k?j?")
72 (pcomplete-here (pcmpl-cvs-modules)))
73 ((pcomplete-test "rtag")
74 (setq pcomplete-help
"(cvs)Creating a branch")
75 (pcomplete-opt "aflRndbr?DF")
76 (pcomplete-here (pcmpl-cvs-modules)))
77 ((pcomplete-test "release")
78 (setq pcomplete-help
"(cvs)release")
80 (while (pcomplete-here (pcomplete-dirs))))
81 ((pcomplete-test "export")
82 (setq pcomplete-help
"(cvs)export")
83 (pcomplete-opt "NflRnr?D?d/k?")
84 (pcomplete-here (pcmpl-cvs-modules)))
85 ((pcomplete-test "commit")
86 (setq pcomplete-help
"(cvs)commit files")
87 (pcomplete-opt "nRlfF.m?r(pcmpl-cvs-tags '(?M ?R ?A))")
88 (while (pcomplete-here (pcmpl-cvs-entries '(?M ?R ?A
)))))
89 ((pcomplete-test "diff")
90 (setq pcomplete-help
"(cvs)Viewing differences")
91 (let ((opt-index pcomplete-index
)
93 (pcomplete-opt "lRD?Nr(pcmpl-cvs-tags)")
94 (while (< opt-index pcomplete-index
)
95 (if (pcomplete-match "^-[Dr]" (- pcomplete-index opt-index
))
96 (setq saw-backdate t opt-index pcomplete-index
)
97 (setq opt-index
(1+ opt-index
))))
98 (while (pcomplete-here
99 (pcmpl-cvs-entries (unless saw-backdate
'(?M
)))))))
100 ((pcomplete-test "unedit")
101 (setq pcomplete-help
"(cvs)Editing files")
103 (while (pcomplete-here (pcmpl-cvs-entries '(?M ?R ?A
)))))
104 ((pcomplete-test "update")
105 (setq pcomplete-help
"(cvs)update")
107 (concat "APdflRpk?r(pcmpl-cvs-tags '(?U ?P))D?"
108 "j(pcmpl-cvs-tags '(?U ?P))"
109 "I(pcmpl-cvs-entries '(??))W?"))
110 (while (pcomplete-here (pcmpl-cvs-entries '(?U ?P
)))))
112 (while (pcomplete-here (pcmpl-cvs-entries)))))))
114 (defun pcmpl-cvs-commands ()
115 "Return a list of available CVS commands."
117 (call-process pcmpl-cvs-binary nil t nil
"--help-commands")
118 (goto-char (point-min))
120 (while (re-search-forward "^\\s-+\\([a-z]+\\)" nil t
)
121 (setq cmds
(cons (match-string 1) cmds
)))
122 (pcomplete-uniqify-list cmds
))))
124 (defun pcmpl-cvs-modules ()
125 "Return a list of available modules under CVS."
127 (call-process pcmpl-cvs-binary nil t nil
"checkout" "-c")
128 (goto-char (point-min))
130 (while (re-search-forward "\\(\\S-+\\)$" nil t
)
131 (setq entries
(cons (match-string 1) entries
)))
132 (pcomplete-uniqify-list entries
))))
134 (defun pcmpl-cvs-tags (&optional opers
)
135 "Return all the tags which could apply to the files related to OPERS."
136 (let ((entries (pcmpl-cvs-entries opers
))
139 (apply 'call-process pcmpl-cvs-binary nil t nil
140 "status" "-v" entries
)
141 (goto-char (point-min))
142 (while (re-search-forward "Existing Tags:" nil t
)
144 (while (not (looking-at "^$"))
145 (unless (looking-at "^\\s-+\\(\\S-+\\)\\s-+")
146 (error "Error in output from `cvs status -v'"))
147 (setq tags
(cons (match-string 1) tags
))
149 (pcomplete-uniqify-list tags
)))
151 (defun pcmpl-cvs-entries (&optional opers
)
152 "Return the Entries for the current directory.
153 If OPERS is a list of characters, return entries for which that
154 operation character applies, as displayed by 'cvs -n update'."
155 (let* ((arg (pcomplete-arg))
156 (dir (file-name-as-directory
157 (or (file-name-directory arg
) "")))
158 (nondir (or (file-name-nondirectory arg
) ""))
163 (call-process pcmpl-cvs-binary nil t nil
164 "-q" "-n" "-f" "update"); "-l")
165 (goto-char (point-min))
166 (while (re-search-forward "^\\(.\\) \\(.+\\)$" nil t
)
167 (if (memq (string-to-char (match-string 1)) opers
)
168 (setq entries
(cons (match-string 2) entries
)))))
170 (insert-file-contents (concat dir
"CVS/Entries"))
171 (goto-char (point-min))
173 (let* ((line (buffer-substring (line-beginning-position)
174 (line-end-position)))
175 (fields (split-string line
"/"))
177 (if (eq (aref line
0) ?
/)
178 (setq fields
(cons "" fields
)))
179 (setq text
(nth 1 fields
))
181 (if (string= (nth 0 fields
) "D")
182 (setq text
(file-name-as-directory text
)))
183 (setq entries
(cons text entries
))))
185 (setq pcomplete-stub nondir
)
186 (pcomplete-uniqify-list entries
)))
188 ;; arch-tag: d2aeac43-4bf5-4509-a496-74b863c6642b
189 ;;; pcmpl-cvs.el ends here