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