fix live process/dead buffer bub on w32
[bpt/emacs.git] / lisp / log-view.el
CommitLineData
e57a1038 1;;; log-view.el --- Major mode for browsing RCS/CVS/SCCS log output
5b467bf4 2
e7cff550 3;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
5b467bf4
SM
4
5;; Author: Stefan Monnier <monnier@cs.yale.edu>
e57a1038 6;; Keywords: rcs sccs cvs log version-control
c64c0551 7;; Revision: $Id: log-view.el,v 1.5 2000/12/06 19:49:40 fx 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
SM
37(require 'pcvs-util)
38
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
cdbb990f
SM
46 '(("n" . log-view-msg-next)
47 ("p" . log-view-msg-prev)
48 ("N" . log-view-file-next)
49 ("P" . log-view-file-prev)
50 ("M-n" . log-view-file-next)
51 ("M-p" . log-view-file-prev))
5b467bf4
SM
52 "Log-View's keymap."
53 :group 'log-view
e57a1038
SM
54 ;; Here I really need either buffer-local keymap-inheritance
55 ;; or a minor-mode-map with lower precedence than the local map.
56 :inherit (if (boundp 'cvs-mode-map) cvs-mode-map))
5b467bf4
SM
57
58(defvar log-view-mode-hook nil
59 "Hook run at the end of `log-view-mode'.")
60
61(defface log-view-file-face
62 '((((class color) (background light))
63 (:background "grey70" :bold t))
64 (t (:bold t)))
65 "Face for the file header line in `log-view-mode'."
66 :group 'log-view)
67(defvar log-view-file-face 'log-view-file-face)
68
69(defface log-view-message-face
70 '((((class color) (background light))
71 (:background "grey85"))
72 (t (:bold t)))
73 "Face for the message header line in `log-view-mode'."
74 :group 'log-view)
75(defvar log-view-message-face 'log-view-message-face)
76
77(defconst log-view-file-re
78 (concat "^\\("
79 "Working file: \\(.+\\)"
80 "\\|SCCS/s\\.\\(.+\\):"
81 "\\)\n"))
cdbb990f 82(defconst log-view-message-re "^\\(revision \\([.0-9]+\\)\\|D \\([.0-9]+\\) .*\\)$")
5b467bf4
SM
83
84(defconst log-view-font-lock-keywords
85 `((,log-view-file-re
e57a1038
SM
86 (2 (if (boundp 'cvs-filename-face) cvs-filename-face) nil t)
87 (3 (if (boundp 'cvs-filename-face) cvs-filename-face) nil t)
88 (0 log-view-file-face append))
5b467bf4
SM
89 (,log-view-message-re . log-view-message-face)))
90(defconst log-view-font-lock-defaults
91 '(log-view-font-lock-keywords t nil nil nil))
92
93;;;;
94;;;; Actual code
95;;;;
96
97;;;###autoload
cdbb990f 98(define-derived-mode log-view-mode fundamental-mode "Log-View"
5b467bf4
SM
99 "Major mode for browsing CVS log output."
100 (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
101 (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap))
102
103;;;;
104;;;; Navigation
105;;;;
106
cdbb990f
SM
107;; define log-view-{msg,file}-{next,prev}
108(easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
109(easy-mmode-define-navigation log-view-file log-view-file-re "file")
5b467bf4 110
3e87f5fc
SM
111(defun log-view-goto-rev (rev)
112 (goto-char (point-min))
113 (ignore-errors
114 (while (not (equal rev (log-view-current-tag)))
115 (log-view-msg-next))
116 t))
117
5b467bf4
SM
118;;;;
119;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
120;;;;
121
122(defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
123
124(defun log-view-current-file ()
125 (save-excursion
126 (forward-line 1)
127 (or (re-search-backward log-view-file-re nil t)
128 (re-search-forward log-view-file-re))
129 (let* ((file (or (match-string 2) (match-string 3)))
130 (cvsdir (and (re-search-backward log-view-dir-re nil t)
131 (match-string 1)))
e57a1038
SM
132 (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
133 (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
5b467bf4
SM
134 (match-string 1)))
135 (dir ""))
136 (let ((default-directory ""))
137 (when pcldir (setq dir (expand-file-name pcldir dir)))
138 (when cvsdir (setq dir (expand-file-name cvsdir dir)))
139 (expand-file-name file dir)))))
140
141(defun log-view-current-tag ()
cdbb990f
SM
142 (save-excursion
143 (forward-line 1)
144 (let ((pt (point)))
145 (when (re-search-backward log-view-message-re nil t)
146 (let ((rev (or (match-string 2) (match-string 3))))
147 (unless (re-search-forward log-view-file-re pt t)
148 rev))))))
5b467bf4
SM
149
150(defun log-view-minor-wrap (buf f)
151 (let ((data (with-current-buffer buf
152 (cons
153 (cons (log-view-current-file)
154 (log-view-current-tag))
3e87f5fc 155 (when mark-active
5b467bf4
SM
156 (save-excursion
157 (goto-char (mark))
158 (cons (log-view-current-file)
159 (log-view-current-tag))))))))
160 (let ((cvs-branch-prefix (cdar data))
161 (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
162 (cvs-minor-current-files
163 (cons (caar data)
164 (when (and (cadr data) (not (equal (caar data) (cadr data))))
165 (list (cadr data)))))
166 ;; FIXME: I need to force because the fileinfos are UNKNOWN
167 (cvs-force-command "/F"))
168 (funcall f))))
169
170(provide 'log-view)
cdbb990f
SM
171
172;;; Change Log:
3e87f5fc 173;; $Log: log-view.el,v $
c64c0551
SM
174;; Revision 1.5 2000/12/06 19:49:40 fx
175;; Fix copyright years.
176;;
e7cff550
DL
177;; Revision 1.4 2000/05/21 02:12:34 monnier
178;; Fix file description.
179;; (log-view-mode-map): Unsatisfying fix for when cvs-mode-map is not
180;; available.
181;; (log-view-font-lock-keywords): Only use cvs-filename-face if present.
182;; (log-view-current-file): Only use cvs-pcl-cvs-dirchange-re if present.
183;;
e57a1038
SM
184;; Revision 1.3 2000/05/10 22:22:21 monnier
185;; (log-view-goto-rev): New function for the new VC.
186;; (log-view-minor-wrap): Use mark-active.
187;;
3e87f5fc
SM
188;; Revision 1.2 2000/03/22 01:10:09 monnier
189;; (log-view-(msg|file)-(prev|next)): Rename from
190;; log-view-*-(message|file) and use easy-mmode-define-navigation.
191;; (log-view-message-re): Match SCCS format as well.
192;; And match the revision line rather than the dashed separator line.
193;; (log-view-mode): Use the new define-derived-mode.
194;; (log-view-current-tag): Fill in with an actual implementation.
195;;
cdbb990f 196
5b467bf4 197;;; log-view.el ends here