* xdisp.c (note_mode_line_or_margin_highlight): Check
[emacs.git] / lisp / pcmpl-cvs.el
blobd5003d5de08f9611d7645fd33d8897e50ea6439b
1 ;;; pcmpl-cvs.el --- functions for dealing with cvs completions
3 ;; Copyright (C) 1999, 2000, 2002 Free Software Foundation
5 ;; Author: John Wiegley <johnw@gnu.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
26 ;; These functions provide completion rules for the `cvs' tool.
28 ;;; Code:
30 (provide 'pcmpl-cvs)
32 (require 'pcomplete)
33 (require 'executable)
35 (defgroup pcmpl-cvs nil
36 "Functions for dealing with CVS completions"
37 :group 'pcomplete)
39 ;; User Variables:
41 (defcustom pcmpl-cvs-binary (or (executable-find "cvs") "cvs")
42 "*The full path of the 'cvs' binary."
43 :type 'file
44 :group 'pcmpl-cvs)
46 ;; Functions:
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)))))
112 (while (pcomplete-here (pcmpl-cvs-entries)))))))
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))))
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))))
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)))
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)))
188 ;;; arch-tag: d2aeac43-4bf5-4509-a496-74b863c6642b
189 ;;; pcmpl-cvs.el ends here