(smtpmail-try-auth-methods): Fix typo.
[emacs.git] / lisp / log-edit.el
blobfa7ea4e842d27ea856457f20d7c110395b137ed2
1 ;;; log-edit.el --- Major mode for editing CVS commit messages
3 ;; Copyright (C) 1999,2000,2003 Free Software Foundation, Inc.
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
6 ;; Keywords: pcl-cvs cvs commit log
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; Todo:
29 ;; - Move in VC's code
30 ;; - Add compatibility for VC's hook variables
32 ;;; Code:
34 (eval-when-compile (require 'cl))
35 (require 'add-log) ; for all the ChangeLog goodies
36 (require 'pcvs-util)
37 (require 'ring)
39 ;;;;
40 ;;;; Global Variables
41 ;;;;
43 (defgroup log-edit nil
44 "Major mode for editing RCS and CVS commit messages."
45 :group 'pcl-cvs
46 :group 'vc ; It's used by VC.
47 :version "21.1"
48 :prefix "log-edit-")
50 ;; compiler pacifiers
51 (defvar cvs-buffer)
54 ;; The main keymap
56 (easy-mmode-defmap log-edit-mode-map
57 `(("\C-c\C-c" . log-edit-done)
58 ("\C-c\C-a" . log-edit-insert-changelog)
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)."
66 :group 'log-edit)
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'."
74 '("Log-Edit"
75 ["Done" log-edit-done
76 :help "Exit log-edit and proceed with the actual action."]
77 "--"
78 ["Insert ChangeLog" log-edit-insert-changelog]
79 ["Add to ChangeLog" log-edit-add-to-changelog]
80 "--"
81 ["List files" log-edit-show-files
82 :help "Show the list of relevant files."]
83 "--"
84 ["Previous comment" log-edit-previous-comment]
85 ["Next comment" log-edit-next-comment]
86 ["Search comment forward" log-edit-comment-search-forward]
87 ["Search comment backward" log-edit-comment-search-backward]))
89 (defcustom log-edit-confirm 'changed
90 "*If non-nil, `log-edit-done' will request confirmation.
91 If 'changed, only request confirmation if the list of files has
92 changed since the beginning of the log-edit session."
93 :group 'log-edit
94 :type '(choice (const changed) (const t) (const nil)))
96 (defcustom log-edit-keep-buffer nil
97 "*If non-nil, don't hide the buffer after `log-edit-done'."
98 :group 'log-edit
99 :type 'boolean)
101 (defvar cvs-commit-buffer-require-final-newline t)
102 (make-obsolete-variable 'cvs-commit-buffer-require-final-newline
103 'log-edit-require-final-newline)
105 (defcustom log-edit-require-final-newline
106 cvs-commit-buffer-require-final-newline
107 "*Enforce a newline at the end of commit log messages.
108 Enforce it silently if t, query if non-nil and don't do anything if nil."
109 :group 'log-edit
110 :type '(choice (const ask) (const t) (const nil)))
112 (defcustom log-edit-setup-invert nil
113 "*Non-nil means `log-edit' should invert the meaning of its SETUP arg.
114 If SETUP is 'force, this variable has no effect."
115 :group 'log-edit
116 :type 'boolean)
118 (defcustom log-edit-hook '(log-edit-insert-cvs-template
119 log-edit-insert-changelog)
120 "*Hook run at the end of `log-edit'."
121 :group 'log-edit
122 :type '(hook :options (log-edit-insert-cvs-template
123 log-edit-insert-changelog)))
125 (defcustom log-edit-mode-hook (if (boundp 'vc-log-mode-hook) vc-log-mode-hook)
126 "*Hook run when entering `log-edit-mode'."
127 :group 'log-edit
128 :type 'hook)
130 (defcustom log-edit-done-hook nil
131 "*Hook run before doing the actual commit.
132 This hook can be used to cleanup the message, enforce various
133 conventions, or to allow recording the message in some other database,
134 such as a bug-tracking system. The list of files about to be committed
135 can be obtained from `log-edit-files'."
136 :group 'log-edit
137 :type '(hook :options (log-edit-set-common-indentation
138 log-edit-add-to-changelog)))
140 (defvar cvs-changelog-full-paragraphs t)
141 (make-obsolete-variable 'cvs-changelog-full-paragraphs
142 'log-edit-changelog-full-paragraphs)
144 (defvar log-edit-changelog-full-paragraphs cvs-changelog-full-paragraphs
145 "*If non-nil, include full ChangeLog paragraphs in the log.
146 This may be set in the ``local variables'' section of a ChangeLog, to
147 indicate the policy for that ChangeLog.
149 A ChangeLog paragraph is a bunch of log text containing no blank lines;
150 a paragraph usually describes a set of changes with a single purpose,
151 but perhaps spanning several functions in several files. Changes in
152 different paragraphs are unrelated.
154 You could argue that the log entry for a file should contain the
155 full ChangeLog paragraph mentioning the change to the file, even though
156 it may mention other files, because that gives you the full context you
157 need to understand the change. This is the behaviour you get when this
158 variable is set to t.
160 On the other hand, you could argue that the log entry for a change
161 should contain only the text for the changes which occurred in that
162 file, because the log is per-file. This is the behaviour you get
163 when this variable is set to nil.")
165 ;;;; Internal global or buffer-local vars
167 (defconst log-edit-files-buf "*log-edit-files*")
168 (defvar log-edit-initial-files nil)
169 (defvar log-edit-callback nil)
170 (defvar log-edit-listfun nil)
171 (defvar log-edit-parent-buffer nil)
173 ;;; Originally taken from VC-Log mode
175 (defconst log-edit-maximum-comment-ring-size 32
176 "Maximum number of saved comments in the comment ring.")
177 (defvar log-edit-comment-ring (make-ring log-edit-maximum-comment-ring-size))
178 (defvar log-edit-comment-ring-index nil)
179 (defvar log-edit-last-comment-match "")
181 (defun log-edit-new-comment-index (stride len)
182 "Return the comment index STRIDE elements from the current one.
183 LEN is the length of `log-edit-comment-ring'."
184 (mod (cond
185 (log-edit-comment-ring-index (+ log-edit-comment-ring-index stride))
186 ;; Initialize the index on the first use of this command
187 ;; so that the first M-p gets index 0, and the first M-n gets
188 ;; index -1.
189 ((> stride 0) (1- stride))
190 (t stride))
191 len))
193 (defun log-edit-previous-comment (arg)
194 "Cycle backwards through comment history.
195 With a numeric prefix ARG, go back ARG comments."
196 (interactive "*p")
197 (let ((len (ring-length log-edit-comment-ring)))
198 (if (<= len 0)
199 (progn (message "Empty comment ring") (ding))
200 ;; Don't use `erase-buffer' because we don't want to `widen'.
201 (delete-region (point-min) (point-max))
202 (setq log-edit-comment-ring-index (log-edit-new-comment-index arg len))
203 (message "Comment %d" (1+ log-edit-comment-ring-index))
204 (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index)))))
206 (defun log-edit-next-comment (arg)
207 "Cycle forwards through comment history.
208 With a numeric prefix ARG, go forward ARG comments."
209 (interactive "*p")
210 (log-edit-previous-comment (- arg)))
212 (defun log-edit-comment-search-backward (str &optional stride)
213 "Search backwards through comment history for substring match of STR.
214 If the optional argument STRIDE is present, that is a step-width to use
215 when going through the comment ring."
216 ;; Why substring rather than regexp ? -sm
217 (interactive
218 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match)))
219 (unless stride (setq stride 1))
220 (if (string= str "")
221 (setq str log-edit-last-comment-match)
222 (setq log-edit-last-comment-match str))
223 (let* ((str (regexp-quote str))
224 (len (ring-length log-edit-comment-ring))
225 (n (log-edit-new-comment-index stride len)))
226 (while (progn (when (or (>= n len) (< n 0)) (error "Not found"))
227 (not (string-match str (ring-ref log-edit-comment-ring n))))
228 (setq n (+ n stride)))
229 (setq log-edit-comment-ring-index n)
230 (log-edit-previous-comment 0)))
232 (defun log-edit-comment-search-forward (str)
233 "Search forwards through comment history for a substring match of STR."
234 (interactive
235 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match)))
236 (log-edit-comment-search-backward str -1))
238 (defun log-edit-comment-to-change-log (&optional whoami file-name)
239 "Enter last VC comment into the change log for the current file.
240 WHOAMI (interactive prefix) non-nil means prompt for user name
241 and site. FILE-NAME is the name of the change log; if nil, use
242 `change-log-default-name'.
244 This may be useful as a `log-edit-checkin-hook' to update change logs
245 automatically."
246 (interactive (if current-prefix-arg
247 (list current-prefix-arg
248 (prompt-for-change-log-name))))
249 (let (;; Extract the comment first so we get any error before doing anything.
250 (comment (ring-ref log-edit-comment-ring 0))
251 ;; Don't let add-change-log-entry insert a defun name.
252 (add-log-current-defun-function 'ignore)
253 end)
254 ;; Call add-log to do half the work.
255 (add-change-log-entry whoami file-name t t)
256 ;; Insert the VC comment, leaving point before it.
257 (setq end (save-excursion (insert comment) (point-marker)))
258 (if (looking-at "\\s *\\s(")
259 ;; It starts with an open-paren, as in "(foo): Frobbed."
260 ;; So remove the ": " add-log inserted.
261 (delete-char -2))
262 ;; Canonicalize the white space between the file name and comment.
263 (just-one-space)
264 ;; Indent rest of the text the same way add-log indented the first line.
265 (let ((indentation (current-indentation)))
266 (save-excursion
267 (while (< (point) end)
268 (forward-line 1)
269 (indent-to indentation))
270 (setq end (point))))
271 ;; Fill the inserted text, preserving open-parens at bol.
272 (let ((paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
273 (beginning-of-line)
274 (fill-region (point) end))
275 ;; Canonicalize the white space at the end of the entry so it is
276 ;; separated from the next entry by a single blank line.
277 (skip-syntax-forward " " end)
278 (delete-char (- (skip-syntax-backward " ")))
279 (or (eobp) (looking-at "\n\n")
280 (insert "\n"))))
282 ;; Compatibility with old names.
283 (defvaralias 'vc-comment-ring 'log-edit-comment-ring)
284 (make-obsolete-variable 'vc-comment-ring 'log-edit-comment-ring "21.5")
285 (defvaralias 'vc-comment-ring-index 'log-edit-comment-ring-index)
286 (make-obsolete-variable 'vc-comment-ring-index 'log-edit-comment-ring-index "21.5")
287 (defalias 'vc-previous-comment 'log-edit-previous-comment)
288 (make-obsolete 'vc-previous-comment 'log-edit-previous-comment "21.5")
289 (defalias 'vc-next-comment 'log-edit-next-comment)
290 (make-obsolete 'vc-next-comment 'log-edit-next-comment "21.5")
291 (defalias 'vc-comment-search-reverse 'log-edit-comment-search-backward)
292 (make-obsolete 'vc-comment-search-reverse 'log-edit-comment-search-backward "21.5")
293 (defalias 'vc-comment-search-forward 'log-edit-comment-search-forward)
294 (make-obsolete 'vc-comment-search-forward 'log-edit-comment-search-forward "21.5")
295 (defalias 'vc-comment-to-change-log 'log-edit-comment-to-change-log)
296 (make-obsolete 'vc-comment-to-change-log 'log-edit-comment-to-change-log "21.5")
299 ;;; Actual code
302 ;;;###autoload
303 (defun log-edit (callback &optional setup listfun buffer &rest ignore)
304 "Setup a buffer to enter a log message.
305 \\<log-edit-mode-map>The buffer will be put in `log-edit-mode'.
306 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
307 Mark and point will be set around the entire contents of the
308 buffer so that it is easy to kill the contents of the buffer with \\[kill-region].
309 Once you're done editing the message, pressing \\[log-edit-done] will call
310 `log-edit-done' which will end up calling CALLBACK to do the actual commit.
311 LISTFUN if non-nil is a function of no arguments returning the list of files
312 that are concerned by the current operation (using relative names).
313 If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
314 log message and go back to the current buffer when done. Otherwise, it
315 uses the current buffer."
316 (let ((parent (current-buffer)))
317 (if buffer (pop-to-buffer buffer))
318 (when (and log-edit-setup-invert (not (eq setup 'force)))
319 (setq setup (not setup)))
320 (when setup (erase-buffer))
321 (log-edit-mode)
322 (set (make-local-variable 'log-edit-callback) callback)
323 (set (make-local-variable 'log-edit-listfun) listfun)
324 (if buffer (set (make-local-variable 'log-edit-parent-buffer) parent))
325 (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
326 (when setup (run-hooks 'log-edit-hook))
327 (goto-char (point-min)) (push-mark (point-max))
328 (message (substitute-command-keys
329 "Press \\[log-edit-done] when you are done editing."))))
331 (define-derived-mode log-edit-mode text-mode "Log-Edit"
332 "Major mode for editing version-control log messages.
333 When done editing the log entry, just type \\[log-edit-done] which
334 will trigger the actual commit of the file(s).
335 Several other handy support commands are provided of course and
336 the package from which this is used might also provide additional
337 commands (under C-x v for VC, for example).
339 \\{log-edit-mode-map}"
340 (make-local-variable 'log-edit-comment-ring-index))
342 (defun log-edit-hide-buf (&optional buf where)
343 (when (setq buf (get-buffer (or buf log-edit-files-buf)))
344 (let ((win (get-buffer-window buf where)))
345 (if win (ignore-errors (delete-window win))))
346 (bury-buffer buf)))
348 (defun log-edit-done ()
349 "Finish editing the log message and commit the files.
350 If you want to abort the commit, simply delete the buffer."
351 (interactive)
352 ;; Get rid of trailing empty lines
353 (goto-char (point-max))
354 (skip-syntax-backward " ")
355 (when (equal (char-after) ?\n) (forward-char 1))
356 (delete-region (point) (point-max))
357 ;; Check for final newline
358 (if (and (> (point-max) (point-min))
359 (/= (char-before (point-max)) ?\n)
360 (or (eq log-edit-require-final-newline t)
361 (and log-edit-require-final-newline
362 (y-or-n-p
363 (format "Buffer %s does not end in newline. Add one? "
364 (buffer-name))))))
365 (save-excursion
366 (goto-char (point-max))
367 (insert ?\n)))
368 (let ((comment (buffer-string)))
369 (when (or (ring-empty-p log-edit-comment-ring)
370 (not (equal comment (ring-ref log-edit-comment-ring 0))))
371 (ring-insert log-edit-comment-ring comment)))
372 (let ((win (get-buffer-window log-edit-files-buf)))
373 (if (and log-edit-confirm
374 (not (and (eq log-edit-confirm 'changed)
375 (equal (log-edit-files) log-edit-initial-files)))
376 (progn
377 (log-edit-show-files)
378 (not (y-or-n-p "Really commit ? "))))
379 (progn (when (not win) (log-edit-hide-buf))
380 (message "Oh, well! Later maybe?"))
381 (run-hooks 'log-edit-done-hook)
382 (log-edit-hide-buf)
383 (unless (or log-edit-keep-buffer (not log-edit-parent-buffer))
384 (cvs-bury-buffer (current-buffer) log-edit-parent-buffer))
385 (call-interactively log-edit-callback))))
387 (defun log-edit-files ()
388 "Return the list of files that are about to be committed."
389 (ignore-errors (funcall log-edit-listfun)))
392 (defun log-edit-insert-changelog ()
393 "Insert a log message by looking at the ChangeLog.
394 The idea is to write your ChangeLog entries first, and then use this
395 command to commit your changes.
397 To select default log text, we:
398 - find the ChangeLog entries for the files to be checked in,
399 - verify that the top entry in the ChangeLog is on the current date
400 and by the current user; if not, we don't provide any default text,
401 - search the ChangeLog entry for paragraphs containing the names of
402 the files we're checking in, and finally
403 - use those paragraphs as the log text."
404 (interactive)
405 (log-edit-insert-changelog-entries (log-edit-files))
406 (log-edit-set-common-indentation)
407 (goto-char (point-min))
408 (when (looking-at "\\*\\s-+")
409 (forward-line 1)
410 (when (not (re-search-forward "^\\*\\s-+" nil t))
411 (goto-char (point-min))
412 (skip-chars-forward "^():")
413 (skip-chars-forward ": ")
414 (delete-region (point-min) (point)))))
416 (defun log-edit-mode-help ()
417 "Provide help for the `log-edit-mode-map'."
418 (interactive)
419 (if (eq last-command 'log-edit-mode-help)
420 (describe-function major-mode)
421 (message
422 (substitute-command-keys
423 "Type `\\[log-edit-done]' to finish commit. Try `\\[describe-function] log-edit-done' for more help."))))
425 (defcustom log-edit-common-indent 0
426 "Minimum indentation to use in `log-edit-set-common-indentation'."
427 :group 'log-edit
428 :type 'integer)
430 (defun log-edit-set-common-indentation ()
431 "(Un)Indent the current buffer rigidly to `log-edit-common-indent'."
432 (save-excursion
433 (let ((common (point-max)))
434 (goto-char (point-min))
435 (while (< (point) (point-max))
436 (if (not (looking-at "^[ \t]*$"))
437 (setq common (min common (current-indentation))))
438 (forward-line 1))
439 (indent-rigidly (point-min) (point-max)
440 (- log-edit-common-indent common)))))
442 (defun log-edit-show-files ()
443 "Show the list of files to be committed."
444 (interactive)
445 (let* ((files (log-edit-files))
446 (buf (get-buffer-create log-edit-files-buf)))
447 (with-current-buffer buf
448 (log-edit-hide-buf buf 'all)
449 (setq buffer-read-only nil)
450 (erase-buffer)
451 (cvs-insert-strings files)
452 (setq buffer-read-only t)
453 (goto-char (point-min))
454 (save-selected-window
455 (cvs-pop-to-buffer-same-frame buf)
456 (shrink-window-if-larger-than-buffer)
457 (selected-window)))))
459 (defun log-edit-insert-cvs-template ()
460 "Insert the template specified by the CVS administrator, if any."
461 (interactive)
462 (when (file-readable-p "CVS/Template")
463 (insert-file-contents "CVS/Template")))
466 (defun log-edit-add-to-changelog ()
467 "Insert this log message into the appropriate ChangeLog file."
468 (interactive)
469 ;; Yuck!
470 (unless (string= (buffer-string) (ring-ref log-edit-comment-ring 0))
471 (ring-insert log-edit-comment-ring (buffer-string)))
472 (dolist (f (log-edit-files))
473 (let ((buffer-file-name (expand-file-name f)))
474 (save-excursion
475 (log-edit-comment-to-change-log)))))
477 ;;;;
478 ;;;; functions for getting commit message from ChangeLog a file...
479 ;;;; Courtesy Jim Blandy
480 ;;;;
482 (defun log-edit-narrow-changelog ()
483 "Narrow to the top page of the current buffer, a ChangeLog file.
484 Actually, the narrowed region doesn't include the date line.
485 A \"page\" in a ChangeLog file is the area between two dates."
486 (or (eq major-mode 'change-log-mode)
487 (error "log-edit-narrow-changelog: current buffer isn't a ChangeLog"))
489 (goto-char (point-min))
491 ;; Skip date line and subsequent blank lines.
492 (forward-line 1)
493 (if (looking-at "[ \t\n]*\n")
494 (goto-char (match-end 0)))
496 (let ((start (point)))
497 (forward-page 1)
498 (narrow-to-region start (point))
499 (goto-char (point-min))))
501 (defun log-edit-changelog-paragraph ()
502 "Return the bounds of the ChangeLog paragraph containing point.
503 If we are between paragraphs, return the previous paragraph."
504 (save-excursion
505 (beginning-of-line)
506 (if (looking-at "^[ \t]*$")
507 (skip-chars-backward " \t\n" (point-min)))
508 (list (progn
509 (if (re-search-backward "^[ \t]*\n" nil 'or-to-limit)
510 (goto-char (match-end 0)))
511 (point))
512 (if (re-search-forward "^[ \t\n]*$" nil t)
513 (match-beginning 0)
514 (point)))))
516 (defun log-edit-changelog-subparagraph ()
517 "Return the bounds of the ChangeLog subparagraph containing point.
518 A subparagraph is a block of non-blank lines beginning with an asterisk.
519 If we are between sub-paragraphs, return the previous subparagraph."
520 (save-excursion
521 (end-of-line)
522 (if (search-backward "*" nil t)
523 (list (progn (beginning-of-line) (point))
524 (progn
525 (forward-line 1)
526 (if (re-search-forward "^[ \t]*[\n*]" nil t)
527 (match-beginning 0)
528 (point-max))))
529 (list (point) (point)))))
531 (defun log-edit-changelog-entry ()
532 "Return the bounds of the ChangeLog entry containing point.
533 The variable `log-edit-changelog-full-paragraphs' decides whether an
534 \"entry\" is a paragraph or a subparagraph; see its documentation string
535 for more details."
536 (if log-edit-changelog-full-paragraphs
537 (log-edit-changelog-paragraph)
538 (log-edit-changelog-subparagraph)))
540 (defvar user-full-name)
541 (defvar user-mail-address)
542 (defun log-edit-changelog-ours-p ()
543 "See if ChangeLog entry at point is for the current user, today.
544 Return non-nil iff it is."
545 ;; Code adapted from add-change-log-entry.
546 (let ((name (or (and (boundp 'add-log-full-name) add-log-full-name)
547 (and (fboundp 'user-full-name) (user-full-name))
548 (and (boundp 'user-full-name) user-full-name)))
549 (mail (or (and (boundp 'add-log-mailing-address) add-log-mailing-address)
550 ;;(and (fboundp 'user-mail-address) (user-mail-address))
551 (and (boundp 'user-mail-address) user-mail-address)))
552 (time (or (and (boundp 'add-log-time-format)
553 (functionp add-log-time-format)
554 (funcall add-log-time-format))
555 (format-time-string "%Y-%m-%d"))))
556 (looking-at (regexp-quote (format "%s %s <%s>" time name mail)))))
558 (defun log-edit-changelog-entries (file)
559 "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
560 The return value looks like this:
561 (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
562 where LOGBUFFER is the name of the ChangeLog buffer, and each
563 \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
564 (save-excursion
565 (let ((changelog-file-name
566 (let ((default-directory
567 (file-name-directory (expand-file-name file)))
568 (visiting-buffer (find-buffer-visiting file)))
569 ;; If there is a buffer visiting FILE, and it has a local
570 ;; value for `change-log-default-name', use that.
571 (if (and visiting-buffer
572 (local-variable-p 'change-log-default-name
573 visiting-buffer))
574 (save-excursion
575 (set-buffer visiting-buffer)
576 change-log-default-name)
577 ;; `find-change-log' uses `change-log-default-name' if set
578 ;; and sets it before exiting, so we need to work around
579 ;; that memoizing which is undesired here
580 (setq change-log-default-name nil)
581 (find-change-log)))))
582 (set-buffer (find-file-noselect changelog-file-name))
583 (unless (eq major-mode 'change-log-mode) (change-log-mode))
584 (goto-char (point-min))
585 (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
586 (if (not (log-edit-changelog-ours-p))
587 (list (current-buffer))
588 (save-restriction
589 (log-edit-narrow-changelog)
590 (goto-char (point-min))
592 ;; Search for the name of FILE relative to the ChangeLog. If that
593 ;; doesn't occur anywhere, they're not using full relative
594 ;; filenames in the ChangeLog, so just look for FILE; we'll accept
595 ;; some false positives.
596 (let ((pattern (file-relative-name
597 file (file-name-directory changelog-file-name))))
598 (if (or (string= pattern "")
599 (not (save-excursion
600 (search-forward pattern nil t))))
601 (setq pattern (file-name-nondirectory file)))
603 (let (texts)
604 (while (search-forward pattern nil t)
605 (let ((entry (log-edit-changelog-entry)))
606 (push entry texts)
607 (goto-char (elt entry 1))))
609 (cons (current-buffer) texts))))))))
611 (defun log-edit-changelog-insert-entries (buffer regions)
612 "Insert those regions in BUFFER specified in REGIONS.
613 Sort REGIONS front-to-back first."
614 (let ((regions (sort regions 'car-less-than-car))
615 (last))
616 (dolist (region regions)
617 (when (and last (< last (car region))) (newline))
618 (setq last (elt region 1))
619 (apply 'insert-buffer-substring buffer region))))
621 (defun log-edit-insert-changelog-entries (files)
622 "Given a list of files FILES, insert the ChangeLog entries for them."
623 (let ((buffer-entries nil))
625 ;; Add each buffer to buffer-entries, and associate it with the list
626 ;; of entries we want from that file.
627 (dolist (file files)
628 (let* ((entries (log-edit-changelog-entries file))
629 (pair (assq (car entries) buffer-entries)))
630 (if pair
631 (setcdr pair (cvs-union (cdr pair) (cdr entries)))
632 (push entries buffer-entries))))
634 ;; Now map over each buffer in buffer-entries, sort the entries for
635 ;; each buffer, and extract them as strings.
636 (dolist (buffer-entry buffer-entries)
637 (log-edit-changelog-insert-entries (car buffer-entry) (cdr buffer-entry))
638 (when (cdr buffer-entry) (newline)))))
640 (provide 'log-edit)
642 ;;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
643 ;;; log-edit.el ends here