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.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This facility is documented in the Emacs Manual.
34 (defgroup change-log nil
35 "Change log maintenance"
37 :link
'(custom-manual "(emacs)Change Log")
42 (defcustom change-log-default-name nil
43 "*Name of a change log file for \\[add-change-log-entry]."
44 :type
'(choice (const :tag
"default" nil
)
48 (defcustom change-log-mode-hook nil
49 "Normal hook run by `change-log-mode'."
53 (defcustom add-log-current-defun-function nil
54 "*If non-nil, function to guess name of surrounding function.
55 It is used by `add-log-current-defun' in preference to built-in rules.
56 Returns function's name as a string, or nil if outside a function."
57 :type
'(choice (const nil
) function
)
61 (defcustom add-log-full-name nil
62 "*Full name of user, for inclusion in ChangeLog daily headers.
63 This defaults to the value returned by the function `user-full-name'."
64 :type
'(choice (const :tag
"Default" nil
)
69 (defcustom add-log-mailing-address nil
70 "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
71 This defaults to the value of `user-mail-address'."
72 :type
'(choice (const :tag
"Default" nil
)
76 (defcustom add-log-time-format
'add-log-iso8601-time-string
77 "*Function that defines the time format.
78 For example, `add-log-iso8601-time-string', which gives the
79 date in international ISO 8601 format,
80 and `current-time-string' are two valid values."
81 :type
'(radio (const :tag
"International ISO 8601 format"
82 add-log-iso8601-time-string
)
83 (const :tag
"Old format, as returned by `current-time-string'"
85 (function :tag
"Other"))
88 (defcustom add-log-keep-changes-together nil
89 "*If non-nil, normally keep day's log entries for one file together.
91 Log entries for a given file made with \\[add-change-log-entry] or
92 \\[add-change-log-entry-other-window] will only be added to others \
94 today if this variable is non-nil or that file comes first in today's
95 entries. Otherwise another entry for that file will be started. An
101 in the latter case, \\[add-change-log-entry-other-window] in a \
102 buffer visiting `bar', yields:
106 * bar (...): change 1
111 * bar (...): change 1
114 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
120 (defcustom add-log-buffer-file-name-function nil
121 "*If non-nil, function to call to identify the full filename of a buffer.
122 This function is called with no argument. If this is nil, the default is to
123 use `buffer-file-name'."
124 :type
'(choice (const nil
) function
)
127 (defcustom add-log-file-name-function nil
128 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
129 This function is called with one argument, the value of variable
130 `buffer-file-name' in that buffer. If this is nil, the default is to
131 use the file's name relative to the directory of the change log file."
132 :type
'(choice (const nil
) function
)
136 (defcustom change-log-version-info-enabled nil
137 "*If non-nil, enable recording version numbers with the changes."
142 (defcustom change-log-version-number-regexp-list
143 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
145 ;; (defconst ad-version "2.15"
146 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re
)
147 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
148 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re
)))
149 "*List of regexps to search for version number.
150 The version number must be in group 1.
151 Note: The search is conducted only within 10%, at the beginning of the file."
153 :type
'(repeat regexp
)
156 (defface change-log-date-face
157 '((t (:inherit font-lock-string-face
)))
158 "Face used to highlight dates in date lines."
162 (defface change-log-name-face
163 '((t (:inherit font-lock-constant-face
)))
164 "Face for highlighting author names."
168 (defface change-log-email-face
169 '((t (:inherit font-lock-variable-name-face
)))
170 "Face for highlighting author email addresses."
174 (defface change-log-file-face
175 '((t (:inherit font-lock-function-name-face
)))
176 "Face for highlighting file names."
180 (defface change-log-list-face
181 '((t (:inherit font-lock-keyword-face
)))
182 "Face for highlighting parenthesized lists of functions or variables."
186 (defface change-log-conditionals-face
187 '((t (:inherit font-lock-variable-name-face
)))
188 "Face for highlighting conditionals of the form `[...]'."
192 (defface change-log-function-face
193 '((t (:inherit font-lock-variable-name-face
)))
194 "Face for highlighting items of the form `<....>'."
198 (defface change-log-acknowledgement-face
199 '((t (:inherit font-lock-comment-face
)))
200 "Face for highlighting acknowledgments."
204 (defvar change-log-font-lock-keywords
206 ;; Date lines, new and old styles.
207 ("^\\sw.........[0-9:+ ]*"
208 (0 'change-log-date-face
)
209 ;; Name and e-mail; some people put e-mail in parens, not angles.
210 ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
211 (1 'change-log-name-face
)
212 (2 'change-log-email-face
)))
215 ("^\t\\* \\([^ ,:([\n]+\\)"
216 (1 'change-log-file-face
)
217 ;; Possibly further names in a list:
218 ("\\=, \\([^ ,:([\n]+\\)" nil nil
(1 'change-log-file-face
))
219 ;; Possibly a parenthesized list of names:
220 ("\\= (\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
))
221 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
223 ;; Function or variable names.
224 ("^\t(\\([^) ,:\n]+\\)"
225 (1 'change-log-list-face
)
226 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
229 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals-face
))
231 ;; Function of change.
232 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function-face
))
235 ("\\(^\t\\| \\)\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
236 2 'change-log-acknowledgement-face
))
237 "Additional expressions to highlight in Change Log mode.")
239 (defvar change-log-mode-map
(make-sparse-keymap)
240 "Keymap for Change Log major mode.")
242 (defvar change-log-time-zone-rule nil
243 "Time zone used for calculating change log time stamps.
244 It takes the same format as the TZ argument of `set-time-zone-rule'.
245 If nil, use local time.")
247 (defun add-log-iso8601-time-zone (time)
248 (let* ((utc-offset (or (car (current-time-zone time
)) 0))
249 (sign (if (< utc-offset
0) ?- ?
+))
250 (sec (abs utc-offset
))
255 (format (cond ((not (zerop ss
)) "%c%02d:%02d:%02d")
256 ((not (zerop mm
)) "%c%02d:%02d")
260 (defun add-log-iso8601-time-string ()
261 (if change-log-time-zone-rule
262 (let ((tz (getenv "TZ"))
263 (now (current-time)))
266 (set-time-zone-rule change-log-time-zone-rule
)
268 (format-time-string "%Y-%m-%d " now
)
269 (add-log-iso8601-time-zone now
)))
270 (set-time-zone-rule tz
)))
271 (format-time-string "%Y-%m-%d")))
273 (defun change-log-name ()
274 "Return (system-dependent) default name for a change log file."
275 (or change-log-default-name
276 (if (eq system-type
'vax-vms
)
281 (defun prompt-for-change-log-name ()
282 "Prompt for a change log name."
283 (let* ((default (change-log-name))
284 (name (expand-file-name
285 (read-file-name (format "Log file (default %s): " default
)
287 ;; Handle something that is syntactically a directory name.
288 ;; Look for ChangeLog or whatever in that directory.
289 (if (string= (file-name-nondirectory name
) "")
290 (expand-file-name (file-name-nondirectory default
)
292 ;; Handle specifying a file that is a directory.
293 (if (file-directory-p name
)
294 (expand-file-name (file-name-nondirectory default
)
295 (file-name-as-directory name
))
298 (defun change-log-version-number-search ()
299 "Return version number of current buffer's file.
300 This is the value returned by `vc-workfile-version' or, if that is
301 nil, by matching `change-log-version-number-regexp-list'."
302 (let* ((size (buffer-size))
304 ;; The version number can be anywhere in the file, but
305 ;; restrict search to the file beginning: 10% should be
306 ;; enough to prevent some mishits.
308 ;; Apply percentage only if buffer size is bigger than
310 (if (> size
(* 100 80))
314 (or (and buffer-file-name
(vc-workfile-version buffer-file-name
))
317 (let ((regexps change-log-version-number-regexp-list
))
320 (goto-char (point-min))
321 (when (re-search-forward (pop regexps
) end t
)
322 (setq version
(match-string 1)
327 (defun find-change-log (&optional file-name buffer-file
)
328 "Find a change log file for \\[add-change-log-entry] and return the name.
330 Optional arg FILE-NAME specifies the file to use.
331 If FILE-NAME is nil, use the value of `change-log-default-name'.
332 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
333 \(or whatever we use on this operating system).
335 If 'change-log-default-name' contains a leading directory component, then
336 simply find it in the current directory. Otherwise, search in the current
337 directory and its successive parents for a file so named.
339 Once a file is found, `change-log-default-name' is set locally in the
340 current buffer to the complete file name.
341 Optional arg BUFFER-FILE overrides `buffer-file-name'."
342 ;; If user specified a file name or if this buffer knows which one to use,
345 (setq file-name
(and change-log-default-name
346 (file-name-directory change-log-default-name
)
347 change-log-default-name
))
349 ;; Chase links in the source file
350 ;; and use the change log in the dir where it points.
351 (setq file-name
(or (and (or buffer-file buffer-file-name
)
354 (or buffer-file buffer-file-name
))))
356 (if (file-directory-p file-name
)
357 (setq file-name
(expand-file-name (change-log-name) file-name
)))
358 ;; Chase links before visiting the file.
359 ;; This makes it easier to use a single change log file
360 ;; for several related directories.
361 (setq file-name
(file-chase-links file-name
))
362 (setq file-name
(expand-file-name file-name
))
363 ;; Move up in the dir hierarchy till we find a change log file.
364 (let ((file1 file-name
)
366 (while (and (not (or (get-file-buffer file1
) (file-exists-p file1
)))
367 (progn (setq parent-dir
370 (file-name-directory file1
))))
371 ;; Give up if we are already at the root dir.
372 (not (string= (file-name-directory file1
)
374 ;; Move up to the parent dir and try again.
375 (setq file1
(expand-file-name
376 (file-name-nondirectory (change-log-name))
378 ;; If we found a change log in a parent, use that.
379 (if (or (get-file-buffer file1
) (file-exists-p file1
))
380 (setq file-name file1
)))))
381 ;; Make a local variable in this buffer so we needn't search again.
382 (set (make-local-variable 'change-log-default-name
) file-name
)
385 (defun add-log-file-name (buffer-file log-file
)
386 ;; Never want to add a change log entry for the ChangeLog file itself.
387 (unless (or (null buffer-file
) (string= buffer-file log-file
))
388 (if add-log-file-name-function
389 (funcall add-log-file-name-function buffer-file
)
392 (concat "^" (regexp-quote (file-name-directory log-file
)))
394 (substring buffer-file
(match-end 0))
395 (file-name-nondirectory buffer-file
)))
396 ;; If we have a backup file, it's presumably because we're
397 ;; comparing old and new versions (e.g. for deleted
398 ;; functions) and we'll want to use the original name.
399 (if (backup-file-name-p buffer-file
)
400 (file-name-sans-versions buffer-file
)
404 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
)
405 "Find change log file and add an entry for today.
406 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
409 Second arg is FILE-NAME of change log. If nil, uses `change-log-default-name'.
410 Third arg OTHER-WINDOW non-nil means visit in other window.
411 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
412 never append to an existing entry. Option `add-log-keep-changes-together'
413 otherwise affects whether a new entry is created.
415 Today's date is calculated according to `change-log-time-zone-rule' if
416 non-nil, otherwise in local time."
417 (interactive (list current-prefix-arg
418 (prompt-for-change-log-name)))
419 (or add-log-full-name
420 (setq add-log-full-name
(user-full-name)))
421 (or add-log-mailing-address
422 (setq add-log-mailing-address user-mail-address
))
425 (setq add-log-full-name
(read-input "Full name: " add-log-full-name
))
426 ;; Note that some sites have room and phone number fields in
427 ;; full name which look silly when inserted. Rather than do
428 ;; anything about that here, let user give prefix argument so that
429 ;; s/he can edit the full name field in prompter if s/he wants.
430 (setq add-log-mailing-address
431 (read-input "Mailing address: " add-log-mailing-address
))))
433 (let* ((defun (add-log-current-defun))
434 (version (and change-log-version-info-enabled
435 (change-log-version-number-search)))
436 (buf-file-name (if add-log-buffer-file-name-function
437 (funcall add-log-buffer-file-name-function
)
439 (buffer-file (if buf-file-name
(expand-file-name buf-file-name
)))
440 (file-name (expand-file-name
441 (or file-name
(find-change-log file-name buffer-file
))))
442 ;; Set ENTRY to the file name to use in the new entry.
443 (entry (add-log-file-name buffer-file file-name
))
446 (if (or (and other-window
(not (equal file-name buffer-file-name
)))
447 (window-dedicated-p (selected-window)))
448 (find-file-other-window file-name
)
449 (find-file file-name
))
450 (or (eq major-mode
'change-log-mode
)
453 (goto-char (point-min))
454 (let ((new-entry (concat (funcall add-log-time-format
)
455 " " add-log-full-name
456 " <" add-log-mailing-address
">")))
457 (if (looking-at (regexp-quote new-entry
))
459 (insert new-entry
"\n\n")))
463 (if (looking-at "\n*[^\n* \t]")
464 (skip-chars-forward "\n")
465 (if add-log-keep-changes-together
466 (forward-page) ; page delimits entries for date
467 (forward-paragraph))) ; paragraph delimits entries for file
469 (goto-char (point-min))
470 ;; Now insert the new line for this entry.
471 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t
)
472 ;; Put this file name into the existing empty entry.
475 ((and (not new-entry
)
476 (let (case-fold-search)
478 (concat (regexp-quote (concat "* " entry
))
479 ;; Don't accept `foo.bar' when
480 ;; looking for `foo':
481 "\\(\\s \\|[(),:]\\)")
483 ;; Add to the existing entry for the same file.
484 (re-search-forward "^\\s *$\\|^\\s \\*")
485 (goto-char (match-beginning 0))
486 ;; Delete excess empty lines; make just 2.
487 (while (and (not (eobp)) (looking-at "^\\s *$"))
488 (delete-region (point) (line-beginning-position 2)))
491 (indent-relative-maybe))
495 (while (looking-at "\\sW")
497 (while (and (not (eobp)) (looking-at "^\\s *$"))
498 (delete-region (point) (line-beginning-position 2)))
501 (indent-to left-margin
)
503 (if entry
(insert entry
))))
504 ;; Now insert the function name, if we have one.
505 ;; Point is at the entry for this file,
506 ;; either at the end of the line or at the first blank line.
509 ;; Make it easy to get rid of the function name.
511 (unless (save-excursion
512 (beginning-of-line 1)
513 (looking-at "\\s *$"))
515 ;; See if the prev function name has a message yet or not
516 ;; If not, merge the two entries.
517 (let ((pos (point-marker)))
518 (if (and (skip-syntax-backward " ")
519 (skip-chars-backward "):")
521 (progn (delete-region (+ 1 (point)) (+ 2 (point))) t
)
522 (> fill-column
(+ (current-column) (length defun
) 3)))
523 (progn (delete-region (point) pos
)
527 (set-marker pos nil
))
530 (insert version ?\
)))
531 ;; No function name, so put in a colon unless we have just a star.
532 (unless (save-excursion
533 (beginning-of-line 1)
534 (looking-at "\\s *\\(\\*\\s *\\)?$"))
536 (if version
(insert version ?\
))))))
539 (defun add-change-log-entry-other-window (&optional whoami file-name
)
540 "Find change log file in other window and add an entry for today.
541 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
543 Second optional arg FILE-NAME is file name of change log.
544 If nil, use `change-log-default-name'.
546 Affected by the same options as `add-change-log-entry'."
547 (interactive (if current-prefix-arg
548 (list current-prefix-arg
549 (prompt-for-change-log-name))))
550 (add-change-log-entry whoami file-name t
))
551 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
554 (defun change-log-mode ()
555 "Major mode for editing change logs; like Indented Text Mode.
556 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
557 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
558 Each entry behaves as a paragraph, and the entries for one day as a page.
559 Runs `change-log-mode-hook'."
561 (kill-all-local-variables)
563 (setq major-mode
'change-log-mode
564 mode-name
"Change Log"
569 (use-local-map change-log-mode-map
)
570 (set (make-local-variable 'fill-paragraph-function
)
571 'change-log-fill-paragraph
)
572 ;; We really do want "^" in paragraph-start below: it is only the
573 ;; lines that begin at column 0 (despite the left-margin of 8) that
574 ;; we are looking for. Adding `* ' allows eliding the blank line
575 ;; between entries for different files.
576 (set (make-local-variable 'paragraph-start
) "\\s *$\\|\f\\|^\\<")
577 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
578 ;; Match null string on the date-line so that the date-line
579 ;; is grouped with what follows.
580 (set (make-local-variable 'page-delimiter
) "^\\<\\|^\f")
581 (set (make-local-variable 'version-control
) 'never
)
582 (set (make-local-variable 'adaptive-fill-regexp
) "\\s *")
583 (set (make-local-variable 'font-lock-defaults
)
584 '(change-log-font-lock-keywords t nil nil backward-paragraph
))
585 (run-hooks 'change-log-mode-hook
))
587 ;; It might be nice to have a general feature to replace this. The idea I
588 ;; have is a variable giving a regexp matching text which should not be
589 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
590 ;; But I don't feel up to implementing that today.
591 (defun change-log-fill-paragraph (&optional justify
)
592 "Fill the paragraph, but preserve open parentheses at beginning of lines.
593 Prefix arg means justify as well."
595 (let ((end (progn (forward-paragraph) (point)))
596 (beg (progn (backward-paragraph) (point)))
597 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
598 (fill-region beg end justify
)
601 (defcustom add-log-current-defun-header-regexp
602 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
603 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
608 (defvar add-log-lisp-like-modes
609 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode
)
610 "*Modes that look like Lisp to `add-log-current-defun'.")
613 (defvar add-log-c-like-modes
614 '(c-mode c
++-mode c
++-c-mode objc-mode
)
615 "*Modes that look like C to `add-log-current-defun'.")
618 (defvar add-log-tex-like-modes
619 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode
)
620 "*Modes that look like TeX to `add-log-current-defun'.")
623 (defun add-log-current-defun ()
624 "Return name of function definition point is in, or nil.
626 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
627 Texinfo (@node titles) and Perl.
629 Other modes are handled by a heuristic that looks in the 10K before
630 point for uppercase headings starting in the first column or
631 identifiers followed by `:' or `='. See variables
632 `add-log-current-defun-header-regexp' and
633 `add-log-current-defun-function'
635 Has a preference of looking backwards."
638 (let ((location (point)))
639 (cond (add-log-current-defun-function
640 (funcall add-log-current-defun-function
))
641 ((memq major-mode add-log-lisp-like-modes
)
642 ;; If we are now precisely at the beginning of a defun,
643 ;; make sure beginning-of-defun finds that one
644 ;; rather than the previous one.
645 (or (eobp) (forward-char 1))
647 ;; Make sure we are really inside the defun found,
649 (when (and (looking-at "\\s(")
650 (progn (end-of-defun)
651 (< location
(point)))
652 (progn (forward-sexp -
1)
653 (>= location
(point))))
654 (if (looking-at "\\s(")
656 ;; Skip the defining construct name, typically "defun"
659 ;; The second element is usually a symbol being defined.
660 ;; If it is not, use the first symbol in it.
661 (skip-chars-forward " \t\n'(")
662 (buffer-substring-no-properties (point)
663 (progn (forward-sexp 1)
665 ((and (memq major-mode add-log-c-like-modes
)
668 ;; Use eq instead of = here to avoid
669 ;; error when at bob and char-after
671 (while (eq (char-after (- (point) 2)) ?
\\)
673 (looking-at "[ \t]*#[ \t]*define[ \t]")))
674 ;; Handle a C macro definition.
676 (while (eq (char-after (- (point) 2)) ?
\\) ;not =; note above
678 (search-forward "define")
679 (skip-chars-forward " \t")
680 (buffer-substring-no-properties (point)
681 (progn (forward-sexp 1)
683 ((memq major-mode add-log-c-like-modes
)
685 ;; See if we are in the beginning part of a function,
686 ;; before the open brace. If so, advance forward.
687 (while (not (looking-at "{\\|\\(\\s *$\\)"))
692 (when (progn (end-of-defun)
693 (< location
(point)))
698 ;; Skip back over typedefs of arglist.
699 (while (and (not (bobp))
700 (looking-at "[ \t\n]"))
702 ;; See if this is using the DEFUN macro used in Emacs,
703 ;; or the DEFUN macro used by the C library.
704 (if (condition-case nil
707 (while (= (preceding-char) ?
\\)
712 (looking-at "DEFUN\\b"))
718 (if (= (char-after (point)) ?
\")
721 (skip-chars-forward " ,")))
722 (buffer-substring-no-properties
724 (progn (forward-sexp 1)
726 (if (looking-at "^[+-]")
727 (change-log-get-method-definition)
728 ;; Ordinary C function syntax.
731 ;; Protect against "Unbalanced parens" error.
734 (down-list 1) ; into arglist
736 (skip-chars-backward " \t")
739 ;; Verify initial pos was after
740 ;; real start of function.
743 ;; For this purpose, include the line
744 ;; that has the decl keywords. This
745 ;; may also include some of the
746 ;; comments before the function.
747 (while (and (not (bobp))
750 (looking-at "[^\n\f]")))
752 (>= location
(point)))
753 ;; Consistency check: going down and up
754 ;; shouldn't take us back before BEG.
757 ;; Don't include any final whitespace
758 ;; in the name we use.
759 (skip-chars-backward " \t\n")
762 ;; Now find the right beginning of the name.
763 ;; Include certain keywords if they
765 (setq middle
(point))
767 ;; Ignore these subparts of a class decl
768 ;; and move back to the class name itself.
769 (while (looking-at "public \\|private ")
770 (skip-chars-backward " \t:")
773 (setq middle
(point))
777 "enum \\|struct \\|union \\|class ")
778 (setq middle
(point)))
780 (when (eq (preceding-char) ?
=)
782 (skip-chars-backward " \t")
784 (buffer-substring-no-properties
786 ((memq major-mode add-log-tex-like-modes
)
787 (if (re-search-backward
788 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
791 (goto-char (match-beginning 0))
792 (buffer-substring-no-properties
793 (1+ (point)) ; without initial backslash
794 (line-end-position)))))
795 ((eq major-mode
'texinfo-mode
)
796 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t
)
797 (match-string-no-properties 1)))
798 ((memq major-mode
'(perl-mode cperl-mode
))
799 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t
)
800 (match-string-no-properties 1)))
801 ;; Emacs's autoconf-mode installs its own
802 ;; `add-log-current-defun-function'. This applies to
803 ;; a different mode apparently for editing .m4
805 ((eq major-mode
'autoconf-mode
)
806 (if (re-search-backward
807 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t
)
808 (match-string-no-properties 3)))
810 ;; If all else fails, try heuristics
811 (let (case-fold-search
814 (when (re-search-backward
815 add-log-current-defun-header-regexp
818 (setq result
(or (match-string-no-properties 1)
819 (match-string-no-properties 0)))
820 ;; Strip whitespace away
821 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
823 (setq result
(match-string-no-properties 1 result
)))
827 (defvar change-log-get-method-definition-md
)
829 ;; Subroutine used within change-log-get-method-definition.
830 ;; Add the last match in the buffer to the end of `md',
831 ;; followed by the string END; move to the end of that match.
832 (defun change-log-get-method-definition-1 (end)
833 (setq change-log-get-method-definition-md
834 (concat change-log-get-method-definition-md
837 (goto-char (match-end 0)))
839 (defun change-log-get-method-definition ()
840 "For objective C, return the method name if we are in a method."
841 (let ((change-log-get-method-definition-md "["))
843 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t
)
844 (change-log-get-method-definition-1 " ")))
847 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t
)
848 (change-log-get-method-definition-1 "")
849 (while (not (looking-at "[{;]"))
851 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
852 (change-log-get-method-definition-1 ""))
853 (concat change-log-get-method-definition-md
"]"))))))
855 (defun change-log-sortable-date-at ()
856 "Return date of log entry in a consistent form for sorting.
857 Point is assumed to be at the start of the entry."
859 (if (looking-at "^\\sw.........[0-9:+ ]*")
860 (let ((date (match-string-no-properties 0)))
862 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date
)
863 (concat (match-string 1 date
) (match-string 2 date
)
864 (match-string 3 date
))
866 (timezone-make-date-sortable date
)
871 (defun change-log-merge (other-log)
872 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
873 Both must be found in Change Log mode (since the merging depends on
874 the appropriate motion commands).
876 Entries are inserted in chronological order. Both the current and
877 old-style time formats for entries are supported."
878 (interactive "*fLog file name to merge: ")
879 (if (not (eq major-mode
'change-log-mode
))
880 (error "Not in Change Log mode"))
881 (let ((other-buf (find-file-noselect other-log
))
882 (buf (current-buffer))
885 (goto-char (point-min))
886 (set-buffer other-buf
)
887 (goto-char (point-min))
888 (if (not (eq major-mode
'change-log-mode
))
889 (error "%s not found in Change Log mode" other-log
))
890 ;; Loop through all the entries in OTHER-LOG.
892 (setq date1
(change-log-sortable-date-at))
894 end
(progn (forward-page) (point)))
895 ;; Look for an entry in original buffer that isn't later.
896 (with-current-buffer buf
897 (while (and (not (eobp))
898 (string< date1
(change-log-sortable-date-at)))
901 (insert-buffer-substring other-buf start end
)
902 ;; At the end of the original buffer, insert a newline to
903 ;; separate entries and then the rest of the file being
904 ;; merged. Move to the end of it to terminate outer loop.
906 (insert-buffer-substring other-buf start
907 (with-current-buffer other-buf
908 (goto-char (point-max))
912 (defun change-log-redate ()
913 "Fix any old-style date entries in the current log file to default format."
917 (goto-char (point-min))
918 (while (re-search-forward "^\\sw.........[0-9:+ ]*" nil t
)
919 (unless (= 12 (- (match-end 0) (match-beginning 0)))
920 (let* ((date (save-match-data
921 (timezone-fix-time (match-string 0) nil nil
)))
922 (zone (if (consp (aref date
6))
923 (nth 1 (aref date
6)))))
924 (replace-match (format-time-string
926 (encode-time (aref date
5)
936 ;;; add-log.el ends here