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