(frame-parameter) <defsetf>: Make it return the assigned value.
[emacs.git] / lisp / log-view.el
blob5737f2435fb1c440213e9eca27bdf4736597a00c
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, 2008 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 ;; ------------------------------------------------------------------------
54 ;; r4622 | ckuethe | 2007-12-23 18:18:01 -0500 (Sun, 23 Dec 2007) | 2 lines
55 ;;
56 ;; uBlox AEK-4T in binary mode. Added to unstable because it breaks gpsfake
57 ;;
58 ;; ------------------------------------------------------------------------
59 ;; r4621 | ckuethe | 2007-12-23 16:48:11 -0500 (Sun, 23 Dec 2007) | 3 lines
60 ;;
61 ;; Add a note about requiring usbfs to use the garmin gps18 (usb)
62 ;; Mention firmware testing the AC12 with firmware BQ00 and BQ04
63 ;;
64 ;; ------------------------------------------------------------------------
65 ;; r4620 | ckuethe | 2007-12-23 15:52:34 -0500 (Sun, 23 Dec 2007) | 1 line
66 ;;
67 ;; add link to latest hardware reference
68 ;; ------------------------------------------------------------------------
69 ;; r4619 | ckuethe | 2007-12-23 14:37:31 -0500 (Sun, 23 Dec 2007) | 1 line
70 ;;
71 ;; there is now a regression test for AC12 without raw data output
73 ;;;; Darcs:
75 ;; Changes to darcsum.el:
76 ;;
77 ;; Mon Nov 28 15:19:38 GMT 2005 Dave Love <fx@gnu.org>
78 ;; * Abstract process startup into darcsum-start-process. Use TERM=dumb.
79 ;; TERM=dumb avoids escape characters, at least, for any old darcs that
80 ;; doesn't understand DARCS_DONT_COLOR & al.
81 ;;
82 ;; Thu Nov 24 15:20:45 GMT 2005 Dave Love <fx@gnu.org>
83 ;; * darcsum-mode-related changes.
84 ;; Don't call font-lock-mode (unnecessary) or use-local-map (redundant).
85 ;; Use mode-class 'special. Add :group.
86 ;; Add trailing-whitespace option to mode hook and fix
87 ;; darcsum-display-changeset not to use trailing whitespace.
89 ;;;; Mercurial
91 ;; changeset: 11:8ff1a4166444
92 ;; tag: tip
93 ;; user: Eric S. Raymond <esr@thyrsus.com>
94 ;; date: Wed Dec 26 12:18:58 2007 -0500
95 ;; summary: Explain keywords. Add markup fixes.
96 ;;
97 ;; changeset: 10:20abc7ab09c3
98 ;; user: Eric S. Raymond <esr@thyrsus.com>
99 ;; date: Wed Dec 26 11:37:28 2007 -0500
100 ;; summary: Typo fixes.
102 ;; changeset: 9:ada9f4da88aa
103 ;; user: Eric S. Raymond <esr@thyrsus.com>
104 ;; date: Wed Dec 26 11:23:00 2007 -0500
105 ;; summary: Add RCS example session.
107 ;;; Todo:
109 ;; - add ability to modify a log-entry (via cvs-mode-admin ;-)
110 ;; - remove references to cvs-*
111 ;; - make it easier to add support for new backends without changing the code.
113 ;;; Code:
115 (eval-when-compile (require 'cl))
116 (require 'pcvs-util)
117 (autoload 'vc-find-revision "vc")
118 (autoload 'vc-version-diff "vc")
120 (defvar cvs-minor-wrap-function)
122 (defgroup log-view nil
123 "Major mode for browsing log output of RCS/CVS/SCCS."
124 :group 'pcl-cvs
125 :prefix "log-view-")
127 (easy-mmode-defmap log-view-mode-map
128 '(("q" . quit-window)
129 ("z" . kill-this-buffer)
130 ("m" . log-view-toggle-mark-entry)
131 ("e" . log-view-modify-change-comment)
132 ("d" . log-view-diff)
133 ("a" . log-view-annotate-version)
134 ("f" . log-view-find-revision)
135 ("n" . log-view-msg-next)
136 ("p" . log-view-msg-prev)
137 ("\t" . log-view-msg-next)
138 ([backtab] . log-view-msg-prev)
139 ("N" . log-view-file-next)
140 ("P" . log-view-file-prev)
141 ("\M-n" . log-view-file-next)
142 ("\M-p" . log-view-file-prev))
143 "Log-View's keymap."
144 :group 'log-view
145 ;; Here I really need either buffer-local keymap-inheritance
146 ;; or a minor-mode-map with lower precedence than the local map.
147 :inherit (if (boundp 'cvs-mode-map) cvs-mode-map))
149 (easy-menu-define log-view-mode-menu log-view-mode-map
150 "Log-View Display Menu"
151 `("Log-View"
152 ;; XXX Do we need menu entries for these?
153 ;; ["Quit" quit-window]
154 ;; ["Kill This Buffer" kill-this-buffer]
155 ["Mark Log Entry for Diff" set-mark-command]
156 ["Diff Revisions" log-view-diff]
157 ["Visit Version" log-view-find-revision]
158 ["Annotate Version" log-view-annotate-version]
159 ["Next Log Entry" log-view-msg-next]
160 ["Previous Log Entry" log-view-msg-prev]
161 ["Next File" log-view-file-next]
162 ["Previous File" log-view-file-prev]))
164 (defvar log-view-mode-hook nil
165 "Hook run at the end of `log-view-mode'.")
167 (defface log-view-file
168 '((((class color) (background light))
169 (:background "grey70" :weight bold))
170 (t (:weight bold)))
171 "Face for the file header line in `log-view-mode'."
172 :group 'log-view)
173 ;; backward-compatibility alias
174 (put 'log-view-file-face 'face-alias 'log-view-file)
175 (defvar log-view-file-face 'log-view-file)
177 (defface log-view-message
178 '((((class color) (background light))
179 (:background "grey85"))
180 (t (:weight bold)))
181 "Face for the message header line in `log-view-mode'."
182 :group 'log-view)
183 ;; backward-compatibility alias
184 (put 'log-view-message-face 'face-alias 'log-view-message)
185 (defvar log-view-message-face 'log-view-message)
187 (defvar log-view-file-re
188 (concat "^\\(?:Working file: \\(?1:.+\\)" ;RCS and CVS.
189 ;; Subversion has no such thing??
190 "\\|\\(?:SCCS/s\\.\\|Changes to \\)\\(?1:.+\\):" ;SCCS and Darcs.
191 "\\)\n") ;Include the \n for font-lock reasons.
192 "Regexp matching the text identifying the file.
193 The match group number 1 should match the file name itself.")
195 (defvar log-view-message-re
196 (concat "^\\(?:revision \\(?1:[.0-9]+\\)\\(?:\t.*\\)?" ; RCS and CVS.
197 "\\|r\\(?1:[0-9]+\\) | .* | .*" ; Subversion.
198 "\\|D \\(?1:[.0-9]+\\) .*" ; SCCS.
199 ;; Darcs doesn't have revision names. VC-darcs uses patch names
200 ;; instead. Darcs patch names are hashcodes, which do not appear
201 ;; in the log output :-(, but darcs accepts any prefix of the log
202 ;; message as a patch name, so we match the first line of the log
203 ;; message.
204 ;; First loosely match the date format.
205 (concat "\\|[^ \n].*[^0-9\n][0-9][0-9]:[0-9][0-9][^0-9\n].*[^ \n]"
206 ;;Email of user and finally Msg, used as revision name.
207 " .*@.*\n\\(?: \\* \\(?1:.*\\)\\)?")
208 "\\)$")
209 "Regexp matching the text identifying a revision.
210 The match group number 1 should match the revision number itself.")
212 (defvar log-view-font-lock-keywords
213 ;; We use `eval' so as to use the buffer-local value of log-view-file-re
214 ;; and log-view-message-re, if applicable.
215 '((eval . `(,log-view-file-re
216 (1 (if (boundp 'cvs-filename-face) cvs-filename-face))
217 (0 log-view-file-face append)))
218 (eval . `(,log-view-message-re . log-view-message-face))))
220 (defconst log-view-font-lock-defaults
221 '(log-view-font-lock-keywords t nil nil nil))
223 ;;;;
224 ;;;; Actual code
225 ;;;;
227 ;;;###autoload
228 (define-derived-mode log-view-mode fundamental-mode "Log-View"
229 "Major mode for browsing CVS log output."
230 (setq buffer-read-only t)
231 (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
232 (set (make-local-variable 'beginning-of-defun-function)
233 'log-view-beginning-of-defun)
234 (set (make-local-variable 'end-of-defun-function)
235 'log-view-end-of-defun)
236 (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap))
238 ;;;;
239 ;;;; Navigation
240 ;;;;
242 ;; define log-view-{msg,file}-{next,prev}
243 (easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
244 (easy-mmode-define-navigation log-view-file log-view-file-re "file")
246 (defun log-view-goto-rev (rev)
247 (goto-char (point-min))
248 (ignore-errors
249 (while (not (equal rev (log-view-current-tag)))
250 (log-view-msg-next))
253 ;;;;
254 ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
255 ;;;;
257 (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
259 (defun log-view-current-file ()
260 (save-excursion
261 (forward-line 1)
262 (or (re-search-backward log-view-file-re nil t)
263 (re-search-forward log-view-file-re nil t)
264 (error "Unable to determine the current file"))
265 (let* ((file (match-string 1))
266 (cvsdir (and (re-search-backward log-view-dir-re nil t)
267 (match-string 1)))
268 (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
269 (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
270 (match-string 1)))
271 (dir ""))
272 (let ((default-directory ""))
273 (when pcldir (setq dir (expand-file-name pcldir dir)))
274 (when cvsdir (setq dir (expand-file-name cvsdir dir))))
275 (expand-file-name file dir))))
277 (defun log-view-current-tag (&optional where)
278 (save-excursion
279 (when where (goto-char where))
280 (forward-line 1)
281 (let ((pt (point)))
282 (when (re-search-backward log-view-message-re nil t)
283 (let ((rev (match-string-no-properties 1)))
284 (unless (re-search-forward log-view-file-re pt t)
285 rev))))))
287 (defun log-view-toggle-mark-entry ()
288 "Toggle the marked state for the log entry at point.
289 Individual log entries can be marked and unmarked. The marked
290 entries are denoted by changing their background color.
291 `log-view-get-marked' returns the list of tags for the marked
292 log entries."
293 (interactive)
294 (save-excursion
295 (forward-line 1)
296 (let ((pt (point)))
297 (when (re-search-backward log-view-message-re nil t)
298 (let ((beg (match-beginning 0))
299 end ov ovlist found tag)
300 (unless (re-search-forward log-view-file-re pt t)
301 ;; Look to see if the current entry is marked.
302 (setq found (get-char-property (point) 'log-view-self))
303 (if found
304 (delete-overlay found)
305 ;; Create an overlay that covers this entry and change
306 ;; its color.
307 (setq tag (log-view-current-tag (point)))
308 (forward-line 1)
309 (setq end
310 (if (re-search-forward log-view-message-re nil t)
311 (match-beginning 0)
312 (point-max)))
313 (setq ov (make-overlay beg end))
314 (overlay-put ov 'face 'log-view-file)
315 ;; This is used to check if the overlay is present.
316 (overlay-put ov 'log-view-self ov)
317 (overlay-put ov 'log-view-marked tag))))))))
319 (defun log-view-get-marked ()
320 "Return the list of tags for the marked log entries."
321 (save-excursion
322 (let ((pos (point-min))
323 marked-list ov)
324 (while (setq pos (next-single-property-change pos 'face))
325 (when (setq ov (get-char-property pos 'log-view-self))
326 (push (overlay-get ov 'log-view-marked) marked-list)
327 (setq pos (overlay-end ov))))
328 marked-list)))
330 (defun log-view-beginning-of-defun ()
331 ;; This assumes that a log entry starts with a line matching
332 ;; `log-view-message-re'. Modes that derive from `log-view-mode'
333 ;; for which this assumption is not valid will have to provide
334 ;; another implementation of this function. `log-view-msg-prev'
335 ;; does a similar job to this function, we can't use it here
336 ;; directly because it prints messages that are not appropriate in
337 ;; this context and it does not move to the beginning of the buffer
338 ;; when the point is before the first log entry.
340 ;; `log-view-beginning-of-defun' and `log-view-end-of-defun' have
341 ;; been checked to work with logs produced by RCS, CVS, git,
342 ;; mercurial and subversion.
344 (re-search-backward log-view-message-re nil 'move))
346 (defun log-view-end-of-defun ()
347 ;; The idea in this function is to search for the beginning of the
348 ;; next log entry using `log-view-message-re' and then go back one
349 ;; line when finding it. Modes that derive from `log-view-mode' for
350 ;; which this assumption is not valid will have to provide another
351 ;; implementation of this function.
353 ;; Look back and if there is no entry there it means we are before
354 ;; the first log entry, so go forward until finding one.
355 (unless (save-excursion (re-search-backward log-view-message-re nil t))
356 (re-search-forward log-view-message-re nil t))
358 ;; In case we are at the end of log entry going forward a line will
359 ;; make us find the next entry when searching. If we are inside of
360 ;; an entry going forward a line will still keep the point inside
361 ;; the same entry.
362 (forward-line 1)
364 ;; In case we are at the beginning of an entry, move past it.
365 (when (looking-at log-view-message-re)
366 (goto-char (match-end 0))
367 (forward-line 1))
369 ;; Search for the start of the next log entry. Go to the end of the
370 ;; buffer if we could not find a next entry.
371 (when (re-search-forward log-view-message-re nil 'move)
372 (goto-char (match-beginning 0))
373 (forward-line -1)))
375 (defvar cvs-minor-current-files)
376 (defvar cvs-branch-prefix)
377 (defvar cvs-secondary-branch-prefix)
379 (defun log-view-minor-wrap (buf f)
380 (let ((data (with-current-buffer buf
381 (let* ((beg (point))
382 (end (if mark-active (mark) (point)))
383 (fr (log-view-current-tag beg))
384 (to (log-view-current-tag end)))
385 (when (string-equal fr to)
386 (save-excursion
387 (goto-char end)
388 (log-view-msg-next)
389 (setq to (log-view-current-tag))))
390 (cons
391 ;; The first revision has to be the one at point, for
392 ;; operations that only take one revision
393 ;; (e.g. cvs-mode-edit).
394 (cons (log-view-current-file) fr)
395 (cons (log-view-current-file) to))))))
396 (let ((cvs-branch-prefix (cdar data))
397 (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
398 (cvs-minor-current-files
399 (cons (caar data)
400 (when (and (cadr data) (not (equal (caar data) (cadr data))))
401 (list (cadr data)))))
402 ;; FIXME: I need to force because the fileinfos are UNKNOWN
403 (cvs-force-command "/F"))
404 (funcall f))))
406 (defun log-view-find-revision (pos)
407 "Visit the version at point."
408 (interactive "d")
409 (save-excursion
410 (goto-char pos)
411 (switch-to-buffer (vc-find-revision (log-view-current-file)
412 (log-view-current-tag)))))
415 (defun log-view-extract-comment ()
416 "Parse comment from around the current point in the log."
417 (save-excursion
418 (let (st en (backend (vc-backend (log-view-current-file))))
419 (log-view-end-of-defun)
420 (cond ((eq backend 'SVN)
421 (forward-line -1)))
422 (setq en (point))
423 (log-view-beginning-of-defun)
424 (cond ((memq backend '(SCCS RCS CVS MCVS SVN))
425 (forward-line 2))
426 ((eq backend 'Hg)
427 (forward-line 4)
428 (re-search-forward "summary: *" nil t)))
429 (setq st (point))
430 (buffer-substring st en))))
432 (declare-function vc-modify-change-comment "vc" (files rev oldcomment))
434 (defun log-view-modify-change-comment ()
435 "Edit the change comment displayed at point."
436 (interactive)
437 (vc-modify-change-comment (list (log-view-current-file))
438 (log-view-current-tag)
439 (log-view-extract-comment)))
441 (defun log-view-annotate-version (pos)
442 "Annotate the version at point."
443 (interactive "d")
444 (save-excursion
445 (goto-char pos)
446 (switch-to-buffer (vc-annotate (log-view-current-file)
447 (log-view-current-tag)))))
450 ;; diff
453 (defun log-view-diff (beg end)
454 "Get the diff between two revisions.
455 If the mark is not active or the mark is on the revision at point,
456 get the diff between the revision at point and its previous revision.
457 Otherwise, get the diff between the revisions where the region starts
458 and ends."
459 (interactive
460 (list (if mark-active (region-beginning) (point))
461 (if mark-active (region-end) (point))))
462 (let ((fr (log-view-current-tag beg))
463 (to (log-view-current-tag end)))
464 (when (string-equal fr to)
465 (save-excursion
466 (goto-char end)
467 (log-view-msg-next)
468 (setq to (log-view-current-tag))))
469 (vc-version-diff (list (log-view-current-file)) to fr)))
471 (provide 'log-view)
473 ;; arch-tag: 0d64220b-ce7e-4f62-9c2a-6b04c2f81f4f
474 ;;; log-view.el ends here