(Custom-reset-current): Don't test for default-boundp.
[emacs.git] / lisp / log-view.el
blob219359344fa9b83cde028ce9a364de1e9f8b9c55
1 ;;; log-view.el --- Major mode for browsing RCS/CVS/SCCS log output
3 ;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
6 ;; Keywords: rcs sccs cvs log version-control
7 ;; Revision: $Id: log-view.el,v 1.12 2001/12/16 16:28:59 monnier Exp $
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 2, or (at your option)
14 ;; 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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; Todo:
30 ;; - add compatibility with cvs-log.el
31 ;; - add ability to modify a log-entry (via cvs-mode-admin ;-)
32 ;; - remove references to cvs-*
34 ;;; Code:
36 (eval-when-compile (require 'cl))
37 (require 'pcvs-util)
38 (autoload 'vc-version-diff "vc")
40 (defgroup log-view nil
41 "Major mode for browsing log output of RCS/CVS/SCCS."
42 :group 'pcl-cvs
43 :prefix "log-view-")
45 (easy-mmode-defmap log-view-mode-map
46 '(("q" . quit-window)
47 ("z" . kill-this-buffer)
48 ("m" . set-mark-command)
49 ("d" . log-view-diff)
50 ("f" . log-view-find-version)
51 ("n" . log-view-msg-next)
52 ("p" . log-view-msg-prev)
53 ("N" . log-view-file-next)
54 ("P" . log-view-file-prev)
55 ("\M-n" . log-view-file-next)
56 ("\M-p" . log-view-file-prev))
57 "Log-View's keymap."
58 :group 'log-view
59 ;; Here I really need either buffer-local keymap-inheritance
60 ;; or a minor-mode-map with lower precedence than the local map.
61 :inherit (if (boundp 'cvs-mode-map) cvs-mode-map))
63 (defvar log-view-mode-hook nil
64 "Hook run at the end of `log-view-mode'.")
66 (defface log-view-file-face
67 '((((class color) (background light))
68 (:background "grey70" :weight bold))
69 (t (:weight bold)))
70 "Face for the file header line in `log-view-mode'."
71 :group 'log-view)
72 (defvar log-view-file-face 'log-view-file-face)
74 (defface log-view-message-face
75 '((((class color) (background light))
76 (:background "grey85"))
77 (t (:weight bold)))
78 "Face for the message header line in `log-view-mode'."
79 :group 'log-view)
80 (defvar log-view-message-face 'log-view-message-face)
82 (defconst log-view-file-re
83 (concat "^\\("
84 "Working file: \\(.+\\)"
85 "\\|SCCS/s\\.\\(.+\\):"
86 "\\)\n"))
87 (defconst log-view-message-re "^\\(revision \\([.0-9]+\\)\\|rev \\([0-9]+\\): .*\\|D \\([.0-9]+\\) .*\\)$")
89 (defconst log-view-font-lock-keywords
90 `((,log-view-file-re
91 (2 (if (boundp 'cvs-filename-face) cvs-filename-face) nil t)
92 (3 (if (boundp 'cvs-filename-face) cvs-filename-face) nil t)
93 (0 log-view-file-face append))
94 (,log-view-message-re . log-view-message-face)))
95 (defconst log-view-font-lock-defaults
96 '(log-view-font-lock-keywords t nil nil nil))
98 ;;;;
99 ;;;; Actual code
100 ;;;;
102 ;;;###autoload
103 (define-derived-mode log-view-mode fundamental-mode "Log-View"
104 "Major mode for browsing CVS log output."
105 (setq buffer-read-only t)
106 (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
107 (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap))
109 ;;;;
110 ;;;; Navigation
111 ;;;;
113 ;; define log-view-{msg,file}-{next,prev}
114 (easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
115 (easy-mmode-define-navigation log-view-file log-view-file-re "file")
117 (defun log-view-goto-rev (rev)
118 (goto-char (point-min))
119 (ignore-errors
120 (while (not (equal rev (log-view-current-tag)))
121 (log-view-msg-next))
124 ;;;;
125 ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
126 ;;;;
128 (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
130 (defun log-view-current-file ()
131 (save-excursion
132 (forward-line 1)
133 (or (re-search-backward log-view-file-re nil t)
134 (re-search-forward log-view-file-re))
135 (let* ((file (or (match-string 2) (match-string 3)))
136 (cvsdir (and (re-search-backward log-view-dir-re nil t)
137 (match-string 1)))
138 (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
139 (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
140 (match-string 1)))
141 (dir ""))
142 (let ((default-directory ""))
143 (when pcldir (setq dir (expand-file-name pcldir dir)))
144 (when cvsdir (setq dir (expand-file-name cvsdir dir))))
145 (expand-file-name file dir))))
147 (defun log-view-current-tag (&optional where)
148 (save-excursion
149 (when where (goto-char where))
150 (forward-line 1)
151 (let ((pt (point)))
152 (when (re-search-backward log-view-message-re nil t)
153 (let ((rev (or (match-string 2) (match-string 3) (match-string 4))))
154 (unless (re-search-forward log-view-file-re pt t)
155 rev))))))
157 (defun log-view-minor-wrap (buf f)
158 (let ((data (with-current-buffer buf
159 (cons
160 (cons (log-view-current-file)
161 (log-view-current-tag))
162 (when mark-active
163 (save-excursion
164 (goto-char (mark))
165 (cons (log-view-current-file)
166 (log-view-current-tag))))))))
167 (let ((cvs-branch-prefix (cdar data))
168 (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
169 (cvs-minor-current-files
170 (cons (caar data)
171 (when (and (cadr data) (not (equal (caar data) (cadr data))))
172 (list (cadr data)))))
173 ;; FIXME: I need to force because the fileinfos are UNKNOWN
174 (cvs-force-command "/F"))
175 (funcall f))))
177 (defun log-view-find-version (pos)
178 "Visit the version at point."
179 (interactive "d")
180 (save-excursion
181 (goto-char pos)
182 (switch-to-buffer (vc-find-version (log-view-current-file)
183 (log-view-current-tag)))))
186 ;; diff
189 (defun log-view-diff (beg end)
190 "Get the diff for several revisions.
191 If the point is the same as the mark, get the diff for this revision.
192 Otherwise, get the diff between the revisions
193 were the region starts and ends."
194 (interactive "r")
195 (let ((fr (log-view-current-tag beg))
196 (to (log-view-current-tag end)))
197 (when (string-equal fr to)
198 (save-excursion
199 (goto-char end)
200 (log-view-msg-next)
201 (setq to (log-view-current-tag))))
202 (vc-version-diff (log-view-current-file) to fr)))
204 (provide 'log-view)
206 ;;; log-view.el ends here