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-parent-buffer nil
)
193 ;;; Originally taken from VC-Log mode
195 (defconst log-edit-maximum-comment-ring-size
32
196 "Maximum number of saved comments in the comment ring.")
197 (defvar log-edit-comment-ring
(make-ring log-edit-maximum-comment-ring-size
))
198 (defvar log-edit-comment-ring-index nil
)
199 (defvar log-edit-last-comment-match
"")
201 (defun log-edit-new-comment-index (stride len
)
202 "Return the comment index STRIDE elements from the current one.
203 LEN is the length of `log-edit-comment-ring'."
205 (log-edit-comment-ring-index (+ log-edit-comment-ring-index stride
))
206 ;; Initialize the index on the first use of this command
207 ;; so that the first M-p gets index 0, and the first M-n gets
209 ((> stride
0) (1- stride
))
213 (defun log-edit-previous-comment (arg)
214 "Cycle backwards through comment history.
215 With a numeric prefix ARG, go back ARG comments."
217 (let ((len (ring-length log-edit-comment-ring
)))
219 (progn (message "Empty comment ring") (ding))
220 ;; Don't use `erase-buffer' because we don't want to `widen'.
221 (delete-region (point-min) (point-max))
222 (setq log-edit-comment-ring-index
(log-edit-new-comment-index arg len
))
223 (message "Comment %d" (1+ log-edit-comment-ring-index
))
224 (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index
)))))
226 (defun log-edit-next-comment (arg)
227 "Cycle forwards through comment history.
228 With a numeric prefix ARG, go forward ARG comments."
230 (log-edit-previous-comment (- arg
)))
232 (defun log-edit-comment-search-backward (str &optional stride
)
233 "Search backwards through comment history for substring match of STR.
234 If the optional argument STRIDE is present, that is a step-width to use
235 when going through the comment ring."
236 ;; Why substring rather than regexp ? -sm
238 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
239 (unless stride
(setq stride
1))
241 (setq str log-edit-last-comment-match
)
242 (setq log-edit-last-comment-match str
))
243 (let* ((str (regexp-quote str
))
244 (len (ring-length log-edit-comment-ring
))
245 (n (log-edit-new-comment-index stride len
)))
246 (while (progn (when (or (>= n len
) (< n
0)) (error "Not found"))
247 (not (string-match str
(ring-ref log-edit-comment-ring n
))))
248 (setq n
(+ n stride
)))
249 (setq log-edit-comment-ring-index n
)
250 (log-edit-previous-comment 0)))
252 (defun log-edit-comment-search-forward (str)
253 "Search forwards through comment history for a substring match of STR."
255 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match
)))
256 (log-edit-comment-search-backward str -
1))
258 (defun log-edit-comment-to-change-log (&optional whoami file-name
)
259 "Enter last VC comment into the change log for the current file.
260 WHOAMI (interactive prefix) non-nil means prompt for user name
261 and site. FILE-NAME is the name of the change log; if nil, use
262 `change-log-default-name'.
264 This may be useful as a `log-edit-checkin-hook' to update change logs
266 (interactive (if current-prefix-arg
267 (list current-prefix-arg
268 (prompt-for-change-log-name))))
269 (let (;; Extract the comment first so we get any error before doing anything.
270 (comment (ring-ref log-edit-comment-ring
0))
271 ;; Don't let add-change-log-entry insert a defun name.
272 (add-log-current-defun-function 'ignore
)
274 ;; Call add-log to do half the work.
275 (add-change-log-entry whoami file-name t t
)
276 ;; Insert the VC comment, leaving point before it.
277 (setq end
(save-excursion (insert comment
) (point-marker)))
278 (if (looking-at "\\s *\\s(")
279 ;; It starts with an open-paren, as in "(foo): Frobbed."
280 ;; So remove the ": " add-log inserted.
282 ;; Canonicalize the white space between the file name and comment.
284 ;; Indent rest of the text the same way add-log indented the first line.
285 (let ((indentation (current-indentation)))
287 (while (< (point) end
)
289 (indent-to indentation
))
291 ;; Fill the inserted text, preserving open-parens at bol.
292 (let ((paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
294 (fill-region (point) end
))
295 ;; Canonicalize the white space at the end of the entry so it is
296 ;; separated from the next entry by a single blank line.
297 (skip-syntax-forward " " end
)
298 (delete-char (- (skip-syntax-backward " ")))
299 (or (eobp) (looking-at "\n\n")
302 ;; Compatibility with old names.
303 (define-obsolete-variable-alias 'vc-comment-ring
'log-edit-comment-ring
"22.1")
304 (define-obsolete-variable-alias 'vc-comment-ring-index
'log-edit-comment-ring-index
"22.1")
305 (define-obsolete-function-alias 'vc-previous-comment
'log-edit-previous-comment
"22.1")
306 (define-obsolete-function-alias 'vc-next-comment
'log-edit-next-comment
"22.1")
307 (define-obsolete-function-alias 'vc-comment-search-reverse
'log-edit-comment-search-backward
"22.1")
308 (define-obsolete-function-alias 'vc-comment-search-forward
'log-edit-comment-search-forward
"22.1")
309 (define-obsolete-function-alias 'vc-comment-to-change-log
'log-edit-comment-to-change-log
"22.1")
315 (defvar log-edit-font-lock-keywords
316 '(("\\`\\(Summary:\\)\\(.*\\)"
317 (1 font-lock-keyword-face
)
318 (2 font-lock-function-name-face
))))
321 (defun log-edit (callback &optional setup params buffer
&rest ignore
)
322 "Setup a buffer to enter a log message.
323 \\<log-edit-mode-map>The buffer will be put in `log-edit-mode'.
324 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
325 Mark and point will be set around the entire contents of the buffer so
326 that it is easy to kill the contents of the buffer with \\[kill-region].
327 Once you're done editing the message, pressing \\[log-edit-done] will call
328 `log-edit-done' which will end up calling CALLBACK to do the actual commit.
330 PARAMS if non-nil is an alist. Possible keys and associated values:
331 `log-edit-listfun' -- function taking no arguments that returns the list of
332 files that are concerned by the current operation (using relative names);
333 `log-edit-diff-function' -- function taking no arguments that
334 displays a diff of the files concerned by the current operation.
336 If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
337 log message and go back to the current buffer when done. Otherwise, it
338 uses the current buffer."
339 (let ((parent (current-buffer)))
340 (if buffer
(pop-to-buffer buffer
))
341 (when (and log-edit-setup-invert
(not (eq setup
'force
)))
342 (setq setup
(not setup
)))
343 (when setup
(erase-buffer))
345 (set (make-local-variable 'log-edit-callback
) callback
)
348 (set (make-local-variable (car crt
)) (cdr crt
)))
349 ;; For backward compatibility with log-edit up to version 22.2
350 ;; accept non-list PARAMS to mean `log-edit-list'.
351 (set (make-local-variable 'log-edit-listfun
) params
))
353 (if buffer
(set (make-local-variable 'log-edit-parent-buffer
) parent
))
354 (set (make-local-variable 'log-edit-initial-files
) (log-edit-files))
355 (when setup
(run-hooks 'log-edit-hook
))
356 (goto-char (point-min)) (push-mark (point-max))
357 (message "%s" (substitute-command-keys
358 "Press \\[log-edit-done] when you are done editing."))))
360 (define-derived-mode log-edit-mode text-mode
"Log-Edit"
361 "Major mode for editing version-control log messages.
362 When done editing the log entry, just type \\[log-edit-done] which
363 will trigger the actual commit of the file(s).
364 Several other handy support commands are provided of course and
365 the package from which this is used might also provide additional
366 commands (under C-x v for VC, for example).
368 \\{log-edit-mode-map}"
369 (set (make-local-variable 'font-lock-defaults
)
370 '(log-edit-font-lock-keywords t
))
371 (make-local-variable 'log-edit-comment-ring-index
))
373 (defun log-edit-hide-buf (&optional buf where
)
374 (when (setq buf
(get-buffer (or buf log-edit-files-buf
)))
375 (let ((win (get-buffer-window buf where
)))
376 (if win
(ignore-errors (delete-window win
))))
379 (defun log-edit-done ()
380 "Finish editing the log message and commit the files.
381 If you want to abort the commit, simply delete the buffer."
383 ;; Get rid of trailing empty lines
384 (goto-char (point-max))
385 (skip-syntax-backward " ")
386 (when (equal (char-after) ?
\n) (forward-char 1))
387 (delete-region (point) (point-max))
388 ;; Check for final newline
389 (if (and (> (point-max) (point-min))
390 (/= (char-before (point-max)) ?
\n)
391 (or (eq log-edit-require-final-newline t
)
392 (and log-edit-require-final-newline
394 (format "Buffer %s does not end in newline. Add one? "
397 (goto-char (point-max))
399 (let ((comment (buffer-string)))
400 (when (or (ring-empty-p log-edit-comment-ring
)
401 (not (equal comment
(ring-ref log-edit-comment-ring
0))))
402 (ring-insert log-edit-comment-ring comment
)))
403 (let ((win (get-buffer-window log-edit-files-buf
)))
404 (if (and log-edit-confirm
405 (not (and (eq log-edit-confirm
'changed
)
406 (equal (log-edit-files) log-edit-initial-files
)))
408 (log-edit-show-files)
409 (not (y-or-n-p "Really commit? "))))
410 (progn (when (not win
) (log-edit-hide-buf))
411 (message "Oh, well! Later maybe?"))
412 (run-hooks 'log-edit-done-hook
)
414 (unless (or log-edit-keep-buffer
(not log-edit-parent-buffer
))
415 (cvs-bury-buffer (current-buffer) log-edit-parent-buffer
))
416 (call-interactively log-edit-callback
))))
418 (defun log-edit-files ()
419 "Return the list of files that are about to be committed."
420 (ignore-errors (funcall log-edit-listfun
)))
422 (defun log-edit-mode-help ()
423 "Provide help for the `log-edit-mode-map'."
425 (if (eq last-command
'log-edit-mode-help
)
426 (describe-function major-mode
)
428 (substitute-command-keys
429 "Type `\\[log-edit-done]' to finish commit. Try `\\[describe-function] log-edit-done' for more help."))))
431 (defcustom log-edit-common-indent
0
432 "Minimum indentation to use in `log-edit-set-common-indentation'."
436 (defun log-edit-set-common-indentation ()
437 "(Un)Indent the current buffer rigidly to `log-edit-common-indent'."
439 (let ((common (point-max)))
440 (goto-char (point-min))
441 (while (< (point) (point-max))
442 (if (not (looking-at "^[ \t]*$"))
443 (setq common
(min common
(current-indentation))))
445 (indent-rigidly (point-min) (point-max)
446 (- log-edit-common-indent common
)))))
448 (defun log-edit-show-diff ()
449 "Show the diff for the files to be committed."
451 (if (functionp log-edit-diff-function
)
452 (funcall log-edit-diff-function
)
453 (error "Diff functionality has not been setup")))
455 (defun log-edit-show-files ()
456 "Show the list of files to be committed."
458 (let* ((files (log-edit-files))
459 (buf (get-buffer-create log-edit-files-buf
)))
460 (with-current-buffer buf
461 (log-edit-hide-buf buf
'all
)
462 (setq buffer-read-only nil
)
464 (cvs-insert-strings files
)
465 (setq buffer-read-only t
)
466 (goto-char (point-min))
467 (save-selected-window
468 (cvs-pop-to-buffer-same-frame buf
)
469 (shrink-window-if-larger-than-buffer)
470 (selected-window)))))
472 (defun log-edit-insert-cvs-template ()
473 "Insert the template specified by the CVS administrator, if any.
474 This simply uses the local CVS/Template file."
476 (when (or (called-interactively-p 'interactive
)
477 (= (point-min) (point-max)))
478 (when (file-readable-p "CVS/Template")
479 (insert-file-contents "CVS/Template"))))
481 (defun log-edit-insert-cvs-rcstemplate ()
482 "Insert the rcstemplate from the CVS repository.
483 This contacts the repository to get the rcstemplate file and
484 can thus take some time."
486 (when (or (called-interactively-p 'interactive
)
487 (= (point-min) (point-max)))
488 (when (file-readable-p "CVS/Root")
489 ;; Ignore the stderr stuff, even if it's an error.
490 (call-process "cvs" nil
'(t nil
) nil
491 "checkout" "-p" "CVSROOT/rcstemplate"))))
493 (defun log-edit-insert-filenames ()
494 "Insert the list of files that are to be committed."
496 (insert "Affected files: \n"
497 (mapconcat 'identity
(log-edit-files) " \n")))
499 (defun log-edit-add-to-changelog ()
500 "Insert this log message into the appropriate ChangeLog file."
503 (unless (string= (buffer-string) (ring-ref log-edit-comment-ring
0))
504 (ring-insert log-edit-comment-ring
(buffer-string)))
505 (dolist (f (log-edit-files))
506 (let ((buffer-file-name (expand-file-name f
)))
508 (log-edit-comment-to-change-log)))))
510 (defvar log-edit-changelog-use-first nil
)
511 (defun log-edit-insert-changelog (&optional use-first
)
512 "Insert a log message by looking at the ChangeLog.
513 The idea is to write your ChangeLog entries first, and then use this
514 command to commit your changes.
516 To select default log text, we:
517 - find the ChangeLog entries for the files to be checked in,
518 - verify that the top entry in the ChangeLog is on the current date
519 and by the current user; if not, we don't provide any default text,
520 - search the ChangeLog entry for paragraphs containing the names of
521 the files we're checking in, and finally
522 - use those paragraphs as the log text.
524 If the optional prefix arg USE-FIRST is given (via \\[universal-argument]),
525 or if the command is repeated a second time in a row, use the first log entry
526 regardless of user name or time."
528 (let ((log-edit-changelog-use-first
529 (or use-first
(eq last-command
'log-edit-insert-changelog
))))
530 (log-edit-insert-changelog-entries (log-edit-files)))
531 (log-edit-set-common-indentation)
532 (goto-char (point-min))
533 (when (and log-edit-strip-single-file-name
(looking-at "\\*\\s-+"))
535 (when (not (re-search-forward "^\\*\\s-+" nil t
))
536 (goto-char (point-min))
537 (skip-chars-forward "^():")
538 (skip-chars-forward ": ")
539 (delete-region (point-min) (point)))))
542 ;;;; functions for getting commit message from ChangeLog a file...
543 ;;;; Courtesy Jim Blandy
546 (defun log-edit-narrow-changelog ()
547 "Narrow to the top page of the current buffer, a ChangeLog file.
548 Actually, the narrowed region doesn't include the date line.
549 A \"page\" in a ChangeLog file is the area between two dates."
550 (or (eq major-mode
'change-log-mode
)
551 (error "log-edit-narrow-changelog: current buffer isn't a ChangeLog"))
553 (goto-char (point-min))
555 ;; Skip date line and subsequent blank lines.
557 (if (looking-at "[ \t\n]*\n")
558 (goto-char (match-end 0)))
560 (let ((start (point)))
562 (narrow-to-region start
(point))
563 (goto-char (point-min))))
565 (defun log-edit-changelog-paragraph ()
566 "Return the bounds of the ChangeLog paragraph containing point.
567 If we are between paragraphs, return the previous paragraph."
569 (if (looking-at "^[ \t]*$")
570 (skip-chars-backward " \t\n" (point-min)))
572 (if (re-search-backward "^[ \t]*\n" nil
'or-to-limit
)
573 (goto-char (match-end 0)))
575 (if (re-search-forward "^[ \t\n]*$" nil t
)
579 (defun log-edit-changelog-subparagraph ()
580 "Return the bounds of the ChangeLog subparagraph containing point.
581 A subparagraph is a block of non-blank lines beginning with an asterisk.
582 If we are between sub-paragraphs, return the previous subparagraph."
584 (if (search-backward "*" nil t
)
585 (list (progn (beginning-of-line) (point))
588 (if (re-search-forward "^[ \t]*[\n*]" nil t
)
591 (list (point) (point))))
593 (defun log-edit-changelog-entry ()
594 "Return the bounds of the ChangeLog entry containing point.
595 The variable `log-edit-changelog-full-paragraphs' decides whether an
596 \"entry\" is a paragraph or a subparagraph; see its documentation string
599 (if log-edit-changelog-full-paragraphs
600 (log-edit-changelog-paragraph)
601 (log-edit-changelog-subparagraph))))
603 (defvar user-full-name
)
604 (defvar user-mail-address
)
605 (defun log-edit-changelog-ours-p ()
606 "See if ChangeLog entry at point is for the current user, today.
607 Return non-nil if it is."
608 ;; Code adapted from add-change-log-entry.
609 (let ((name (or (and (boundp 'add-log-full-name
) add-log-full-name
)
610 (and (fboundp 'user-full-name
) (user-full-name))
611 (and (boundp 'user-full-name
) user-full-name
)))
612 (mail (or (and (boundp 'add-log-mailing-address
) add-log-mailing-address
)
613 ;;(and (fboundp 'user-mail-address) (user-mail-address))
614 (and (boundp 'user-mail-address
) user-mail-address
)))
615 (time (or (and (boundp 'add-log-time-format
)
616 (functionp add-log-time-format
)
617 (funcall add-log-time-format
))
618 (format-time-string "%Y-%m-%d"))))
619 (looking-at (if log-edit-changelog-use-first
621 (regexp-quote (format "%s %s <%s>" time name mail
))))))
623 (defun log-edit-changelog-entries (file)
624 "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
625 The return value looks like this:
626 (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
627 where LOGBUFFER is the name of the ChangeLog buffer, and each
628 \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
629 (let ((changelog-file-name
630 (let ((default-directory
631 (file-name-directory (expand-file-name file
)))
632 (visiting-buffer (find-buffer-visiting file
)))
633 ;; If there is a buffer visiting FILE, and it has a local
634 ;; value for `change-log-default-name', use that.
635 (if (and visiting-buffer
636 (local-variable-p 'change-log-default-name
638 (with-current-buffer visiting-buffer
639 change-log-default-name
)
640 ;; `find-change-log' uses `change-log-default-name' if set
641 ;; and sets it before exiting, so we need to work around
642 ;; that memoizing which is undesired here
643 (setq change-log-default-name nil
)
644 (find-change-log)))))
645 (with-current-buffer (find-file-noselect changelog-file-name
)
646 (unless (eq major-mode
'change-log-mode
) (change-log-mode))
647 (goto-char (point-min))
648 (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
649 (if (not (log-edit-changelog-ours-p))
650 (list (current-buffer))
652 (log-edit-narrow-changelog)
653 (goto-char (point-min))
655 ;; Search for the name of FILE relative to the ChangeLog. If that
656 ;; doesn't occur anywhere, they're not using full relative
657 ;; filenames in the ChangeLog, so just look for FILE; we'll accept
658 ;; some false positives.
659 (let ((pattern (file-relative-name
660 file
(file-name-directory changelog-file-name
))))
661 (if (or (string= pattern
"")
663 (search-forward pattern nil t
))))
664 (setq pattern
(file-name-nondirectory file
)))
666 (setq pattern
(concat "\\(^\\|[^[:alnum:]]\\)"
668 "\\($\\|[^[:alnum:]]\\)"))
672 (while (and (not (eobp)) (re-search-forward pattern nil t
))
673 (let ((entry (log-edit-changelog-entry)))
674 (if (< (elt entry
1) (max (1+ pos
) (point)))
675 ;; This is not relevant, actually.
678 ;; Make sure we make progress.
679 (setq pos
(max (1+ pos
) (elt entry
1)))
682 (cons (current-buffer) texts
))))))))
684 (defun log-edit-changelog-insert-entries (buffer regions
)
685 "Insert those regions in BUFFER specified in REGIONS.
686 Sort REGIONS front-to-back first."
687 (let ((regions (sort regions
'car-less-than-car
))
689 (dolist (region regions
)
690 (when (and last
(< last
(car region
))) (newline))
691 (setq last
(elt region
1))
692 (apply 'insert-buffer-substring buffer region
))))
694 (defun log-edit-insert-changelog-entries (files)
695 "Given a list of files FILES, insert the ChangeLog entries for them."
696 (let ((buffer-entries nil
))
698 ;; Add each buffer to buffer-entries, and associate it with the list
699 ;; of entries we want from that file.
701 (let* ((entries (log-edit-changelog-entries file
))
702 (pair (assq (car entries
) buffer-entries
)))
704 (setcdr pair
(cvs-union (cdr pair
) (cdr entries
)))
705 (push entries buffer-entries
))))
707 ;; Now map over each buffer in buffer-entries, sort the entries for
708 ;; each buffer, and extract them as strings.
709 (dolist (buffer-entry buffer-entries
)
710 (log-edit-changelog-insert-entries (car buffer-entry
) (cdr buffer-entry
))
711 (when (cdr buffer-entry
) (newline)))))
715 ;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
716 ;;; log-edit.el ends here