* progmodes/octave-mod.el (inferior-octave-send-list-and-digest):
[bpt/emacs.git] / lisp / add-log.el
1 ;;; add-log.el --- change log maintenance commands for Emacs
2
3 ;; Copyright (C) 1985, 1986, 1988, 1993, 1994, 1997, 1998, 2000, 2001,
4 ;; 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: tools
8
9 ;; This file is part of GNU Emacs.
10
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, or (at your option)
14 ;; any later version.
15
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.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This facility is documented in the Emacs Manual.
29
30 ;; Todo:
31
32 ;; - Find/use/create _MTN/log if there's a _MTN directory.
33 ;; - Find/use/create ++log.* if there's an {arch} directory.
34 ;; - Use an open *VC-Log* or *cvs-commit* buffer if it's related to the
35 ;; source file.
36 ;; - Don't add TAB indents (and username?) if inserting entries in those
37 ;; special places.
38
39 ;;; Code:
40
41 (eval-when-compile
42 (require 'timezone))
43
44 (defgroup change-log nil
45 "Change log maintenance."
46 :group 'tools
47 :link '(custom-manual "(emacs)Change Log")
48 :prefix "change-log-"
49 :prefix "add-log-")
50
51
52 (defcustom change-log-default-name nil
53 "Name of a change log file for \\[add-change-log-entry]."
54 :type '(choice (const :tag "default" nil)
55 string)
56 :group 'change-log)
57 (put 'change-log-default-name 'safe-local-variable 'string-or-null-p)
58
59 (defcustom change-log-mode-hook nil
60 "Normal hook run by `change-log-mode'."
61 :type 'hook
62 :group 'change-log)
63
64 ;; Many modes set this variable, so avoid warnings.
65 ;;;###autoload
66 (defcustom add-log-current-defun-function nil
67 "If non-nil, function to guess name of surrounding function.
68 It is used by `add-log-current-defun' in preference to built-in rules.
69 Returns function's name as a string, or nil if outside a function."
70 :type '(choice (const nil) function)
71 :group 'change-log)
72
73 ;;;###autoload
74 (defcustom add-log-full-name nil
75 "Full name of user, for inclusion in ChangeLog daily headers.
76 This defaults to the value returned by the function `user-full-name'."
77 :type '(choice (const :tag "Default" nil)
78 string)
79 :group 'change-log)
80
81 ;;;###autoload
82 (defcustom add-log-mailing-address nil
83 "Email addresses of user, for inclusion in ChangeLog headers.
84 This defaults to the value of `user-mail-address'. In addition to
85 being a simple string, this value can also be a list. All elements
86 will be recognized as referring to the same user; when creating a new
87 ChangeLog entry, one element will be chosen at random."
88 :type '(choice (const :tag "Default" nil)
89 (string :tag "String")
90 (repeat :tag "List of Strings" string))
91 :group 'change-log)
92
93 (defcustom add-log-time-format 'add-log-iso8601-time-string
94 "Function that defines the time format.
95 For example, `add-log-iso8601-time-string', which gives the
96 date in international ISO 8601 format,
97 and `current-time-string' are two valid values."
98 :type '(radio (const :tag "International ISO 8601 format"
99 add-log-iso8601-time-string)
100 (const :tag "Old format, as returned by `current-time-string'"
101 current-time-string)
102 (function :tag "Other"))
103 :group 'change-log)
104
105 (defcustom add-log-keep-changes-together nil
106 "If non-nil, normally keep day's log entries for one file together.
107
108 Log entries for a given file made with \\[add-change-log-entry] or
109 \\[add-change-log-entry-other-window] will only be added to others \
110 for that file made
111 today if this variable is non-nil or that file comes first in today's
112 entries. Otherwise another entry for that file will be started. An
113 original log:
114
115 * foo (...): ...
116 * bar (...): change 1
117
118 in the latter case, \\[add-change-log-entry-other-window] in a \
119 buffer visiting `bar', yields:
120
121 * bar (...): -!-
122 * foo (...): ...
123 * bar (...): change 1
124
125 and in the former:
126
127 * foo (...): ...
128 * bar (...): change 1
129 (...): -!-
130
131 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
132 this variable."
133 :version "20.3"
134 :type 'boolean
135 :group 'change-log)
136
137 (defcustom add-log-always-start-new-record nil
138 "If non-nil, `add-change-log-entry' will always start a new record."
139 :version "22.1"
140 :type 'boolean
141 :group 'change-log)
142
143 (defcustom add-log-buffer-file-name-function nil
144 "If non-nil, function to call to identify the full filename of a buffer.
145 This function is called with no argument. If this is nil, the default is to
146 use `buffer-file-name'."
147 :type '(choice (const nil) function)
148 :group 'change-log)
149
150 (defcustom add-log-file-name-function nil
151 "If non-nil, function to call to identify the filename for a ChangeLog entry.
152 This function is called with one argument, the value of variable
153 `buffer-file-name' in that buffer. If this is nil, the default is to
154 use the file's name relative to the directory of the change log file."
155 :type '(choice (const nil) function)
156 :group 'change-log)
157
158
159 (defcustom change-log-version-info-enabled nil
160 "If non-nil, enable recording version numbers with the changes."
161 :version "21.1"
162 :type 'boolean
163 :group 'change-log)
164
165 (defcustom change-log-version-number-regexp-list
166 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
167 (list
168 ;; (defconst ad-version "2.15"
169 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re)
170 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
171 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re)))
172 "List of regexps to search for version number.
173 The version number must be in group 1.
174 Note: The search is conducted only within 10%, at the beginning of the file."
175 :version "21.1"
176 :type '(repeat regexp)
177 :group 'change-log)
178
179 (defface change-log-date
180 '((t (:inherit font-lock-string-face)))
181 "Face used to highlight dates in date lines."
182 :version "21.1"
183 :group 'change-log)
184 ;; backward-compatibility alias
185 (put 'change-log-date-face 'face-alias 'change-log-date)
186
187 (defface change-log-name
188 '((t (:inherit font-lock-constant-face)))
189 "Face for highlighting author names."
190 :version "21.1"
191 :group 'change-log)
192 ;; backward-compatibility alias
193 (put 'change-log-name-face 'face-alias 'change-log-name)
194
195 (defface change-log-email
196 '((t (:inherit font-lock-variable-name-face)))
197 "Face for highlighting author email addresses."
198 :version "21.1"
199 :group 'change-log)
200 ;; backward-compatibility alias
201 (put 'change-log-email-face 'face-alias 'change-log-email)
202
203 (defface change-log-file
204 '((t (:inherit font-lock-function-name-face)))
205 "Face for highlighting file names."
206 :version "21.1"
207 :group 'change-log)
208 ;; backward-compatibility alias
209 (put 'change-log-file-face 'face-alias 'change-log-file)
210
211 (defface change-log-list
212 '((t (:inherit font-lock-keyword-face)))
213 "Face for highlighting parenthesized lists of functions or variables."
214 :version "21.1"
215 :group 'change-log)
216 ;; backward-compatibility alias
217 (put 'change-log-list-face 'face-alias 'change-log-list)
218
219 (defface change-log-conditionals
220 '((t (:inherit font-lock-variable-name-face)))
221 "Face for highlighting conditionals of the form `[...]'."
222 :version "21.1"
223 :group 'change-log)
224 ;; backward-compatibility alias
225 (put 'change-log-conditionals-face 'face-alias 'change-log-conditionals)
226
227 (defface change-log-function
228 '((t (:inherit font-lock-variable-name-face)))
229 "Face for highlighting items of the form `<....>'."
230 :version "21.1"
231 :group 'change-log)
232 ;; backward-compatibility alias
233 (put 'change-log-function-face 'face-alias 'change-log-function)
234
235 (defface change-log-acknowledgement
236 '((t (:inherit font-lock-comment-face)))
237 "Face for highlighting acknowledgments."
238 :version "21.1"
239 :group 'change-log)
240 ;; backward-compatibility alias
241 (put 'change-log-acknowledgement-face 'face-alias 'change-log-acknowledgement)
242
243 (defvar change-log-font-lock-keywords
244 '(;;
245 ;; Date lines, new (2000-01-01) and old (Sat Jan 1 00:00:00 2000) styles.
246 ;; Fixme: this regepx is just an approximate one and may match
247 ;; wrongly with a non-date line existing as a random note. In
248 ;; addition, using any kind of fixed setting like this doesn't
249 ;; work if a user customizes add-log-time-format.
250 ("^[0-9-]+ +\\|^\\(Sun\\|Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\) [A-z][a-z][a-z] [0-9:+ ]+"
251 (0 'change-log-date-face)
252 ;; Name and e-mail; some people put e-mail in parens, not angles.
253 ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
254 (1 'change-log-name)
255 (2 'change-log-email)))
256 ;;
257 ;; File names.
258 ("^\\( +\\|\t\\)\\* \\([^ ,:([\n]+\\)"
259 (2 'change-log-file)
260 ;; Possibly further names in a list:
261 ("\\=, \\([^ ,:([\n]+\\)" nil nil (1 'change-log-file))
262 ;; Possibly a parenthesized list of names:
263 ("\\= (\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)"
264 nil nil (1 'change-log-list))
265 ("\\=, *\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)"
266 nil nil (1 'change-log-list)))
267 ;;
268 ;; Function or variable names.
269 ("^\\( +\\|\t\\)(\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)"
270 (2 'change-log-list)
271 ("\\=, *\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)" nil nil
272 (1 'change-log-list)))
273 ;;
274 ;; Conditionals.
275 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals))
276 ;;
277 ;; Function of change.
278 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function))
279 ;;
280 ;; Acknowledgements.
281 ;; Don't include plain "From" because that is vague;
282 ;; we want to encourage people to say something more specific.
283 ;; Note that the FSF does not use "Patches by"; our convention
284 ;; is to put the name of the author of the changes at the top
285 ;; of the change log entry.
286 ("\\(^\\( +\\|\t\\)\\| \\)\\(Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
287 3 'change-log-acknowledgement))
288 "Additional expressions to highlight in Change Log mode.")
289
290 (defvar change-log-mode-map
291 (let ((map (make-sparse-keymap)))
292 (define-key map [?\C-c ?\C-p] 'add-log-edit-prev-comment)
293 (define-key map [?\C-c ?\C-n] 'add-log-edit-next-comment)
294 map)
295 "Keymap for Change Log major mode.")
296
297 ;; It used to be called change-log-time-zone-rule but really should be
298 ;; called add-log-time-zone-rule since it's only used from add-log-* code.
299 (defvaralias 'change-log-time-zone-rule 'add-log-time-zone-rule)
300 (defvar add-log-time-zone-rule nil
301 "Time zone used for calculating change log time stamps.
302 It takes the same format as the TZ argument of `set-time-zone-rule'.
303 If nil, use local time.
304 If t, use universal time.")
305 (put 'add-log-time-zone-rule 'safe-local-variable
306 '(lambda (x) (or (booleanp x) (stringp x))))
307
308 (defun add-log-iso8601-time-zone (&optional time)
309 (let* ((utc-offset (or (car (current-time-zone time)) 0))
310 (sign (if (< utc-offset 0) ?- ?+))
311 (sec (abs utc-offset))
312 (ss (% sec 60))
313 (min (/ sec 60))
314 (mm (% min 60))
315 (hh (/ min 60)))
316 (format (cond ((not (zerop ss)) "%c%02d:%02d:%02d")
317 ((not (zerop mm)) "%c%02d:%02d")
318 (t "%c%02d"))
319 sign hh mm ss)))
320
321 (defvar add-log-iso8601-with-time-zone nil)
322
323 (defun add-log-iso8601-time-string ()
324 (let ((time (format-time-string "%Y-%m-%d"
325 nil (eq t add-log-time-zone-rule))))
326 (if add-log-iso8601-with-time-zone
327 (concat time " " (add-log-iso8601-time-zone))
328 time)))
329
330 (defun change-log-name ()
331 "Return (system-dependent) default name for a change log file."
332 (or change-log-default-name
333 (if (eq system-type 'vax-vms)
334 "$CHANGE_LOG$.TXT"
335 "ChangeLog")))
336
337 (defun add-log-edit-prev-comment (arg)
338 "Cycle backward through Log-Edit mode comment history.
339 With a numeric prefix ARG, go back ARG comments."
340 (interactive "*p")
341 (save-restriction
342 (narrow-to-region (point)
343 (if (memq last-command '(add-log-edit-prev-comment
344 add-log-edit-next-comment))
345 (mark) (point)))
346 (when (fboundp 'log-edit-previous-comment)
347 (log-edit-previous-comment arg)
348 (indent-region (point-min) (point-max))
349 (goto-char (point-min))
350 (unless (save-restriction (widen) (bolp))
351 (delete-region (point) (progn (skip-chars-forward " \t\n") (point))))
352 (set-mark (point-min))
353 (goto-char (point-max))
354 (delete-region (point) (progn (skip-chars-backward " \t\n") (point))))))
355
356 (defun add-log-edit-next-comment (arg)
357 "Cycle forward through Log-Edit mode comment history.
358 With a numeric prefix ARG, go back ARG comments."
359 (interactive "*p")
360 (add-log-edit-prev-comment (- arg)))
361
362 ;;;###autoload
363 (defun prompt-for-change-log-name ()
364 "Prompt for a change log name."
365 (let* ((default (change-log-name))
366 (name (expand-file-name
367 (read-file-name (format "Log file (default %s): " default)
368 nil default))))
369 ;; Handle something that is syntactically a directory name.
370 ;; Look for ChangeLog or whatever in that directory.
371 (if (string= (file-name-nondirectory name) "")
372 (expand-file-name (file-name-nondirectory default)
373 name)
374 ;; Handle specifying a file that is a directory.
375 (if (file-directory-p name)
376 (expand-file-name (file-name-nondirectory default)
377 (file-name-as-directory name))
378 name))))
379
380 (defun change-log-version-number-search ()
381 "Return version number of current buffer's file.
382 This is the value returned by `vc-working-revision' or, if that is
383 nil, by matching `change-log-version-number-regexp-list'."
384 (let* ((size (buffer-size))
385 (limit
386 ;; The version number can be anywhere in the file, but
387 ;; restrict search to the file beginning: 10% should be
388 ;; enough to prevent some mishits.
389 ;;
390 ;; Apply percentage only if buffer size is bigger than
391 ;; approx 100 lines.
392 (if (> size (* 100 80)) (+ (point) (/ size 10)))))
393 (or (and buffer-file-name (vc-working-revision buffer-file-name))
394 (save-restriction
395 (widen)
396 (let ((regexps change-log-version-number-regexp-list)
397 version)
398 (while regexps
399 (save-excursion
400 (goto-char (point-min))
401 (when (re-search-forward (pop regexps) limit t)
402 (setq version (match-string 1)
403 regexps nil))))
404 version)))))
405
406
407 ;;;###autoload
408 (defun find-change-log (&optional file-name buffer-file)
409 "Find a change log file for \\[add-change-log-entry] and return the name.
410
411 Optional arg FILE-NAME specifies the file to use.
412 If FILE-NAME is nil, use the value of `change-log-default-name'.
413 If `change-log-default-name' is nil, behave as though it were 'ChangeLog'
414 \(or whatever we use on this operating system).
415
416 If `change-log-default-name' contains a leading directory component, then
417 simply find it in the current directory. Otherwise, search in the current
418 directory and its successive parents for a file so named.
419
420 Once a file is found, `change-log-default-name' is set locally in the
421 current buffer to the complete file name.
422 Optional arg BUFFER-FILE overrides `buffer-file-name'."
423 ;; If user specified a file name or if this buffer knows which one to use,
424 ;; just use that.
425 (or file-name
426 (setq file-name (and change-log-default-name
427 (file-name-directory change-log-default-name)
428 change-log-default-name))
429 (progn
430 ;; Chase links in the source file
431 ;; and use the change log in the dir where it points.
432 (setq file-name (or (and (or buffer-file buffer-file-name)
433 (file-name-directory
434 (file-chase-links
435 (or buffer-file buffer-file-name))))
436 default-directory))
437 (if (file-directory-p file-name)
438 (setq file-name (expand-file-name (change-log-name) file-name)))
439 ;; Chase links before visiting the file.
440 ;; This makes it easier to use a single change log file
441 ;; for several related directories.
442 (setq file-name (file-chase-links file-name))
443 (setq file-name (expand-file-name file-name))
444 ;; Move up in the dir hierarchy till we find a change log file.
445 (let ((file1 file-name)
446 parent-dir)
447 (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
448 (progn (setq parent-dir
449 (file-name-directory
450 (directory-file-name
451 (file-name-directory file1))))
452 ;; Give up if we are already at the root dir.
453 (not (string= (file-name-directory file1)
454 parent-dir))))
455 ;; Move up to the parent dir and try again.
456 (setq file1 (expand-file-name
457 (file-name-nondirectory (change-log-name))
458 parent-dir)))
459 ;; If we found a change log in a parent, use that.
460 (if (or (get-file-buffer file1) (file-exists-p file1))
461 (setq file-name file1)))))
462 ;; Make a local variable in this buffer so we needn't search again.
463 (set (make-local-variable 'change-log-default-name) file-name)
464 file-name)
465
466 (defun add-log-file-name (buffer-file log-file)
467 ;; Never want to add a change log entry for the ChangeLog file itself.
468 (unless (or (null buffer-file) (string= buffer-file log-file))
469 (if add-log-file-name-function
470 (funcall add-log-file-name-function buffer-file)
471 (setq buffer-file
472 (file-relative-name buffer-file (file-name-directory log-file)))
473 ;; If we have a backup file, it's presumably because we're
474 ;; comparing old and new versions (e.g. for deleted
475 ;; functions) and we'll want to use the original name.
476 (if (backup-file-name-p buffer-file)
477 (file-name-sans-versions buffer-file)
478 buffer-file))))
479
480 ;;;###autoload
481 (defun add-change-log-entry (&optional whoami file-name other-window new-entry)
482 "Find change log file, and add an entry for today and an item for this file.
483 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
484 name and email (stored in `add-log-full-name' and `add-log-mailing-address').
485
486 Second arg FILE-NAME is file name of the change log.
487 If nil, use the value of `change-log-default-name'.
488
489 Third arg OTHER-WINDOW non-nil means visit in other window.
490
491 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
492 never append to an existing entry. Option `add-log-keep-changes-together'
493 otherwise affects whether a new entry is created.
494
495 Option `add-log-always-start-new-record' non-nil means always create a
496 new record, even when the last record was made on the same date and by
497 the same person.
498
499 The change log file can start with a copyright notice and a copying
500 permission notice. The first blank line indicates the end of these
501 notices.
502
503 Today's date is calculated according to `add-log-time-zone-rule' if
504 non-nil, otherwise in local time."
505 (interactive (list current-prefix-arg
506 (prompt-for-change-log-name)))
507 (let* ((defun (add-log-current-defun))
508 (version (and change-log-version-info-enabled
509 (change-log-version-number-search)))
510 (buf-file-name (if add-log-buffer-file-name-function
511 (funcall add-log-buffer-file-name-function)
512 buffer-file-name))
513 (buffer-file (if buf-file-name (expand-file-name buf-file-name)))
514 (file-name (expand-file-name (find-change-log file-name buffer-file)))
515 ;; Set ITEM to the file name to use in the new item.
516 (item (add-log-file-name buffer-file file-name)))
517
518 (unless (equal file-name buffer-file-name)
519 (if (or other-window (window-dedicated-p (selected-window)))
520 (find-file-other-window file-name)
521 (find-file file-name)))
522 (or (derived-mode-p 'change-log-mode)
523 (change-log-mode))
524 (undo-boundary)
525 (goto-char (point-min))
526
527 (let ((full-name (or add-log-full-name (user-full-name)))
528 (mailing-address (or add-log-mailing-address user-mail-address)))
529
530 (when whoami
531 (setq full-name (read-string "Full name: " full-name))
532 ;; Note that some sites have room and phone number fields in
533 ;; full name which look silly when inserted. Rather than do
534 ;; anything about that here, let user give prefix argument so that
535 ;; s/he can edit the full name field in prompter if s/he wants.
536 (setq mailing-address
537 (read-string "Mailing address: " mailing-address)))
538
539 ;; If file starts with a copyright and permission notice, skip them.
540 ;; Assume they end at first blank line.
541 (when (looking-at "Copyright")
542 (search-forward "\n\n")
543 (skip-chars-forward "\n"))
544
545 ;; Advance into first entry if it is usable; else make new one.
546 (let ((new-entries
547 (mapcar (lambda (addr)
548 (concat
549 (if (stringp add-log-time-zone-rule)
550 (let ((tz (getenv "TZ")))
551 (unwind-protect
552 (progn
553 (set-time-zone-rule add-log-time-zone-rule)
554 (funcall add-log-time-format))
555 (set-time-zone-rule tz)))
556 (funcall add-log-time-format))
557 " " full-name
558 " <" addr ">"))
559 (if (consp mailing-address)
560 mailing-address
561 (list mailing-address)))))
562 (if (and (not add-log-always-start-new-record)
563 (let ((hit nil))
564 (dolist (entry new-entries hit)
565 (when (looking-at (regexp-quote entry))
566 (setq hit t)))))
567 (forward-line 1)
568 (insert (nth (random (length new-entries))
569 new-entries)
570 (if use-hard-newlines hard-newline "\n")
571 (if use-hard-newlines hard-newline "\n"))
572 (forward-line -1))))
573
574 ;; Determine where we should stop searching for a usable
575 ;; item to add to, within this entry.
576 (let ((bound
577 (save-excursion
578 (if (looking-at "\n*[^\n* \t]")
579 (skip-chars-forward "\n")
580 (if add-log-keep-changes-together
581 (forward-page) ; page delimits entries for date
582 (forward-paragraph))) ; paragraph delimits entries for file
583 (point))))
584
585 ;; Now insert the new line for this item.
586 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t)
587 ;; Put this file name into the existing empty item.
588 (if item
589 (insert item)))
590 ((and (not new-entry)
591 (let (case-fold-search)
592 (re-search-forward
593 (concat (regexp-quote (concat "* " item))
594 ;; Don't accept `foo.bar' when
595 ;; looking for `foo':
596 "\\(\\s \\|[(),:]\\)")
597 bound t)))
598 ;; Add to the existing item for the same file.
599 (re-search-forward "^\\s *$\\|^\\s \\*")
600 (goto-char (match-beginning 0))
601 ;; Delete excess empty lines; make just 2.
602 (while (and (not (eobp)) (looking-at "^\\s *$"))
603 (delete-region (point) (line-beginning-position 2)))
604 (insert (if use-hard-newlines hard-newline "\n")
605 (if use-hard-newlines hard-newline "\n"))
606 (forward-line -2)
607 (indent-relative-maybe))
608 (t
609 ;; Make a new item.
610 (while (looking-at "\\sW")
611 (forward-line 1))
612 (while (and (not (eobp)) (looking-at "^\\s *$"))
613 (delete-region (point) (line-beginning-position 2)))
614 (insert (if use-hard-newlines hard-newline "\n")
615 (if use-hard-newlines hard-newline "\n")
616 (if use-hard-newlines hard-newline "\n"))
617 (forward-line -2)
618 (indent-to left-margin)
619 (insert "* ")
620 (if item (insert item)))))
621 ;; Now insert the function name, if we have one.
622 ;; Point is at the item for this file,
623 ;; either at the end of the line or at the first blank line.
624 (if (not defun)
625 ;; No function name, so put in a colon unless we have just a star.
626 (unless (save-excursion
627 (beginning-of-line 1)
628 (looking-at "\\s *\\(\\*\\s *\\)?$"))
629 (insert ": ")
630 (if version (insert version ?\s)))
631 ;; Make it easy to get rid of the function name.
632 (undo-boundary)
633 (unless (save-excursion
634 (beginning-of-line 1)
635 (looking-at "\\s *$"))
636 (insert ?\s))
637 ;; See if the prev function name has a message yet or not.
638 ;; If not, merge the two items.
639 (let ((pos (point-marker)))
640 (skip-syntax-backward " ")
641 (skip-chars-backward "):")
642 (if (and (looking-at "):")
643 (let ((pos (save-excursion (backward-sexp 1) (point))))
644 (when (equal (buffer-substring pos (point)) defun)
645 (delete-region pos (point)))
646 (> fill-column (+ (current-column) (length defun) 4))))
647 (progn (skip-chars-backward ", ")
648 (delete-region (point) pos)
649 (unless (memq (char-before) '(?\()) (insert ", ")))
650 (if (looking-at "):")
651 (delete-region (+ 1 (point)) (line-end-position)))
652 (goto-char pos)
653 (insert "("))
654 (set-marker pos nil))
655 (insert defun "): ")
656 (if version (insert version ?\s)))))
657
658 ;;;###autoload
659 (defun add-change-log-entry-other-window (&optional whoami file-name)
660 "Find change log file in other window and add entry and item.
661 This is just like `add-change-log-entry' except that it displays
662 the change log file in another window."
663 (interactive (if current-prefix-arg
664 (list current-prefix-arg
665 (prompt-for-change-log-name))))
666 (add-change-log-entry whoami file-name t))
667 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
668
669
670 (defvar change-log-indent-text 0)
671
672 (defun change-log-fill-parenthesized-list ()
673 ;; Fill parenthesized lists of names according to GNU standards.
674 ;; * file-name.ext (very-long-foo, very-long-bar, very-long-foobar):
675 ;; should be filled as
676 ;; * file-name.ext (very-long-foo, very-long-bar)
677 ;; (very-long-foobar):
678 (save-excursion
679 (end-of-line 0)
680 (skip-chars-backward " \t")
681 (when (and (equal (char-before) ?\,)
682 (> (point) (1+ (point-min))))
683 (condition-case nil
684 (when (save-excursion
685 (and (prog2
686 (up-list -1)
687 (equal (char-after) ?\()
688 (skip-chars-backward " \t"))
689 (or (bolp)
690 ;; Skip everything but a whitespace or asterisk.
691 (and (not (zerop (skip-chars-backward "^ \t\n*")))
692 (skip-chars-backward " \t")
693 ;; We want one asterisk here.
694 (= (skip-chars-backward "*") -1)
695 (skip-chars-backward " \t")
696 (bolp)))))
697 ;; Delete the comma.
698 (delete-char -1)
699 ;; Close list on previous line.
700 (insert ")")
701 (skip-chars-forward " \t\n")
702 ;; Start list on new line.
703 (insert-before-markers "("))
704 (error nil)))))
705
706 (defun change-log-indent ()
707 (change-log-fill-parenthesized-list)
708 (let* ((indent
709 (save-excursion
710 (beginning-of-line)
711 (skip-chars-forward " \t")
712 (cond
713 ((and (looking-at "\\(.*\\) [^ \n].*[^ \n] <.*>\\(?: +(.*)\\)? *$")
714 ;; Matching the output of add-log-time-format is difficult,
715 ;; but I'll get it has at least two adjacent digits.
716 (string-match "[[:digit:]][[:digit:]]" (match-string 1)))
717 0)
718 ((looking-at "[^*(]")
719 (+ (current-left-margin) change-log-indent-text))
720 (t (current-left-margin)))))
721 (pos (save-excursion (indent-line-to indent) (point))))
722 (if (> pos (point)) (goto-char pos))))
723
724
725 (defvar smerge-resolve-function)
726
727 ;;;###autoload
728 (define-derived-mode change-log-mode text-mode "Change Log"
729 "Major mode for editing change logs; like Indented Text Mode.
730 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
731 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
732 Each entry behaves as a paragraph, and the entries for one day as a page.
733 Runs `change-log-mode-hook'.
734 \\{change-log-mode-map}"
735 (setq left-margin 8
736 fill-column 74
737 indent-tabs-mode t
738 tab-width 8
739 show-trailing-whitespace t)
740 (set (make-local-variable 'fill-paragraph-function)
741 'change-log-fill-paragraph)
742 ;; Avoid that filling leaves behind a single "*" on a line.
743 (add-hook 'fill-nobreak-predicate
744 '(lambda ()
745 (looking-back "^\\s *\\*\\s *" (line-beginning-position)))
746 nil t)
747 (set (make-local-variable 'indent-line-function) 'change-log-indent)
748 (set (make-local-variable 'tab-always-indent) nil)
749 ;; We really do want "^" in paragraph-start below: it is only the
750 ;; lines that begin at column 0 (despite the left-margin of 8) that
751 ;; we are looking for. Adding `* ' allows eliding the blank line
752 ;; between entries for different files.
753 (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\<")
754 (set (make-local-variable 'paragraph-separate) paragraph-start)
755 ;; Match null string on the date-line so that the date-line
756 ;; is grouped with what follows.
757 (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
758 (set (make-local-variable 'version-control) 'never)
759 (set (make-local-variable 'smerge-resolve-function)
760 'change-log-resolve-conflict)
761 (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
762 (set (make-local-variable 'font-lock-defaults)
763 '(change-log-font-lock-keywords t nil nil backward-paragraph))
764 (set (make-local-variable 'isearch-buffers-next-buffer-function)
765 'change-log-next-buffer)
766 (set (make-local-variable 'beginning-of-defun-function)
767 'change-log-beginning-of-defun)
768 (set (make-local-variable 'end-of-defun-function)
769 'change-log-end-of-defun)
770 (isearch-buffers-minor-mode))
771
772 (defun change-log-next-buffer (&optional buffer wrap)
773 "Return the next buffer in the series of ChangeLog file buffers.
774 This function is used for multiple buffers isearch.
775 A sequence of buffers is formed by ChangeLog files with decreasing
776 numeric file name suffixes in the directory of the initial ChangeLog
777 file were isearch was started."
778 (let* ((name (change-log-name))
779 (files (cons name (sort (file-expand-wildcards
780 (concat name "[-.][0-9]*"))
781 (lambda (a b)
782 (version< (substring b (length name))
783 (substring a (length name)))))))
784 (files (if isearch-forward files (reverse files))))
785 (find-file-noselect
786 (if wrap
787 (car files)
788 (cadr (member (file-name-nondirectory (buffer-file-name buffer))
789 files))))))
790
791 ;; It might be nice to have a general feature to replace this. The idea I
792 ;; have is a variable giving a regexp matching text which should not be
793 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
794 ;; But I don't feel up to implementing that today.
795 (defun change-log-fill-paragraph (&optional justify)
796 "Fill the paragraph, but preserve open parentheses at beginning of lines.
797 Prefix arg means justify as well."
798 (interactive "P")
799 (let ((end (progn (forward-paragraph) (point)))
800 (beg (progn (backward-paragraph) (point)))
801 ;; Add lines starting with whitespace followed by a left paren or an
802 ;; asterisk.
803 (paragraph-start (concat paragraph-start "\\|\\s *\\(?:\\s(\\|\\*\\)"))
804 ;; Make sure we call `change-log-indent'.
805 (fill-indent-according-to-mode t))
806 (fill-region beg end justify)
807 t))
808 \f
809 (defcustom add-log-current-defun-header-regexp
810 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
811 "Heuristic regexp used by `add-log-current-defun' for unknown major modes."
812 :type 'regexp
813 :group 'change-log)
814
815 ;;;###autoload
816 (defvar add-log-lisp-like-modes
817 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode)
818 "*Modes that look like Lisp to `add-log-current-defun'.")
819
820 ;;;###autoload
821 (defvar add-log-c-like-modes
822 '(c-mode c++-mode c++-c-mode objc-mode)
823 "*Modes that look like C to `add-log-current-defun'.")
824
825 ;;;###autoload
826 (defvar add-log-tex-like-modes
827 '(TeX-mode plain-TeX-mode LaTeX-mode tex-mode)
828 "*Modes that look like TeX to `add-log-current-defun'.")
829
830 (declare-function c-beginning-of-defun "progmodes/cc-cmds" (&optional arg))
831 (declare-function c-end-of-defun "progmodes/cc-cmds" (&optional arg))
832
833 ;;;###autoload
834 (defun add-log-current-defun ()
835 "Return name of function definition point is in, or nil.
836
837 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
838 Texinfo (@node titles) and Perl.
839
840 Other modes are handled by a heuristic that looks in the 10K before
841 point for uppercase headings starting in the first column or
842 identifiers followed by `:' or `='. See variables
843 `add-log-current-defun-header-regexp' and
844 `add-log-current-defun-function'.
845
846 Has a preference of looking backwards."
847 (condition-case nil
848 (save-excursion
849 (let ((location (point)))
850 (cond (add-log-current-defun-function
851 (funcall add-log-current-defun-function))
852 ((apply 'derived-mode-p add-log-lisp-like-modes)
853 ;; If we are now precisely at the beginning of a defun,
854 ;; make sure beginning-of-defun finds that one
855 ;; rather than the previous one.
856 (or (eobp) (forward-char 1))
857 (beginning-of-defun)
858 ;; Make sure we are really inside the defun found,
859 ;; not after it.
860 (when (and (looking-at "\\s(")
861 (progn (end-of-defun)
862 (< location (point)))
863 (progn (forward-sexp -1)
864 (>= location (point))))
865 (if (looking-at "\\s(")
866 (forward-char 1))
867 ;; Skip the defining construct name, typically "defun"
868 ;; or "defvar".
869 (forward-sexp 1)
870 ;; The second element is usually a symbol being defined.
871 ;; If it is not, use the first symbol in it.
872 (skip-chars-forward " \t\n'(")
873 (buffer-substring-no-properties (point)
874 (progn (forward-sexp 1)
875 (point)))))
876 ((and (apply 'derived-mode-p add-log-c-like-modes)
877 (save-excursion
878 (beginning-of-line)
879 ;; Use eq instead of = here to avoid
880 ;; error when at bob and char-after
881 ;; returns nil.
882 (while (eq (char-after (- (point) 2)) ?\\)
883 (forward-line -1))
884 (looking-at "[ \t]*#[ \t]*define[ \t]")))
885 ;; Handle a C macro definition.
886 (beginning-of-line)
887 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
888 (forward-line -1))
889 (search-forward "define")
890 (skip-chars-forward " \t")
891 (buffer-substring-no-properties (point)
892 (progn (forward-sexp 1)
893 (point))))
894 ((apply 'derived-mode-p add-log-c-like-modes)
895 ;; See whether the point is inside a defun.
896 (let (having-previous-defun
897 having-next-defun
898 previous-defun-end
899 next-defun-beginning)
900
901 (save-excursion
902 (setq having-previous-defun
903 (c-beginning-of-defun))
904 (c-end-of-defun)
905 ;; `c-end-of-defun' moves point to the line after
906 ;; the function close, but the position we prefer
907 ;; here is the position after the final }.
908 (backward-sexp 1)
909 (forward-sexp 1)
910 ;; Skip the semicolon ``;'' for
911 ;; enum/union/struct/class definition.
912 (if (= (char-after (point)) ?\;)
913 (forward-char 1))
914 (setq previous-defun-end (point)))
915
916 (save-excursion
917 (setq having-next-defun
918 (c-end-of-defun))
919 (c-beginning-of-defun)
920 (setq next-defun-beginning (point)))
921
922 (if (and having-next-defun
923 (< location next-defun-beginning))
924 (skip-syntax-forward " "))
925 (if (and having-previous-defun
926 (> location previous-defun-end))
927 (skip-syntax-backward " "))
928 (unless (or
929 ;; When there is no previous defun, the
930 ;; point is not in a defun if it is not at
931 ;; the beginning of the next defun.
932 (and (not having-previous-defun)
933 (not (= (point)
934 next-defun-beginning)))
935 ;; When there is no next defun, the point
936 ;; is not in a defun if it is not at the
937 ;; end of the previous defun.
938 (and (not having-next-defun)
939 (not (= (point)
940 previous-defun-end)))
941 ;; If the point is between two defuns, it
942 ;; is not in a defun.
943 (and (> (point) previous-defun-end)
944 (< (point) next-defun-beginning)))
945 ;; If the point is already at the beginning of a
946 ;; defun, there is no need to move point again.
947 (if (not (= (point) next-defun-beginning))
948 (c-beginning-of-defun))
949 ;; Is this a DEFUN construct? And is LOCATION in it?
950 (if (and (looking-at "DEFUN\\b")
951 (>= location (point)))
952 ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
953 ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
954 (progn
955 (down-list 1)
956 (when (= (char-after (point)) ?\")
957 (forward-sexp 1)
958 (search-forward ","))
959 (skip-syntax-forward " ")
960 (buffer-substring-no-properties
961 (point)
962 (progn (search-forward ",")
963 (forward-char -1)
964 (skip-syntax-backward " ")
965 (point))))
966 (if (looking-at "^[+-]")
967 ;; Objective-C
968 (change-log-get-method-definition)
969 ;; Ordinary C function syntax.
970 (let ((beg (point)))
971 (if (and
972 ;; Protect against "Unbalanced parens" error.
973 (condition-case nil
974 (progn
975 (down-list 1) ; into arglist
976 (backward-up-list 1)
977 (skip-chars-backward " \t")
978 t)
979 (error nil))
980 ;; Verify initial pos was after
981 ;; real start of function.
982 (save-excursion
983 (goto-char beg)
984 ;; For this purpose, include the line
985 ;; that has the decl keywords. This
986 ;; may also include some of the
987 ;; comments before the function.
988 (while (and (not (bobp))
989 (save-excursion
990 (forward-line -1)
991 (looking-at "[^\n\f]")))
992 (forward-line -1))
993 (>= location (point)))
994 ;; Consistency check: going down and up
995 ;; shouldn't take us back before BEG.
996 (> (point) beg))
997 (let (end middle)
998 ;; Don't include any final whitespace
999 ;; in the name we use.
1000 (skip-chars-backward " \t\n")
1001 (setq end (point))
1002 (backward-sexp 1)
1003 ;; Now find the right beginning of the name.
1004 ;; Include certain keywords if they
1005 ;; precede the name.
1006 (setq middle (point))
1007 ;; We tried calling `forward-sexp' in a loop
1008 ;; but it causes inconsistency for C names.
1009 (forward-sexp -1)
1010 ;; Is this C++ method?
1011 (when (and (< 2 middle)
1012 (string= (buffer-substring (- middle 2)
1013 middle)
1014 "::"))
1015 ;; Include "classname::".
1016 (setq middle (point)))
1017 ;; Ignore these subparts of a class decl
1018 ;; and move back to the class name itself.
1019 (while (looking-at "public \\|private ")
1020 (skip-chars-backward " \t:")
1021 (setq end (point))
1022 (backward-sexp 1)
1023 (setq middle (point))
1024 (forward-word -1))
1025 (and (bolp)
1026 (looking-at
1027 "enum \\|struct \\|union \\|class ")
1028 (setq middle (point)))
1029 (goto-char end)
1030 (when (eq (preceding-char) ?=)
1031 (forward-char -1)
1032 (skip-chars-backward " \t")
1033 (setq end (point)))
1034 (buffer-substring-no-properties
1035 middle end)))))))))
1036 ((apply 'derived-mode-p add-log-tex-like-modes)
1037 (if (re-search-backward
1038 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
1039 nil t)
1040 (progn
1041 (goto-char (match-beginning 0))
1042 (buffer-substring-no-properties
1043 (1+ (point)) ; without initial backslash
1044 (line-end-position)))))
1045 ((derived-mode-p 'texinfo-mode)
1046 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
1047 (match-string-no-properties 1)))
1048 ((derived-mode-p 'perl-mode 'cperl-mode)
1049 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t)
1050 (match-string-no-properties 1)))
1051 ;; Emacs's autoconf-mode installs its own
1052 ;; `add-log-current-defun-function'. This applies to
1053 ;; a different mode apparently for editing .m4
1054 ;; autoconf source.
1055 ((derived-mode-p 'autoconf-mode)
1056 (if (re-search-backward
1057 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t)
1058 (match-string-no-properties 3)))
1059 (t
1060 ;; If all else fails, try heuristics
1061 (let (case-fold-search
1062 result)
1063 (end-of-line)
1064 (when (re-search-backward
1065 add-log-current-defun-header-regexp
1066 (- (point) 10000)
1067 t)
1068 (setq result (or (match-string-no-properties 1)
1069 (match-string-no-properties 0)))
1070 ;; Strip whitespace away
1071 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
1072 result)
1073 (setq result (match-string-no-properties 1 result)))
1074 result))))))
1075 (error nil)))
1076
1077 (defvar change-log-get-method-definition-md)
1078
1079 ;; Subroutine used within change-log-get-method-definition.
1080 ;; Add the last match in the buffer to the end of `md',
1081 ;; followed by the string END; move to the end of that match.
1082 (defun change-log-get-method-definition-1 (end)
1083 (setq change-log-get-method-definition-md
1084 (concat change-log-get-method-definition-md
1085 (match-string 1)
1086 end))
1087 (goto-char (match-end 0)))
1088
1089 (defun change-log-get-method-definition ()
1090 "For Objective C, return the method name if we are in a method."
1091 (let ((change-log-get-method-definition-md "["))
1092 (save-excursion
1093 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
1094 (change-log-get-method-definition-1 " ")))
1095 (save-excursion
1096 (cond
1097 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
1098 (change-log-get-method-definition-1 "")
1099 (while (not (looking-at "[{;]"))
1100 (looking-at
1101 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
1102 (change-log-get-method-definition-1 ""))
1103 (concat change-log-get-method-definition-md "]"))))))
1104 \f
1105 (defconst change-log-start-entry-re "^\\sw.........[0-9:+ ]*")
1106
1107 (defun change-log-sortable-date-at ()
1108 "Return date of log entry in a consistent form for sorting.
1109 Point is assumed to be at the start of the entry."
1110 (require 'timezone)
1111 (if (looking-at change-log-start-entry-re)
1112 (let ((date (match-string-no-properties 0)))
1113 (if date
1114 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date)
1115 (concat (match-string 1 date) (match-string 2 date)
1116 (match-string 3 date))
1117 (condition-case nil
1118 (timezone-make-date-sortable date)
1119 (error nil)))))
1120 (error "Bad date")))
1121
1122 (defun change-log-resolve-conflict ()
1123 "Function to be used in `smerge-resolve-function'."
1124 (save-excursion
1125 (save-restriction
1126 (narrow-to-region (match-beginning 0) (match-end 0))
1127 (let ((mb1 (match-beginning 1))
1128 (me1 (match-end 1))
1129 (mb3 (match-beginning 3))
1130 (me3 (match-end 3))
1131 (tmp1 (generate-new-buffer " *changelog-resolve-1*"))
1132 (tmp2 (generate-new-buffer " *changelog-resolve-2*")))
1133 (unwind-protect
1134 (let ((buf (current-buffer)))
1135 (with-current-buffer tmp1
1136 (change-log-mode)
1137 (insert-buffer-substring buf mb1 me1))
1138 (with-current-buffer tmp2
1139 (change-log-mode)
1140 (insert-buffer-substring buf mb3 me3)
1141 ;; Do the merge here instead of inside `buf' so as to be
1142 ;; more robust in case change-log-merge fails.
1143 (change-log-merge tmp1))
1144 (goto-char (point-max))
1145 (delete-region (point-min)
1146 (prog1 (point)
1147 (insert-buffer-substring tmp2))))
1148 (kill-buffer tmp1)
1149 (kill-buffer tmp2))))))
1150
1151 ;;;###autoload
1152 (defun change-log-merge (other-log)
1153 "Merge the contents of change log file OTHER-LOG with this buffer.
1154 Both must be found in Change Log mode (since the merging depends on
1155 the appropriate motion commands). OTHER-LOG can be either a file name
1156 or a buffer.
1157
1158 Entries are inserted in chronological order. Both the current and
1159 old-style time formats for entries are supported."
1160 (interactive "*fLog file name to merge: ")
1161 (if (not (derived-mode-p 'change-log-mode))
1162 (error "Not in Change Log mode"))
1163 (let ((other-buf (if (bufferp other-log) other-log
1164 (find-file-noselect other-log)))
1165 (buf (current-buffer))
1166 date1 start end)
1167 (save-excursion
1168 (goto-char (point-min))
1169 (set-buffer other-buf)
1170 (goto-char (point-min))
1171 (if (not (derived-mode-p 'change-log-mode))
1172 (error "%s not found in Change Log mode" other-log))
1173 ;; Loop through all the entries in OTHER-LOG.
1174 (while (not (eobp))
1175 (setq date1 (change-log-sortable-date-at))
1176 (setq start (point)
1177 end (progn (forward-page) (point)))
1178 ;; Look for an entry in original buffer that isn't later.
1179 (with-current-buffer buf
1180 (while (and (not (eobp))
1181 (string< date1 (change-log-sortable-date-at)))
1182 (forward-page))
1183 (if (not (eobp))
1184 (insert-buffer-substring other-buf start end)
1185 ;; At the end of the original buffer, insert a newline to
1186 ;; separate entries and then the rest of the file being
1187 ;; merged.
1188 (unless (or (bobp)
1189 (and (= ?\n (char-before))
1190 (or (<= (1- (point)) (point-min))
1191 (= ?\n (char-before (1- (point)))))))
1192 (insert (if use-hard-newlines hard-newline "\n")))
1193 ;; Move to the end of it to terminate outer loop.
1194 (with-current-buffer other-buf
1195 (goto-char (point-max)))
1196 (insert-buffer-substring other-buf start)))))))
1197
1198 (defun change-log-beginning-of-defun ()
1199 (re-search-backward change-log-start-entry-re nil 'move))
1200
1201 (defun change-log-end-of-defun ()
1202 ;; Look back and if there is no entry there it means we are before
1203 ;; the first ChangeLog entry, so go forward until finding one.
1204 (unless (save-excursion (re-search-backward change-log-start-entry-re nil t))
1205 (re-search-forward change-log-start-entry-re nil t))
1206
1207 ;; In case we are at the end of log entry going forward a line will
1208 ;; make us find the next entry when searching. If we are inside of
1209 ;; an entry going forward a line will still keep the point inside
1210 ;; the same entry.
1211 (forward-line 1)
1212
1213 ;; In case we are at the beginning of an entry, move past it.
1214 (when (looking-at change-log-start-entry-re)
1215 (goto-char (match-end 0))
1216 (forward-line 1))
1217
1218 ;; Search for the start of the next log entry. Go to the end of the
1219 ;; buffer if we could not find a next entry.
1220 (when (re-search-forward change-log-start-entry-re nil 'move)
1221 (goto-char (match-beginning 0))
1222 (forward-line -1)))
1223
1224 (provide 'add-log)
1225
1226 ;; arch-tag: 81eee6fc-088f-4372-a37f-80ad9620e762
1227 ;;; add-log.el ends here