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-always-start-new-record nil
121 "*If non-nil, `add-change-log-entry' will always start a new record."
126 (defcustom add-log-buffer-file-name-function nil
127 "*If non-nil, function to call to identify the full filename of a buffer.
128 This function is called with no argument. If this is nil, the default is to
129 use `buffer-file-name'."
130 :type
'(choice (const nil
) function
)
133 (defcustom add-log-file-name-function nil
134 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
135 This function is called with one argument, the value of variable
136 `buffer-file-name' in that buffer. If this is nil, the default is to
137 use the file's name relative to the directory of the change log file."
138 :type
'(choice (const nil
) function
)
142 (defcustom change-log-version-info-enabled nil
143 "*If non-nil, enable recording version numbers with the changes."
148 (defcustom change-log-version-number-regexp-list
149 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
151 ;; (defconst ad-version "2.15"
152 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re
)
153 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
154 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re
)))
155 "*List of regexps to search for version number.
156 The version number must be in group 1.
157 Note: The search is conducted only within 10%, at the beginning of the file."
159 :type
'(repeat regexp
)
162 (defface change-log-date-face
163 '((t (:inherit font-lock-string-face
)))
164 "Face used to highlight dates in date lines."
168 (defface change-log-name-face
169 '((t (:inherit font-lock-constant-face
)))
170 "Face for highlighting author names."
174 (defface change-log-email-face
175 '((t (:inherit font-lock-variable-name-face
)))
176 "Face for highlighting author email addresses."
180 (defface change-log-file-face
181 '((t (:inherit font-lock-function-name-face
)))
182 "Face for highlighting file names."
186 (defface change-log-list-face
187 '((t (:inherit font-lock-keyword-face
)))
188 "Face for highlighting parenthesized lists of functions or variables."
192 (defface change-log-conditionals-face
193 '((t (:inherit font-lock-variable-name-face
)))
194 "Face for highlighting conditionals of the form `[...]'."
198 (defface change-log-function-face
199 '((t (:inherit font-lock-variable-name-face
)))
200 "Face for highlighting items of the form `<....>'."
204 (defface change-log-acknowledgement-face
205 '((t (:inherit font-lock-comment-face
)))
206 "Face for highlighting acknowledgments."
210 (defvar change-log-font-lock-keywords
212 ;; Date lines, new and old styles.
213 ("^\\sw.........[0-9:+ ]*"
214 (0 'change-log-date-face
)
215 ;; Name and e-mail; some people put e-mail in parens, not angles.
216 ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
217 (1 'change-log-name-face
)
218 (2 'change-log-email-face
)))
221 ("^\t\\* \\([^ ,:([\n]+\\)"
222 (1 'change-log-file-face
)
223 ;; Possibly further names in a list:
224 ("\\=, \\([^ ,:([\n]+\\)" nil nil
(1 'change-log-file-face
))
225 ;; Possibly a parenthesized list of names:
226 ("\\= (\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
))
227 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
229 ;; Function or variable names.
230 ("^\t(\\([^) ,:\n]+\\)"
231 (1 'change-log-list-face
)
232 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
235 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals-face
))
237 ;; Function of change.
238 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function-face
))
241 ("\\(^\t\\| \\)\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
242 2 'change-log-acknowledgement-face
))
243 "Additional expressions to highlight in Change Log mode.")
245 (defvar change-log-mode-map
(make-sparse-keymap)
246 "Keymap for Change Log major mode.")
248 (defvar change-log-time-zone-rule nil
249 "Time zone used for calculating change log time stamps.
250 It takes the same format as the TZ argument of `set-time-zone-rule'.
251 If nil, use local time.")
253 (defun add-log-iso8601-time-zone (time)
254 (let* ((utc-offset (or (car (current-time-zone time
)) 0))
255 (sign (if (< utc-offset
0) ?- ?
+))
256 (sec (abs utc-offset
))
261 (format (cond ((not (zerop ss
)) "%c%02d:%02d:%02d")
262 ((not (zerop mm
)) "%c%02d:%02d")
266 (defun add-log-iso8601-time-string ()
267 (if change-log-time-zone-rule
268 (let ((tz (getenv "TZ"))
269 (now (current-time)))
272 (set-time-zone-rule change-log-time-zone-rule
)
274 (format-time-string "%Y-%m-%d " now
)
275 (add-log-iso8601-time-zone now
)))
276 (set-time-zone-rule tz
)))
277 (format-time-string "%Y-%m-%d")))
279 (defun change-log-name ()
280 "Return (system-dependent) default name for a change log file."
281 (or change-log-default-name
282 (if (eq system-type
'vax-vms
)
287 (defun prompt-for-change-log-name ()
288 "Prompt for a change log name."
289 (let* ((default (change-log-name))
290 (name (expand-file-name
291 (read-file-name (format "Log file (default %s): " default
)
293 ;; Handle something that is syntactically a directory name.
294 ;; Look for ChangeLog or whatever in that directory.
295 (if (string= (file-name-nondirectory name
) "")
296 (expand-file-name (file-name-nondirectory default
)
298 ;; Handle specifying a file that is a directory.
299 (if (file-directory-p name
)
300 (expand-file-name (file-name-nondirectory default
)
301 (file-name-as-directory name
))
304 (defun change-log-version-number-search ()
305 "Return version number of current buffer's file.
306 This is the value returned by `vc-workfile-version' or, if that is
307 nil, by matching `change-log-version-number-regexp-list'."
308 (let* ((size (buffer-size))
310 ;; The version number can be anywhere in the file, but
311 ;; restrict search to the file beginning: 10% should be
312 ;; enough to prevent some mishits.
314 ;; Apply percentage only if buffer size is bigger than
316 (if (> size
(* 100 80))
320 (or (and buffer-file-name
(vc-workfile-version buffer-file-name
))
323 (let ((regexps change-log-version-number-regexp-list
))
326 (goto-char (point-min))
327 (when (re-search-forward (pop regexps
) end t
)
328 (setq version
(match-string 1)
333 (defun find-change-log (&optional file-name buffer-file
)
334 "Find a change log file for \\[add-change-log-entry] and return the name.
336 Optional arg FILE-NAME specifies the file to use.
337 If FILE-NAME is nil, use the value of `change-log-default-name'.
338 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
339 \(or whatever we use on this operating system).
341 If 'change-log-default-name' contains a leading directory component, then
342 simply find it in the current directory. Otherwise, search in the current
343 directory and its successive parents for a file so named.
345 Once a file is found, `change-log-default-name' is set locally in the
346 current buffer to the complete file name.
347 Optional arg BUFFER-FILE overrides `buffer-file-name'."
348 ;; If user specified a file name or if this buffer knows which one to use,
351 (setq file-name
(and change-log-default-name
352 (file-name-directory change-log-default-name
)
353 change-log-default-name
))
355 ;; Chase links in the source file
356 ;; and use the change log in the dir where it points.
357 (setq file-name
(or (and (or buffer-file buffer-file-name
)
360 (or buffer-file buffer-file-name
))))
362 (if (file-directory-p file-name
)
363 (setq file-name
(expand-file-name (change-log-name) file-name
)))
364 ;; Chase links before visiting the file.
365 ;; This makes it easier to use a single change log file
366 ;; for several related directories.
367 (setq file-name
(file-chase-links file-name
))
368 (setq file-name
(expand-file-name file-name
))
369 ;; Move up in the dir hierarchy till we find a change log file.
370 (let ((file1 file-name
)
372 (while (and (not (or (get-file-buffer file1
) (file-exists-p file1
)))
373 (progn (setq parent-dir
376 (file-name-directory file1
))))
377 ;; Give up if we are already at the root dir.
378 (not (string= (file-name-directory file1
)
380 ;; Move up to the parent dir and try again.
381 (setq file1
(expand-file-name
382 (file-name-nondirectory (change-log-name))
384 ;; If we found a change log in a parent, use that.
385 (if (or (get-file-buffer file1
) (file-exists-p file1
))
386 (setq file-name file1
)))))
387 ;; Make a local variable in this buffer so we needn't search again.
388 (set (make-local-variable 'change-log-default-name
) file-name
)
391 (defun add-log-file-name (buffer-file log-file
)
392 ;; Never want to add a change log entry for the ChangeLog file itself.
393 (unless (or (null buffer-file
) (string= buffer-file log-file
))
394 (if add-log-file-name-function
395 (funcall add-log-file-name-function buffer-file
)
398 (concat "^" (regexp-quote (file-name-directory log-file
)))
400 (substring buffer-file
(match-end 0))
401 (file-name-nondirectory buffer-file
)))
402 ;; If we have a backup file, it's presumably because we're
403 ;; comparing old and new versions (e.g. for deleted
404 ;; functions) and we'll want to use the original name.
405 (if (backup-file-name-p buffer-file
)
406 (file-name-sans-versions buffer-file
)
410 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
)
411 "Find change log file, and add an entry for today and an item for this file.
412 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
415 Second arg FILE-NAME is file name of the change log.
416 If nil, use the value of `change-log-default-name'.
418 Third arg OTHER-WINDOW non-nil means visit in other window.
420 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
421 never append to an existing entry. Option `add-log-keep-changes-together'
422 otherwise affects whether a new entry is created.
424 Option `add-log-always-start-new-record' non-nil means always create a
425 new record, even when the last record was made on the same date and by
428 The change log file can start with a copyright notice and a copying
429 permission notice. The first blank line indicates the end of these
432 Today's date is calculated according to `change-log-time-zone-rule' if
433 non-nil, otherwise in local time."
434 (interactive (list current-prefix-arg
435 (prompt-for-change-log-name)))
436 (or add-log-full-name
437 (setq add-log-full-name
(user-full-name)))
438 (or add-log-mailing-address
439 (setq add-log-mailing-address user-mail-address
))
442 (setq add-log-full-name
(read-input "Full name: " add-log-full-name
))
443 ;; Note that some sites have room and phone number fields in
444 ;; full name which look silly when inserted. Rather than do
445 ;; anything about that here, let user give prefix argument so that
446 ;; s/he can edit the full name field in prompter if s/he wants.
447 (setq add-log-mailing-address
448 (read-input "Mailing address: " add-log-mailing-address
))))
450 (let* ((defun (add-log-current-defun))
451 (version (and change-log-version-info-enabled
452 (change-log-version-number-search)))
453 (buf-file-name (if add-log-buffer-file-name-function
454 (funcall add-log-buffer-file-name-function
)
456 (buffer-file (if buf-file-name
(expand-file-name buf-file-name
)))
457 (file-name (expand-file-name
458 (or file-name
(find-change-log file-name buffer-file
))))
459 ;; Set ITEM to the file name to use in the new item.
460 (item (add-log-file-name buffer-file file-name
))
463 (if (or (and other-window
(not (equal file-name buffer-file-name
)))
464 (window-dedicated-p (selected-window)))
465 (find-file-other-window file-name
)
466 (find-file file-name
))
467 (or (eq major-mode
'change-log-mode
)
470 (goto-char (point-min))
472 ;; If file starts with a copyright and permission notice, skip them.
473 ;; Assume they end at first blank line.
474 (when (looking-at "Copyright")
475 (search-forward "\n\n")
476 (skip-chars-forward "\n"))
478 ;; Advance into first entry if it is usable; else make new one.
479 (let ((new-entry (concat (funcall add-log-time-format
)
480 " " add-log-full-name
481 " <" add-log-mailing-address
">")))
482 (if (and (not add-log-always-start-new-record
)
483 (looking-at (regexp-quote new-entry
)))
485 (insert new-entry
"\n\n")
488 ;; Determine where we should stop searching for a usable
489 ;; item to add to, within this entry.
492 (if (looking-at "\n*[^\n* \t]")
493 (skip-chars-forward "\n")
494 (if add-log-keep-changes-together
495 (forward-page) ; page delimits entries for date
496 (forward-paragraph))) ; paragraph delimits entries for file
499 ;; Now insert the new line for this item.
500 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t
)
501 ;; Put this file name into the existing empty item.
504 ((and (not new-entry
)
505 (let (case-fold-search)
507 (concat (regexp-quote (concat "* " item
))
508 ;; Don't accept `foo.bar' when
509 ;; looking for `foo':
510 "\\(\\s \\|[(),:]\\)")
512 ;; Add to the existing item for the same file.
513 (re-search-forward "^\\s *$\\|^\\s \\*")
514 (goto-char (match-beginning 0))
515 ;; Delete excess empty lines; make just 2.
516 (while (and (not (eobp)) (looking-at "^\\s *$"))
517 (delete-region (point) (line-beginning-position 2)))
520 (indent-relative-maybe))
523 (while (looking-at "\\sW")
525 (while (and (not (eobp)) (looking-at "^\\s *$"))
526 (delete-region (point) (line-beginning-position 2)))
529 (indent-to left-margin
)
531 (if item
(insert item
))))
532 ;; Now insert the function name, if we have one.
533 ;; Point is at the item for this file,
534 ;; either at the end of the line or at the first blank line.
537 ;; Make it easy to get rid of the function name.
539 (unless (save-excursion
540 (beginning-of-line 1)
541 (looking-at "\\s *$"))
543 ;; See if the prev function name has a message yet or not.
544 ;; If not, merge the two items.
545 (let ((pos (point-marker)))
546 (if (and (skip-syntax-backward " ")
547 (skip-chars-backward "):")
549 (progn (delete-region (+ 1 (point)) (+ 2 (point))) t
)
550 (> fill-column
(+ (current-column) (length defun
) 3)))
551 (progn (delete-region (point) pos
)
555 (set-marker pos nil
))
558 (insert version ?\
)))
559 ;; No function name, so put in a colon unless we have just a star.
560 (unless (save-excursion
561 (beginning-of-line 1)
562 (looking-at "\\s *\\(\\*\\s *\\)?$"))
564 (if version
(insert version ?\
))))))
567 (defun add-change-log-entry-other-window (&optional whoami file-name
)
568 "Find change log file in other window and add entry and item.
569 This is just like `add-change-log-entry' except that it displays
570 the change log file in another window."
571 (interactive (if current-prefix-arg
572 (list current-prefix-arg
573 (prompt-for-change-log-name))))
574 (add-change-log-entry whoami file-name t
))
575 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
578 (defun change-log-mode ()
579 "Major mode for editing change logs; like Indented Text Mode.
580 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
581 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
582 Each entry behaves as a paragraph, and the entries for one day as a page.
583 Runs `change-log-mode-hook'."
585 (kill-all-local-variables)
587 (setq major-mode
'change-log-mode
588 mode-name
"Change Log"
593 (use-local-map change-log-mode-map
)
594 (set (make-local-variable 'fill-paragraph-function
)
595 'change-log-fill-paragraph
)
596 ;; We really do want "^" in paragraph-start below: it is only the
597 ;; lines that begin at column 0 (despite the left-margin of 8) that
598 ;; we are looking for. Adding `* ' allows eliding the blank line
599 ;; between entries for different files.
600 (set (make-local-variable 'paragraph-start
) "\\s *$\\|\f\\|^\\<")
601 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
602 ;; Match null string on the date-line so that the date-line
603 ;; is grouped with what follows.
604 (set (make-local-variable 'page-delimiter
) "^\\<\\|^\f")
605 (set (make-local-variable 'version-control
) 'never
)
606 (set (make-local-variable 'adaptive-fill-regexp
) "\\s *")
607 (set (make-local-variable 'font-lock-defaults
)
608 '(change-log-font-lock-keywords t nil nil backward-paragraph
))
609 (run-hooks 'change-log-mode-hook
))
611 ;; It might be nice to have a general feature to replace this. The idea I
612 ;; have is a variable giving a regexp matching text which should not be
613 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
614 ;; But I don't feel up to implementing that today.
615 (defun change-log-fill-paragraph (&optional justify
)
616 "Fill the paragraph, but preserve open parentheses at beginning of lines.
617 Prefix arg means justify as well."
619 (let ((end (progn (forward-paragraph) (point)))
620 (beg (progn (backward-paragraph) (point)))
621 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
622 (fill-region beg end justify
)
625 (defcustom add-log-current-defun-header-regexp
626 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
627 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
632 (defvar add-log-lisp-like-modes
633 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode
)
634 "*Modes that look like Lisp to `add-log-current-defun'.")
637 (defvar add-log-c-like-modes
638 '(c-mode c
++-mode c
++-c-mode objc-mode
)
639 "*Modes that look like C to `add-log-current-defun'.")
642 (defvar add-log-tex-like-modes
643 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode
)
644 "*Modes that look like TeX to `add-log-current-defun'.")
647 (defun add-log-current-defun ()
648 "Return name of function definition point is in, or nil.
650 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
651 Texinfo (@node titles) and Perl.
653 Other modes are handled by a heuristic that looks in the 10K before
654 point for uppercase headings starting in the first column or
655 identifiers followed by `:' or `='. See variables
656 `add-log-current-defun-header-regexp' and
657 `add-log-current-defun-function'
659 Has a preference of looking backwards."
662 (let ((location (point)))
663 (cond (add-log-current-defun-function
664 (funcall add-log-current-defun-function
))
665 ((memq major-mode add-log-lisp-like-modes
)
666 ;; If we are now precisely at the beginning of a defun,
667 ;; make sure beginning-of-defun finds that one
668 ;; rather than the previous one.
669 (or (eobp) (forward-char 1))
671 ;; Make sure we are really inside the defun found,
673 (when (and (looking-at "\\s(")
674 (progn (end-of-defun)
675 (< location
(point)))
676 (progn (forward-sexp -
1)
677 (>= location
(point))))
678 (if (looking-at "\\s(")
680 ;; Skip the defining construct name, typically "defun"
683 ;; The second element is usually a symbol being defined.
684 ;; If it is not, use the first symbol in it.
685 (skip-chars-forward " \t\n'(")
686 (buffer-substring-no-properties (point)
687 (progn (forward-sexp 1)
689 ((and (memq major-mode add-log-c-like-modes
)
692 ;; Use eq instead of = here to avoid
693 ;; error when at bob and char-after
695 (while (eq (char-after (- (point) 2)) ?
\\)
697 (looking-at "[ \t]*#[ \t]*define[ \t]")))
698 ;; Handle a C macro definition.
700 (while (eq (char-after (- (point) 2)) ?
\\) ;not =; note above
702 (search-forward "define")
703 (skip-chars-forward " \t")
704 (buffer-substring-no-properties (point)
705 (progn (forward-sexp 1)
707 ((memq major-mode add-log-c-like-modes
)
709 ;; See if we are in the beginning part of a function,
710 ;; before the open brace. If so, advance forward.
711 (while (not (looking-at "{\\|\\(\\s *$\\)"))
716 (when (progn (end-of-defun)
717 (< location
(point)))
722 ;; Skip back over typedefs of arglist.
723 (while (and (not (bobp))
724 (looking-at "[ \t\n]"))
726 ;; See if this is using the DEFUN macro used in Emacs,
727 ;; or the DEFUN macro used by the C library.
728 (if (condition-case nil
731 (while (= (preceding-char) ?
\\)
736 (looking-at "DEFUN\\b"))
742 (if (= (char-after (point)) ?
\")
745 (skip-chars-forward " ,")))
746 (buffer-substring-no-properties
748 (progn (forward-sexp 1)
750 (if (looking-at "^[+-]")
751 (change-log-get-method-definition)
752 ;; Ordinary C function syntax.
755 ;; Protect against "Unbalanced parens" error.
758 (down-list 1) ; into arglist
760 (skip-chars-backward " \t")
763 ;; Verify initial pos was after
764 ;; real start of function.
767 ;; For this purpose, include the line
768 ;; that has the decl keywords. This
769 ;; may also include some of the
770 ;; comments before the function.
771 (while (and (not (bobp))
774 (looking-at "[^\n\f]")))
776 (>= location
(point)))
777 ;; Consistency check: going down and up
778 ;; shouldn't take us back before BEG.
781 ;; Don't include any final whitespace
782 ;; in the name we use.
783 (skip-chars-backward " \t\n")
786 ;; Now find the right beginning of the name.
787 ;; Include certain keywords if they
789 (setq middle
(point))
791 ;; Ignore these subparts of a class decl
792 ;; and move back to the class name itself.
793 (while (looking-at "public \\|private ")
794 (skip-chars-backward " \t:")
797 (setq middle
(point))
801 "enum \\|struct \\|union \\|class ")
802 (setq middle
(point)))
804 (when (eq (preceding-char) ?
=)
806 (skip-chars-backward " \t")
808 (buffer-substring-no-properties
810 ((memq major-mode add-log-tex-like-modes
)
811 (if (re-search-backward
812 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
815 (goto-char (match-beginning 0))
816 (buffer-substring-no-properties
817 (1+ (point)) ; without initial backslash
818 (line-end-position)))))
819 ((eq major-mode
'texinfo-mode
)
820 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t
)
821 (match-string-no-properties 1)))
822 ((memq major-mode
'(perl-mode cperl-mode
))
823 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t
)
824 (match-string-no-properties 1)))
825 ;; Emacs's autoconf-mode installs its own
826 ;; `add-log-current-defun-function'. This applies to
827 ;; a different mode apparently for editing .m4
829 ((eq major-mode
'autoconf-mode
)
830 (if (re-search-backward
831 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t
)
832 (match-string-no-properties 3)))
834 ;; If all else fails, try heuristics
835 (let (case-fold-search
838 (when (re-search-backward
839 add-log-current-defun-header-regexp
842 (setq result
(or (match-string-no-properties 1)
843 (match-string-no-properties 0)))
844 ;; Strip whitespace away
845 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
847 (setq result
(match-string-no-properties 1 result
)))
851 (defvar change-log-get-method-definition-md
)
853 ;; Subroutine used within change-log-get-method-definition.
854 ;; Add the last match in the buffer to the end of `md',
855 ;; followed by the string END; move to the end of that match.
856 (defun change-log-get-method-definition-1 (end)
857 (setq change-log-get-method-definition-md
858 (concat change-log-get-method-definition-md
861 (goto-char (match-end 0)))
863 (defun change-log-get-method-definition ()
864 "For objective C, return the method name if we are in a method."
865 (let ((change-log-get-method-definition-md "["))
867 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t
)
868 (change-log-get-method-definition-1 " ")))
871 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t
)
872 (change-log-get-method-definition-1 "")
873 (while (not (looking-at "[{;]"))
875 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
876 (change-log-get-method-definition-1 ""))
877 (concat change-log-get-method-definition-md
"]"))))))
879 (defun change-log-sortable-date-at ()
880 "Return date of log entry in a consistent form for sorting.
881 Point is assumed to be at the start of the entry."
883 (if (looking-at "^\\sw.........[0-9:+ ]*")
884 (let ((date (match-string-no-properties 0)))
886 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date
)
887 (concat (match-string 1 date
) (match-string 2 date
)
888 (match-string 3 date
))
890 (timezone-make-date-sortable date
)
895 (defun change-log-merge (other-log)
896 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
897 Both must be found in Change Log mode (since the merging depends on
898 the appropriate motion commands).
900 Entries are inserted in chronological order. Both the current and
901 old-style time formats for entries are supported."
902 (interactive "*fLog file name to merge: ")
903 (if (not (eq major-mode
'change-log-mode
))
904 (error "Not in Change Log mode"))
905 (let ((other-buf (find-file-noselect other-log
))
906 (buf (current-buffer))
909 (goto-char (point-min))
910 (set-buffer other-buf
)
911 (goto-char (point-min))
912 (if (not (eq major-mode
'change-log-mode
))
913 (error "%s not found in Change Log mode" other-log
))
914 ;; Loop through all the entries in OTHER-LOG.
916 (setq date1
(change-log-sortable-date-at))
918 end
(progn (forward-page) (point)))
919 ;; Look for an entry in original buffer that isn't later.
920 (with-current-buffer buf
921 (while (and (not (eobp))
922 (string< date1
(change-log-sortable-date-at)))
925 (insert-buffer-substring other-buf start end
)
926 ;; At the end of the original buffer, insert a newline to
927 ;; separate entries and then the rest of the file being
928 ;; merged. Move to the end of it to terminate outer loop.
930 (insert-buffer-substring other-buf start
931 (with-current-buffer other-buf
932 (goto-char (point-max))
936 (defun change-log-redate ()
937 "Fix any old-style date entries in the current log file to default format."
941 (goto-char (point-min))
942 (while (re-search-forward "^\\sw.........[0-9:+ ]*" nil t
)
943 (unless (= 12 (- (match-end 0) (match-beginning 0)))
944 (let* ((date (save-match-data
945 (timezone-fix-time (match-string 0) nil nil
)))
946 (zone (if (consp (aref date
6))
947 (nth 1 (aref date
6)))))
948 (replace-match (format-time-string
950 (encode-time (aref date
5)
960 ;;; add-log.el ends here