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."
56 :type
'(choice (const nil
) 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-buffer-file-name-function nil
120 "*If non-nil, function to call to identify the full filename of a buffer.
121 This function is called with no argument. If this is nil, the default is to
122 use `buffer-file-name'."
123 :type
'(choice (const nil
) function
)
126 (defcustom add-log-file-name-function nil
127 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
128 This function is called with one argument, the value of variable
129 `buffer-file-name' in that buffer. If this is nil, the default is to
130 use the file's name relative to the directory of the change log file."
131 :type
'(choice (const nil
) function
)
135 (defcustom change-log-version-info-enabled nil
136 "*If non-nil, enable recording version numbers with the changes."
141 (defcustom change-log-version-number-regexp-list
142 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
144 ;; (defconst ad-version "2.15"
145 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re
)
146 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
147 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re
)))
148 "*List of regexps to search for version number.
149 The version number must be in group 1.
150 Note: The search is conducted only within 10%, at the beginning of the file."
152 :type
'(repeat regexp
)
155 (defface change-log-date-face
156 '((t (:inherit font-lock-string-face
)))
157 "Face used to highlight dates in date lines."
161 (defface change-log-name-face
162 '((t (:inherit font-lock-constant-face
)))
163 "Face for highlighting author names."
167 (defface change-log-email-face
168 '((t (:inherit font-lock-variable-name-face
)))
169 "Face for highlighting author email addresses."
173 (defface change-log-file-face
174 '((t (:inherit font-lock-function-name-face
)))
175 "Face for highlighting file names."
179 (defface change-log-list-face
180 '((t (:inherit font-lock-keyword-face
)))
181 "Face for highlighting parenthesized lists of functions or variables."
185 (defface change-log-conditionals-face
186 '((t (:inherit font-lock-variable-name-face
)))
187 "Face for highlighting conditionals of the form `[...]'."
191 (defface change-log-function-face
192 '((t (:inherit font-lock-variable-name-face
)))
193 "Face for highlighting items of the form `<....>'."
197 (defface change-log-acknowledgement-face
198 '((t (:inherit font-lock-comment-face
)))
199 "Face for highlighting acknowledgments."
203 (defvar change-log-font-lock-keywords
205 ;; Date lines, new and old styles.
206 ("^\\sw.........[0-9:+ ]*"
207 (0 'change-log-date-face
)
208 ;; Name and e-mail; some people put e-mail in parens, not angles.
209 ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
210 (1 'change-log-name-face
)
211 (2 'change-log-email-face
)))
214 ("^\t\\* \\([^ ,:([\n]+\\)"
215 (1 'change-log-file-face
)
216 ;; Possibly further names in a list:
217 ("\\=, \\([^ ,:([\n]+\\)" nil nil
(1 'change-log-file-face
))
218 ;; Possibly a parenthesized list of names:
219 ("\\= (\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
))
220 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
222 ;; Function or variable names.
223 ("^\t(\\([^) ,:\n]+\\)"
224 (1 'change-log-list-face
)
225 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
228 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals-face
))
230 ;; Function of change.
231 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function-face
))
234 ("\\(^\t\\| \\)\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
235 2 'change-log-acknowledgement-face
))
236 "Additional expressions to highlight in Change Log mode.")
238 (defvar change-log-mode-map
(make-sparse-keymap)
239 "Keymap for Change Log major mode.")
241 (defvar change-log-time-zone-rule nil
242 "Time zone used for calculating change log time stamps.
243 It takes the same format as the TZ argument of `set-time-zone-rule'.
244 If nil, use local time.")
246 (defun add-log-iso8601-time-zone (time)
247 (let* ((utc-offset (or (car (current-time-zone time
)) 0))
248 (sign (if (< utc-offset
0) ?- ?
+))
249 (sec (abs utc-offset
))
254 (format (cond ((not (zerop ss
)) "%c%02d:%02d:%02d")
255 ((not (zerop mm
)) "%c%02d:%02d")
259 (defun add-log-iso8601-time-string ()
260 (if change-log-time-zone-rule
261 (let ((tz (getenv "TZ"))
262 (now (current-time)))
265 (set-time-zone-rule change-log-time-zone-rule
)
267 (format-time-string "%Y-%m-%d " now
)
268 (add-log-iso8601-time-zone now
)))
269 (set-time-zone-rule tz
)))
270 (format-time-string "%Y-%m-%d")))
272 (defun change-log-name ()
273 "Return (system-dependent) default name for a change log file."
274 (or change-log-default-name
275 (if (eq system-type
'vax-vms
)
280 (defun prompt-for-change-log-name ()
281 "Prompt for a change log name."
282 (let* ((default (change-log-name))
283 (name (expand-file-name
284 (read-file-name (format "Log file (default %s): " default
)
286 ;; Handle something that is syntactically a directory name.
287 ;; Look for ChangeLog or whatever in that directory.
288 (if (string= (file-name-nondirectory name
) "")
289 (expand-file-name (file-name-nondirectory default
)
291 ;; Handle specifying a file that is a directory.
292 (if (file-directory-p name
)
293 (expand-file-name (file-name-nondirectory default
)
294 (file-name-as-directory name
))
297 (defun change-log-version-number-search ()
298 "Return version number of current buffer's file.
299 This is the value returned by `vc-workfile-version' or, if that is
300 nil, by matching `change-log-version-number-regexp-list'."
301 (let* ((size (buffer-size))
303 ;; The version number can be anywhere in the file, but
304 ;; restrict search to the file beginning: 10% should be
305 ;; enough to prevent some mishits.
307 ;; Apply percentage only if buffer size is bigger than
309 (if (> size
(* 100 80))
313 (or (and buffer-file-name
(vc-workfile-version buffer-file-name
))
316 (let ((regexps change-log-version-number-regexp-list
))
319 (goto-char (point-min))
320 (when (re-search-forward (pop regexps
) end t
)
321 (setq version
(match-string 1)
326 (defun find-change-log (&optional file-name buffer-file
)
327 "Find a change log file for \\[add-change-log-entry] and return the name.
329 Optional arg FILE-NAME specifies the file to use.
330 If FILE-NAME is nil, use the value of `change-log-default-name'.
331 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
332 \(or whatever we use on this operating system).
334 If 'change-log-default-name' contains a leading directory component, then
335 simply find it in the current directory. Otherwise, search in the current
336 directory and its successive parents for a file so named.
338 Once a file is found, `change-log-default-name' is set locally in the
339 current buffer to the complete file name.
340 Optional arg BUFFER-FILE overrides `buffer-file-name'."
341 ;; If user specified a file name or if this buffer knows which one to use,
344 (setq file-name
(and change-log-default-name
345 (file-name-directory change-log-default-name
)
346 change-log-default-name
))
348 ;; Chase links in the source file
349 ;; and use the change log in the dir where it points.
350 (setq file-name
(or (and (or buffer-file buffer-file-name
)
353 (or buffer-file buffer-file-name
))))
355 (if (file-directory-p file-name
)
356 (setq file-name
(expand-file-name (change-log-name) file-name
)))
357 ;; Chase links before visiting the file.
358 ;; This makes it easier to use a single change log file
359 ;; for several related directories.
360 (setq file-name
(file-chase-links file-name
))
361 (setq file-name
(expand-file-name file-name
))
362 ;; Move up in the dir hierarchy till we find a change log file.
363 (let ((file1 file-name
)
365 (while (and (not (or (get-file-buffer file1
) (file-exists-p file1
)))
366 (progn (setq parent-dir
369 (file-name-directory file1
))))
370 ;; Give up if we are already at the root dir.
371 (not (string= (file-name-directory file1
)
373 ;; Move up to the parent dir and try again.
374 (setq file1
(expand-file-name
375 (file-name-nondirectory (change-log-name))
377 ;; If we found a change log in a parent, use that.
378 (if (or (get-file-buffer file1
) (file-exists-p file1
))
379 (setq file-name file1
)))))
380 ;; Make a local variable in this buffer so we needn't search again.
381 (set (make-local-variable 'change-log-default-name
) file-name
)
384 (defun add-log-file-name (buffer-file log-file
)
385 ;; Never want to add a change log entry for the ChangeLog file itself.
386 (unless (or (null buffer-file
) (string= buffer-file log-file
))
387 (if add-log-file-name-function
388 (funcall add-log-file-name-function buffer-file
)
391 (concat "^" (regexp-quote (file-name-directory log-file
)))
393 (substring buffer-file
(match-end 0))
394 (file-name-nondirectory buffer-file
)))
395 ;; If we have a backup file, it's presumably because we're
396 ;; comparing old and new versions (e.g. for deleted
397 ;; functions) and we'll want to use the original name.
398 (if (backup-file-name-p buffer-file
)
399 (file-name-sans-versions buffer-file
)
403 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
)
404 "Find change log file and add an entry for today.
405 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
408 Second arg is FILE-NAME of change log. If nil, uses `change-log-default-name'.
409 Third arg OTHER-WINDOW non-nil means visit in other window.
410 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
411 never append to an existing entry. Option `add-log-keep-changes-together'
412 otherwise affects whether a new entry is created.
414 Today's date is calculated according to `change-log-time-zone-rule' if
415 non-nil, otherwise in local time."
416 (interactive (list current-prefix-arg
417 (prompt-for-change-log-name)))
418 (or add-log-full-name
419 (setq add-log-full-name
(user-full-name)))
420 (or add-log-mailing-address
421 (setq add-log-mailing-address user-mail-address
))
424 (setq add-log-full-name
(read-input "Full name: " add-log-full-name
))
425 ;; Note that some sites have room and phone number fields in
426 ;; full name which look silly when inserted. Rather than do
427 ;; anything about that here, let user give prefix argument so that
428 ;; s/he can edit the full name field in prompter if s/he wants.
429 (setq add-log-mailing-address
430 (read-input "Mailing address: " add-log-mailing-address
))))
432 (let* ((defun (add-log-current-defun))
433 (version (and change-log-version-info-enabled
434 (change-log-version-number-search)))
435 (buf-file-name (if add-log-buffer-file-name-function
436 (funcall add-log-buffer-file-name-function
)
438 (buffer-file (if buf-file-name
(expand-file-name buf-file-name
)))
439 (file-name (expand-file-name
440 (or file-name
(find-change-log file-name buffer-file
))))
441 ;; Set ENTRY to the file name to use in the new entry.
442 (entry (add-log-file-name buffer-file file-name
))
445 (if (or (and other-window
(not (equal file-name buffer-file-name
)))
446 (window-dedicated-p (selected-window)))
447 (find-file-other-window file-name
)
448 (find-file file-name
))
449 (or (eq major-mode
'change-log-mode
)
452 (goto-char (point-min))
453 (let ((new-entry (concat (funcall add-log-time-format
)
454 " " add-log-full-name
455 " <" add-log-mailing-address
">")))
456 (if (looking-at (regexp-quote new-entry
))
458 (insert new-entry
"\n\n")))
462 (if (looking-at "\n*[^\n* \t]")
463 (skip-chars-forward "\n")
464 (if add-log-keep-changes-together
465 (forward-page) ; page delimits entries for date
466 (forward-paragraph))) ; paragraph delimits entries for file
468 (goto-char (point-min))
469 ;; Now insert the new line for this entry.
470 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t
)
471 ;; Put this file name into the existing empty entry.
474 ((and (not new-entry
)
475 (let (case-fold-search)
477 (concat (regexp-quote (concat "* " entry
))
478 ;; Don't accept `foo.bar' when
479 ;; looking for `foo':
480 "\\(\\s \\|[(),:]\\)")
482 ;; Add to the existing entry for the same file.
483 (re-search-forward "^\\s *$\\|^\\s \\*")
484 (goto-char (match-beginning 0))
485 ;; Delete excess empty lines; make just 2.
486 (while (and (not (eobp)) (looking-at "^\\s *$"))
487 (delete-region (point) (line-beginning-position 2)))
490 (indent-relative-maybe))
494 (while (looking-at "\\sW")
496 (while (and (not (eobp)) (looking-at "^\\s *$"))
497 (delete-region (point) (line-beginning-position 2)))
500 (indent-to left-margin
)
502 (if entry
(insert entry
))))
503 ;; Now insert the function name, if we have one.
504 ;; Point is at the entry for this file,
505 ;; either at the end of the line or at the first blank line.
508 ;; Make it easy to get rid of the function name.
510 (unless (save-excursion
511 (beginning-of-line 1)
512 (looking-at "\\s *$"))
514 ;; See if the prev function name has a message yet or not
515 ;; If not, merge the two entries.
516 (let ((pos (point-marker)))
517 (if (and (skip-syntax-backward " ")
518 (skip-chars-backward "):")
520 (progn (delete-region (+ 1 (point)) (+ 2 (point))) t
)
521 (> fill-column
(+ (current-column) (length defun
) 3)))
522 (progn (delete-region (point) pos
)
526 (set-marker pos nil
))
529 (insert version ?\
)))
530 ;; No function name, so put in a colon unless we have just a star.
531 (unless (save-excursion
532 (beginning-of-line 1)
533 (looking-at "\\s *\\(\\*\\s *\\)?$"))
535 (if version
(insert version ?\
))))))
538 (defun add-change-log-entry-other-window (&optional whoami file-name
)
539 "Find change log file in other window and add an entry for today.
540 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
542 Second optional arg FILE-NAME is file name of change log.
543 If nil, use `change-log-default-name'.
545 Affected by the same options as `add-change-log-entry'."
546 (interactive (if current-prefix-arg
547 (list current-prefix-arg
548 (prompt-for-change-log-name))))
549 (add-change-log-entry whoami file-name t
))
550 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
553 (defun change-log-mode ()
554 "Major mode for editing change logs; like Indented Text Mode.
555 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
556 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
557 Each entry behaves as a paragraph, and the entries for one day as a page.
558 Runs `change-log-mode-hook'."
560 (kill-all-local-variables)
562 (setq major-mode
'change-log-mode
563 mode-name
"Change Log"
568 (use-local-map change-log-mode-map
)
569 (set (make-local-variable 'fill-paragraph-function
)
570 'change-log-fill-paragraph
)
571 ;; We really do want "^" in paragraph-start below: it is only the
572 ;; lines that begin at column 0 (despite the left-margin of 8) that
573 ;; we are looking for. Adding `* ' allows eliding the blank line
574 ;; between entries for different files.
575 (set (make-local-variable 'paragraph-start
) "\\s *$\\|\f\\|^\\<")
576 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
577 ;; Match null string on the date-line so that the date-line
578 ;; is grouped with what follows.
579 (set (make-local-variable 'page-delimiter
) "^\\<\\|^\f")
580 (set (make-local-variable 'version-control
) 'never
)
581 (set (make-local-variable 'adaptive-fill-regexp
) "\\s *")
582 (set (make-local-variable 'font-lock-defaults
)
583 '(change-log-font-lock-keywords t nil nil backward-paragraph
))
584 (run-hooks 'change-log-mode-hook
))
586 ;; It might be nice to have a general feature to replace this. The idea I
587 ;; have is a variable giving a regexp matching text which should not be
588 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
589 ;; But I don't feel up to implementing that today.
590 (defun change-log-fill-paragraph (&optional justify
)
591 "Fill the paragraph, but preserve open parentheses at beginning of lines.
592 Prefix arg means justify as well."
594 (let ((end (progn (forward-paragraph) (point)))
595 (beg (progn (backward-paragraph) (point)))
596 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
597 (fill-region beg end justify
)
600 (defcustom add-log-current-defun-header-regexp
601 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
602 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
607 (defvar add-log-lisp-like-modes
608 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode
)
609 "*Modes that look like Lisp to `add-log-current-defun'.")
612 (defvar add-log-c-like-modes
613 '(c-mode c
++-mode c
++-c-mode objc-mode
)
614 "*Modes that look like C to `add-log-current-defun'.")
617 (defvar add-log-tex-like-modes
618 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode
)
619 "*Modes that look like TeX to `add-log-current-defun'.")
622 (defun add-log-current-defun ()
623 "Return name of function definition point is in, or nil.
625 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
626 Texinfo (@node titles) and Perl.
628 Other modes are handled by a heuristic that looks in the 10K before
629 point for uppercase headings starting in the first column or
630 identifiers followed by `:' or `='. See variables
631 `add-log-current-defun-header-regexp' and
632 `add-log-current-defun-function'
634 Has a preference of looking backwards."
637 (let ((location (point)))
638 (cond (add-log-current-defun-function
639 (funcall add-log-current-defun-function
))
640 ((memq major-mode add-log-lisp-like-modes
)
641 ;; If we are now precisely at the beginning of a defun,
642 ;; make sure beginning-of-defun finds that one
643 ;; rather than the previous one.
644 (or (eobp) (forward-char 1))
646 ;; Make sure we are really inside the defun found,
648 (when (and (looking-at "\\s(")
649 (progn (end-of-defun)
650 (< location
(point)))
651 (progn (forward-sexp -
1)
652 (>= location
(point))))
653 (if (looking-at "\\s(")
655 ;; Skip the defining construct name, typically "defun"
658 ;; The second element is usually a symbol being defined.
659 ;; If it is not, use the first symbol in it.
660 (skip-chars-forward " \t\n'(")
661 (buffer-substring-no-properties (point)
662 (progn (forward-sexp 1)
664 ((and (memq major-mode add-log-c-like-modes
)
667 ;; Use eq instead of = here to avoid
668 ;; error when at bob and char-after
670 (while (eq (char-after (- (point) 2)) ?
\\)
672 (looking-at "[ \t]*#[ \t]*define[ \t]")))
673 ;; Handle a C macro definition.
675 (while (eq (char-after (- (point) 2)) ?
\\) ;not =; note above
677 (search-forward "define")
678 (skip-chars-forward " \t")
679 (buffer-substring-no-properties (point)
680 (progn (forward-sexp 1)
682 ((memq major-mode add-log-c-like-modes
)
684 ;; See if we are in the beginning part of a function,
685 ;; before the open brace. If so, advance forward.
686 (while (not (looking-at "{\\|\\(\\s *$\\)"))
691 (when (progn (end-of-defun)
692 (< location
(point)))
697 ;; Skip back over typedefs of arglist.
698 (while (and (not (bobp))
699 (looking-at "[ \t\n]"))
701 ;; See if this is using the DEFUN macro used in Emacs,
702 ;; or the DEFUN macro used by the C library.
703 (if (condition-case nil
706 (while (= (preceding-char) ?
\\)
711 (looking-at "DEFUN\\b"))
717 (if (= (char-after (point)) ?
\")
720 (skip-chars-forward " ,")))
721 (buffer-substring-no-properties
723 (progn (forward-sexp 1)
725 (if (looking-at "^[+-]")
726 (change-log-get-method-definition)
727 ;; Ordinary C function syntax.
730 ;; Protect against "Unbalanced parens" error.
733 (down-list 1) ; into arglist
735 (skip-chars-backward " \t")
738 ;; Verify initial pos was after
739 ;; real start of function.
742 ;; For this purpose, include the line
743 ;; that has the decl keywords. This
744 ;; may also include some of the
745 ;; comments before the function.
746 (while (and (not (bobp))
749 (looking-at "[^\n\f]")))
751 (>= location
(point)))
752 ;; Consistency check: going down and up
753 ;; shouldn't take us back before BEG.
756 ;; Don't include any final whitespace
757 ;; in the name we use.
758 (skip-chars-backward " \t\n")
761 ;; Now find the right beginning of the name.
762 ;; Include certain keywords if they
764 (setq middle
(point))
766 ;; Ignore these subparts of a class decl
767 ;; and move back to the class name itself.
768 (while (looking-at "public \\|private ")
769 (skip-chars-backward " \t:")
772 (setq middle
(point))
776 "enum \\|struct \\|union \\|class ")
777 (setq middle
(point)))
779 (when (eq (preceding-char) ?
=)
781 (skip-chars-backward " \t")
783 (buffer-substring-no-properties
785 ((memq major-mode add-log-tex-like-modes
)
786 (if (re-search-backward
787 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
790 (goto-char (match-beginning 0))
791 (buffer-substring-no-properties
792 (1+ (point)) ; without initial backslash
793 (line-end-position)))))
794 ((eq major-mode
'texinfo-mode
)
795 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t
)
796 (match-string-no-properties 1)))
797 ((eq major-mode
'perl-mode
)
798 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t
)
799 (match-string-no-properties 1)))
800 ;; Emacs's autoconf-mode installs its own
801 ;; `add-log-current-defun-function'. This applies to
802 ;; a different mode apparently for editing .m4
804 ((eq major-mode
'autoconf-mode
)
805 (if (re-search-backward
806 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t
)
807 (match-string-no-properties 3)))
809 ;; If all else fails, try heuristics
810 (let (case-fold-search
813 (when (re-search-backward
814 add-log-current-defun-header-regexp
817 (setq result
(or (match-string-no-properties 1)
818 (match-string-no-properties 0)))
819 ;; Strip whitespace away
820 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
822 (setq result
(match-string-no-properties 1 result
)))
826 (defvar change-log-get-method-definition-md
)
828 ;; Subroutine used within change-log-get-method-definition.
829 ;; Add the last match in the buffer to the end of `md',
830 ;; followed by the string END; move to the end of that match.
831 (defun change-log-get-method-definition-1 (end)
832 (setq change-log-get-method-definition-md
833 (concat change-log-get-method-definition-md
836 (goto-char (match-end 0)))
838 (defun change-log-get-method-definition ()
839 "For objective C, return the method name if we are in a method."
840 (let ((change-log-get-method-definition-md "["))
842 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t
)
843 (change-log-get-method-definition-1 " ")))
846 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t
)
847 (change-log-get-method-definition-1 "")
848 (while (not (looking-at "[{;]"))
850 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
851 (change-log-get-method-definition-1 ""))
852 (concat change-log-get-method-definition-md
"]"))))))
854 (defun change-log-sortable-date-at ()
855 "Return date of log entry in a consistent form for sorting.
856 Point is assumed to be at the start of the entry."
858 (if (looking-at "^\\sw.........[0-9:+ ]*")
859 (let ((date (match-string-no-properties 0)))
861 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date
)
862 (concat (match-string 1 date
) (match-string 2 date
)
863 (match-string 3 date
))
865 (timezone-make-date-sortable date
)
870 (defun change-log-merge (other-log)
871 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
872 Both must be found in Change Log mode (since the merging depends on
873 the appropriate motion commands).
875 Entries are inserted in chronological order. Both the current and
876 old-style time formats for entries are supported."
877 (interactive "*fLog file name to merge: ")
878 (if (not (eq major-mode
'change-log-mode
))
879 (error "Not in Change Log mode"))
880 (let ((other-buf (find-file-noselect other-log
))
881 (buf (current-buffer))
884 (goto-char (point-min))
885 (set-buffer other-buf
)
886 (goto-char (point-min))
887 (if (not (eq major-mode
'change-log-mode
))
888 (error "%s not found in Change Log mode" other-log
))
889 ;; Loop through all the entries in OTHER-LOG.
891 (setq date1
(change-log-sortable-date-at))
893 end
(progn (forward-page) (point)))
894 ;; Look for an entry in original buffer that isn't later.
895 (with-current-buffer buf
896 (while (and (not (eobp))
897 (string< date1
(change-log-sortable-date-at)))
900 (insert-buffer-substring other-buf start end
)
901 ;; At the end of the original buffer, insert a newline to
902 ;; separate entries and then the rest of the file being
903 ;; merged. Move to the end of it to terminate outer loop.
905 (insert-buffer-substring other-buf start
906 (with-current-buffer other-buf
907 (goto-char (point-max))
911 (defun change-log-redate ()
912 "Fix any old-style date entries in the current log file to default format."
916 (goto-char (point-min))
917 (while (re-search-forward "^\\sw.........[0-9:+ ]*" nil t
)
918 (unless (= 12 (- (match-end 0) (match-beginning 0)))
919 (let* ((date (save-match-data
920 (timezone-fix-time (match-string 0) nil nil
)))
921 (zone (if (consp (aref date
6))
922 (nth 1 (aref date
6)))))
923 (replace-match (format-time-string
925 (encode-time (aref date
5)
935 ;;; add-log.el ends here