1 ;;; add-log.el --- change log maintenance commands for Emacs
3 ;; Copyright (C) 1985, 86, 88, 93, 94, 97, 98, 2000 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This facility is documented in the Emacs Manual.
33 (defgroup change-log nil
34 "Change log maintenance"
36 :link
'(custom-manual "(emacs)Change Log")
41 (defcustom change-log-default-name nil
42 "*Name of a change log file for \\[add-change-log-entry]."
43 :type
'(choice (const :tag
"default" nil
)
47 (defcustom change-log-mode-hook nil
48 "Normal hook run by `change-log-mode'."
52 (defcustom add-log-current-defun-function nil
53 "*If non-nil, function to guess name of surrounding function.
54 It is used by `add-log-current-defun' in preference to built-in rules.
55 Returns function's name as a string, or nil if outside a function."
60 (defcustom add-log-full-name nil
61 "*Full name of user, for inclusion in ChangeLog daily headers.
62 This defaults to the value returned by the function `user-full-name'."
63 :type
'(choice (const :tag
"Default" nil
)
68 (defcustom add-log-mailing-address nil
69 "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
70 This defaults to the value of `user-mail-address'."
71 :type
'(choice (const :tag
"Default" nil
)
75 (defcustom add-log-time-format
'add-log-iso8601-time-string
76 "*Function that defines the time format.
77 For example, `add-log-iso8601-time-string', which gives the
78 date in international ISO 8601 format,
79 and `current-time-string' are two valid values."
80 :type
'(radio (const :tag
"International ISO 8601 format"
81 add-log-iso8601-time-string
)
82 (const :tag
"Old format, as returned by `current-time-string'"
84 (function :tag
"Other"))
87 (defcustom add-log-keep-changes-together nil
88 "*If non-nil, normally keep day's log entries for one file together.
90 Log entries for a given file made with \\[add-change-log-entry] or
91 \\[add-change-log-entry-other-window] will only be added to others \
93 today if this variable is non-nil or that file comes first in today's
94 entries. Otherwise another entry for that file will be started. An
100 in the latter case, \\[add-change-log-entry-other-window] in a \
101 buffer visiting `bar', yields:
105 * bar (...): change 1
110 * bar (...): change 1
113 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
119 (defcustom add-log-file-name-function nil
120 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
121 This function is called with one argument, the value of variable
122 `buffer-file-name' in that buffer. If this is nil, the default is to
123 use the file's name relative to the directory of the change log file."
128 (defcustom change-log-version-info-enabled nil
129 "*If non-nil, enable recording version numbers with the changes."
134 (defcustom change-log-version-number-regexp-list
135 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
137 ;; (defconst ad-version "2.15"
138 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re
)
139 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
140 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re
)))
141 "*List of regexps to search for version number.
142 The version number must be in group 1.
143 Note: The search is conducted only within 10%, at the beginning of the file."
145 :type
'(repeat regexp
)
149 (defvar change-log-font-lock-keywords
151 ;; Date lines, new and old styles.
152 ("^\\sw.........[0-9:+ ]*"
153 (0 font-lock-string-face
)
154 ;; Name and e-mail; some people put e-mail in parens, not angles.
155 ("\\([^<(]+\\)[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
156 (1 font-lock-constant-face
)
157 (2 font-lock-variable-name-face
)))
160 ("^\t\\* \\([^ ,:([\n]+\\)"
161 (1 font-lock-function-name-face
)
162 ;; Possibly further names in a list:
163 ("\\=, \\([^ ,:([\n]+\\)" nil nil
(1 font-lock-function-name-face
))
164 ;; Possibly a parenthesized list of names:
165 ("\\= (\\([^) ,:\n]+\\)" nil nil
(1 font-lock-keyword-face
))
166 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 font-lock-keyword-face
)))
168 ;; Function or variable names.
169 ("^\t(\\([^) ,:\n]+\\)"
170 (1 font-lock-keyword-face
)
171 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 font-lock-keyword-face
)))
174 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 font-lock-variable-name-face
))
176 ;; Function of change.
177 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 font-lock-variable-name-face
))
180 ("\\(^\t\\| \\)\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
181 2 font-lock-comment-face
))
182 "Additional expressions to highlight in Change Log mode.")
184 (defvar change-log-mode-map
(make-sparse-keymap)
185 "Keymap for Change Log major mode.")
187 (defvar change-log-time-zone-rule nil
188 "Time zone used for calculating change log time stamps.
189 It takes the same format as the TZ argument of `set-time-zone-rule'.
190 If nil, use local time.")
192 (defun add-log-iso8601-time-zone (time)
193 (let* ((utc-offset (or (car (current-time-zone time
)) 0))
194 (sign (if (< utc-offset
0) ?- ?
+))
195 (sec (abs utc-offset
))
200 (format (cond ((not (zerop ss
)) "%c%02d:%02d:%02d")
201 ((not (zerop mm
)) "%c%02d:%02d")
205 (defun add-log-iso8601-time-string ()
206 (if change-log-time-zone-rule
207 (let ((tz (getenv "TZ"))
208 (now (current-time)))
212 change-log-time-zone-rule
)
214 (format-time-string "%Y-%m-%d " now
)
215 (add-log-iso8601-time-zone now
)))
216 (set-time-zone-rule tz
)))
217 (format-time-string "%Y-%m-%d")))
219 (defun change-log-name ()
220 "Return (system-dependent) default name for a change log file."
221 (or change-log-default-name
222 (if (eq system-type
'vax-vms
)
227 (defun prompt-for-change-log-name ()
228 "Prompt for a change log name."
229 (let* ((default (change-log-name))
230 (name (expand-file-name
231 (read-file-name (format "Log file (default %s): " default
)
233 ;; Handle something that is syntactically a directory name.
234 ;; Look for ChangeLog or whatever in that directory.
235 (if (string= (file-name-nondirectory name
) "")
236 (expand-file-name (file-name-nondirectory default
)
238 ;; Handle specifying a file that is a directory.
239 (if (file-directory-p name
)
240 (expand-file-name (file-name-nondirectory default
)
241 (file-name-as-directory name
))
244 (defun change-log-version-number-search ()
245 "Return version number of current buffer's file.
246 This is the value returned by `vc-workfile-version' or, if that is
247 nil, by matching `change-log-version-number-regexp-list'."
248 (let* ((size (buffer-size))
250 ;; The version number can be anywhere in the file, but
251 ;; restrict search to the file beginning: 10% should be
252 ;; enough to prevent some mishits.
254 ;; Apply percentage only if buffer size is bigger than
256 (if (> size
(* 100 80))
260 (or (and buffer-file-name
261 (vc-workfile-version buffer-file-name
))
264 (let ((regexps change-log-version-number-regexp-list
))
267 (goto-char (point-min))
268 (when (re-search-forward (pop regexps
) end t
)
269 (setq version
(match-string 1)
274 (defun find-change-log (&optional file-name
)
275 "Find a change log file for \\[add-change-log-entry] and return the name.
277 Optional arg FILE-NAME specifies the file to use.
278 If FILE-NAME is nil, use the value of `change-log-default-name'.
279 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
280 \(or whatever we use on this operating system).
282 If 'change-log-default-name' contains a leading directory component, then
283 simply find it in the current directory. Otherwise, search in the current
284 directory and its successive parents for a file so named.
286 Once a file is found, `change-log-default-name' is set locally in the
287 current buffer to the complete file name."
288 ;; If user specified a file name or if this buffer knows which one to use,
291 (setq file-name
(and change-log-default-name
292 (file-name-directory change-log-default-name
)
293 change-log-default-name
))
295 ;; Chase links in the source file
296 ;; and use the change log in the dir where it points.
297 (setq file-name
(or (and buffer-file-name
299 (file-chase-links buffer-file-name
)))
301 (if (file-directory-p file-name
)
302 (setq file-name
(expand-file-name (change-log-name) file-name
)))
303 ;; Chase links before visiting the file.
304 ;; This makes it easier to use a single change log file
305 ;; for several related directories.
306 (setq file-name
(file-chase-links file-name
))
307 (setq file-name
(expand-file-name file-name
))
308 ;; Move up in the dir hierarchy till we find a change log file.
309 (let ((file1 file-name
)
311 (while (and (not (or (get-file-buffer file1
) (file-exists-p file1
)))
312 (progn (setq parent-dir
315 (file-name-directory file1
))))
316 ;; Give up if we are already at the root dir.
317 (not (string= (file-name-directory file1
)
319 ;; Move up to the parent dir and try again.
320 (setq file1
(expand-file-name
321 (file-name-nondirectory (change-log-name))
323 ;; If we found a change log in a parent, use that.
324 (if (or (get-file-buffer file1
) (file-exists-p file1
))
325 (setq file-name file1
)))))
326 ;; Make a local variable in this buffer so we needn't search again.
327 (set (make-local-variable 'change-log-default-name
) file-name
)
331 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
)
332 "Find change log file and add an entry for today.
333 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
336 Second arg is FILE-NAME of change log. If nil, uses `change-log-default-name'.
337 Third arg OTHER-WINDOW non-nil means visit in other window.
338 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
339 never append to an existing entry. Option `add-log-keep-changes-together'
340 otherwise affects whether a new entry is created.
342 Today's date is calculated according to `change-log-time-zone-rule' if
343 non-nil, otherwise in local time."
344 (interactive (list current-prefix-arg
345 (prompt-for-change-log-name)))
346 (or add-log-full-name
347 (setq add-log-full-name
(user-full-name)))
348 (or add-log-mailing-address
349 (setq add-log-mailing-address user-mail-address
))
352 (setq add-log-full-name
(read-input "Full name: " add-log-full-name
))
353 ;; Note that some sites have room and phone number fields in
354 ;; full name which look silly when inserted. Rather than do
355 ;; anything about that here, let user give prefix argument so that
356 ;; s/he can edit the full name field in prompter if s/he wants.
357 (setq add-log-mailing-address
358 (read-input "Mailing address: " add-log-mailing-address
))))
359 (let ((defun (add-log-current-defun))
360 (version (and change-log-version-info-enabled
361 (change-log-version-number-search)))
364 (setq file-name
(expand-file-name (find-change-log file-name
)))
366 ;; Set ENTRY to the file name to use in the new entry.
367 (and buffer-file-name
368 ;; Never want to add a change log entry for the ChangeLog file itself.
369 (not (string= buffer-file-name file-name
))
370 (if add-log-file-name-function
372 (funcall add-log-file-name-function buffer-file-name
))
375 (concat "^" (regexp-quote (file-name-directory
378 (substring buffer-file-name
(match-end 0))
379 (file-name-nondirectory buffer-file-name
)))
380 ;; If we have a backup file, it's presumably because we're
381 ;; comparing old and new versions (e.g. for deleted
382 ;; functions) and we'll want to use the original name.
383 (if (backup-file-name-p entry
)
384 (setq entry
(file-name-sans-versions entry
)))))
386 (if (and other-window
(not (equal file-name buffer-file-name
)))
387 (find-file-other-window file-name
)
388 (find-file file-name
))
389 (or (eq major-mode
'change-log-mode
)
392 (goto-char (point-min))
393 (let ((new-entry (concat (funcall add-log-time-format
)
394 " " add-log-full-name
395 " <" add-log-mailing-address
">")))
396 (if (looking-at (regexp-quote new-entry
))
398 (insert new-entry
"\n\n")))
402 (if (looking-at "\n*[^\n* \t]")
403 (skip-chars-forward "\n")
404 (if add-log-keep-changes-together
405 (forward-page) ; page delimits entries for date
406 (forward-paragraph))) ; paragraph delimits entries for file
408 (goto-char (point-min))
409 ;; Now insert the new line for this entry.
410 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t
)
411 ;; Put this file name into the existing empty entry.
414 ((and (not new-entry
)
415 (let (case-fold-search)
417 (concat (regexp-quote (concat "* " entry
))
418 ;; Don't accept `foo.bar' when
419 ;; looking for `foo':
420 "\\(\\s \\|[(),:]\\)")
422 ;; Add to the existing entry for the same file.
423 (re-search-forward "^\\s *$\\|^\\s \\*")
424 (goto-char (match-beginning 0))
425 ;; Delete excess empty lines; make just 2.
426 (while (and (not (eobp)) (looking-at "^\\s *$"))
427 (delete-region (point) (line-beginning-position 2)))
430 (indent-relative-maybe))
434 (while (looking-at "\\sW")
436 (while (and (not (eobp)) (looking-at "^\\s *$"))
437 (delete-region (point) (line-beginning-position 2)))
440 (indent-to left-margin
)
441 (insert "* " (or entry
""))))
442 ;; Now insert the function name, if we have one.
443 ;; Point is at the entry for this file,
444 ;; either at the end of the line or at the first blank line.
447 ;; Make it easy to get rid of the function name.
449 (unless (save-excursion
450 (beginning-of-line 1)
451 (looking-at "\\s *$"))
453 ;; See if the prev function name has a message yet or not
454 ;; If not, merge the two entries.
455 (let ((pos (point-marker)))
456 (if (and (skip-syntax-backward " ")
457 (skip-chars-backward "):")
459 (progn (delete-region (+ 1 (point)) (+ 2 (point))) t
)
460 (> fill-column
(+ (current-column) (length defun
) 3)))
461 (progn (delete-region (point) pos
)
465 (set-marker pos nil
))
468 (insert version ?\
)))
469 ;; No function name, so put in a colon unless we have just a star.
470 (unless (save-excursion
471 (beginning-of-line 1)
472 (looking-at "\\s *\\(\\*\\s *\\)?$"))
474 (if version
(insert version ?\
))))))
477 (defun add-change-log-entry-other-window (&optional whoami file-name
)
478 "Find change log file in other window and add an entry for today.
479 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
481 Second optional arg FILE-NAME is file name of change log.
482 If nil, use `change-log-default-name'.
484 Affected by the same options as `add-change-log-entry'."
485 (interactive (if current-prefix-arg
486 (list current-prefix-arg
487 (prompt-for-change-log-name))))
488 (add-change-log-entry whoami file-name t
))
489 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
492 (defun change-log-mode ()
493 "Major mode for editing change logs; like Indented Text Mode.
494 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
495 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
496 Each entry behaves as a paragraph, and the entries for one day as a page.
497 Runs `change-log-mode-hook'."
499 (kill-all-local-variables)
501 (setq major-mode
'change-log-mode
502 mode-name
"Change Log"
507 (use-local-map change-log-mode-map
)
508 (set (make-local-variable 'fill-paragraph-function
)
509 'change-log-fill-paragraph
)
510 ;; We really do want "^" in paragraph-start below: it is only the
511 ;; lines that begin at column 0 (despite the left-margin of 8) that
512 ;; we are looking for. Adding `* ' allows eliding the blank line
513 ;; between entries for different files.
514 (set (make-local-variable 'paragraph-start
) "\\s *$\\|\f\\|^\\<")
515 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
516 ;; Match null string on the date-line so that the date-line
517 ;; is grouped with what follows.
518 (set (make-local-variable 'page-delimiter
) "^\\<\\|^\f")
519 (set (make-local-variable 'version-control
) 'never
)
520 (set (make-local-variable 'adaptive-fill-regexp
) "\\s *")
521 (set (make-local-variable 'font-lock-defaults
)
522 '(change-log-font-lock-keywords t
))
523 (run-hooks 'change-log-mode-hook
))
525 ;; It might be nice to have a general feature to replace this. The idea I
526 ;; have is a variable giving a regexp matching text which should not be
527 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
528 ;; But I don't feel up to implementing that today.
529 (defun change-log-fill-paragraph (&optional justify
)
530 "Fill the paragraph, but preserve open parentheses at beginning of lines.
531 Prefix arg means justify as well."
533 (let ((end (progn (forward-paragraph) (point)))
534 (beg (progn (backward-paragraph) (point)))
535 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
536 (fill-region beg end justify
)
539 (defcustom add-log-current-defun-header-regexp
540 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
541 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
546 (defvar add-log-lisp-like-modes
547 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode
)
548 "*Modes that look like Lisp to `add-log-current-defun'.")
551 (defvar add-log-c-like-modes
552 '(c-mode c
++-mode c
++-c-mode objc-mode
)
553 "*Modes that look like C to `add-log-current-defun'.")
556 (defvar add-log-tex-like-modes
557 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode
)
558 "*Modes that look like TeX to `add-log-current-defun'.")
561 (defun add-log-current-defun ()
562 "Return name of function definition point is in, or nil.
564 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
565 Texinfo (@node titles) and Perl.
567 Other modes are handled by a heuristic that looks in the 10K before
568 point for uppercase headings starting in the first column or
569 identifiers followed by `:' or `='. See variables
570 `add-log-current-defun-header-regexp' and
571 `add-log-current-defun-function'
573 Has a preference of looking backwards."
576 (let ((location (point)))
577 (cond (add-log-current-defun-function
578 (funcall add-log-current-defun-function
))
579 ((memq major-mode add-log-lisp-like-modes
)
580 ;; If we are now precisely at the beginning of a defun,
581 ;; make sure beginning-of-defun finds that one
582 ;; rather than the previous one.
583 (or (eobp) (forward-char 1))
585 ;; Make sure we are really inside the defun found,
587 (when (and (looking-at "\\s(")
588 (progn (end-of-defun)
589 (< location
(point)))
590 (progn (forward-sexp -
1)
591 (>= location
(point))))
592 (if (looking-at "\\s(")
594 ;; Skip the defining construct name, typically "defun"
597 ;; The second element is usually a symbol being defined.
598 ;; If it is not, use the first symbol in it.
599 (skip-chars-forward " \t\n'(")
600 (buffer-substring-no-properties (point)
601 (progn (forward-sexp 1)
603 ((and (memq major-mode add-log-c-like-modes
)
606 ;; Use eq instead of = here to avoid
607 ;; error when at bob and char-after
609 (while (eq (char-after (- (point) 2)) ?
\\)
611 (looking-at "[ \t]*#[ \t]*define[ \t]")))
612 ;; Handle a C macro definition.
614 (while (eq (char-after (- (point) 2)) ?
\\) ;not =; note above
616 (search-forward "define")
617 (skip-chars-forward " \t")
618 (buffer-substring-no-properties (point)
619 (progn (forward-sexp 1)
621 ((memq major-mode add-log-c-like-modes
)
623 ;; See if we are in the beginning part of a function,
624 ;; before the open brace. If so, advance forward.
625 (while (not (looking-at "{\\|\\(\\s *$\\)"))
630 (when (progn (end-of-defun)
631 (< location
(point)))
636 ;; Skip back over typedefs of arglist.
637 (while (and (not (bobp))
638 (looking-at "[ \t\n]"))
640 ;; See if this is using the DEFUN macro used in Emacs,
641 ;; or the DEFUN macro used by the C library.
642 (if (condition-case nil
645 (while (= (preceding-char) ?
\\)
650 (looking-at "DEFUN\\b"))
656 (if (= (char-after (point)) ?
\")
659 (skip-chars-forward " ,")))
660 (buffer-substring-no-properties
662 (progn (forward-sexp 1)
664 (if (looking-at "^[+-]")
665 (change-log-get-method-definition)
666 ;; Ordinary C function syntax.
669 ;; Protect against "Unbalanced parens" error.
672 (down-list 1) ; into arglist
674 (skip-chars-backward " \t")
677 ;; Verify initial pos was after
678 ;; real start of function.
681 ;; For this purpose, include the line
682 ;; that has the decl keywords. This
683 ;; may also include some of the
684 ;; comments before the function.
685 (while (and (not (bobp))
688 (looking-at "[^\n\f]")))
690 (>= location
(point)))
691 ;; Consistency check: going down and up
692 ;; shouldn't take us back before BEG.
695 ;; Don't include any final whitespace
696 ;; in the name we use.
697 (skip-chars-backward " \t\n")
700 ;; Now find the right beginning of the name.
701 ;; Include certain keywords if they
703 (setq middle
(point))
705 ;; Ignore these subparts of a class decl
706 ;; and move back to the class name itself.
707 (while (looking-at "public \\|private ")
708 (skip-chars-backward " \t:")
711 (setq middle
(point))
715 "enum \\|struct \\|union \\|class ")
716 (setq middle
(point)))
718 (when (eq (preceding-char) ?
=)
720 (skip-chars-backward " \t")
722 (buffer-substring-no-properties
724 ((memq major-mode add-log-tex-like-modes
)
725 (if (re-search-backward
726 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
729 (goto-char (match-beginning 0))
730 (buffer-substring-no-properties
731 (1+ (point)) ; without initial backslash
732 (line-end-position)))))
733 ((eq major-mode
'texinfo-mode
)
734 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t
)
735 (match-string-no-properties 1)))
736 ((eq major-mode
'perl-mode
)
737 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t
)
738 (match-string-no-properties 1)))
739 ;; Emacs's autoconf-mode installs its own
740 ;; `add-log-current-defun-function'. This applies to
741 ;; a different mode apparently for editing .m4
743 ((eq major-mode
'autoconf-mode
)
744 (if (re-search-backward
745 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t
)
746 (match-string-no-properties 3)))
748 ;; If all else fails, try heuristics
749 (let (case-fold-search
752 (when (re-search-backward
753 add-log-current-defun-header-regexp
756 (setq result
(or (match-string-no-properties 1)
757 (match-string-no-properties 0)))
758 ;; Strip whitespace away
759 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
761 (setq result
(match-string-no-properties 1 result
)))
765 (defvar change-log-get-method-definition-md
)
767 ;; Subroutine used within change-log-get-method-definition.
768 ;; Add the last match in the buffer to the end of `md',
769 ;; followed by the string END; move to the end of that match.
770 (defun change-log-get-method-definition-1 (end)
771 (setq change-log-get-method-definition-md
772 (concat change-log-get-method-definition-md
775 (goto-char (match-end 0)))
777 (defun change-log-get-method-definition ()
778 "For objective C, return the method name if we are in a method."
779 (let ((change-log-get-method-definition-md "["))
781 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t
)
782 (change-log-get-method-definition-1 " ")))
785 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t
)
786 (change-log-get-method-definition-1 "")
787 (while (not (looking-at "[{;]"))
789 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
790 (change-log-get-method-definition-1 ""))
791 (concat change-log-get-method-definition-md
"]"))))))
793 (defun change-log-sortable-date-at ()
794 "Return date of log entry in a consistent form for sorting.
795 Point is assumed to be at the start of the entry."
797 (if (looking-at "^\\sw.........[0-9:+ ]*")
798 (let ((date (match-string-no-properties 0)))
800 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date
)
801 (concat (match-string 1 date
) (match-string 2 date
)
802 (match-string 3 date
))
804 (timezone-make-date-sortable date
)
809 (defun change-log-merge (other-log)
810 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
811 Both must be found in Change Log mode (since the merging depends on
812 the appropriate motion commands).
814 Entries are inserted in chronological order.
816 Both the current and old-style time formats for entries are supported,
817 so this command could be used to convert old-style logs by merging
819 (interactive "*fLog file name to merge: ")
820 (if (not (eq major-mode
'change-log-mode
))
821 (error "Not in Change Log mode"))
822 (let ((other-buf (find-file-noselect other-log
))
823 (buf (current-buffer))
826 (goto-char (point-min))
827 (set-buffer other-buf
)
828 (goto-char (point-min))
829 (if (not (eq major-mode
'change-log-mode
))
830 (error "%s not found in Change Log mode" other-log
))
831 ;; Loop through all the entries in OTHER-LOG.
833 (setq date1
(change-log-sortable-date-at))
835 end
(progn (forward-page) (point)))
836 ;; Look for an entry in original buffer that isn't later.
837 (with-current-buffer buf
838 (while (and (not (eobp))
839 (string< date1
(change-log-sortable-date-at)))
842 (insert-buffer-substring other-buf start end
)
843 ;; At the end of the original buffer, insert a newline to
844 ;; separate entries and then the rest of the file being
845 ;; merged. Move to the end of it to terminate outer loop.
847 (insert-buffer-substring other-buf start
848 (with-current-buffer other-buf
849 (goto-char (point-max))
854 ;;; add-log.el ends here