Commit | Line | Data |
---|---|---|
ba83908c | 1 | ;;; log-view.el --- Major mode for browsing RCS/CVS/SCCS log output -*- lexical-binding: t -*- |
5b467bf4 | 2 | |
acaf905b | 3 | ;; Copyright (C) 1999-2012 Free Software Foundation, Inc. |
5b467bf4 | 4 | |
cc1eecfd | 5 | ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> |
9766adfb | 6 | ;; Keywords: rcs, sccs, cvs, log, vc, tools |
5b467bf4 SM |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
eb3fa2cf | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
5b467bf4 | 11 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
5b467bf4 SM |
14 | |
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
5b467bf4 SM |
22 | |
23 | ;;; Commentary: | |
24 | ||
aa230d94 SM |
25 | ;; Major mode to browse revision log histories. |
26 | ;; Currently supports the format output by: | |
62c5f375 | 27 | ;; RCS, SCCS, CVS, Subversion, and DaRCS. |
aa230d94 SM |
28 | |
29 | ;; Examples of log output: | |
30 | ||
31 | ;;;; RCS/CVS: | |
32 | ||
33 | ;; ---------------------------- | |
34 | ;; revision 1.35 locked by: turlutut | |
35 | ;; date: 2005-03-22 18:48:38 +0000; author: monnier; state: Exp; lines: +6 -8 | |
36 | ;; (gnus-display-time-event-handler): | |
37 | ;; Check display-time-timer at runtime rather than only at load time | |
38 | ;; in case display-time-mode is turned off in the mean time. | |
39 | ;; ---------------------------- | |
40 | ;; revision 1.34 | |
41 | ;; date: 2005-02-09 15:50:38 +0000; author: kfstorm; state: Exp; lines: +7 -7 | |
42 | ;; branches: 1.34.2; | |
43 | ;; Change release version from 21.4 to 22.1 throughout. | |
44 | ;; Change development version from 21.3.50 to 22.0.50. | |
45 | ||
46 | ;;;; SCCS: | |
47 | ||
48 | ;;;; Subversion: | |
49 | ||
813e8939 ER |
50 | ;; ------------------------------------------------------------------------ |
51 | ;; r4622 | ckuethe | 2007-12-23 18:18:01 -0500 (Sun, 23 Dec 2007) | 2 lines | |
20ac86f4 | 52 | ;; |
813e8939 | 53 | ;; uBlox AEK-4T in binary mode. Added to unstable because it breaks gpsfake |
20ac86f4 | 54 | ;; |
813e8939 ER |
55 | ;; ------------------------------------------------------------------------ |
56 | ;; r4621 | ckuethe | 2007-12-23 16:48:11 -0500 (Sun, 23 Dec 2007) | 3 lines | |
20ac86f4 | 57 | ;; |
813e8939 ER |
58 | ;; Add a note about requiring usbfs to use the garmin gps18 (usb) |
59 | ;; Mention firmware testing the AC12 with firmware BQ00 and BQ04 | |
20ac86f4 | 60 | ;; |
813e8939 ER |
61 | ;; ------------------------------------------------------------------------ |
62 | ;; r4620 | ckuethe | 2007-12-23 15:52:34 -0500 (Sun, 23 Dec 2007) | 1 line | |
20ac86f4 | 63 | ;; |
813e8939 ER |
64 | ;; add link to latest hardware reference |
65 | ;; ------------------------------------------------------------------------ | |
66 | ;; r4619 | ckuethe | 2007-12-23 14:37:31 -0500 (Sun, 23 Dec 2007) | 1 line | |
20ac86f4 | 67 | ;; |
813e8939 ER |
68 | ;; there is now a regression test for AC12 without raw data output |
69 | ||
62c5f375 SM |
70 | ;;;; Darcs: |
71 | ||
72 | ;; Changes to darcsum.el: | |
20ac86f4 | 73 | ;; |
62c5f375 SM |
74 | ;; Mon Nov 28 15:19:38 GMT 2005 Dave Love <fx@gnu.org> |
75 | ;; * Abstract process startup into darcsum-start-process. Use TERM=dumb. | |
20ac86f4 | 76 | ;; TERM=dumb avoids escape characters, at least, for any old darcs that |
62c5f375 | 77 | ;; doesn't understand DARCS_DONT_COLOR & al. |
20ac86f4 | 78 | ;; |
62c5f375 SM |
79 | ;; Thu Nov 24 15:20:45 GMT 2005 Dave Love <fx@gnu.org> |
80 | ;; * darcsum-mode-related changes. | |
81 | ;; Don't call font-lock-mode (unnecessary) or use-local-map (redundant). | |
82 | ;; Use mode-class 'special. Add :group. | |
83 | ;; Add trailing-whitespace option to mode hook and fix | |
84 | ;; darcsum-display-changeset not to use trailing whitespace. | |
85 | ||
813e8939 ER |
86 | ;;;; Mercurial |
87 | ||
88 | ;; changeset: 11:8ff1a4166444 | |
89 | ;; tag: tip | |
90 | ;; user: Eric S. Raymond <esr@thyrsus.com> | |
91 | ;; date: Wed Dec 26 12:18:58 2007 -0500 | |
92 | ;; summary: Explain keywords. Add markup fixes. | |
20ac86f4 | 93 | ;; |
813e8939 ER |
94 | ;; changeset: 10:20abc7ab09c3 |
95 | ;; user: Eric S. Raymond <esr@thyrsus.com> | |
96 | ;; date: Wed Dec 26 11:37:28 2007 -0500 | |
97 | ;; summary: Typo fixes. | |
20ac86f4 | 98 | ;; |
813e8939 ER |
99 | ;; changeset: 9:ada9f4da88aa |
100 | ;; user: Eric S. Raymond <esr@thyrsus.com> | |
101 | ;; date: Wed Dec 26 11:23:00 2007 -0500 | |
102 | ;; summary: Add RCS example session. | |
103 | ||
aa230d94 | 104 | ;;; Todo: |
5b467bf4 | 105 | |
5b467bf4 | 106 | ;; - add ability to modify a log-entry (via cvs-mode-admin ;-) |
e57a1038 | 107 | ;; - remove references to cvs-* |
aa230d94 | 108 | ;; - make it easier to add support for new backends without changing the code. |
5b467bf4 SM |
109 | |
110 | ;;; Code: | |
111 | ||
5b467bf4 | 112 | (require 'pcvs-util) |
ac3f4c6f | 113 | (autoload 'vc-find-revision "vc") |
c66b7ac0 | 114 | (autoload 'vc-diff-internal "vc") |
5b467bf4 | 115 | |
71f6f911 | 116 | (defvar cvs-minor-wrap-function) |
ba83908c | 117 | (defvar cvs-force-command) |
71f6f911 | 118 | |
5b467bf4 | 119 | (defgroup log-view nil |
e57a1038 | 120 | "Major mode for browsing log output of RCS/CVS/SCCS." |
5b467bf4 SM |
121 | :group 'pcl-cvs |
122 | :prefix "log-view-") | |
123 | ||
124 | (easy-mmode-defmap log-view-mode-map | |
abef340a SS |
125 | '( |
126 | ;; FIXME: (copy-keymap special-mode-map) instead | |
127 | ("z" . kill-this-buffer) | |
9eaeec5b | 128 | ("q" . quit-window) |
293e7c22 | 129 | ("g" . revert-buffer) |
d4eb88c7 | 130 | ("\C-m" . log-view-toggle-entry-display) |
abef340a | 131 | |
83db937c | 132 | ("m" . log-view-toggle-mark-entry) |
9b64a7f0 | 133 | ("e" . log-view-modify-change-comment) |
99cb8c8b | 134 | ("d" . log-view-diff) |
238a0f3a | 135 | ("=" . log-view-diff) |
6653c6b7 | 136 | ("D" . log-view-diff-changeset) |
a3f5d84d | 137 | ("a" . log-view-annotate-version) |
ac3f4c6f | 138 | ("f" . log-view-find-revision) |
99cb8c8b | 139 | ("n" . log-view-msg-next) |
cdbb990f | 140 | ("p" . log-view-msg-prev) |
25edda53 DN |
141 | ("\t" . log-view-msg-next) |
142 | ([backtab] . log-view-msg-prev) | |
cdbb990f SM |
143 | ("N" . log-view-file-next) |
144 | ("P" . log-view-file-prev) | |
e2c2a3e2 KG |
145 | ("\M-n" . log-view-file-next) |
146 | ("\M-p" . log-view-file-prev)) | |
5b467bf4 | 147 | "Log-View's keymap." |
c9829c70 | 148 | :group 'log-view) |
5b467bf4 | 149 | |
d621bc0a DN |
150 | (easy-menu-define log-view-mode-menu log-view-mode-map |
151 | "Log-View Display Menu" | |
152 | `("Log-View" | |
153 | ;; XXX Do we need menu entries for these? | |
154 | ;; ["Quit" quit-window] | |
155 | ;; ["Kill This Buffer" kill-this-buffer] | |
799224fe DN |
156 | ["Mark Log Entry for Diff" set-mark-command |
157 | :help ""] | |
158 | ["Diff Revisions" log-view-diff | |
159 | :help "Get the diff between two revisions"] | |
6653c6b7 DN |
160 | ["Changeset Diff" log-view-diff-changeset |
161 | :help "Get the changeset diff between two revisions"] | |
799224fe DN |
162 | ["Visit Version" log-view-find-revision |
163 | :help "Visit the version at point"] | |
164 | ["Annotate Version" log-view-annotate-version | |
165 | :help "Annotate the version at point"] | |
031f1766 DN |
166 | ["Modify Log Comment" log-view-modify-change-comment |
167 | :help "Edit the change comment displayed at point"] | |
33f6cf7b CY |
168 | ["Toggle Details at Point" log-view-toggle-entry-display |
169 | :active log-view-expanded-log-entry-function] | |
031f1766 | 170 | "-----" |
799224fe DN |
171 | ["Next Log Entry" log-view-msg-next |
172 | :help "Go to the next count'th log message"] | |
173 | ["Previous Log Entry" log-view-msg-prev | |
174 | :help "Go to the previous count'th log message"] | |
175 | ["Next File" log-view-file-next | |
176 | :help "Go to the next count'th file"] | |
177 | ["Previous File" log-view-file-prev | |
178 | :help "Go to the previous count'th file"])) | |
d621bc0a | 179 | |
5b467bf4 SM |
180 | (defvar log-view-mode-hook nil |
181 | "Hook run at the end of `log-view-mode'.") | |
182 | ||
d4eb88c7 CY |
183 | (defvar log-view-expanded-log-entry-function nil |
184 | "Function returning the detailed description of a Log View entry. | |
185 | It is called by the command `log-view-toggle-entry-display' with | |
186 | one arg, the revision tag (a string), and should return a string. | |
187 | If it is nil, `log-view-toggle-entry-display' does nothing.") | |
188 | ||
d842de85 | 189 | (defface log-view-file |
5b467bf4 | 190 | '((((class color) (background light)) |
1fd714a4 RS |
191 | (:background "grey70" :weight bold)) |
192 | (t (:weight bold))) | |
5b467bf4 SM |
193 | "Face for the file header line in `log-view-mode'." |
194 | :group 'log-view) | |
c4f6e489 | 195 | (define-obsolete-face-alias 'log-view-file-face 'log-view-file "22.1") |
d842de85 | 196 | (defvar log-view-file-face 'log-view-file) |
5b467bf4 | 197 | |
d842de85 | 198 | (defface log-view-message |
5b467bf4 SM |
199 | '((((class color) (background light)) |
200 | (:background "grey85")) | |
1fd714a4 | 201 | (t (:weight bold))) |
5b467bf4 SM |
202 | "Face for the message header line in `log-view-mode'." |
203 | :group 'log-view) | |
d842de85 | 204 | ;; backward-compatibility alias |
c4f6e489 | 205 | (define-obsolete-face-alias 'log-view-message-face 'log-view-message "22.1") |
d842de85 | 206 | (defvar log-view-message-face 'log-view-message) |
5b467bf4 | 207 | |
18b2e5b9 | 208 | (defvar log-view-file-re |
95588f91 SM |
209 | (concat "^\\(?:Working file: \\(?1:.+\\)" ;RCS and CVS. |
210 | ;; Subversion has no such thing?? | |
211 | "\\|\\(?:SCCS/s\\.\\|Changes to \\)\\(?1:.+\\):" ;SCCS and Darcs. | |
2ef3b3fe SM |
212 | "\\)\n") ;Include the \n for font-lock reasons. |
213 | "Regexp matching the text identifying the file. | |
214 | The match group number 1 should match the file name itself.") | |
aa230d94 | 215 | |
6653c6b7 DN |
216 | (defvar log-view-per-file-logs t |
217 | "Set if to t if the logs are shown one file at a time.") | |
218 | ||
18b2e5b9 | 219 | (defvar log-view-message-re |
95588f91 SM |
220 | (concat "^\\(?:revision \\(?1:[.0-9]+\\)\\(?:\t.*\\)?" ; RCS and CVS. |
221 | "\\|r\\(?1:[0-9]+\\) | .* | .*" ; Subversion. | |
222 | "\\|D \\(?1:[.0-9]+\\) .*" ; SCCS. | |
62c5f375 SM |
223 | ;; Darcs doesn't have revision names. VC-darcs uses patch names |
224 | ;; instead. Darcs patch names are hashcodes, which do not appear | |
225 | ;; in the log output :-(, but darcs accepts any prefix of the log | |
226 | ;; message as a patch name, so we match the first line of the log | |
227 | ;; message. | |
228 | ;; First loosely match the date format. | |
229 | (concat "\\|[^ \n].*[^0-9\n][0-9][0-9]:[0-9][0-9][^0-9\n].*[^ \n]" | |
230 | ;;Email of user and finally Msg, used as revision name. | |
95588f91 | 231 | " .*@.*\n\\(?: \\* \\(?1:.*\\)\\)?") |
2ef3b3fe SM |
232 | "\\)$") |
233 | "Regexp matching the text identifying a revision. | |
234 | The match group number 1 should match the revision number itself.") | |
5b467bf4 | 235 | |
18b2e5b9 SM |
236 | (defvar log-view-font-lock-keywords |
237 | ;; We use `eval' so as to use the buffer-local value of log-view-file-re | |
238 | ;; and log-view-message-re, if applicable. | |
239 | '((eval . `(,log-view-file-re | |
240 | (1 (if (boundp 'cvs-filename-face) cvs-filename-face)) | |
241 | (0 log-view-file-face append))) | |
242 | (eval . `(,log-view-message-re . log-view-message-face)))) | |
5bdc71d0 | 243 | |
5b467bf4 SM |
244 | (defconst log-view-font-lock-defaults |
245 | '(log-view-font-lock-keywords t nil nil nil)) | |
246 | ||
6653c6b7 | 247 | (defvar log-view-vc-fileset nil |
9af57756 | 248 | "The VC fileset corresponding to the current log.") |
6653c6b7 DN |
249 | |
250 | (defvar log-view-vc-backend nil | |
9af57756 | 251 | "The VC backend that created the current log.") |
6653c6b7 | 252 | |
edb33387 | 253 | ;;;; |
5b467bf4 | 254 | ;;;; Actual code |
edb33387 | 255 | ;;;; |
5b467bf4 SM |
256 | |
257 | ;;;###autoload | |
c9829c70 | 258 | (define-derived-mode log-view-mode special-mode "Log-View" |
5b467bf4 | 259 | "Major mode for browsing CVS log output." |
99cb8c8b | 260 | (setq buffer-read-only t) |
5b467bf4 | 261 | (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults) |
20ac86f4 | 262 | (set (make-local-variable 'beginning-of-defun-function) |
a3f5d84d | 263 | 'log-view-beginning-of-defun) |
20ac86f4 | 264 | (set (make-local-variable 'end-of-defun-function) |
a3f5d84d | 265 | 'log-view-end-of-defun) |
8117868f DN |
266 | (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap) |
267 | (hack-dir-local-variables-non-file-buffer)) | |
5b467bf4 SM |
268 | |
269 | ;;;; | |
270 | ;;;; Navigation | |
271 | ;;;; | |
272 | ||
cdbb990f SM |
273 | ;; define log-view-{msg,file}-{next,prev} |
274 | (easy-mmode-define-navigation log-view-msg log-view-message-re "log message") | |
275 | (easy-mmode-define-navigation log-view-file log-view-file-re "file") | |
5b467bf4 | 276 | |
3e87f5fc SM |
277 | (defun log-view-goto-rev (rev) |
278 | (goto-char (point-min)) | |
279 | (ignore-errors | |
280 | (while (not (equal rev (log-view-current-tag))) | |
281 | (log-view-msg-next)) | |
282 | t)) | |
283 | ||
5b467bf4 SM |
284 | ;;;; |
285 | ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el) | |
286 | ;;;; | |
287 | ||
288 | (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$") | |
289 | ||
290 | (defun log-view-current-file () | |
291 | (save-excursion | |
292 | (forward-line 1) | |
293 | (or (re-search-backward log-view-file-re nil t) | |
22f4e5c1 | 294 | (re-search-forward log-view-file-re nil t) |
ccf89694 | 295 | (error "Unable to determine the current file")) |
95588f91 | 296 | (let* ((file (match-string 1)) |
5b467bf4 SM |
297 | (cvsdir (and (re-search-backward log-view-dir-re nil t) |
298 | (match-string 1))) | |
e57a1038 SM |
299 | (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re) |
300 | (re-search-backward cvs-pcl-cvs-dirchange-re nil t) | |
5b467bf4 SM |
301 | (match-string 1))) |
302 | (dir "")) | |
303 | (let ((default-directory "")) | |
304 | (when pcldir (setq dir (expand-file-name pcldir dir))) | |
99cb8c8b SS |
305 | (when cvsdir (setq dir (expand-file-name cvsdir dir)))) |
306 | (expand-file-name file dir)))) | |
5b467bf4 | 307 | |
d4eb88c7 CY |
308 | (defun log-view-current-entry (&optional pos move) |
309 | "Return the position and revision tag of the Log View entry at POS. | |
310 | This is a list (BEG TAG), where BEG is a buffer position and TAG | |
311 | is a string. If POS is nil or omitted, it defaults to point. | |
312 | If there is no entry at POS, return nil. | |
313 | ||
314 | If optional arg MOVE is non-nil, move point to BEG if found. | |
315 | Otherwise, don't move point." | |
316 | (let ((looping t) | |
317 | result) | |
318 | (save-excursion | |
319 | (when pos (goto-char pos)) | |
320 | (forward-line 1) | |
321 | (while looping | |
322 | (setq pos (re-search-backward log-view-message-re nil 'move) | |
323 | looping (and pos (log-view-inside-comment-p (point))))) | |
324 | (when pos | |
325 | (setq result | |
326 | (list pos (match-string-no-properties 1))))) | |
327 | (and move result (goto-char pos)) | |
328 | result)) | |
329 | ||
330 | (defun log-view-inside-comment-p (pos) | |
331 | "Return non-nil if POS lies inside an expanded log entry." | |
332 | (eq (get-text-property pos 'log-view-comment) t)) | |
333 | ||
334 | (defun log-view-current-tag (&optional pos) | |
335 | "Return the revision tag (a string) of the Log View entry at POS. | |
336 | if POS is omitted or nil, it defaults to point." | |
337 | (cadr (log-view-current-entry pos))) | |
5b467bf4 | 338 | |
83db937c | 339 | (defun log-view-toggle-mark-entry () |
a0902360 DN |
340 | "Toggle the marked state for the log entry at point. |
341 | Individual log entries can be marked and unmarked. The marked | |
342 | entries are denoted by changing their background color. | |
343 | `log-view-get-marked' returns the list of tags for the marked | |
344 | log entries." | |
83db937c DN |
345 | (interactive) |
346 | (save-excursion | |
d4eb88c7 CY |
347 | (let* ((entry (log-view-current-entry nil t)) |
348 | (beg (car entry)) | |
349 | found) | |
350 | (when entry | |
351 | ;; Look to see if the current entry is marked. | |
352 | (setq found (get-char-property beg 'log-view-self)) | |
353 | (if found | |
354 | (delete-overlay found) | |
355 | ;; Create an overlay covering this entry and change its color. | |
356 | (let* ((end (if (get-text-property beg 'log-view-entry-expanded) | |
357 | (next-single-property-change beg 'log-view-comment) | |
358 | (log-view-end-of-defun) | |
359 | (point))) | |
360 | (ov (make-overlay beg end))) | |
361 | (overlay-put ov 'face 'log-view-file) | |
362 | ;; This is used to check if the overlay is present. | |
363 | (overlay-put ov 'log-view-self ov) | |
364 | (overlay-put ov 'log-view-marked (nth 1 entry)))))))) | |
83db937c | 365 | |
3a44b2ae | 366 | (defun log-view-get-marked () |
a0902360 | 367 | "Return the list of tags for the marked log entries." |
3a44b2ae DN |
368 | (save-excursion |
369 | (let ((pos (point-min)) | |
370 | marked-list ov) | |
371 | (while (setq pos (next-single-property-change pos 'face)) | |
372 | (when (setq ov (get-char-property pos 'log-view-self)) | |
373 | (push (overlay-get ov 'log-view-marked) marked-list) | |
374 | (setq pos (overlay-end ov)))) | |
375 | marked-list))) | |
376 | ||
d4eb88c7 | 377 | (defun log-view-toggle-entry-display () |
dab3703d GM |
378 | "If possible, expand the current Log View entry. |
379 | This calls `log-view-expanded-log-entry-function' to do the work." | |
d4eb88c7 CY |
380 | (interactive) |
381 | ;; Don't do anything unless `log-view-expanded-log-entry-function' | |
382 | ;; is defined in this mode. | |
383 | (when (functionp log-view-expanded-log-entry-function) | |
384 | (let* ((opoint (point)) | |
385 | (entry (log-view-current-entry nil t)) | |
386 | (beg (car entry)) | |
387 | (buffer-read-only nil)) | |
388 | (when entry | |
389 | (if (get-text-property beg 'log-view-entry-expanded) | |
390 | ;; If the entry is expanded, collapse it. | |
391 | (let ((pos (next-single-property-change beg 'log-view-comment))) | |
392 | (unless (and pos (log-view-inside-comment-p pos)) | |
393 | (error "Broken markup in `log-view-toggle-entry-display'")) | |
394 | (delete-region pos | |
395 | (next-single-property-change pos 'log-view-comment)) | |
396 | (put-text-property beg (1+ beg) 'log-view-entry-expanded nil) | |
397 | (if (< opoint pos) | |
398 | (goto-char opoint))) | |
399 | ;; Otherwise, expand the entry. | |
400 | (let ((long-entry (funcall log-view-expanded-log-entry-function | |
401 | (nth 1 entry)))) | |
402 | (when long-entry | |
403 | (put-text-property beg (1+ beg) 'log-view-entry-expanded t) | |
404 | (log-view-end-of-defun) | |
405 | (setq beg (point)) | |
406 | (insert long-entry "\n") | |
407 | (add-text-properties | |
408 | beg (point) | |
409 | '(font-lock-face font-lock-comment-face log-view-comment t)) | |
410 | (goto-char opoint)))))))) | |
411 | ||
412 | (defun log-view-beginning-of-defun (&optional arg) | |
413 | "Move backward to the beginning of a Log View entry. | |
414 | With ARG, do it that many times. Negative ARG means move forward | |
415 | to the beginning of the ARGth following entry. | |
416 | ||
417 | This is Log View mode's default `beginning-of-defun-function'. | |
418 | It assumes that a log entry starts with a line matching | |
419 | `log-view-message-re'." | |
420 | (if (or (null arg) (zerop arg)) | |
421 | (setq arg 1)) | |
422 | (if (< arg 0) | |
b3e945d3 | 423 | (dotimes (_n (- arg)) |
d4eb88c7 CY |
424 | (log-view-end-of-defun)) |
425 | (catch 'beginning-of-buffer | |
b3e945d3 | 426 | (dotimes (_n arg) |
d4eb88c7 CY |
427 | (or (log-view-current-entry nil t) |
428 | (throw 'beginning-of-buffer nil))) | |
429 | (point)))) | |
a3f5d84d DN |
430 | |
431 | (defun log-view-end-of-defun () | |
d4eb88c7 CY |
432 | "Move forward to the next Log View entry." |
433 | (let ((looping t)) | |
434 | (if (looking-at log-view-message-re) | |
435 | (goto-char (match-end 0))) | |
436 | (while looping | |
437 | (cond | |
438 | ((re-search-forward log-view-message-re nil 'move) | |
439 | (unless (log-view-inside-comment-p (point)) | |
440 | (setq looping nil) | |
441 | (goto-char (match-beginning 0)))) | |
442 | ;; Don't advance past the end buttons inserted by | |
443 | ;; `vc-print-log-setup-buttons'. | |
444 | ((looking-back "Show 2X entries Show unlimited entries") | |
445 | (setq looping nil) | |
446 | (forward-line -1)))))) | |
a3f5d84d | 447 | |
aa230d94 SM |
448 | (defvar cvs-minor-current-files) |
449 | (defvar cvs-branch-prefix) | |
450 | (defvar cvs-secondary-branch-prefix) | |
451 | ||
5b467bf4 SM |
452 | (defun log-view-minor-wrap (buf f) |
453 | (let ((data (with-current-buffer buf | |
243afed7 | 454 | (let* ((beg (point)) |
a9f5a649 | 455 | (end (if (use-region-p) (mark) (point))) |
cbc98273 JL |
456 | (fr (log-view-current-tag beg)) |
457 | (to (log-view-current-tag end))) | |
458 | (when (string-equal fr to) | |
459 | (save-excursion | |
460 | (goto-char end) | |
461 | (log-view-msg-next) | |
462 | (setq to (log-view-current-tag)))) | |
463 | (cons | |
243afed7 SM |
464 | ;; The first revision has to be the one at point, for |
465 | ;; operations that only take one revision | |
466 | ;; (e.g. cvs-mode-edit). | |
467 | (cons (log-view-current-file) fr) | |
468 | (cons (log-view-current-file) to)))))) | |
5b467bf4 SM |
469 | (let ((cvs-branch-prefix (cdar data)) |
470 | (cvs-secondary-branch-prefix (and (cdar data) (cddr data))) | |
471 | (cvs-minor-current-files | |
472 | (cons (caar data) | |
473 | (when (and (cadr data) (not (equal (caar data) (cadr data)))) | |
474 | (list (cadr data))))) | |
475 | ;; FIXME: I need to force because the fileinfos are UNKNOWN | |
476 | (cvs-force-command "/F")) | |
477 | (funcall f)))) | |
478 | ||
ac3f4c6f | 479 | (defun log-view-find-revision (pos) |
c0313667 AS |
480 | "Visit the version at point." |
481 | (interactive "d") | |
6653c6b7 DN |
482 | (unless log-view-per-file-logs |
483 | (when (> (length log-view-vc-fileset) 1) | |
484 | (error "Multiple files shown in this buffer, cannot use this command here"))) | |
c0313667 AS |
485 | (save-excursion |
486 | (goto-char pos) | |
6653c6b7 DN |
487 | (switch-to-buffer (vc-find-revision (if log-view-per-file-logs |
488 | (log-view-current-file) | |
489 | (car log-view-vc-fileset)) | |
490 | (log-view-current-tag))))) | |
c0313667 | 491 | |
9b64a7f0 ER |
492 | |
493 | (defun log-view-extract-comment () | |
494 | "Parse comment from around the current point in the log." | |
495 | (save-excursion | |
496 | (let (st en (backend (vc-backend (log-view-current-file)))) | |
497 | (log-view-end-of-defun) | |
498 | (cond ((eq backend 'SVN) | |
499 | (forward-line -1))) | |
500 | (setq en (point)) | |
501 | (log-view-beginning-of-defun) | |
502 | (cond ((memq backend '(SCCS RCS CVS MCVS SVN)) | |
503 | (forward-line 2)) | |
504 | ((eq backend 'Hg) | |
505 | (forward-line 4) | |
20ac86f4 | 506 | (re-search-forward "summary: *" nil t))) |
9b64a7f0 ER |
507 | (setq st (point)) |
508 | (buffer-substring st en)))) | |
509 | ||
8df5b06d GM |
510 | (declare-function vc-modify-change-comment "vc" (files rev oldcomment)) |
511 | ||
9b64a7f0 ER |
512 | (defun log-view-modify-change-comment () |
513 | "Edit the change comment displayed at point." | |
514 | (interactive) | |
6653c6b7 DN |
515 | (vc-modify-change-comment (list (if log-view-per-file-logs |
516 | (log-view-current-file) | |
517 | (car log-view-vc-fileset))) | |
518 | (log-view-current-tag) | |
519 | (log-view-extract-comment))) | |
9b64a7f0 | 520 | |
a3f5d84d DN |
521 | (defun log-view-annotate-version (pos) |
522 | "Annotate the version at point." | |
523 | (interactive "d") | |
6653c6b7 DN |
524 | (unless log-view-per-file-logs |
525 | (when (> (length log-view-vc-fileset) 1) | |
526 | (error "Multiple files shown in this buffer, cannot use this command here"))) | |
a3f5d84d DN |
527 | (save-excursion |
528 | (goto-char pos) | |
c9c95fc3 CY |
529 | (vc-annotate (if log-view-per-file-logs |
530 | (log-view-current-file) | |
531 | (car log-view-vc-fileset)) | |
532 | (log-view-current-tag)))) | |
a3f5d84d | 533 | |
467ee23f SM |
534 | ;; |
535 | ;; diff | |
536 | ;; | |
99cb8c8b SS |
537 | |
538 | (defun log-view-diff (beg end) | |
e8171d36 | 539 | "Get the diff between two revisions. |
c7fe9adc CY |
540 | If the region is inactive or the mark is on the revision at |
541 | point, get the diff between the revision at point and its | |
542 | previous revision. Otherwise, get the diff between the revisions | |
543 | where the region starts and ends. | |
544 | ||
545 | Unlike `log-view-diff-changeset', this function only shows the | |
546 | part of the changeset which affected the currently considered | |
547 | file(s)." | |
da4ae7d3 | 548 | (interactive |
a9f5a649 CY |
549 | (list (if (use-region-p) (region-beginning) (point)) |
550 | (if (use-region-p) (region-end) (point)))) | |
99cb8c8b SS |
551 | (let ((fr (log-view-current-tag beg)) |
552 | (to (log-view-current-tag end))) | |
553 | (when (string-equal fr to) | |
554 | (save-excursion | |
555 | (goto-char end) | |
556 | (log-view-msg-next) | |
557 | (setq to (log-view-current-tag)))) | |
c66b7ac0 DN |
558 | (vc-diff-internal |
559 | t (list log-view-vc-backend | |
560 | (if log-view-per-file-logs | |
561 | (list (log-view-current-file)) | |
562 | log-view-vc-fileset)) | |
563 | to fr))) | |
6653c6b7 DN |
564 | |
565 | (defun log-view-diff-changeset (beg end) | |
566 | "Get the diff between two revisions. | |
c7fe9adc CY |
567 | If the region is inactive or the mark is on the revision at |
568 | point, get the diff between the revision at point and its | |
569 | previous revision. Otherwise, get the diff between the revisions | |
570 | where the region starts and ends. | |
571 | ||
572 | Unlike `log-view-diff' this function shows the whole changeset, | |
573 | including changes affecting other files than the currently | |
574 | considered file(s)." | |
6653c6b7 | 575 | (interactive |
a9f5a649 CY |
576 | (list (if (use-region-p) (region-beginning) (point)) |
577 | (if (use-region-p) (region-end) (point)))) | |
6653c6b7 DN |
578 | (when (eq (vc-call-backend log-view-vc-backend 'revision-granularity) 'file) |
579 | (error "The %s backend does not support changeset diffs" log-view-vc-backend)) | |
580 | (let ((fr (log-view-current-tag beg)) | |
581 | (to (log-view-current-tag end))) | |
582 | (when (string-equal fr to) | |
583 | ;; TO and FR are the same, look at the previous revision. | |
584 | (setq to (vc-call-backend log-view-vc-backend 'previous-revision nil fr))) | |
585 | (vc-diff-internal | |
586 | t | |
587 | ;; We want to see the diff for all the files in the changeset, so | |
588 | ;; pass NIL for the file list. The value passed here should | |
589 | ;; follow what `vc-deduce-fileset' returns. | |
590 | (list log-view-vc-backend nil) | |
591 | to fr))) | |
99cb8c8b | 592 | |
5b467bf4 | 593 | (provide 'log-view) |
cdbb990f | 594 | |
5b467bf4 | 595 | ;;; log-view.el ends here |