1 ;;; log-edit.el --- Major mode for editing CVS commit messages
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7 ;; Keywords: pcl-cvs cvs commit log
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 of the License, or
14 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
28 ;; - Move in VC's code
29 ;; - Add compatibility for VC's hook variables
33 (eval-when-compile (require 'cl
))
34 (require 'add-log
) ; for all the ChangeLog goodies
42 (defgroup log-edit nil
43 "Major mode for editing RCS and CVS commit messages."
45 :group
'vc
; It's used by VC.
55 (easy-mmode-defmap log-edit-mode-map
56 `(("\C-c\C-c" . log-edit-done
)
57 ("\C-c\C-a" . log-edit-insert-changelog
)
58 ("\C-c\C-d" . log-edit-show-diff
)
59 ("\C-c\C-f" . log-edit-show-files
)
60 ("\M-n" . log-edit-next-comment
)
61 ("\M-p" . log-edit-previous-comment
)
62 ("\M-r" . log-edit-comment-search-backward
)
63 ("\M-s" . log-edit-comment-search-forward
)
64 ("\C-c?" . log-edit-mode-help
))
65 "Keymap for the `log-edit-mode' (to edit version control log messages)."
68 ;; Compatibility with old names. Should we bother ?
69 (defvar vc-log-mode-map log-edit-mode-map
)
70 (defvar vc-log-entry-mode vc-log-mode-map
)
72 (easy-menu-define log-edit-menu log-edit-mode-map
73 "Menu used for `log-edit-mode'."
76 :help
"Exit log-edit and proceed with the actual action."]
78 ["Insert ChangeLog" log-edit-insert-changelog
79 :help
"Insert a log message by looking at the ChangeLog"]
80 ["Add to ChangeLog" log-edit-add-to-changelog
81 :help
"Insert this log message into the appropriate ChangeLog file"]
83 ["Show diff" log-edit-show-diff
84 :help
"Show the diff for the files to be committed."]
85 ["List files" log-edit-show-files
86 :help
"Show the list of relevant files."]
88 ["Previous comment" log-edit-previous-comment
89 :help
"Cycle backwards through comment history"]
90 ["Next comment" log-edit-next-comment
91 :help
"Cycle forwards through comment history."]
92 ["Search comment forward" log-edit-comment-search-forward
93 :help
"Search forwards through comment history for a substring match of str"]
94 ["Search comment backward" log-edit-comment-search-backward
95 :help
"Search backwards through comment history for substring match of str"]))
97 (defcustom log-edit-confirm
'changed
98 "If non-nil, `log-edit-done' will request confirmation.
99 If 'changed, only request confirmation if the list of files has
100 changed since the beginning of the log-edit session."
102 :type
'(choice (const changed
) (const t
) (const nil
)))
104 (defcustom log-edit-keep-buffer nil
105 "If non-nil, don't hide the buffer after `log-edit-done'."
109 (defvar cvs-commit-buffer-require-final-newline t
)
110 (make-obsolete-variable 'cvs-commit-buffer-require-final-newline
111 'log-edit-require-final-newline
114 (defcustom log-edit-require-final-newline
115 cvs-commit-buffer-require-final-newline
116 "Enforce a newline at the end of commit log messages.
117 Enforce it silently if t, query if non-nil and don't do anything if nil."
119 :type
'(choice (const ask
) (const t
) (const nil
)))
121 (defcustom log-edit-setup-invert nil
122 "Non-nil means `log-edit' should invert the meaning of its SETUP arg.
123 If SETUP is 'force, this variable has no effect."
127 (defcustom log-edit-hook
'(log-edit-insert-cvs-template
128 log-edit-insert-changelog
)
129 "Hook run at the end of `log-edit'."
131 :type
'(hook :options
(log-edit-insert-changelog
132 log-edit-insert-cvs-rcstemplate
133 log-edit-insert-cvs-template
134 log-edit-insert-filenames
)))
136 (defcustom log-edit-mode-hook
(if (boundp 'vc-log-mode-hook
) vc-log-mode-hook
)
137 "Hook run when entering `log-edit-mode'."
141 (defcustom log-edit-done-hook nil
142 "Hook run before doing the actual commit.
143 This hook can be used to cleanup the message, enforce various
144 conventions, or to allow recording the message in some other database,
145 such as a bug-tracking system. The list of files about to be committed
146 can be obtained from `log-edit-files'."
148 :type
'(hook :options
(log-edit-set-common-indentation
149 log-edit-add-to-changelog
)))
151 (defcustom log-edit-strip-single-file-name t
152 "If non-nil, remove file name from single-file log entries."
158 (defvar cvs-changelog-full-paragraphs t
)
159 (make-obsolete-variable 'cvs-changelog-full-paragraphs
160 'log-edit-changelog-full-paragraphs
163 (defvar log-edit-changelog-full-paragraphs cvs-changelog-full-paragraphs
164 "*If non-nil, include full ChangeLog paragraphs in the log.
165 This may be set in the ``local variables'' section of a ChangeLog, to
166 indicate the policy for that ChangeLog.
168 A ChangeLog paragraph is a bunch of log text containing no blank lines;
169 a paragraph usually describes a set of changes with a single purpose,
170 but perhaps spanning several functions in several files. Changes in
171 different paragraphs are unrelated.
173 You could argue that the log entry for a file should contain the
174 full ChangeLog paragraph mentioning the change to the file, even though
175 it may mention other files, because that gives you the full context you
176 need to understand the change. This is the behavior you get when this
177 variable is set to t.
179 On the other hand, you could argue that the log entry for a change
180 should contain only the text for the changes which occurred in that
181 file, because the log is per-file. This is the behavior you get
182 when this variable is set to nil.")
184 ;;;; Internal global or buffer-local vars
186 (defconst log-edit-files-buf
"*log-edit-files*")
187 (defvar log-edit-initial-files nil
)
188 (defvar log-edit-callback nil
)
189 (defvar log-edit-diff-function nil
)
190 (defvar log-edit-listfun nil
)
191 (defvar log-edit-extra-flags nil
192 "List of extra flags to pass to the check in command.")
193 (defvar log-edit-before-checkin-process nil
194 "Alist with instructions for processing the commit message before check in.
195 The format is: (REGEXP . INSTRUCTIONS).
196 All lines matching REGEXP are removed. For example:
200 means: just remove all lines starting with #. This can be used
201 to insert lines in the commit buffer that contain, for example, the
202 list of files to be committed.
204 \(\"Author: \\\\(.*\\\\)\" . (list \"--author\" (match-string 1)))
206 means: append (list \"--author\" (match-string 1)) to `log-edit-extra-flags'.")
208 (defvar log-edit-parent-buffer nil
)
210 ;;; Originally taken from VC-Log mode
212 (defconst log-edit-maximum-comment-ring-size
32
213 "Maximum number of saved comments in the comment ring.")
214 (defvar log-edit-comment-ring
(make-ring log-edit-maximum-comment-ring-size
))
215 (defvar log-edit-comment-ring-index nil
)
216 (defvar log-edit-last-comment-match
"")
218 (defun log-edit-new-comment-index (stride len
)
219 "Return the comment index STRIDE elements from the current one.
220 LEN is the length of `log-edit-comment-ring'."
222 (log-edit-comment-ring-index (+ log-edit-comment-ring-index stride
))
223 ;; Initialize the index on the first use of this command
224 ;; so that the first M-p gets index 0, and the first M-n gets
226 ((> stride
0) (1- stride
))
230 (defun log-edit-previous-comment (arg)
231 "Cycle backwards through comment history.
232 With a numeric prefix ARG, go back ARG comments."
234 (let ((len (ring-length log-edit-comment-ring
)))
236 (progn (message "Empty comment ring") (ding))
237 ;; Don't use `erase-buffer' because we don't want to `widen'.
238 (delete-region (point-min) (point-max))
239 (setq log-edit-comment-ring-index
(log-edit-new-comment-index arg len
))
240 (message "Comment %d" (1+ log-edit-comment-ring-index
))
241 (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index
)))))
243 (defun log-edit-next-comment (arg)
244 "Cycle forwards through comment history.
245 With a numeric prefix ARG, go forward ARG comments."
247 (log-edit-previous-comment (- arg
)))
249 (defun log-edit-comment-search-backward (str &optional stride
)
250 "Search backwards through comment history for substring match of STR.
251 If the optional argument STRIDE is present, that is a step-width to use
252 when going through the comment ring."
253 ;; Why substring rather than regexp ? -sm
255 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
256 (unless stride
(setq stride
1))
258 (setq str log-edit-last-comment-match
)
259 (setq log-edit-last-comment-match str
))
260 (let* ((str (regexp-quote str
))
261 (len (ring-length log-edit-comment-ring
))
262 (n (log-edit-new-comment-index stride len
)))
263 (while (progn (when (or (>= n len
) (< n
0)) (error "Not found"))
264 (not (string-match str
(ring-ref log-edit-comment-ring n
))))
265 (setq n
(+ n stride
)))
266 (setq log-edit-comment-ring-index n
)
267 (log-edit-previous-comment 0)))
269 (defun log-edit-comment-search-forward (str)
270 "Search forwards through comment history for a substring match of STR."
272 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
273 (log-edit-comment-search-backward str -
1))
275 (defun log-edit-comment-to-change-log (&optional whoami file-name
)
276 "Enter last VC comment into the change log for the current file.
277 WHOAMI (interactive prefix) non-nil means prompt for user name
278 and site. FILE-NAME is the name of the change log; if nil, use
279 `change-log-default-name'.
281 This may be useful as a `log-edit-checkin-hook' to update change logs
283 (interactive (if current-prefix-arg
284 (list current-prefix-arg
285 (prompt-for-change-log-name))))
286 (let (;; Extract the comment first so we get any error before doing anything.
287 (comment (ring-ref log-edit-comment-ring
0))
288 ;; Don't let add-change-log-entry insert a defun name.
289 (add-log-current-defun-function 'ignore
)
291 ;; Call add-log to do half the work.
292 (add-change-log-entry whoami file-name t t
)
293 ;; Insert the VC comment, leaving point before it.
294 (setq end
(save-excursion (insert comment
) (point-marker)))
295 (if (looking-at "\\s *\\s(")
296 ;; It starts with an open-paren, as in "(foo): Frobbed."
297 ;; So remove the ": " add-log inserted.
299 ;; Canonicalize the white space between the file name and comment.
301 ;; Indent rest of the text the same way add-log indented the first line.
302 (let ((indentation (current-indentation)))
304 (while (< (point) end
)
306 (indent-to indentation
))
308 ;; Fill the inserted text, preserving open-parens at bol.
309 (let ((paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
311 (fill-region (point) end
))
312 ;; Canonicalize the white space at the end of the entry so it is
313 ;; separated from the next entry by a single blank line.
314 (skip-syntax-forward " " end
)
315 (delete-char (- (skip-syntax-backward " ")))
316 (or (eobp) (looking-at "\n\n")
319 ;; Compatibility with old names.
320 (define-obsolete-variable-alias 'vc-comment-ring
'log-edit-comment-ring
"22.1")
321 (define-obsolete-variable-alias 'vc-comment-ring-index
'log-edit-comment-ring-index
"22.1")
322 (define-obsolete-function-alias 'vc-previous-comment
'log-edit-previous-comment
"22.1")
323 (define-obsolete-function-alias 'vc-next-comment
'log-edit-next-comment
"22.1")
324 (define-obsolete-function-alias 'vc-comment-search-reverse
'log-edit-comment-search-backward
"22.1")
325 (define-obsolete-function-alias 'vc-comment-search-forward
'log-edit-comment-search-forward
"22.1")
326 (define-obsolete-function-alias 'vc-comment-to-change-log
'log-edit-comment-to-change-log
"22.1")
332 (defvar log-edit-font-lock-keywords
333 '(("\\`\\(Summary:\\)\\(.*\\)"
334 (1 font-lock-keyword-face
)
335 (2 font-lock-function-name-face
))))
338 (defun log-edit (callback &optional setup params buffer mode
&rest ignore
)
339 "Setup a buffer to enter a log message.
340 \\<log-edit-mode-map>The buffer will be put in mode MODE or `log-edit-mode'
342 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
343 Mark and point will be set around the entire contents of the buffer so
344 that it is easy to kill the contents of the buffer with \\[kill-region].
345 Once you're done editing the message, pressing \\[log-edit-done] will call
346 `log-edit-done' which will end up calling CALLBACK to do the actual commit.
348 PARAMS if non-nil is an alist. Possible keys and associated values:
349 `log-edit-listfun' -- function taking no arguments that returns the list of
350 files that are concerned by the current operation (using relative names);
351 `log-edit-diff-function' -- function taking no arguments that
352 displays a diff of the files concerned by the current operation.
354 If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
355 log message and go back to the current buffer when done. Otherwise, it
356 uses the current buffer."
357 (let ((parent (current-buffer)))
358 (if buffer
(pop-to-buffer buffer
))
359 (when (and log-edit-setup-invert
(not (eq setup
'force
)))
360 (setq setup
(not setup
)))
361 (when setup
(erase-buffer))
365 (set (make-local-variable 'log-edit-callback
) callback
)
368 (set (make-local-variable (car crt
)) (cdr crt
)))
369 ;; For backward compatibility with log-edit up to version 22.2
370 ;; accept non-list PARAMS to mean `log-edit-list'.
371 (set (make-local-variable 'log-edit-listfun
) params
))
373 (if buffer
(set (make-local-variable 'log-edit-parent-buffer
) parent
))
374 (set (make-local-variable 'log-edit-initial-files
) (log-edit-files))
375 (when setup
(run-hooks 'log-edit-hook
))
376 (goto-char (point-min)) (push-mark (point-max))
377 (message "%s" (substitute-command-keys
378 "Press \\[log-edit-done] when you are done editing."))))
380 (define-derived-mode log-edit-mode text-mode
"Log-Edit"
381 "Major mode for editing version-control log messages.
382 When done editing the log entry, just type \\[log-edit-done] which
383 will trigger the actual commit of the file(s).
384 Several other handy support commands are provided of course and
385 the package from which this is used might also provide additional
386 commands (under C-x v for VC, for example).
388 \\{log-edit-mode-map}"
389 (set (make-local-variable 'font-lock-defaults
)
390 '(log-edit-font-lock-keywords t
))
391 (make-local-variable 'log-edit-comment-ring-index
)
392 (hack-dir-local-variables-non-file-buffer))
394 (defun log-edit-hide-buf (&optional buf where
)
395 (when (setq buf
(get-buffer (or buf log-edit-files-buf
)))
396 (let ((win (get-buffer-window buf where
)))
397 (if win
(ignore-errors (delete-window win
))))
400 (defun log-edit-done ()
401 "Finish editing the log message and commit the files.
402 If you want to abort the commit, simply delete the buffer."
404 ;; Get rid of trailing empty lines
405 (goto-char (point-max))
406 (skip-syntax-backward " ")
407 (when (equal (char-after) ?
\n) (forward-char 1))
408 (delete-region (point) (point-max))
409 ;; Check for final newline
410 (if (and (> (point-max) (point-min))
411 (/= (char-before (point-max)) ?
\n)
412 (or (eq log-edit-require-final-newline t
)
413 (and log-edit-require-final-newline
415 (format "Buffer %s does not end in newline. Add one? "
418 (goto-char (point-max))
420 (let ((comment (buffer-string)))
421 (when (or (ring-empty-p log-edit-comment-ring
)
422 (not (equal comment
(ring-ref log-edit-comment-ring
0))))
423 (ring-insert log-edit-comment-ring comment
)))
424 (let ((win (get-buffer-window log-edit-files-buf
)))
425 (if (and log-edit-confirm
426 (not (and (eq log-edit-confirm
'changed
)
427 (equal (log-edit-files) log-edit-initial-files
)))
429 (log-edit-show-files)
430 (not (y-or-n-p "Really commit? "))))
431 (progn (when (not win
) (log-edit-hide-buf))
432 (message "Oh, well! Later maybe?"))
433 (run-hooks 'log-edit-done-hook
)
435 (unless (or log-edit-keep-buffer
(not log-edit-parent-buffer
))
436 (cvs-bury-buffer (current-buffer) log-edit-parent-buffer
))
437 (call-interactively log-edit-callback
))))
439 (defun log-edit-files ()
440 "Return the list of files that are about to be committed."
441 (ignore-errors (funcall log-edit-listfun
)))
443 (defun log-edit-mode-help ()
444 "Provide help for the `log-edit-mode-map'."
446 (if (eq last-command
'log-edit-mode-help
)
447 (describe-function major-mode
)
449 (substitute-command-keys
450 "Type `\\[log-edit-done]' to finish commit. Try `\\[describe-function] log-edit-done' for more help."))))
452 (defcustom log-edit-common-indent
0
453 "Minimum indentation to use in `log-edit-set-common-indentation'."
457 (defun log-edit-set-common-indentation ()
458 "(Un)Indent the current buffer rigidly to `log-edit-common-indent'."
460 (let ((common (point-max)))
461 (goto-char (point-min))
462 (while (< (point) (point-max))
463 (if (not (looking-at "^[ \t]*$"))
464 (setq common
(min common
(current-indentation))))
466 (indent-rigidly (point-min) (point-max)
467 (- log-edit-common-indent common
)))))
469 (defun log-edit-show-diff ()
470 "Show the diff for the files to be committed."
472 (if (functionp log-edit-diff-function
)
473 (funcall log-edit-diff-function
)
474 (error "Diff functionality has not been setup")))
476 (defun log-edit-show-files ()
477 "Show the list of files to be committed."
479 (let* ((files (log-edit-files))
480 (buf (get-buffer-create log-edit-files-buf
)))
481 (with-current-buffer buf
482 (log-edit-hide-buf buf
'all
)
483 (setq buffer-read-only nil
)
485 (cvs-insert-strings files
)
486 (setq buffer-read-only t
)
487 (goto-char (point-min))
488 (save-selected-window
489 (cvs-pop-to-buffer-same-frame buf
)
490 (shrink-window-if-larger-than-buffer)
491 (selected-window)))))
493 (defun log-edit-insert-cvs-template ()
494 "Insert the template specified by the CVS administrator, if any.
495 This simply uses the local CVS/Template file."
497 (when (or (called-interactively-p 'interactive
)
498 (= (point-min) (point-max)))
499 (when (file-readable-p "CVS/Template")
500 (insert-file-contents "CVS/Template"))))
502 (defun log-edit-insert-cvs-rcstemplate ()
503 "Insert the rcstemplate from the CVS repository.
504 This contacts the repository to get the rcstemplate file and
505 can thus take some time."
507 (when (or (called-interactively-p 'interactive
)
508 (= (point-min) (point-max)))
509 (when (file-readable-p "CVS/Root")
510 ;; Ignore the stderr stuff, even if it's an error.
511 (call-process "cvs" nil
'(t nil
) nil
512 "checkout" "-p" "CVSROOT/rcstemplate"))))
514 (defun log-edit-insert-filenames ()
515 "Insert the list of files that are to be committed."
517 (insert "Affected files: \n"
518 (mapconcat 'identity
(log-edit-files) " \n")))
520 (defun log-edit-add-to-changelog ()
521 "Insert this log message into the appropriate ChangeLog file."
524 (unless (string= (buffer-string) (ring-ref log-edit-comment-ring
0))
525 (ring-insert log-edit-comment-ring
(buffer-string)))
526 (dolist (f (log-edit-files))
527 (let ((buffer-file-name (expand-file-name f
)))
529 (log-edit-comment-to-change-log)))))
531 (defvar log-edit-changelog-use-first nil
)
532 (defun log-edit-insert-changelog (&optional use-first
)
533 "Insert a log message by looking at the ChangeLog.
534 The idea is to write your ChangeLog entries first, and then use this
535 command to commit your changes.
537 To select default log text, we:
538 - find the ChangeLog entries for the files to be checked in,
539 - verify that the top entry in the ChangeLog is on the current date
540 and by the current user; if not, we don't provide any default text,
541 - search the ChangeLog entry for paragraphs containing the names of
542 the files we're checking in, and finally
543 - use those paragraphs as the log text.
545 If the optional prefix arg USE-FIRST is given (via \\[universal-argument]),
546 or if the command is repeated a second time in a row, use the first log entry
547 regardless of user name or time."
549 (let ((log-edit-changelog-use-first
550 (or use-first
(eq last-command
'log-edit-insert-changelog
))))
551 (log-edit-insert-changelog-entries (log-edit-files)))
552 (log-edit-set-common-indentation)
553 (goto-char (point-min))
554 (when (and log-edit-strip-single-file-name
(looking-at "\\*\\s-+"))
556 (when (not (re-search-forward "^\\*\\s-+" nil t
))
557 (goto-char (point-min))
558 (skip-chars-forward "^():")
559 (skip-chars-forward ": ")
560 (delete-region (point-min) (point)))))
563 ;;;; functions for getting commit message from ChangeLog a file...
564 ;;;; Courtesy Jim Blandy
567 (defun log-edit-narrow-changelog ()
568 "Narrow to the top page of the current buffer, a ChangeLog file.
569 Actually, the narrowed region doesn't include the date line.
570 A \"page\" in a ChangeLog file is the area between two dates."
571 (or (eq major-mode
'change-log-mode
)
572 (error "log-edit-narrow-changelog: current buffer isn't a ChangeLog"))
574 (goto-char (point-min))
576 ;; Skip date line and subsequent blank lines.
578 (if (looking-at "[ \t\n]*\n")
579 (goto-char (match-end 0)))
581 (let ((start (point)))
583 (narrow-to-region start
(point))
584 (goto-char (point-min))))
586 (defun log-edit-changelog-paragraph ()
587 "Return the bounds of the ChangeLog paragraph containing point.
588 If we are between paragraphs, return the previous paragraph."
590 (if (looking-at "^[ \t]*$")
591 (skip-chars-backward " \t\n" (point-min)))
593 (if (re-search-backward "^[ \t]*\n" nil
'or-to-limit
)
594 (goto-char (match-end 0)))
596 (if (re-search-forward "^[ \t\n]*$" nil t
)
600 (defun log-edit-changelog-subparagraph ()
601 "Return the bounds of the ChangeLog subparagraph containing point.
602 A subparagraph is a block of non-blank lines beginning with an asterisk.
603 If we are between sub-paragraphs, return the previous subparagraph."
605 (if (search-backward "*" nil t
)
606 (list (progn (beginning-of-line) (point))
609 (if (re-search-forward "^[ \t]*[\n*]" nil t
)
612 (list (point) (point))))
614 (defun log-edit-changelog-entry ()
615 "Return the bounds of the ChangeLog entry containing point.
616 The variable `log-edit-changelog-full-paragraphs' decides whether an
617 \"entry\" is a paragraph or a subparagraph; see its documentation string
620 (if log-edit-changelog-full-paragraphs
621 (log-edit-changelog-paragraph)
622 (log-edit-changelog-subparagraph))))
624 (defvar user-full-name
)
625 (defvar user-mail-address
)
626 (defun log-edit-changelog-ours-p ()
627 "See if ChangeLog entry at point is for the current user, today.
628 Return non-nil if it is."
629 ;; Code adapted from add-change-log-entry.
630 (let ((name (or (and (boundp 'add-log-full-name
) add-log-full-name
)
631 (and (fboundp 'user-full-name
) (user-full-name))
632 (and (boundp 'user-full-name
) user-full-name
)))
633 (mail (or (and (boundp 'add-log-mailing-address
) add-log-mailing-address
)
634 ;;(and (fboundp 'user-mail-address) (user-mail-address))
635 (and (boundp 'user-mail-address
) user-mail-address
)))
636 (time (or (and (boundp 'add-log-time-format
)
637 (functionp add-log-time-format
)
638 (funcall add-log-time-format
))
639 (format-time-string "%Y-%m-%d"))))
640 (looking-at (if log-edit-changelog-use-first
642 (regexp-quote (format "%s %s <%s>" time name mail
))))))
644 (defun log-edit-changelog-entries (file)
645 "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
646 The return value looks like this:
647 (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
648 where LOGBUFFER is the name of the ChangeLog buffer, and each
649 \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
650 (let ((changelog-file-name
651 (let ((default-directory
652 (file-name-directory (expand-file-name file
)))
653 (visiting-buffer (find-buffer-visiting file
)))
654 ;; If there is a buffer visiting FILE, and it has a local
655 ;; value for `change-log-default-name', use that.
656 (if (and visiting-buffer
657 (local-variable-p 'change-log-default-name
659 (with-current-buffer visiting-buffer
660 change-log-default-name
)
661 ;; `find-change-log' uses `change-log-default-name' if set
662 ;; and sets it before exiting, so we need to work around
663 ;; that memoizing which is undesired here
664 (setq change-log-default-name nil
)
665 (find-change-log)))))
666 (with-current-buffer (find-file-noselect changelog-file-name
)
667 (unless (eq major-mode
'change-log-mode
) (change-log-mode))
668 (goto-char (point-min))
669 (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
670 (if (not (log-edit-changelog-ours-p))
671 (list (current-buffer))
673 (log-edit-narrow-changelog)
674 (goto-char (point-min))
676 ;; Search for the name of FILE relative to the ChangeLog. If that
677 ;; doesn't occur anywhere, they're not using full relative
678 ;; filenames in the ChangeLog, so just look for FILE; we'll accept
679 ;; some false positives.
680 (let ((pattern (file-relative-name
681 file
(file-name-directory changelog-file-name
))))
682 (if (or (string= pattern
"")
684 (search-forward pattern nil t
))))
685 (setq pattern
(file-name-nondirectory file
)))
687 (setq pattern
(concat "\\(^\\|[^[:alnum:]]\\)"
689 "\\($\\|[^[:alnum:]]\\)"))
693 (while (and (not (eobp)) (re-search-forward pattern nil t
))
694 (let ((entry (log-edit-changelog-entry)))
695 (if (< (elt entry
1) (max (1+ pos
) (point)))
696 ;; This is not relevant, actually.
699 ;; Make sure we make progress.
700 (setq pos
(max (1+ pos
) (elt entry
1)))
703 (cons (current-buffer) texts
))))))))
705 (defun log-edit-changelog-insert-entries (buffer regions
)
706 "Insert those regions in BUFFER specified in REGIONS.
707 Sort REGIONS front-to-back first."
708 (let ((regions (sort regions
'car-less-than-car
))
710 (dolist (region regions
)
711 (when (and last
(< last
(car region
))) (newline))
712 (setq last
(elt region
1))
713 (apply 'insert-buffer-substring buffer region
))))
715 (defun log-edit-insert-changelog-entries (files)
716 "Given a list of files FILES, insert the ChangeLog entries for them."
717 (let ((buffer-entries nil
))
719 ;; Add each buffer to buffer-entries, and associate it with the list
720 ;; of entries we want from that file.
722 (let* ((entries (log-edit-changelog-entries file
))
723 (pair (assq (car entries
) buffer-entries
)))
725 (setcdr pair
(cvs-union (cdr pair
) (cdr entries
)))
726 (push entries buffer-entries
))))
728 ;; Now map over each buffer in buffer-entries, sort the entries for
729 ;; each buffer, and extract them as strings.
730 (dolist (buffer-entry buffer-entries
)
731 (log-edit-changelog-insert-entries (car buffer-entry
) (cdr buffer-entry
))
732 (when (cdr buffer-entry
) (newline)))))
734 (defun log-view-process-buffer ()
735 (when log-edit-before-checkin-process
736 (dolist (crt log-edit-before-checkin-process
)
737 ;; Remove all lines matching (car crt)
738 ;; Append to `log-edit-extra-flags' the results of (cdr crt).
739 (goto-char (point-min))
740 (while (re-search-forward (car crt
) nil t
)
742 (setq log-edit-extra-flags
(append log-edit-extra-flags
(eval (cdr crt
)))))
743 (replace-match "" nil t
)))))
747 ;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
748 ;;; log-edit.el ends here