(longlines-decoded): New variable.
[emacs.git] / lisp / log-view.el
blob6a1fc9a11b17e50899ba09f4aca70e5e0cee01b5
1 ;;; log-view.el --- Major mode for browsing RCS/CVS/SCCS log output
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7 ;; Keywords: rcs sccs cvs log version-control
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 3, 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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;; Major mode to browse revision log histories.
29 ;; Currently supports the format output by:
30 ;; RCS, SCCS, CVS, Subversion, and DaRCS.
32 ;; Examples of log output:
34 ;;;; RCS/CVS:
36 ;; ----------------------------
37 ;; revision 1.35 locked by: turlutut
38 ;; date: 2005-03-22 18:48:38 +0000; author: monnier; state: Exp; lines: +6 -8
39 ;; (gnus-display-time-event-handler):
40 ;; Check display-time-timer at runtime rather than only at load time
41 ;; in case display-time-mode is turned off in the mean time.
42 ;; ----------------------------
43 ;; revision 1.34
44 ;; date: 2005-02-09 15:50:38 +0000; author: kfstorm; state: Exp; lines: +7 -7
45 ;; branches: 1.34.2;
46 ;; Change release version from 21.4 to 22.1 throughout.
47 ;; Change development version from 21.3.50 to 22.0.50.
49 ;;;; SCCS:
51 ;;;; Subversion:
53 ;;;; Darcs:
55 ;; Changes to darcsum.el:
56 ;;
57 ;; Mon Nov 28 15:19:38 GMT 2005 Dave Love <fx@gnu.org>
58 ;; * Abstract process startup into darcsum-start-process. Use TERM=dumb.
59 ;; TERM=dumb avoids escape characters, at least, for any old darcs that
60 ;; doesn't understand DARCS_DONT_COLOR & al.
61 ;;
62 ;; Thu Nov 24 15:20:45 GMT 2005 Dave Love <fx@gnu.org>
63 ;; * darcsum-mode-related changes.
64 ;; Don't call font-lock-mode (unnecessary) or use-local-map (redundant).
65 ;; Use mode-class 'special. Add :group.
66 ;; Add trailing-whitespace option to mode hook and fix
67 ;; darcsum-display-changeset not to use trailing whitespace.
69 ;;; Todo:
71 ;; - add ability to modify a log-entry (via cvs-mode-admin ;-)
72 ;; - remove references to cvs-*
73 ;; - make it easier to add support for new backends without changing the code.
75 ;;; Code:
77 (eval-when-compile (require 'cl))
78 (require 'pcvs-util)
79 (autoload 'vc-find-version "vc")
80 (autoload 'vc-version-diff "vc")
82 (defvar cvs-minor-wrap-function)
84 (defgroup log-view nil
85 "Major mode for browsing log output of RCS/CVS/SCCS."
86 :group 'pcl-cvs
87 :prefix "log-view-")
89 (easy-mmode-defmap log-view-mode-map
90 '(("q" . quit-window)
91 ("z" . kill-this-buffer)
92 ("m" . set-mark-command)
93 ;; ("e" . cvs-mode-edit-log)
94 ("d" . log-view-diff)
95 ("f" . log-view-find-version)
96 ("n" . log-view-msg-next)
97 ("p" . log-view-msg-prev)
98 ("N" . log-view-file-next)
99 ("P" . log-view-file-prev)
100 ("\M-n" . log-view-file-next)
101 ("\M-p" . log-view-file-prev))
102 "Log-View's keymap."
103 :group 'log-view
104 ;; Here I really need either buffer-local keymap-inheritance
105 ;; or a minor-mode-map with lower precedence than the local map.
106 :inherit (if (boundp 'cvs-mode-map) cvs-mode-map))
108 (easy-menu-define log-view-mode-menu log-view-mode-map
109 "Log-View Display Menu"
110 `("Log-View"
111 ;; XXX Do we need menu entries for these?
112 ;; ["Quit" quit-window]
113 ;; ["Kill This Buffer" kill-this-buffer]
114 ["Mark Log Entry for Diff" set-mark-command]
115 ["Diff Revisions" log-view-diff]
116 ["Visit Version" log-view-find-version]
117 ["Next Log Entry" log-view-msg-next]
118 ["Previous Log Entry" log-view-msg-prev]
119 ["Next File" log-view-file-next]
120 ["Previous File" log-view-file-prev]))
122 (defvar log-view-mode-hook nil
123 "Hook run at the end of `log-view-mode'.")
125 (defface log-view-file
126 '((((class color) (background light))
127 (:background "grey70" :weight bold))
128 (t (:weight bold)))
129 "Face for the file header line in `log-view-mode'."
130 :group 'log-view)
131 ;; backward-compatibility alias
132 (put 'log-view-file-face 'face-alias 'log-view-file)
133 (defvar log-view-file-face 'log-view-file)
135 (defface log-view-message
136 '((((class color) (background light))
137 (:background "grey85"))
138 (t (:weight bold)))
139 "Face for the message header line in `log-view-mode'."
140 :group 'log-view)
141 ;; backward-compatibility alias
142 (put 'log-view-message-face 'face-alias 'log-view-message)
143 (defvar log-view-message-face 'log-view-message)
145 (defconst log-view-file-re
146 (concat "^\\(?:Working file: \\(.+\\)" ;RCS and CVS.
147 "\\|\\(?:SCCS/s\\.\\|Changes to \\)\\(.+\\):" ;SCCS and Darcs.
148 "\\)\n")) ;Include the \n for font-lock reasons.
150 (defconst log-view-message-re
151 (concat "^\\(?:revision \\([.0-9]+\\)\\(?:\t.*\\)?" ; RCS and CVS.
152 "\\|r\\([0-9]+\\) | .* | .*" ; Subversion.
153 "\\|D \\([.0-9]+\\) .*" ; SCCS.
154 ;; Darcs doesn't have revision names. VC-darcs uses patch names
155 ;; instead. Darcs patch names are hashcodes, which do not appear
156 ;; in the log output :-(, but darcs accepts any prefix of the log
157 ;; message as a patch name, so we match the first line of the log
158 ;; message.
159 ;; First loosely match the date format.
160 (concat "\\|[^ \n].*[^0-9\n][0-9][0-9]:[0-9][0-9][^0-9\n].*[^ \n]"
161 ;;Email of user and finally Msg, used as revision name.
162 " .*@.*\n\\(?: \\* \\(.*\\)\\)?")
163 "\\)$"))
165 (defconst log-view-font-lock-keywords
166 `((,log-view-file-re
167 (1 (if (boundp 'cvs-filename-face) cvs-filename-face) nil t)
168 (2 (if (boundp 'cvs-filename-face) cvs-filename-face) nil t)
169 (0 log-view-file-face append))
170 (,log-view-message-re . log-view-message-face)))
171 (defconst log-view-font-lock-defaults
172 '(log-view-font-lock-keywords t nil nil nil))
174 ;;;;
175 ;;;; Actual code
176 ;;;;
178 ;;;###autoload
179 (define-derived-mode log-view-mode fundamental-mode "Log-View"
180 "Major mode for browsing CVS log output."
181 (setq buffer-read-only t)
182 (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
183 (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap))
185 ;;;;
186 ;;;; Navigation
187 ;;;;
189 ;; define log-view-{msg,file}-{next,prev}
190 (easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
191 (easy-mmode-define-navigation log-view-file log-view-file-re "file")
193 (defun log-view-goto-rev (rev)
194 (goto-char (point-min))
195 (ignore-errors
196 (while (not (equal rev (log-view-current-tag)))
197 (log-view-msg-next))
200 ;;;;
201 ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
202 ;;;;
204 (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
206 (defun log-view-current-file ()
207 (save-excursion
208 (forward-line 1)
209 (or (re-search-backward log-view-file-re nil t)
210 (re-search-forward log-view-file-re))
211 (let* ((file (or (match-string 1) (match-string 2)))
212 (cvsdir (and (re-search-backward log-view-dir-re nil t)
213 (match-string 1)))
214 (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
215 (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
216 (match-string 1)))
217 (dir ""))
218 (let ((default-directory ""))
219 (when pcldir (setq dir (expand-file-name pcldir dir)))
220 (when cvsdir (setq dir (expand-file-name cvsdir dir))))
221 (expand-file-name file dir))))
223 (defun log-view-current-tag (&optional where)
224 (save-excursion
225 (when where (goto-char where))
226 (forward-line 1)
227 (let ((pt (point)))
228 (when (re-search-backward log-view-message-re nil t)
229 (let (rev)
230 ;; Find the subgroup that matched.
231 (dotimes (i (/ (length (match-data 'integers)) 2))
232 (setq rev (or rev (match-string (1+ i)))))
233 (unless (re-search-forward log-view-file-re pt t)
234 rev))))))
236 (defvar cvs-minor-current-files)
237 (defvar cvs-branch-prefix)
238 (defvar cvs-secondary-branch-prefix)
240 (defun log-view-minor-wrap (buf f)
241 (let ((data (with-current-buffer buf
242 (let* ((beg (point))
243 (end (if mark-active (mark) (point)))
244 (fr (log-view-current-tag beg))
245 (to (log-view-current-tag end)))
246 (when (string-equal fr to)
247 (save-excursion
248 (goto-char end)
249 (log-view-msg-next)
250 (setq to (log-view-current-tag))))
251 (cons
252 ;; The first revision has to be the one at point, for
253 ;; operations that only take one revision
254 ;; (e.g. cvs-mode-edit).
255 (cons (log-view-current-file) fr)
256 (cons (log-view-current-file) to))))))
257 (let ((cvs-branch-prefix (cdar data))
258 (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
259 (cvs-minor-current-files
260 (cons (caar data)
261 (when (and (cadr data) (not (equal (caar data) (cadr data))))
262 (list (cadr data)))))
263 ;; FIXME: I need to force because the fileinfos are UNKNOWN
264 (cvs-force-command "/F"))
265 (funcall f))))
267 (defun log-view-find-version (pos)
268 "Visit the version at point."
269 (interactive "d")
270 (save-excursion
271 (goto-char pos)
272 (switch-to-buffer (vc-find-version (log-view-current-file)
273 (log-view-current-tag)))))
276 ;; diff
279 (defun log-view-diff (beg end)
280 "Get the diff between two revisions.
281 If the mark is not active or the mark is on the revision at point,
282 get the diff between the revision at point and its previous revision.
283 Otherwise, get the diff between the revisions where the region starts
284 and ends."
285 (interactive
286 (list (if mark-active (region-beginning) (point))
287 (if mark-active (region-end) (point))))
288 (let ((fr (log-view-current-tag beg))
289 (to (log-view-current-tag end)))
290 (when (string-equal fr to)
291 (save-excursion
292 (goto-char end)
293 (log-view-msg-next)
294 (setq to (log-view-current-tag))))
295 (vc-version-diff (log-view-current-file) to fr)))
297 (provide 'log-view)
299 ;; arch-tag: 0d64220b-ce7e-4f62-9c2a-6b04c2f81f4f
300 ;;; log-view.el ends here