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