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 (defvar cvs-changelog-full-paragraphs t
)
152 (make-obsolete-variable 'cvs-changelog-full-paragraphs
153 'log-edit-changelog-full-paragraphs
156 (defvar log-edit-changelog-full-paragraphs cvs-changelog-full-paragraphs
157 "*If non-nil, include full ChangeLog paragraphs in the log.
158 This may be set in the ``local variables'' section of a ChangeLog, to
159 indicate the policy for that ChangeLog.
161 A ChangeLog paragraph is a bunch of log text containing no blank lines;
162 a paragraph usually describes a set of changes with a single purpose,
163 but perhaps spanning several functions in several files. Changes in
164 different paragraphs are unrelated.
166 You could argue that the log entry for a file should contain the
167 full ChangeLog paragraph mentioning the change to the file, even though
168 it may mention other files, because that gives you the full context you
169 need to understand the change. This is the behavior you get when this
170 variable is set to t.
172 On the other hand, you could argue that the log entry for a change
173 should contain only the text for the changes which occurred in that
174 file, because the log is per-file. This is the behavior you get
175 when this variable is set to nil.")
177 ;;;; Internal global or buffer-local vars
179 (defconst log-edit-files-buf
"*log-edit-files*")
180 (defvar log-edit-initial-files nil
)
181 (defvar log-edit-callback nil
)
182 (defvar log-edit-diff-function nil
)
183 (defvar log-edit-listfun nil
)
184 (defvar log-edit-parent-buffer nil
)
186 ;;; Originally taken from VC-Log mode
188 (defconst log-edit-maximum-comment-ring-size
32
189 "Maximum number of saved comments in the comment ring.")
190 (defvar log-edit-comment-ring
(make-ring log-edit-maximum-comment-ring-size
))
191 (defvar log-edit-comment-ring-index nil
)
192 (defvar log-edit-last-comment-match
"")
194 (defun log-edit-new-comment-index (stride len
)
195 "Return the comment index STRIDE elements from the current one.
196 LEN is the length of `log-edit-comment-ring'."
198 (log-edit-comment-ring-index (+ log-edit-comment-ring-index stride
))
199 ;; Initialize the index on the first use of this command
200 ;; so that the first M-p gets index 0, and the first M-n gets
202 ((> stride
0) (1- stride
))
206 (defun log-edit-previous-comment (arg)
207 "Cycle backwards through comment history.
208 With a numeric prefix ARG, go back ARG comments."
210 (let ((len (ring-length log-edit-comment-ring
)))
212 (progn (message "Empty comment ring") (ding))
213 ;; Don't use `erase-buffer' because we don't want to `widen'.
214 (delete-region (point-min) (point-max))
215 (setq log-edit-comment-ring-index
(log-edit-new-comment-index arg len
))
216 (message "Comment %d" (1+ log-edit-comment-ring-index
))
217 (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index
)))))
219 (defun log-edit-next-comment (arg)
220 "Cycle forwards through comment history.
221 With a numeric prefix ARG, go forward ARG comments."
223 (log-edit-previous-comment (- arg
)))
225 (defun log-edit-comment-search-backward (str &optional stride
)
226 "Search backwards through comment history for substring match of STR.
227 If the optional argument STRIDE is present, that is a step-width to use
228 when going through the comment ring."
229 ;; Why substring rather than regexp ? -sm
231 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
232 (unless stride
(setq stride
1))
234 (setq str log-edit-last-comment-match
)
235 (setq log-edit-last-comment-match str
))
236 (let* ((str (regexp-quote str
))
237 (len (ring-length log-edit-comment-ring
))
238 (n (log-edit-new-comment-index stride len
)))
239 (while (progn (when (or (>= n len
) (< n
0)) (error "Not found"))
240 (not (string-match str
(ring-ref log-edit-comment-ring n
))))
241 (setq n
(+ n stride
)))
242 (setq log-edit-comment-ring-index n
)
243 (log-edit-previous-comment 0)))
245 (defun log-edit-comment-search-forward (str)
246 "Search forwards through comment history for a substring match of STR."
248 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
249 (log-edit-comment-search-backward str -
1))
251 (defun log-edit-comment-to-change-log (&optional whoami file-name
)
252 "Enter last VC comment into the change log for the current file.
253 WHOAMI (interactive prefix) non-nil means prompt for user name
254 and site. FILE-NAME is the name of the change log; if nil, use
255 `change-log-default-name'.
257 This may be useful as a `log-edit-checkin-hook' to update change logs
259 (interactive (if current-prefix-arg
260 (list current-prefix-arg
261 (prompt-for-change-log-name))))
262 (let (;; Extract the comment first so we get any error before doing anything.
263 (comment (ring-ref log-edit-comment-ring
0))
264 ;; Don't let add-change-log-entry insert a defun name.
265 (add-log-current-defun-function 'ignore
)
267 ;; Call add-log to do half the work.
268 (add-change-log-entry whoami file-name t t
)
269 ;; Insert the VC comment, leaving point before it.
270 (setq end
(save-excursion (insert comment
) (point-marker)))
271 (if (looking-at "\\s *\\s(")
272 ;; It starts with an open-paren, as in "(foo): Frobbed."
273 ;; So remove the ": " add-log inserted.
275 ;; Canonicalize the white space between the file name and comment.
277 ;; Indent rest of the text the same way add-log indented the first line.
278 (let ((indentation (current-indentation)))
280 (while (< (point) end
)
282 (indent-to indentation
))
284 ;; Fill the inserted text, preserving open-parens at bol.
285 (let ((paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
287 (fill-region (point) end
))
288 ;; Canonicalize the white space at the end of the entry so it is
289 ;; separated from the next entry by a single blank line.
290 (skip-syntax-forward " " end
)
291 (delete-char (- (skip-syntax-backward " ")))
292 (or (eobp) (looking-at "\n\n")
295 ;; Compatibility with old names.
296 (define-obsolete-variable-alias 'vc-comment-ring
'log-edit-comment-ring
"22.1")
297 (define-obsolete-variable-alias 'vc-comment-ring-index
'log-edit-comment-ring-index
"22.1")
298 (define-obsolete-function-alias 'vc-previous-comment
'log-edit-previous-comment
"22.1")
299 (define-obsolete-function-alias 'vc-next-comment
'log-edit-next-comment
"22.1")
300 (define-obsolete-function-alias 'vc-comment-search-reverse
'log-edit-comment-search-backward
"22.1")
301 (define-obsolete-function-alias 'vc-comment-search-forward
'log-edit-comment-search-forward
"22.1")
302 (define-obsolete-function-alias 'vc-comment-to-change-log
'log-edit-comment-to-change-log
"22.1")
308 (defvar log-edit-font-lock-keywords
309 '(("\\`\\(Summary:\\)\\(.*\\)"
310 (1 font-lock-keyword-face
)
311 (2 font-lock-function-name-face
))))
314 (defun log-edit (callback &optional setup params buffer
&rest ignore
)
315 "Setup a buffer to enter a log message.
316 \\<log-edit-mode-map>The buffer will be put in `log-edit-mode'.
317 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
318 Mark and point will be set around the entire contents of the buffer so
319 that it is easy to kill the contents of the buffer with \\[kill-region].
320 Once you're done editing the message, pressing \\[log-edit-done] will call
321 `log-edit-done' which will end up calling CALLBACK to do the actual commit.
323 PARAMS if non-nil is an alist. Possible keys and associated values:
324 `log-edit-listfun' -- function taking no arguments that returns the list of
325 files that are concerned by the current operation (using relative names);
326 `log-edit-diff-function' -- function taking no arguments that
327 displays a diff of the files concerned by the current operation.
329 If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
330 log message and go back to the current buffer when done. Otherwise, it
331 uses the current buffer."
332 (let ((parent (current-buffer)))
333 (if buffer
(pop-to-buffer buffer
))
334 (when (and log-edit-setup-invert
(not (eq setup
'force
)))
335 (setq setup
(not setup
)))
336 (when setup
(erase-buffer))
338 (set (make-local-variable 'log-edit-callback
) callback
)
341 (set (make-local-variable (car crt
)) (cdr crt
)))
342 ;; For backward compatibility with log-edit up to version 22.2
343 ;; accept non-list PARAMS to mean `log-edit-list'.
344 (set (make-local-variable 'log-edit-listfun
) params
))
346 (if buffer
(set (make-local-variable 'log-edit-parent-buffer
) parent
))
347 (set (make-local-variable 'log-edit-initial-files
) (log-edit-files))
348 (when setup
(run-hooks 'log-edit-hook
))
349 (goto-char (point-min)) (push-mark (point-max))
350 (message "%s" (substitute-command-keys
351 "Press \\[log-edit-done] when you are done editing."))))
353 (define-derived-mode log-edit-mode text-mode
"Log-Edit"
354 "Major mode for editing version-control log messages.
355 When done editing the log entry, just type \\[log-edit-done] which
356 will trigger the actual commit of the file(s).
357 Several other handy support commands are provided of course and
358 the package from which this is used might also provide additional
359 commands (under C-x v for VC, for example).
361 \\{log-edit-mode-map}"
362 (set (make-local-variable 'font-lock-defaults
)
363 '(log-edit-font-lock-keywords t
))
364 (make-local-variable 'log-edit-comment-ring-index
))
366 (defun log-edit-hide-buf (&optional buf where
)
367 (when (setq buf
(get-buffer (or buf log-edit-files-buf
)))
368 (let ((win (get-buffer-window buf where
)))
369 (if win
(ignore-errors (delete-window win
))))
372 (defun log-edit-done ()
373 "Finish editing the log message and commit the files.
374 If you want to abort the commit, simply delete the buffer."
376 ;; Get rid of trailing empty lines
377 (goto-char (point-max))
378 (skip-syntax-backward " ")
379 (when (equal (char-after) ?
\n) (forward-char 1))
380 (delete-region (point) (point-max))
381 ;; Check for final newline
382 (if (and (> (point-max) (point-min))
383 (/= (char-before (point-max)) ?
\n)
384 (or (eq log-edit-require-final-newline t
)
385 (and log-edit-require-final-newline
387 (format "Buffer %s does not end in newline. Add one? "
390 (goto-char (point-max))
392 (let ((comment (buffer-string)))
393 (when (or (ring-empty-p log-edit-comment-ring
)
394 (not (equal comment
(ring-ref log-edit-comment-ring
0))))
395 (ring-insert log-edit-comment-ring comment
)))
396 (let ((win (get-buffer-window log-edit-files-buf
)))
397 (if (and log-edit-confirm
398 (not (and (eq log-edit-confirm
'changed
)
399 (equal (log-edit-files) log-edit-initial-files
)))
401 (log-edit-show-files)
402 (not (y-or-n-p "Really commit? "))))
403 (progn (when (not win
) (log-edit-hide-buf))
404 (message "Oh, well! Later maybe?"))
405 (run-hooks 'log-edit-done-hook
)
407 (unless (or log-edit-keep-buffer
(not log-edit-parent-buffer
))
408 (cvs-bury-buffer (current-buffer) log-edit-parent-buffer
))
409 (call-interactively log-edit-callback
))))
411 (defun log-edit-files ()
412 "Return the list of files that are about to be committed."
413 (ignore-errors (funcall log-edit-listfun
)))
415 (defun log-edit-mode-help ()
416 "Provide help for the `log-edit-mode-map'."
418 (if (eq last-command
'log-edit-mode-help
)
419 (describe-function major-mode
)
421 (substitute-command-keys
422 "Type `\\[log-edit-done]' to finish commit. Try `\\[describe-function] log-edit-done' for more help."))))
424 (defcustom log-edit-common-indent
0
425 "Minimum indentation to use in `log-edit-set-common-indentation'."
429 (defun log-edit-set-common-indentation ()
430 "(Un)Indent the current buffer rigidly to `log-edit-common-indent'."
432 (let ((common (point-max)))
433 (goto-char (point-min))
434 (while (< (point) (point-max))
435 (if (not (looking-at "^[ \t]*$"))
436 (setq common
(min common
(current-indentation))))
438 (indent-rigidly (point-min) (point-max)
439 (- log-edit-common-indent common
)))))
441 (defun log-edit-show-diff ()
442 "Show the diff for the files to be committed."
444 (if (functionp log-edit-diff-function
)
445 (funcall log-edit-diff-function
)
446 (error "Diff functionality has not been setup")))
448 (defun log-edit-show-files ()
449 "Show the list of files to be committed."
451 (let* ((files (log-edit-files))
452 (buf (get-buffer-create log-edit-files-buf
)))
453 (with-current-buffer buf
454 (log-edit-hide-buf buf
'all
)
455 (setq buffer-read-only nil
)
457 (cvs-insert-strings files
)
458 (setq buffer-read-only t
)
459 (goto-char (point-min))
460 (save-selected-window
461 (cvs-pop-to-buffer-same-frame buf
)
462 (shrink-window-if-larger-than-buffer)
463 (selected-window)))))
465 (defun log-edit-insert-cvs-template ()
466 "Insert the template specified by the CVS administrator, if any.
467 This simply uses the local CVS/Template file."
469 (when (or (interactive-p) (= (point-min) (point-max)))
470 (when (file-readable-p "CVS/Template")
471 (insert-file-contents "CVS/Template"))))
473 (defun log-edit-insert-cvs-rcstemplate ()
474 "Insert the rcstemplate from the CVS repository.
475 This contacts the repository to get the rcstemplate file and
476 can thus take some time."
478 (when (or (interactive-p) (= (point-min) (point-max)))
479 (when (file-readable-p "CVS/Root")
480 ;; Ignore the stderr stuff, even if it's an error.
481 (call-process "cvs" nil
'(t nil
) nil
482 "checkout" "-p" "CVSROOT/rcstemplate"))))
484 (defun log-edit-insert-filenames ()
485 "Insert the list of files that are to be committed."
487 (insert "Affected files: \n"
488 (mapconcat 'identity
(log-edit-files) " \n")))
490 (defun log-edit-add-to-changelog ()
491 "Insert this log message into the appropriate ChangeLog file."
494 (unless (string= (buffer-string) (ring-ref log-edit-comment-ring
0))
495 (ring-insert log-edit-comment-ring
(buffer-string)))
496 (dolist (f (log-edit-files))
497 (let ((buffer-file-name (expand-file-name f
)))
499 (log-edit-comment-to-change-log)))))
501 (defvar log-edit-changelog-use-first nil
)
502 (defun log-edit-insert-changelog (&optional use-first
)
503 "Insert a log message by looking at the ChangeLog.
504 The idea is to write your ChangeLog entries first, and then use this
505 command to commit your changes.
507 To select default log text, we:
508 - find the ChangeLog entries for the files to be checked in,
509 - verify that the top entry in the ChangeLog is on the current date
510 and by the current user; if not, we don't provide any default text,
511 - search the ChangeLog entry for paragraphs containing the names of
512 the files we're checking in, and finally
513 - use those paragraphs as the log text.
515 If the optional prefix arg USE-FIRST is given (via \\[universal-argument]),
516 or if the command is repeated a second time in a row, use the first log entry
517 regardless of user name or time."
519 (let ((log-edit-changelog-use-first
520 (or use-first
(eq last-command
'log-edit-insert-changelog
))))
521 (log-edit-insert-changelog-entries (log-edit-files)))
522 (log-edit-set-common-indentation)
523 (goto-char (point-min))
524 (when (looking-at "\\*\\s-+")
526 (when (not (re-search-forward "^\\*\\s-+" nil t
))
527 (goto-char (point-min))
528 (skip-chars-forward "^():")
529 (skip-chars-forward ": ")
530 (delete-region (point-min) (point)))))
533 ;;;; functions for getting commit message from ChangeLog a file...
534 ;;;; Courtesy Jim Blandy
537 (defun log-edit-narrow-changelog ()
538 "Narrow to the top page of the current buffer, a ChangeLog file.
539 Actually, the narrowed region doesn't include the date line.
540 A \"page\" in a ChangeLog file is the area between two dates."
541 (or (eq major-mode
'change-log-mode
)
542 (error "log-edit-narrow-changelog: current buffer isn't a ChangeLog"))
544 (goto-char (point-min))
546 ;; Skip date line and subsequent blank lines.
548 (if (looking-at "[ \t\n]*\n")
549 (goto-char (match-end 0)))
551 (let ((start (point)))
553 (narrow-to-region start
(point))
554 (goto-char (point-min))))
556 (defun log-edit-changelog-paragraph ()
557 "Return the bounds of the ChangeLog paragraph containing point.
558 If we are between paragraphs, return the previous paragraph."
561 (if (looking-at "^[ \t]*$")
562 (skip-chars-backward " \t\n" (point-min)))
564 (if (re-search-backward "^[ \t]*\n" nil
'or-to-limit
)
565 (goto-char (match-end 0)))
567 (if (re-search-forward "^[ \t\n]*$" nil t
)
571 (defun log-edit-changelog-subparagraph ()
572 "Return the bounds of the ChangeLog subparagraph containing point.
573 A subparagraph is a block of non-blank lines beginning with an asterisk.
574 If we are between sub-paragraphs, return the previous subparagraph."
577 (if (search-backward "*" nil t
)
578 (list (progn (beginning-of-line) (point))
581 (if (re-search-forward "^[ \t]*[\n*]" nil t
)
584 (list (point) (point)))))
586 (defun log-edit-changelog-entry ()
587 "Return the bounds of the ChangeLog entry containing point.
588 The variable `log-edit-changelog-full-paragraphs' decides whether an
589 \"entry\" is a paragraph or a subparagraph; see its documentation string
591 (if log-edit-changelog-full-paragraphs
592 (log-edit-changelog-paragraph)
593 (log-edit-changelog-subparagraph)))
595 (defvar user-full-name
)
596 (defvar user-mail-address
)
597 (defun log-edit-changelog-ours-p ()
598 "See if ChangeLog entry at point is for the current user, today.
599 Return non-nil if it is."
600 ;; Code adapted from add-change-log-entry.
601 (let ((name (or (and (boundp 'add-log-full-name
) add-log-full-name
)
602 (and (fboundp 'user-full-name
) (user-full-name))
603 (and (boundp 'user-full-name
) user-full-name
)))
604 (mail (or (and (boundp 'add-log-mailing-address
) add-log-mailing-address
)
605 ;;(and (fboundp 'user-mail-address) (user-mail-address))
606 (and (boundp 'user-mail-address
) user-mail-address
)))
607 (time (or (and (boundp 'add-log-time-format
)
608 (functionp add-log-time-format
)
609 (funcall add-log-time-format
))
610 (format-time-string "%Y-%m-%d"))))
611 (looking-at (if log-edit-changelog-use-first
613 (regexp-quote (format "%s %s <%s>" time name mail
))))))
615 (defun log-edit-changelog-entries (file)
616 "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
617 The return value looks like this:
618 (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
619 where LOGBUFFER is the name of the ChangeLog buffer, and each
620 \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
621 (let ((changelog-file-name
622 (let ((default-directory
623 (file-name-directory (expand-file-name file
)))
624 (visiting-buffer (find-buffer-visiting file
)))
625 ;; If there is a buffer visiting FILE, and it has a local
626 ;; value for `change-log-default-name', use that.
627 (if (and visiting-buffer
628 (local-variable-p 'change-log-default-name
630 (with-current-buffer visiting-buffer
631 change-log-default-name
)
632 ;; `find-change-log' uses `change-log-default-name' if set
633 ;; and sets it before exiting, so we need to work around
634 ;; that memoizing which is undesired here
635 (setq change-log-default-name nil
)
636 (find-change-log)))))
637 (with-current-buffer (find-file-noselect changelog-file-name
)
638 (unless (eq major-mode
'change-log-mode
) (change-log-mode))
639 (goto-char (point-min))
640 (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
641 (if (not (log-edit-changelog-ours-p))
642 (list (current-buffer))
644 (log-edit-narrow-changelog)
645 (goto-char (point-min))
647 ;; Search for the name of FILE relative to the ChangeLog. If that
648 ;; doesn't occur anywhere, they're not using full relative
649 ;; filenames in the ChangeLog, so just look for FILE; we'll accept
650 ;; some false positives.
651 (let ((pattern (file-relative-name
652 file
(file-name-directory changelog-file-name
))))
653 (if (or (string= pattern
"")
655 (search-forward pattern nil t
))))
656 (setq pattern
(file-name-nondirectory file
)))
658 (setq pattern
(concat "\\(^\\|[^[:alnum:]]\\)"
660 "\\($\\|[^[:alnum:]]\\)"))
663 (while (re-search-forward pattern nil t
)
664 (let ((entry (log-edit-changelog-entry)))
666 (goto-char (elt entry
1))))
668 (cons (current-buffer) texts
))))))))
670 (defun log-edit-changelog-insert-entries (buffer regions
)
671 "Insert those regions in BUFFER specified in REGIONS.
672 Sort REGIONS front-to-back first."
673 (let ((regions (sort regions
'car-less-than-car
))
675 (dolist (region regions
)
676 (when (and last
(< last
(car region
))) (newline))
677 (setq last
(elt region
1))
678 (apply 'insert-buffer-substring buffer region
))))
680 (defun log-edit-insert-changelog-entries (files)
681 "Given a list of files FILES, insert the ChangeLog entries for them."
682 (let ((buffer-entries nil
))
684 ;; Add each buffer to buffer-entries, and associate it with the list
685 ;; of entries we want from that file.
687 (let* ((entries (log-edit-changelog-entries file
))
688 (pair (assq (car entries
) buffer-entries
)))
690 (setcdr pair
(cvs-union (cdr pair
) (cdr entries
)))
691 (push entries buffer-entries
))))
693 ;; Now map over each buffer in buffer-entries, sort the entries for
694 ;; each buffer, and extract them as strings.
695 (dolist (buffer-entry buffer-entries
)
696 (log-edit-changelog-insert-entries (car buffer-entry
) (cdr buffer-entry
))
697 (when (cdr buffer-entry
) (newline)))))
701 ;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
702 ;;; log-edit.el ends here