b3c1f8c1343f90b0e964e75e64c553575509f3a6
[bpt/emacs.git] / lisp / vc / pcvs-defs.el
1 ;;; pcvs-defs.el --- variable definitions for PCL-CVS
2
3 ;; Copyright (C) 1991-2012 Free Software Foundation, Inc.
4
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
6 ;; Keywords: pcl-cvs
7 ;; Package: pcvs
8
9 ;; This file is part of GNU Emacs.
10
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.
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
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26
27 ;;; Code:
28
29 (require 'pcvs-util)
30
31 ;;;; -------------------------------------------------------
32 ;;;; START OF THINGS TO CHECK WHEN INSTALLING
33
34 (defvar cvs-program "cvs"
35 "Name or full path of the cvs executable.")
36
37 (defvar cvs-version
38 ;; With the divergence of the CVSNT codebase and version numbers, this is
39 ;; not really good any more.
40 (ignore-errors
41 (with-temp-buffer
42 (call-process cvs-program nil t nil "-v")
43 (goto-char (point-min))
44 (when (re-search-forward "(CVS\\(NT\\)?) \\([0-9]+\\)\\.\\([0-9]+\\)"
45 nil t)
46 (cons (string-to-number (match-string 1))
47 (string-to-number (match-string 2))))))
48 "Version of `cvs' installed on your system.
49 It must be in the (MAJOR . MINOR) format.")
50
51 ;; FIXME: this is only used by cvs-mode-diff-backup
52 (defvar cvs-diff-program (or (and (boundp 'diff-command) diff-command) "diff")
53 "Name or full path of the best diff program you've got.
54 NOTE: there are some nasty bugs in the context diff variants of some vendor
55 versions, such as the one in SunOS-4.")
56
57 ;;;; END OF THINGS TO CHECK WHEN INSTALLING
58 ;;;; --------------------------------------------------------
59
60 ;;;; User configuration variables:
61
62 (defgroup pcl-cvs nil
63 "Special support for the CVS versioning system."
64 :version "21.1"
65 :group 'tools
66 :prefix "cvs-")
67
68 ;;
69 ;; cvsrc options
70 ;;
71
72 (defcustom cvs-cvsrc-file (convert-standard-filename "~/.cvsrc")
73 "Path to your cvsrc file."
74 :group 'pcl-cvs
75 :type '(file))
76
77 (defvar cvs-shared-start 4
78 "Index of the first shared flag.
79 If set to 4, for instance, a numeric argument smaller than 4 will
80 select a non-shared flag, while a numeric argument greater than 3
81 will select a shared-flag.")
82
83 (defvar cvs-shared-flags (make-list cvs-shared-start nil)
84 "List of flags whose settings is shared among several commands.")
85
86 (defvar cvs-cvsroot nil
87 "Specifies where the (current) cvs master repository is.
88 Overrides the environment variable $CVSROOT by sending \" -d dir\" to
89 all CVS commands. This switch is useful if you have multiple CVS
90 repositories. It can be set interactively with \\[cvs-change-cvsroot.]
91 There is no need to set this if $CVSROOT is set to a correct value.")
92
93 (defcustom cvs-auto-remove-handled nil
94 "If up-to-date files should be acknowledged automatically.
95 If T, they will be removed from the *cvs* buffer after every command.
96 If DELAYED, they will be removed from the *cvs* buffer before every command.
97 If STATUS, they will only be removed after a `cvs-mode-status' command.
98 Else, they will never be automatically removed from the *cvs* buffer."
99 :group 'pcl-cvs
100 :type '(choice (const nil) (const status) (const delayed) (const t)))
101
102 (defcustom cvs-auto-remove-directories 'handled
103 "If ALL, directory entries will never be shown.
104 If HANDLED, only non-handled directories will be shown.
105 If EMPTY, only non-empty directories will be shown."
106 :group 'pcl-cvs
107 :type '(choice (const :tag "No" nil) (const all) (const handled) (const empty)))
108
109 (defcustom cvs-auto-revert t
110 "Non-nil if changed files should automatically be reverted."
111 :group 'pcl-cvs
112 :type '(boolean))
113
114 (defcustom cvs-sort-ignore-file t
115 "Non-nil if `cvs-mode-ignore' should sort the .cvsignore automatically."
116 :group 'pcl-cvs
117 :type '(boolean))
118
119 (defcustom cvs-force-dir-tag t
120 "If non-nil, tagging can only be applied to directories.
121 Tagging should generally be applied a directory at a time, but sometimes it is
122 useful to be able to tag a single file. The normal way to do that is to use
123 `cvs-mode-force-command' so as to temporarily override the restrictions,"
124 :group 'pcl-cvs
125 :type '(boolean))
126
127 (defcustom cvs-default-ignore-marks nil
128 "Non-nil if cvs mode commands should ignore any marked files.
129 Normally they run on the files that are marked (with `cvs-mode-mark'),
130 or the file under the cursor if no files are marked. If this variable
131 is set to a non-nil value they will by default run on the file on the
132 current line. See also `cvs-invert-ignore-marks'"
133 :group 'pcl-cvs
134 :type '(boolean))
135
136 (defcustom cvs-invert-ignore-marks
137 (let ((l ()))
138 (unless (equal cvs-default-ignore-marks t)
139 (push "diff" l))
140 (when (and cvs-force-dir-tag (not cvs-default-ignore-marks))
141 (push "tag" l))
142 l)
143 "List of cvs commands that invert the default ignore-mark behavior.
144 Commands in this set will use the opposite default from the one set
145 in `cvs-default-ignore-marks'."
146 :group 'pcl-cvs
147 :type '(set (const "diff")
148 (const "tag")
149 (const "ignore")))
150
151 (defcustom cvs-confirm-removals t
152 "Ask for confirmation before removing files.
153 Non-nil means that PCL-CVS will ask confirmation before removing files
154 except for files whose content can readily be recovered from the repository.
155 A value of `list' means that the list of files to be deleted will be
156 displayed when asking for confirmation."
157 :group 'pcl-cvs
158 :type '(choice (const list)
159 (const t)
160 (const nil)))
161
162 (defcustom cvs-add-default-message nil
163 "Default message to use when adding files.
164 If set to nil, `cvs-mode-add' will always prompt for a message."
165 :group 'pcl-cvs
166 :type '(choice (const :tag "Prompt" nil)
167 (string)))
168
169 (defcustom cvs-find-file-and-jump nil
170 "Jump to the modified area when finding a file.
171 If non-nil, `cvs-mode-find-file' will place the cursor at the beginning of
172 the modified area. If the file is not locally modified, this will obviously
173 have no effect."
174 :group 'pcl-cvs
175 :type '(boolean))
176
177 (defcustom cvs-buffer-name-alist
178 '(("diff" "*cvs-diff*" diff-mode)
179 ("status" "*cvs-info*" cvs-status-mode)
180 ("tree" "*cvs-info*" cvs-status-mode)
181 ("message" "*cvs-commit*" nil log-edit)
182 ("log" "*cvs-info*" log-view-mode))
183 "Buffer name and mode to be used for each command.
184 This is a list of elements of the form
185
186 (CMD BUFNAME MODE &optional POSTPROC)
187
188 CMD is the name of the command.
189 BUFNAME is an expression that should evaluate to a string used as
190 a buffer name. It can use the variable CMD if it wants to.
191 MODE is the command to use to setup the buffer.
192 POSTPROC is a function that should be executed when the command terminates
193
194 The CMD used for `cvs-mode-commit' is \"message\". For that special
195 case, POSTPROC is called just after MODE with special arguments."
196 :group 'pcl-cvs
197 :type '(repeat
198 (list (choice (const "diff")
199 (const "status")
200 (const "tree")
201 (const "message")
202 (const "log")
203 (string))
204 (choice (const "*vc-diff*")
205 (const "*cvs-info*")
206 (const "*cvs-commit*")
207 (const (expand-file-name "*cvs-commit*"))
208 (const (format "*cvs-%s*" cmd))
209 (const (expand-file-name (format "*cvs-%s*" cmd)))
210 (sexp :value "my-cvs-info-buffer")
211 (const nil))
212 (choice (function-item diff-mode)
213 (function-item cvs-edit-mode)
214 (function-item cvs-status-mode)
215 function
216 (const nil))
217 (set :inline t
218 (choice (function-item cvs-status-cvstrees)
219 (function-item cvs-status-trees)
220 function)))))
221
222 (defvar cvs-buffer-name '(expand-file-name "*cvs*" dir) ;; "*cvs*"
223 "Name of the cvs buffer.
224 This expression will be evaluated in an environment where DIR is set to
225 the directory name of the cvs buffer.")
226
227 (defvar cvs-temp-buffer-name
228 ;; Was '(expand-file-name " *cvs-tmp*" dir), but that causes them to
229 ;; become non-hidden if uniquification is done `forward'.
230 " *cvs-tmp*"
231 "Name of the cvs temporary buffer.
232 Output from cvs is placed here for asynchronous commands.")
233
234 (defcustom cvs-idiff-imerge-handlers
235 (if (fboundp 'ediff)
236 '(cvs-ediff-diff . cvs-ediff-merge)
237 '(cvs-emerge-diff . cvs-emerge-merge))
238 "Pair of functions to be used for resp. diff'ing and merg'ing interactively."
239 :group 'pcl-cvs
240 :type '(choice (const :tag "Ediff" (cvs-ediff-diff . cvs-ediff-merge))
241 (const :tag "Emerge" (cvs-emerge-diff . cvs-emerge-merge))))
242
243 (defvar cvs-mode-hook nil
244 "Run after `cvs-mode' was setup.")
245
246 \f
247 ;;;;
248 ;;;; Internal variables, used in the process buffer.
249 ;;;;
250
251 (defvar cvs-postprocess nil
252 "(Buffer local) what to do once the process exits.")
253
254 ;;;;
255 ;;;; Internal variables for the *cvs* buffer.
256 ;;;;
257
258 (defcustom cvs-reuse-cvs-buffer 'subdir
259 "When to reuse an existing cvs buffer.
260 Alternatives are:
261 CURRENT: just reuse the current buffer if it is a cvs buffer
262 SAMEDIR: reuse any cvs buffer displaying the same directory
263 SUBDIR: or reuse any cvs buffer displaying any sub- or super- directory
264 ALWAYS: reuse any cvs buffer."
265 :group 'pcl-cvs
266 :type '(choice (const always) (const subdir) (const samedir) (const current)))
267
268 (defvar cvs-temp-buffer nil
269 "(Buffer local) The temporary buffer associated with this *cvs* buffer.")
270
271 (defvar cvs-lock-file nil
272 "Full path to a lock file that CVS is waiting for (or was waiting for).
273 This variable is buffer local and only used in the *cvs* buffer.")
274
275 (defvar cvs-lock-file-regexp "^#cvs\\.\\([trw]fl\\.[-.a-z0-9]+\\|lock\\)\\'"
276 "Regexp matching the possible names of locks in the CVS repository.")
277
278 (defconst cvs-cursor-column 22
279 "Column to position cursor in in `cvs-mode'.")
280
281 ;;;;
282 ;;;; Global internal variables
283 ;;;;
284
285 (defconst cvs-vendor-branch "1.1.1"
286 "The default branch used by CVS for vendor code.")
287
288 (easy-mmode-defmap cvs-mode-diff-map
289 '(("E" "imerge" . cvs-mode-imerge)
290 ("=" . cvs-mode-diff)
291 ("e" "idiff" . cvs-mode-idiff)
292 ("2" "other" . cvs-mode-idiff-other)
293 ("d" "diff" . cvs-mode-diff)
294 ("b" "backup" . cvs-mode-diff-backup)
295 ("h" "head" . cvs-mode-diff-head)
296 ("r" "repository" . cvs-mode-diff-repository)
297 ("y" "yesterday" . cvs-mode-diff-yesterday)
298 ("v" "vendor" . cvs-mode-diff-vendor))
299 "Keymap for diff-related operations in `cvs-mode'."
300 :name "Diff")
301 ;; This is necessary to allow correct handling of \\[cvs-mode-diff-map]
302 ;; in substitute-command-keys.
303 (fset 'cvs-mode-diff-map cvs-mode-diff-map)
304
305 (easy-mmode-defmap cvs-mode-map
306 ;;(define-prefix-command 'cvs-mode-map-diff-prefix)
307 ;;(define-prefix-command 'cvs-mode-map-control-c-prefix)
308 '(;; various
309 ;; (undo . cvs-mode-undo)
310 ("?" . cvs-help)
311 ("h" . cvs-help)
312 ("q" . cvs-bury-buffer)
313 ("z" . kill-this-buffer)
314 ("F" . cvs-mode-set-flags)
315 ;; ("\M-f" . cvs-mode-force-command)
316 ("!" . cvs-mode-force-command)
317 ("\C-c\C-c" . cvs-mode-kill-process)
318 ;; marking
319 ("m" . cvs-mode-mark)
320 ("M" . cvs-mode-mark-all-files)
321 ("S" . cvs-mode-mark-on-state)
322 ("u" . cvs-mode-unmark)
323 ("\C-?". cvs-mode-unmark-up)
324 ("%" . cvs-mode-mark-matching-files)
325 ("T" . cvs-mode-toggle-marks)
326 ("\M-\C-?" . cvs-mode-unmark-all-files)
327 ;; navigation keys
328 (" " . cvs-mode-next-line)
329 ("n" . cvs-mode-next-line)
330 ("p" . cvs-mode-previous-line)
331 ("\t" . cvs-mode-next-line)
332 ([backtab] . cvs-mode-previous-line)
333 ;; M- keys are usually those that operate on modules
334 ;;("\M-C". cvs-mode-rcs2log) ; i.e. "Create a ChangeLog"
335 ;;("\M-t". cvs-rtag)
336 ;;("\M-l". cvs-rlog)
337 ("\M-c". cvs-checkout)
338 ("\M-e". cvs-examine)
339 ("g" . cvs-mode-revert-buffer)
340 ("\M-u". cvs-update)
341 ("\M-s". cvs-status)
342 ;; diff commands
343 ("=" . cvs-mode-diff)
344 ("d" . cvs-mode-diff-map)
345 ;; keys that operate on individual files
346 ("\C-k" . cvs-mode-acknowledge)
347 ("A" . cvs-mode-add-change-log-entry-other-window)
348 ;;("B" . cvs-mode-byte-compile-files)
349 ("C" . cvs-mode-commit-setup)
350 ("O" . cvs-mode-update)
351 ("U" . cvs-mode-undo)
352 ("I" . cvs-mode-insert)
353 ("a" . cvs-mode-add)
354 ("b" . cvs-set-branch-prefix)
355 ("B" . cvs-set-secondary-branch-prefix)
356 ("c" . cvs-mode-commit)
357 ("e" . cvs-mode-examine)
358 ("f" . cvs-mode-find-file)
359 ("\C-m" . cvs-mode-find-file)
360 ("i" . cvs-mode-ignore)
361 ("l" . cvs-mode-log)
362 ("o" . cvs-mode-find-file-other-window)
363 ("r" . cvs-mode-remove)
364 ("s" . cvs-mode-status)
365 ("t" . cvs-mode-tag)
366 ("v" . cvs-mode-view-file)
367 ("x" . cvs-mode-remove-handled)
368 ;; cvstree bindings
369 ("+" . cvs-mode-tree)
370 ;; mouse bindings
371 ([mouse-2] . cvs-mode-find-file)
372 ([follow-link] . (lambda (pos)
373 (if (eq (get-char-property pos 'face) 'cvs-filename) t)))
374 ([(down-mouse-3)] . cvs-menu)
375 ;; dired-like bindings
376 ("\C-o" . cvs-mode-display-file)
377 ;; Emacs-21 toolbar
378 ;;([tool-bar item1] . (menu-item "Examine" cvs-examine :image (image :file "/usr/share/icons/xpaint.xpm" :type xpm)))
379 ;;([tool-bar item2] . (menu-item "Update" cvs-update :image (image :file "/usr/share/icons/mail1.xpm" :type xpm)))
380 )
381 "Keymap for `cvs-mode'."
382 :dense t
383 :suppress t)
384
385 (fset 'cvs-mode-map cvs-mode-map)
386
387 (easy-menu-define cvs-menu cvs-mode-map "Menu used in `cvs-mode'."
388 '("CVS"
389 ["Open file" cvs-mode-find-file t]
390 ["Open in other window" cvs-mode-find-file-other-window t]
391 ["Display in other window" cvs-mode-display-file t]
392 ["Interactive merge" cvs-mode-imerge t]
393 ("View diff"
394 ["Interactive diff" cvs-mode-idiff t]
395 ["Current diff" cvs-mode-diff t]
396 ["Diff with head" cvs-mode-diff-head t]
397 ["Diff with vendor" cvs-mode-diff-vendor t]
398 ["Diff against yesterday" cvs-mode-diff-yesterday t]
399 ["Diff with backup" cvs-mode-diff-backup t])
400 ["View log" cvs-mode-log t]
401 ["View status" cvs-mode-status t]
402 ["View tag tree" cvs-mode-tree t]
403 "----"
404 ["Insert" cvs-mode-insert]
405 ["Update" cvs-mode-update (cvs-enabledp 'update)]
406 ["Re-examine" cvs-mode-examine t]
407 ["Commit" cvs-mode-commit-setup (cvs-enabledp 'commit)]
408 ["Tag" cvs-mode-tag (cvs-enabledp (when cvs-force-dir-tag 'tag))]
409 ["Undo changes" cvs-mode-undo (cvs-enabledp 'undo)]
410 ["Add" cvs-mode-add (cvs-enabledp 'add)]
411 ["Remove" cvs-mode-remove (cvs-enabledp 'remove)]
412 ["Ignore" cvs-mode-ignore (cvs-enabledp 'ignore)]
413 ["Add ChangeLog" cvs-mode-add-change-log-entry-other-window t]
414 "----"
415 ["Mark" cvs-mode-mark t]
416 ["Mark all" cvs-mode-mark-all-files t]
417 ["Mark by regexp..." cvs-mode-mark-matching-files t]
418 ["Mark by state..." cvs-mode-mark-on-state t]
419 ["Unmark" cvs-mode-unmark t]
420 ["Unmark all" cvs-mode-unmark-all-files t]
421 ["Hide handled" cvs-mode-remove-handled t]
422 "----"
423 ["PCL-CVS Manual" (lambda () (interactive)
424 (info "(pcl-cvs)Top")) t]
425 "----"
426 ["Quit" cvs-mode-quit t]))
427
428 ;;;;
429 ;;;; CVS-Minor mode
430 ;;;;
431
432 (defcustom cvs-minor-mode-prefix "\C-xc"
433 "Prefix key for the `cvs-mode' bindings in `cvs-minor-mode'."
434 :group 'pcl-cvs)
435
436 (easy-mmode-defmap cvs-minor-mode-map
437 `((,cvs-minor-mode-prefix . cvs-mode-map)
438 ("e" . (menu-item nil cvs-mode-edit-log
439 :filter (lambda (x) (if (derived-mode-p 'log-view-mode) x)))))
440 "Keymap for `cvs-minor-mode', used in buffers related to PCL-CVS.")
441
442 (defvar cvs-buffer nil
443 "(Buffer local) The *cvs* buffer associated with this buffer.")
444 (put 'cvs-buffer 'permanent-local t)
445 ;;(make-variable-buffer-local 'cvs-buffer)
446
447 (defvar cvs-minor-wrap-function nil
448 "Function to call when switching to the *cvs* buffer.
449 Takes two arguments:
450 - a *cvs* buffer.
451 - a zero-arg function which is guaranteed not to switch buffer.
452 It is expected to call the function.")
453 ;;(make-variable-buffer-local 'cvs-minor-wrap-function)
454
455 (defvar cvs-minor-current-files)
456 ;;"Current files in a `cvs-minor-mode' buffer."
457 ;; This should stay `void' because we want to be able to tell the difference
458 ;; between an empty list and no list at all.
459
460 (defconst cvs-pcl-cvs-dirchange-re "^pcl-cvs: descending directory \\(.*\\)$")
461
462 ;;;;
463 ;;;; autoload the global menu
464 ;;;;
465
466 ;;;###autoload
467 (defvar cvs-global-menu
468 (let ((m (make-sparse-keymap "PCL-CVS")))
469 (define-key m [status]
470 `(menu-item ,(purecopy "Directory Status") cvs-status
471 :help ,(purecopy "A more verbose status of a workarea")))
472 (define-key m [checkout]
473 `(menu-item ,(purecopy "Checkout Module") cvs-checkout
474 :help ,(purecopy "Check out a module from the repository")))
475 (define-key m [update]
476 `(menu-item ,(purecopy "Update Directory") cvs-update
477 :help ,(purecopy "Fetch updates from the repository")))
478 (define-key m [examine]
479 `(menu-item ,(purecopy "Examine Directory") cvs-examine
480 :help ,(purecopy "Examine the current state of a workarea")))
481 (fset 'cvs-global-menu m))
482 "Global menu used by PCL-CVS.")
483
484
485 ;; cvs-1.10 and above can take file arguments in other directories
486 ;; while others need to be executed once per directory
487 (defvar cvs-execute-single-dir
488 (if (or (null cvs-version)
489 (or (>= (cdr cvs-version) 10) (> (car cvs-version) 1)))
490 ;; Supposedly some recent versions of CVS output some directory info
491 ;; as they recurse down the tree, but it's not good enough in the case
492 ;; where we run "cvs status foo bar/foo".
493 '("status")
494 t)
495 "Whether cvs commands should be executed a directory at a time.
496 If a list, specifies for which commands the single-dir mode should be used.
497 If T, single-dir mode should be used for all operations.
498
499 CVS versions before 1.10 did not allow passing them arguments in different
500 directories, so pcl-cvs checks what version you're using to determine
501 whether to use the new feature or not.
502 Sadly, even with a new cvs executable, if you connect to an older cvs server
503 \(typically a cvs-1.9 on the server), the old restriction applies. In such
504 a case the sanity check made by pcl-cvs fails and you will have to manually
505 set this variable to t (until the cvs server is upgraded).
506 When the above problem occurs, pcl-cvs should (hopefully) catch cvs' error
507 message and replace it with a message telling you to change this variable.")
508
509 ;;
510 (provide 'pcvs-defs)
511
512 ;;; pcvs-defs.el ends here