1 ;;; log-edit.el --- Major mode for editing CVS commit messages
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009 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."
155 (defvar cvs-changelog-full-paragraphs t
)
156 (make-obsolete-variable 'cvs-changelog-full-paragraphs
157 'log-edit-changelog-full-paragraphs
160 (defvar log-edit-changelog-full-paragraphs cvs-changelog-full-paragraphs
161 "*If non-nil, include full ChangeLog paragraphs in the log.
162 This may be set in the ``local variables'' section of a ChangeLog, to
163 indicate the policy for that ChangeLog.
165 A ChangeLog paragraph is a bunch of log text containing no blank lines;
166 a paragraph usually describes a set of changes with a single purpose,
167 but perhaps spanning several functions in several files. Changes in
168 different paragraphs are unrelated.
170 You could argue that the log entry for a file should contain the
171 full ChangeLog paragraph mentioning the change to the file, even though
172 it may mention other files, because that gives you the full context you
173 need to understand the change. This is the behavior you get when this
174 variable is set to t.
176 On the other hand, you could argue that the log entry for a change
177 should contain only the text for the changes which occurred in that
178 file, because the log is per-file. This is the behavior you get
179 when this variable is set to nil.")
181 ;;;; Internal global or buffer-local vars
183 (defconst log-edit-files-buf
"*log-edit-files*")
184 (defvar log-edit-initial-files nil
)
185 (defvar log-edit-callback nil
)
186 (defvar log-edit-diff-function nil
)
187 (defvar log-edit-listfun nil
)
188 (defvar log-edit-parent-buffer nil
)
190 ;;; Originally taken from VC-Log mode
192 (defconst log-edit-maximum-comment-ring-size
32
193 "Maximum number of saved comments in the comment ring.")
194 (defvar log-edit-comment-ring
(make-ring log-edit-maximum-comment-ring-size
))
195 (defvar log-edit-comment-ring-index nil
)
196 (defvar log-edit-last-comment-match
"")
198 (defun log-edit-new-comment-index (stride len
)
199 "Return the comment index STRIDE elements from the current one.
200 LEN is the length of `log-edit-comment-ring'."
202 (log-edit-comment-ring-index (+ log-edit-comment-ring-index stride
))
203 ;; Initialize the index on the first use of this command
204 ;; so that the first M-p gets index 0, and the first M-n gets
206 ((> stride
0) (1- stride
))
210 (defun log-edit-previous-comment (arg)
211 "Cycle backwards through comment history.
212 With a numeric prefix ARG, go back ARG comments."
214 (let ((len (ring-length log-edit-comment-ring
)))
216 (progn (message "Empty comment ring") (ding))
217 ;; Don't use `erase-buffer' because we don't want to `widen'.
218 (delete-region (point-min) (point-max))
219 (setq log-edit-comment-ring-index
(log-edit-new-comment-index arg len
))
220 (message "Comment %d" (1+ log-edit-comment-ring-index
))
221 (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index
)))))
223 (defun log-edit-next-comment (arg)
224 "Cycle forwards through comment history.
225 With a numeric prefix ARG, go forward ARG comments."
227 (log-edit-previous-comment (- arg
)))
229 (defun log-edit-comment-search-backward (str &optional stride
)
230 "Search backwards through comment history for substring match of STR.
231 If the optional argument STRIDE is present, that is a step-width to use
232 when going through the comment ring."
233 ;; Why substring rather than regexp ? -sm
235 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
236 (unless stride
(setq stride
1))
238 (setq str log-edit-last-comment-match
)
239 (setq log-edit-last-comment-match str
))
240 (let* ((str (regexp-quote str
))
241 (len (ring-length log-edit-comment-ring
))
242 (n (log-edit-new-comment-index stride len
)))
243 (while (progn (when (or (>= n len
) (< n
0)) (error "Not found"))
244 (not (string-match str
(ring-ref log-edit-comment-ring n
))))
245 (setq n
(+ n stride
)))
246 (setq log-edit-comment-ring-index n
)
247 (log-edit-previous-comment 0)))
249 (defun log-edit-comment-search-forward (str)
250 "Search forwards through comment history for a substring match of STR."
252 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
253 (log-edit-comment-search-backward str -
1))
255 (defun log-edit-comment-to-change-log (&optional whoami file-name
)
256 "Enter last VC comment into the change log for the current file.
257 WHOAMI (interactive prefix) non-nil means prompt for user name
258 and site. FILE-NAME is the name of the change log; if nil, use
259 `change-log-default-name'.
261 This may be useful as a `log-edit-checkin-hook' to update change logs
263 (interactive (if current-prefix-arg
264 (list current-prefix-arg
265 (prompt-for-change-log-name))))
266 (let (;; Extract the comment first so we get any error before doing anything.
267 (comment (ring-ref log-edit-comment-ring
0))
268 ;; Don't let add-change-log-entry insert a defun name.
269 (add-log-current-defun-function 'ignore
)
271 ;; Call add-log to do half the work.
272 (add-change-log-entry whoami file-name t t
)
273 ;; Insert the VC comment, leaving point before it.
274 (setq end
(save-excursion (insert comment
) (point-marker)))
275 (if (looking-at "\\s *\\s(")
276 ;; It starts with an open-paren, as in "(foo): Frobbed."
277 ;; So remove the ": " add-log inserted.
279 ;; Canonicalize the white space between the file name and comment.
281 ;; Indent rest of the text the same way add-log indented the first line.
282 (let ((indentation (current-indentation)))
284 (while (< (point) end
)
286 (indent-to indentation
))
288 ;; Fill the inserted text, preserving open-parens at bol.
289 (let ((paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
291 (fill-region (point) end
))
292 ;; Canonicalize the white space at the end of the entry so it is
293 ;; separated from the next entry by a single blank line.
294 (skip-syntax-forward " " end
)
295 (delete-char (- (skip-syntax-backward " ")))
296 (or (eobp) (looking-at "\n\n")
299 ;; Compatibility with old names.
300 (define-obsolete-variable-alias 'vc-comment-ring
'log-edit-comment-ring
"22.1")
301 (define-obsolete-variable-alias 'vc-comment-ring-index
'log-edit-comment-ring-index
"22.1")
302 (define-obsolete-function-alias 'vc-previous-comment
'log-edit-previous-comment
"22.1")
303 (define-obsolete-function-alias 'vc-next-comment
'log-edit-next-comment
"22.1")
304 (define-obsolete-function-alias 'vc-comment-search-reverse
'log-edit-comment-search-backward
"22.1")
305 (define-obsolete-function-alias 'vc-comment-search-forward
'log-edit-comment-search-forward
"22.1")
306 (define-obsolete-function-alias 'vc-comment-to-change-log
'log-edit-comment-to-change-log
"22.1")
312 (defvar log-edit-font-lock-keywords
313 '(("\\`\\(Summary:\\)\\(.*\\)"
314 (1 font-lock-keyword-face
)
315 (2 font-lock-function-name-face
))))
318 (defun log-edit (callback &optional setup params buffer
&rest ignore
)
319 "Setup a buffer to enter a log message.
320 \\<log-edit-mode-map>The buffer will be put in `log-edit-mode'.
321 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
322 Mark and point will be set around the entire contents of the buffer so
323 that it is easy to kill the contents of the buffer with \\[kill-region].
324 Once you're done editing the message, pressing \\[log-edit-done] will call
325 `log-edit-done' which will end up calling CALLBACK to do the actual commit.
327 PARAMS if non-nil is an alist. Possible keys and associated values:
328 `log-edit-listfun' -- function taking no arguments that returns the list of
329 files that are concerned by the current operation (using relative names);
330 `log-edit-diff-function' -- function taking no arguments that
331 displays a diff of the files concerned by the current operation.
333 If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
334 log message and go back to the current buffer when done. Otherwise, it
335 uses the current buffer."
336 (let ((parent (current-buffer)))
337 (if buffer
(pop-to-buffer buffer
))
338 (when (and log-edit-setup-invert
(not (eq setup
'force
)))
339 (setq setup
(not setup
)))
340 (when setup
(erase-buffer))
342 (set (make-local-variable 'log-edit-callback
) callback
)
345 (set (make-local-variable (car crt
)) (cdr crt
)))
346 ;; For backward compatibility with log-edit up to version 22.2
347 ;; accept non-list PARAMS to mean `log-edit-list'.
348 (set (make-local-variable 'log-edit-listfun
) params
))
350 (if buffer
(set (make-local-variable 'log-edit-parent-buffer
) parent
))
351 (set (make-local-variable 'log-edit-initial-files
) (log-edit-files))
352 (when setup
(run-hooks 'log-edit-hook
))
353 (goto-char (point-min)) (push-mark (point-max))
354 (message "%s" (substitute-command-keys
355 "Press \\[log-edit-done] when you are done editing."))))
357 (define-derived-mode log-edit-mode text-mode
"Log-Edit"
358 "Major mode for editing version-control log messages.
359 When done editing the log entry, just type \\[log-edit-done] which
360 will trigger the actual commit of the file(s).
361 Several other handy support commands are provided of course and
362 the package from which this is used might also provide additional
363 commands (under C-x v for VC, for example).
365 \\{log-edit-mode-map}"
366 (set (make-local-variable 'font-lock-defaults
)
367 '(log-edit-font-lock-keywords t
))
368 (make-local-variable 'log-edit-comment-ring-index
))
370 (defun log-edit-hide-buf (&optional buf where
)
371 (when (setq buf
(get-buffer (or buf log-edit-files-buf
)))
372 (let ((win (get-buffer-window buf where
)))
373 (if win
(ignore-errors (delete-window win
))))
376 (defun log-edit-done ()
377 "Finish editing the log message and commit the files.
378 If you want to abort the commit, simply delete the buffer."
380 ;; Get rid of trailing empty lines
381 (goto-char (point-max))
382 (skip-syntax-backward " ")
383 (when (equal (char-after) ?
\n) (forward-char 1))
384 (delete-region (point) (point-max))
385 ;; Check for final newline
386 (if (and (> (point-max) (point-min))
387 (/= (char-before (point-max)) ?
\n)
388 (or (eq log-edit-require-final-newline t
)
389 (and log-edit-require-final-newline
391 (format "Buffer %s does not end in newline. Add one? "
394 (goto-char (point-max))
396 (let ((comment (buffer-string)))
397 (when (or (ring-empty-p log-edit-comment-ring
)
398 (not (equal comment
(ring-ref log-edit-comment-ring
0))))
399 (ring-insert log-edit-comment-ring comment
)))
400 (let ((win (get-buffer-window log-edit-files-buf
)))
401 (if (and log-edit-confirm
402 (not (and (eq log-edit-confirm
'changed
)
403 (equal (log-edit-files) log-edit-initial-files
)))
405 (log-edit-show-files)
406 (not (y-or-n-p "Really commit? "))))
407 (progn (when (not win
) (log-edit-hide-buf))
408 (message "Oh, well! Later maybe?"))
409 (run-hooks 'log-edit-done-hook
)
411 (unless (or log-edit-keep-buffer
(not log-edit-parent-buffer
))
412 (cvs-bury-buffer (current-buffer) log-edit-parent-buffer
))
413 (call-interactively log-edit-callback
))))
415 (defun log-edit-files ()
416 "Return the list of files that are about to be committed."
417 (ignore-errors (funcall log-edit-listfun
)))
419 (defun log-edit-mode-help ()
420 "Provide help for the `log-edit-mode-map'."
422 (if (eq last-command
'log-edit-mode-help
)
423 (describe-function major-mode
)
425 (substitute-command-keys
426 "Type `\\[log-edit-done]' to finish commit. Try `\\[describe-function] log-edit-done' for more help."))))
428 (defcustom log-edit-common-indent
0
429 "Minimum indentation to use in `log-edit-set-common-indentation'."
433 (defun log-edit-set-common-indentation ()
434 "(Un)Indent the current buffer rigidly to `log-edit-common-indent'."
436 (let ((common (point-max)))
437 (goto-char (point-min))
438 (while (< (point) (point-max))
439 (if (not (looking-at "^[ \t]*$"))
440 (setq common
(min common
(current-indentation))))
442 (indent-rigidly (point-min) (point-max)
443 (- log-edit-common-indent common
)))))
445 (defun log-edit-show-diff ()
446 "Show the diff for the files to be committed."
448 (if (functionp log-edit-diff-function
)
449 (funcall log-edit-diff-function
)
450 (error "Diff functionality has not been setup")))
452 (defun log-edit-show-files ()
453 "Show the list of files to be committed."
455 (let* ((files (log-edit-files))
456 (buf (get-buffer-create log-edit-files-buf
)))
457 (with-current-buffer buf
458 (log-edit-hide-buf buf
'all
)
459 (setq buffer-read-only nil
)
461 (cvs-insert-strings files
)
462 (setq buffer-read-only t
)
463 (goto-char (point-min))
464 (save-selected-window
465 (cvs-pop-to-buffer-same-frame buf
)
466 (shrink-window-if-larger-than-buffer)
467 (selected-window)))))
469 (defun log-edit-insert-cvs-template ()
470 "Insert the template specified by the CVS administrator, if any.
471 This simply uses the local CVS/Template file."
473 (when (or (interactive-p) (= (point-min) (point-max)))
474 (when (file-readable-p "CVS/Template")
475 (insert-file-contents "CVS/Template"))))
477 (defun log-edit-insert-cvs-rcstemplate ()
478 "Insert the rcstemplate from the CVS repository.
479 This contacts the repository to get the rcstemplate file and
480 can thus take some time."
482 (when (or (interactive-p) (= (point-min) (point-max)))
483 (when (file-readable-p "CVS/Root")
484 ;; Ignore the stderr stuff, even if it's an error.
485 (call-process "cvs" nil
'(t nil
) nil
486 "checkout" "-p" "CVSROOT/rcstemplate"))))
488 (defun log-edit-insert-filenames ()
489 "Insert the list of files that are to be committed."
491 (insert "Affected files: \n"
492 (mapconcat 'identity
(log-edit-files) " \n")))
494 (defun log-edit-add-to-changelog ()
495 "Insert this log message into the appropriate ChangeLog file."
498 (unless (string= (buffer-string) (ring-ref log-edit-comment-ring
0))
499 (ring-insert log-edit-comment-ring
(buffer-string)))
500 (dolist (f (log-edit-files))
501 (let ((buffer-file-name (expand-file-name f
)))
503 (log-edit-comment-to-change-log)))))
505 (defvar log-edit-changelog-use-first nil
)
506 (defun log-edit-insert-changelog (&optional use-first
)
507 "Insert a log message by looking at the ChangeLog.
508 The idea is to write your ChangeLog entries first, and then use this
509 command to commit your changes.
511 To select default log text, we:
512 - find the ChangeLog entries for the files to be checked in,
513 - verify that the top entry in the ChangeLog is on the current date
514 and by the current user; if not, we don't provide any default text,
515 - search the ChangeLog entry for paragraphs containing the names of
516 the files we're checking in, and finally
517 - use those paragraphs as the log text.
519 If the optional prefix arg USE-FIRST is given (via \\[universal-argument]),
520 or if the command is repeated a second time in a row, use the first log entry
521 regardless of user name or time."
523 (let ((log-edit-changelog-use-first
524 (or use-first
(eq last-command
'log-edit-insert-changelog
))))
525 (log-edit-insert-changelog-entries (log-edit-files)))
526 (log-edit-set-common-indentation)
527 (goto-char (point-min))
528 (when (and log-edit-strip-single-file-name
(looking-at "\\*\\s-+"))
530 (when (not (re-search-forward "^\\*\\s-+" nil t
))
531 (goto-char (point-min))
532 (skip-chars-forward "^():")
533 (skip-chars-forward ": ")
534 (delete-region (point-min) (point)))))
537 ;;;; functions for getting commit message from ChangeLog a file...
538 ;;;; Courtesy Jim Blandy
541 (defun log-edit-narrow-changelog ()
542 "Narrow to the top page of the current buffer, a ChangeLog file.
543 Actually, the narrowed region doesn't include the date line.
544 A \"page\" in a ChangeLog file is the area between two dates."
545 (or (eq major-mode
'change-log-mode
)
546 (error "log-edit-narrow-changelog: current buffer isn't a ChangeLog"))
548 (goto-char (point-min))
550 ;; Skip date line and subsequent blank lines.
552 (if (looking-at "[ \t\n]*\n")
553 (goto-char (match-end 0)))
555 (let ((start (point)))
557 (narrow-to-region start
(point))
558 (goto-char (point-min))))
560 (defun log-edit-changelog-paragraph ()
561 "Return the bounds of the ChangeLog paragraph containing point.
562 If we are between paragraphs, return the previous paragraph."
564 (if (looking-at "^[ \t]*$")
565 (skip-chars-backward " \t\n" (point-min)))
567 (if (re-search-backward "^[ \t]*\n" nil
'or-to-limit
)
568 (goto-char (match-end 0)))
570 (if (re-search-forward "^[ \t\n]*$" nil t
)
574 (defun log-edit-changelog-subparagraph ()
575 "Return the bounds of the ChangeLog subparagraph containing point.
576 A subparagraph is a block of non-blank lines beginning with an asterisk.
577 If we are between sub-paragraphs, return the previous subparagraph."
579 (if (search-backward "*" nil t
)
580 (list (progn (beginning-of-line) (point))
583 (if (re-search-forward "^[ \t]*[\n*]" nil t
)
586 (list (point) (point))))
588 (defun log-edit-changelog-entry ()
589 "Return the bounds of the ChangeLog entry containing point.
590 The variable `log-edit-changelog-full-paragraphs' decides whether an
591 \"entry\" is a paragraph or a subparagraph; see its documentation string
594 (if log-edit-changelog-full-paragraphs
595 (log-edit-changelog-paragraph)
596 (log-edit-changelog-subparagraph))))
598 (defvar user-full-name
)
599 (defvar user-mail-address
)
600 (defun log-edit-changelog-ours-p ()
601 "See if ChangeLog entry at point is for the current user, today.
602 Return non-nil if it is."
603 ;; Code adapted from add-change-log-entry.
604 (let ((name (or (and (boundp 'add-log-full-name
) add-log-full-name
)
605 (and (fboundp 'user-full-name
) (user-full-name))
606 (and (boundp 'user-full-name
) user-full-name
)))
607 (mail (or (and (boundp 'add-log-mailing-address
) add-log-mailing-address
)
608 ;;(and (fboundp 'user-mail-address) (user-mail-address))
609 (and (boundp 'user-mail-address
) user-mail-address
)))
610 (time (or (and (boundp 'add-log-time-format
)
611 (functionp add-log-time-format
)
612 (funcall add-log-time-format
))
613 (format-time-string "%Y-%m-%d"))))
614 (looking-at (if log-edit-changelog-use-first
616 (regexp-quote (format "%s %s <%s>" time name mail
))))))
618 (defun log-edit-changelog-entries (file)
619 "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
620 The return value looks like this:
621 (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
622 where LOGBUFFER is the name of the ChangeLog buffer, and each
623 \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
624 (let ((changelog-file-name
625 (let ((default-directory
626 (file-name-directory (expand-file-name file
)))
627 (visiting-buffer (find-buffer-visiting file
)))
628 ;; If there is a buffer visiting FILE, and it has a local
629 ;; value for `change-log-default-name', use that.
630 (if (and visiting-buffer
631 (local-variable-p 'change-log-default-name
633 (with-current-buffer visiting-buffer
634 change-log-default-name
)
635 ;; `find-change-log' uses `change-log-default-name' if set
636 ;; and sets it before exiting, so we need to work around
637 ;; that memoizing which is undesired here
638 (setq change-log-default-name nil
)
639 (find-change-log)))))
640 (with-current-buffer (find-file-noselect changelog-file-name
)
641 (unless (eq major-mode
'change-log-mode
) (change-log-mode))
642 (goto-char (point-min))
643 (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
644 (if (not (log-edit-changelog-ours-p))
645 (list (current-buffer))
647 (log-edit-narrow-changelog)
648 (goto-char (point-min))
650 ;; Search for the name of FILE relative to the ChangeLog. If that
651 ;; doesn't occur anywhere, they're not using full relative
652 ;; filenames in the ChangeLog, so just look for FILE; we'll accept
653 ;; some false positives.
654 (let ((pattern (file-relative-name
655 file
(file-name-directory changelog-file-name
))))
656 (if (or (string= pattern
"")
658 (search-forward pattern nil t
))))
659 (setq pattern
(file-name-nondirectory file
)))
661 (setq pattern
(concat "\\(^\\|[^[:alnum:]]\\)"
663 "\\($\\|[^[:alnum:]]\\)"))
667 (while (and (not (eobp)) (re-search-forward pattern nil t
))
668 (let ((entry (log-edit-changelog-entry)))
669 (if (< (elt entry
1) (max (1+ pos
) (point)))
670 ;; This is not relevant, actually.
673 ;; Make sure we make progress.
674 (setq pos
(max (1+ pos
) (elt entry
1)))
677 (cons (current-buffer) texts
))))))))
679 (defun log-edit-changelog-insert-entries (buffer regions
)
680 "Insert those regions in BUFFER specified in REGIONS.
681 Sort REGIONS front-to-back first."
682 (let ((regions (sort regions
'car-less-than-car
))
684 (dolist (region regions
)
685 (when (and last
(< last
(car region
))) (newline))
686 (setq last
(elt region
1))
687 (apply 'insert-buffer-substring buffer region
))))
689 (defun log-edit-insert-changelog-entries (files)
690 "Given a list of files FILES, insert the ChangeLog entries for them."
691 (let ((buffer-entries nil
))
693 ;; Add each buffer to buffer-entries, and associate it with the list
694 ;; of entries we want from that file.
696 (let* ((entries (log-edit-changelog-entries file
))
697 (pair (assq (car entries
) buffer-entries
)))
699 (setcdr pair
(cvs-union (cdr pair
) (cdr entries
)))
700 (push entries buffer-entries
))))
702 ;; Now map over each buffer in buffer-entries, sort the entries for
703 ;; each buffer, and extract them as strings.
704 (dolist (buffer-entry buffer-entries
)
705 (log-edit-changelog-insert-entries (car buffer-entry
) (cdr buffer-entry
))
706 (when (cdr buffer-entry
) (newline)))))
710 ;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
711 ;;; log-edit.el ends here