Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; pcmpl-cvs.el --- functions for dealing with cvs completions |
4fa9f636 | 2 | |
c90f2757 | 3 | ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
5df4f04c | 4 | ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
feb69f49 JW |
5 | |
6 | ;; Author: John Wiegley <johnw@gnu.org> | |
bd78fa1d | 7 | ;; Package: pcomplete |
4fa9f636 GM |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
4fa9f636 | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
4fa9f636 GM |
15 | |
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. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
4fa9f636 GM |
23 | |
24 | ;;; Commentary: | |
25 | ||
26 | ;; These functions provide completion rules for the `cvs' tool. | |
27 | ||
28 | ;;; Code: | |
29 | ||
30 | (provide 'pcmpl-cvs) | |
31 | ||
32 | (require 'pcomplete) | |
33 | (require 'executable) | |
34 | ||
35 | (defgroup pcmpl-cvs nil | |
1818080f | 36 | "Functions for dealing with CVS completions." |
4fa9f636 GM |
37 | :group 'pcomplete) |
38 | ||
39 | ;; User Variables: | |
40 | ||
41 | (defcustom pcmpl-cvs-binary (or (executable-find "cvs") "cvs") | |
9201cc28 | 42 | "The full path of the 'cvs' binary." |
4fa9f636 GM |
43 | :type 'file |
44 | :group 'pcmpl-cvs) | |
45 | ||
46 | ;; Functions: | |
47 | ||
48 | ;;;###autoload | |
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") | |
60 | (pcomplete-opt "flR") | |
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") | |
79 | (pcomplete-opt "d") | |
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) | |
92 | saw-backdate) | |
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") | |
102 | (pcomplete-opt "lR") | |
103 | (while (pcomplete-here (pcmpl-cvs-entries '(?M ?R ?A))))) | |
104 | ((pcomplete-test "update") | |
105 | (setq pcomplete-help "(cvs)update") | |
106 | (pcomplete-opt | |
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))))) | |
111 | (t | |
112 | (while (pcomplete-here (pcmpl-cvs-entries))))))) | |
113 | ||
114 | (defun pcmpl-cvs-commands () | |
115 | "Return a list of available CVS commands." | |
116 | (with-temp-buffer | |
117 | (call-process pcmpl-cvs-binary nil t nil "--help-commands") | |
118 | (goto-char (point-min)) | |
119 | (let (cmds) | |
120 | (while (re-search-forward "^\\s-+\\([a-z]+\\)" nil t) | |
121 | (setq cmds (cons (match-string 1) cmds))) | |
122 | (pcomplete-uniqify-list cmds)))) | |
123 | ||
124 | (defun pcmpl-cvs-modules () | |
125 | "Return a list of available modules under CVS." | |
126 | (with-temp-buffer | |
127 | (call-process pcmpl-cvs-binary nil t nil "checkout" "-c") | |
128 | (goto-char (point-min)) | |
129 | (let (entries) | |
130 | (while (re-search-forward "\\(\\S-+\\)$" nil t) | |
131 | (setq entries (cons (match-string 1) entries))) | |
132 | (pcomplete-uniqify-list entries)))) | |
133 | ||
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)) | |
137 | tags) | |
138 | (with-temp-buffer | |
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) | |
143 | (forward-line) | |
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)) | |
148 | (forward-line)))) | |
149 | (pcomplete-uniqify-list tags))) | |
150 | ||
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) "")) | |
159 | entries) | |
160 | (if opers | |
161 | (with-temp-buffer | |
162 | (and dir (cd dir)) | |
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))))) | |
169 | (with-temp-buffer | |
170 | (insert-file-contents (concat dir "CVS/Entries")) | |
171 | (goto-char (point-min)) | |
172 | (while (not (eobp)) | |
173 | (let* ((line (buffer-substring (line-beginning-position) | |
174 | (line-end-position))) | |
175 | (fields (split-string line "/")) | |
176 | text) | |
177 | (if (eq (aref line 0) ?/) | |
178 | (setq fields (cons "" fields))) | |
179 | (setq text (nth 1 fields)) | |
180 | (when text | |
181 | (if (string= (nth 0 fields) "D") | |
182 | (setq text (file-name-as-directory text))) | |
183 | (setq entries (cons text entries)))) | |
184 | (forward-line)))) | |
185 | (setq pcomplete-stub nondir) | |
186 | (pcomplete-uniqify-list entries))) | |
187 | ||
188 | ;;; pcmpl-cvs.el ends here |