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 ;; Many modes set this variable, so avoid warnings.
55 (defcustom add-log-current-defun-function nil
56 "*If non-nil, function to guess name of surrounding function.
57 It is used by `add-log-current-defun' in preference to built-in rules.
58 Returns function's name as a string, or nil if outside a function."
59 :type
'(choice (const nil
) function
)
63 (defcustom add-log-full-name nil
64 "*Full name of user, for inclusion in ChangeLog daily headers.
65 This defaults to the value returned by the function `user-full-name'."
66 :type
'(choice (const :tag
"Default" nil
)
71 (defcustom add-log-mailing-address nil
72 "*Electronic mail addresses of user, for inclusion in ChangeLog headers.
73 This defaults to the value of `user-mail-address'. In addition to
74 being a simple string, this value can also be a list. All elements
75 will be recognized as referring to the same user; when creating a new
76 ChangeLog entry, one element will be chosen at random."
77 :type
'(choice (const :tag
"Default" nil
)
78 (string :tag
"String")
79 (repeat :tag
"List of Strings" string
))
82 (defcustom add-log-time-format
'add-log-iso8601-time-string
83 "*Function that defines the time format.
84 For example, `add-log-iso8601-time-string', which gives the
85 date in international ISO 8601 format,
86 and `current-time-string' are two valid values."
87 :type
'(radio (const :tag
"International ISO 8601 format"
88 add-log-iso8601-time-string
)
89 (const :tag
"Old format, as returned by `current-time-string'"
91 (function :tag
"Other"))
94 (defcustom add-log-keep-changes-together nil
95 "*If non-nil, normally keep day's log entries for one file together.
97 Log entries for a given file made with \\[add-change-log-entry] or
98 \\[add-change-log-entry-other-window] will only be added to others \
100 today if this variable is non-nil or that file comes first in today's
101 entries. Otherwise another entry for that file will be started. An
105 * bar (...): change 1
107 in the latter case, \\[add-change-log-entry-other-window] in a \
108 buffer visiting `bar', yields:
112 * bar (...): change 1
117 * bar (...): change 1
120 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
126 (defcustom add-log-always-start-new-record nil
127 "*If non-nil, `add-change-log-entry' will always start a new record."
132 (defcustom add-log-buffer-file-name-function nil
133 "*If non-nil, function to call to identify the full filename of a buffer.
134 This function is called with no argument. If this is nil, the default is to
135 use `buffer-file-name'."
136 :type
'(choice (const nil
) function
)
139 (defcustom add-log-file-name-function nil
140 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
141 This function is called with one argument, the value of variable
142 `buffer-file-name' in that buffer. If this is nil, the default is to
143 use the file's name relative to the directory of the change log file."
144 :type
'(choice (const nil
) function
)
148 (defcustom change-log-version-info-enabled nil
149 "*If non-nil, enable recording version numbers with the changes."
154 (defcustom change-log-version-number-regexp-list
155 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
157 ;; (defconst ad-version "2.15"
158 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re
)
159 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
160 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re
)))
161 "*List of regexps to search for version number.
162 The version number must be in group 1.
163 Note: The search is conducted only within 10%, at the beginning of the file."
165 :type
'(repeat regexp
)
168 (defface change-log-date-face
169 '((t (:inherit font-lock-string-face
)))
170 "Face used to highlight dates in date lines."
174 (defface change-log-name-face
175 '((t (:inherit font-lock-constant-face
)))
176 "Face for highlighting author names."
180 (defface change-log-email-face
181 '((t (:inherit font-lock-variable-name-face
)))
182 "Face for highlighting author email addresses."
186 (defface change-log-file-face
187 '((t (:inherit font-lock-function-name-face
)))
188 "Face for highlighting file names."
192 (defface change-log-list-face
193 '((t (:inherit font-lock-keyword-face
)))
194 "Face for highlighting parenthesized lists of functions or variables."
198 (defface change-log-conditionals-face
199 '((t (:inherit font-lock-variable-name-face
)))
200 "Face for highlighting conditionals of the form `[...]'."
204 (defface change-log-function-face
205 '((t (:inherit font-lock-variable-name-face
)))
206 "Face for highlighting items of the form `<....>'."
210 (defface change-log-acknowledgement-face
211 '((t (:inherit font-lock-comment-face
)))
212 "Face for highlighting acknowledgments."
216 (defvar change-log-font-lock-keywords
218 ;; Date lines, new and old styles.
219 ("^\\sw.........[0-9:+ ]*"
220 (0 'change-log-date-face
)
221 ;; Name and e-mail; some people put e-mail in parens, not angles.
222 ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
223 (1 'change-log-name-face
)
224 (2 'change-log-email-face
)))
227 ("^\t\\* \\([^ ,:([\n]+\\)"
228 (1 'change-log-file-face
)
229 ;; Possibly further names in a list:
230 ("\\=, \\([^ ,:([\n]+\\)" nil nil
(1 'change-log-file-face
))
231 ;; Possibly a parenthesized list of names:
232 ("\\= (\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
))
233 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
235 ;; Function or variable names.
236 ("^\t(\\([^) ,:\n]+\\)"
237 (1 'change-log-list-face
)
238 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 'change-log-list-face
)))
241 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals-face
))
243 ;; Function of change.
244 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function-face
))
247 ("\\(^\t\\| \\)\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
248 2 'change-log-acknowledgement-face
))
249 "Additional expressions to highlight in Change Log mode.")
251 (defvar change-log-mode-map
(make-sparse-keymap)
252 "Keymap for Change Log major mode.")
254 (defvar change-log-time-zone-rule nil
255 "Time zone used for calculating change log time stamps.
256 It takes the same format as the TZ argument of `set-time-zone-rule'.
257 If nil, use local time.")
259 (defun add-log-iso8601-time-zone (time)
260 (let* ((utc-offset (or (car (current-time-zone time
)) 0))
261 (sign (if (< utc-offset
0) ?- ?
+))
262 (sec (abs utc-offset
))
267 (format (cond ((not (zerop ss
)) "%c%02d:%02d:%02d")
268 ((not (zerop mm
)) "%c%02d:%02d")
272 (defun add-log-iso8601-time-string ()
273 (if change-log-time-zone-rule
274 (let ((tz (getenv "TZ"))
275 (now (current-time)))
278 (set-time-zone-rule change-log-time-zone-rule
)
280 (format-time-string "%Y-%m-%d " now
)
281 (add-log-iso8601-time-zone now
)))
282 (set-time-zone-rule tz
)))
283 (format-time-string "%Y-%m-%d")))
285 (defun change-log-name ()
286 "Return (system-dependent) default name for a change log file."
287 (or change-log-default-name
288 (if (eq system-type
'vax-vms
)
293 (defun prompt-for-change-log-name ()
294 "Prompt for a change log name."
295 (let* ((default (change-log-name))
296 (name (expand-file-name
297 (read-file-name (format "Log file (default %s): " default
)
299 ;; Handle something that is syntactically a directory name.
300 ;; Look for ChangeLog or whatever in that directory.
301 (if (string= (file-name-nondirectory name
) "")
302 (expand-file-name (file-name-nondirectory default
)
304 ;; Handle specifying a file that is a directory.
305 (if (file-directory-p name
)
306 (expand-file-name (file-name-nondirectory default
)
307 (file-name-as-directory name
))
310 (defun change-log-version-number-search ()
311 "Return version number of current buffer's file.
312 This is the value returned by `vc-workfile-version' or, if that is
313 nil, by matching `change-log-version-number-regexp-list'."
314 (let* ((size (buffer-size))
316 ;; The version number can be anywhere in the file, but
317 ;; restrict search to the file beginning: 10% should be
318 ;; enough to prevent some mishits.
320 ;; Apply percentage only if buffer size is bigger than
322 (if (> size
(* 100 80)) (+ (point) (/ size
10)))))
323 (or (and buffer-file-name
(vc-workfile-version buffer-file-name
))
326 (let ((regexps change-log-version-number-regexp-list
)
330 (goto-char (point-min))
331 (when (re-search-forward (pop regexps
) limit t
)
332 (setq version
(match-string 1)
338 (defun find-change-log (&optional file-name buffer-file
)
339 "Find a change log file for \\[add-change-log-entry] and return the name.
341 Optional arg FILE-NAME specifies the file to use.
342 If FILE-NAME is nil, use the value of `change-log-default-name'.
343 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
344 \(or whatever we use on this operating system).
346 If 'change-log-default-name' contains a leading directory component, then
347 simply find it in the current directory. Otherwise, search in the current
348 directory and its successive parents for a file so named.
350 Once a file is found, `change-log-default-name' is set locally in the
351 current buffer to the complete file name.
352 Optional arg BUFFER-FILE overrides `buffer-file-name'."
353 ;; If user specified a file name or if this buffer knows which one to use,
356 (setq file-name
(and change-log-default-name
357 (file-name-directory change-log-default-name
)
358 change-log-default-name
))
360 ;; Chase links in the source file
361 ;; and use the change log in the dir where it points.
362 (setq file-name
(or (and (or buffer-file buffer-file-name
)
365 (or buffer-file buffer-file-name
))))
367 (if (file-directory-p file-name
)
368 (setq file-name
(expand-file-name (change-log-name) file-name
)))
369 ;; Chase links before visiting the file.
370 ;; This makes it easier to use a single change log file
371 ;; for several related directories.
372 (setq file-name
(file-chase-links file-name
))
373 (setq file-name
(expand-file-name file-name
))
374 ;; Move up in the dir hierarchy till we find a change log file.
375 (let ((file1 file-name
)
377 (while (and (not (or (get-file-buffer file1
) (file-exists-p file1
)))
378 (progn (setq parent-dir
381 (file-name-directory file1
))))
382 ;; Give up if we are already at the root dir.
383 (not (string= (file-name-directory file1
)
385 ;; Move up to the parent dir and try again.
386 (setq file1
(expand-file-name
387 (file-name-nondirectory (change-log-name))
389 ;; If we found a change log in a parent, use that.
390 (if (or (get-file-buffer file1
) (file-exists-p file1
))
391 (setq file-name file1
)))))
392 ;; Make a local variable in this buffer so we needn't search again.
393 (set (make-local-variable 'change-log-default-name
) file-name
)
396 (defun add-log-file-name (buffer-file log-file
)
397 ;; Never want to add a change log entry for the ChangeLog file itself.
398 (unless (or (null buffer-file
) (string= buffer-file log-file
))
399 (if add-log-file-name-function
400 (funcall add-log-file-name-function buffer-file
)
403 (concat "^" (regexp-quote (file-name-directory log-file
)))
405 (substring buffer-file
(match-end 0))
406 (file-name-nondirectory buffer-file
)))
407 ;; If we have a backup file, it's presumably because we're
408 ;; comparing old and new versions (e.g. for deleted
409 ;; functions) and we'll want to use the original name.
410 (if (backup-file-name-p buffer-file
)
411 (file-name-sans-versions buffer-file
)
415 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
)
416 "Find change log file, and add an entry for today and an item for this file.
417 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
420 Second arg FILE-NAME is file name of the change log.
421 If nil, use the value of `change-log-default-name'.
423 Third arg OTHER-WINDOW non-nil means visit in other window.
425 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
426 never append to an existing entry. Option `add-log-keep-changes-together'
427 otherwise affects whether a new entry is created.
429 Option `add-log-always-start-new-record' non-nil means always create a
430 new record, even when the last record was made on the same date and by
433 The change log file can start with a copyright notice and a copying
434 permission notice. The first blank line indicates the end of these
437 Today's date is calculated according to `change-log-time-zone-rule' if
438 non-nil, otherwise in local time."
439 (interactive (list current-prefix-arg
440 (prompt-for-change-log-name)))
441 (or add-log-full-name
442 (setq add-log-full-name
(user-full-name)))
443 (or add-log-mailing-address
444 (setq add-log-mailing-address user-mail-address
))
447 (setq add-log-full-name
(read-input "Full name: " add-log-full-name
))
448 ;; Note that some sites have room and phone number fields in
449 ;; full name which look silly when inserted. Rather than do
450 ;; anything about that here, let user give prefix argument so that
451 ;; s/he can edit the full name field in prompter if s/he wants.
452 (setq add-log-mailing-address
453 (read-input "Mailing address: " add-log-mailing-address
))))
455 (let* ((defun (add-log-current-defun))
456 (version (and change-log-version-info-enabled
457 (change-log-version-number-search)))
458 (buf-file-name (if add-log-buffer-file-name-function
459 (funcall add-log-buffer-file-name-function
)
461 (buffer-file (if buf-file-name
(expand-file-name buf-file-name
)))
462 (file-name (expand-file-name
463 (or file-name
(find-change-log file-name buffer-file
))))
464 ;; Set ITEM to the file name to use in the new item.
465 (item (add-log-file-name buffer-file file-name
))
468 (unless (equal file-name buffer-file-name
)
469 (if (or other-window
(window-dedicated-p (selected-window)))
470 (find-file-other-window file-name
)
471 (find-file file-name
)))
472 (or (eq major-mode
'change-log-mode
)
475 (goto-char (point-min))
477 ;; If file starts with a copyright and permission notice, skip them.
478 ;; Assume they end at first blank line.
479 (when (looking-at "Copyright")
480 (search-forward "\n\n")
481 (skip-chars-forward "\n"))
483 ;; Advance into first entry if it is usable; else make new one.
484 (let ((new-entries (mapcar (lambda (addr)
485 (concat (funcall add-log-time-format
)
486 " " add-log-full-name
488 (if (consp add-log-mailing-address
)
489 add-log-mailing-address
490 (list add-log-mailing-address
)))))
491 (if (and (not add-log-always-start-new-record
)
493 (dolist (entry new-entries hit
)
494 (when (looking-at (regexp-quote entry
))
497 (insert (nth (random (length new-entries
))
502 ;; Determine where we should stop searching for a usable
503 ;; item to add to, within this entry.
506 (if (looking-at "\n*[^\n* \t]")
507 (skip-chars-forward "\n")
508 (if add-log-keep-changes-together
509 (forward-page) ; page delimits entries for date
510 (forward-paragraph))) ; paragraph delimits entries for file
513 ;; Now insert the new line for this item.
514 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t
)
515 ;; Put this file name into the existing empty item.
518 ((and (not new-entry
)
519 (let (case-fold-search)
521 (concat (regexp-quote (concat "* " item
))
522 ;; Don't accept `foo.bar' when
523 ;; looking for `foo':
524 "\\(\\s \\|[(),:]\\)")
526 ;; Add to the existing item for the same file.
527 (re-search-forward "^\\s *$\\|^\\s \\*")
528 (goto-char (match-beginning 0))
529 ;; Delete excess empty lines; make just 2.
530 (while (and (not (eobp)) (looking-at "^\\s *$"))
531 (delete-region (point) (line-beginning-position 2)))
534 (indent-relative-maybe))
537 (while (looking-at "\\sW")
539 (while (and (not (eobp)) (looking-at "^\\s *$"))
540 (delete-region (point) (line-beginning-position 2)))
543 (indent-to left-margin
)
545 (if item
(insert item
))))
546 ;; Now insert the function name, if we have one.
547 ;; Point is at the item for this file,
548 ;; either at the end of the line or at the first blank line.
550 ;; No function name, so put in a colon unless we have just a star.
551 (unless (save-excursion
552 (beginning-of-line 1)
553 (looking-at "\\s *\\(\\*\\s *\\)?$"))
555 (if version
(insert version ?\
)))
556 ;; Make it easy to get rid of the function name.
558 (unless (save-excursion
559 (beginning-of-line 1)
560 (looking-at "\\s *$"))
562 ;; See if the prev function name has a message yet or not.
563 ;; If not, merge the two items.
564 (let ((pos (point-marker)))
565 (skip-syntax-backward " ")
566 (skip-chars-backward "):")
567 (if (and (looking-at "):")
568 (let ((pos (save-excursion (backward-sexp 1) (point))))
569 (when (equal (buffer-substring pos
(point)) defun
)
570 (delete-region pos
(point)))
571 (> fill-column
(+ (current-column) (length defun
) 4))))
572 (progn (skip-chars-backward ", ")
573 (delete-region (point) pos
)
574 (unless (memq (char-before) '(?\
()) (insert ", ")))
575 (if (looking-at "):")
576 (delete-region (+ 1 (point)) (line-end-position)))
579 (set-marker pos nil
))
581 (if version
(insert version ?\
)))))
584 (defun add-change-log-entry-other-window (&optional whoami file-name
)
585 "Find change log file in other window and add entry and item.
586 This is just like `add-change-log-entry' except that it displays
587 the change log file in another window."
588 (interactive (if current-prefix-arg
589 (list current-prefix-arg
590 (prompt-for-change-log-name))))
591 (add-change-log-entry whoami file-name t
))
592 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
594 (defvar add-log-indent-text
0)
596 (defun add-log-indent ()
600 (skip-chars-forward " \t")
602 ((and (looking-at "\\(.*\\) [^ \n].*[^ \n] <.*>$")
603 ;; Matching the output of add-log-time-format is difficult,
604 ;; but I'll get it has at least two adjacent digits.
605 (string-match "[[:digit:]][[:digit:]]" (match-string 1)))
607 ((looking-at "[^*(]")
608 (+ (current-left-margin) add-log-indent-text
))
609 (t (current-left-margin)))))
610 (pos (save-excursion (indent-line-to indent
) (point))))
611 (if (> pos
(point)) (goto-char pos
))))
615 (define-derived-mode change-log-mode text-mode
"Change Log"
616 "Major mode for editing change logs; like Indented Text Mode.
617 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
618 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
619 Each entry behaves as a paragraph, and the entries for one day as a page.
620 Runs `change-log-mode-hook'."
625 (set (make-local-variable 'fill-paragraph-function
)
626 'change-log-fill-paragraph
)
627 (set (make-local-variable 'indent-line-function
) 'add-log-indent
)
628 (set (make-local-variable 'tab-always-indent
) nil
)
629 ;; We really do want "^" in paragraph-start below: it is only the
630 ;; lines that begin at column 0 (despite the left-margin of 8) that
631 ;; we are looking for. Adding `* ' allows eliding the blank line
632 ;; between entries for different files.
633 (set (make-local-variable 'paragraph-start
) "\\s *$\\|\f\\|^\\<")
634 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
635 ;; Match null string on the date-line so that the date-line
636 ;; is grouped with what follows.
637 (set (make-local-variable 'page-delimiter
) "^\\<\\|^\f")
638 (set (make-local-variable 'version-control
) 'never
)
639 (set (make-local-variable 'smerge-resolve-function
)
640 'change-log-resolve-conflict
)
641 (set (make-local-variable 'adaptive-fill-regexp
) "\\s *")
642 (set (make-local-variable 'font-lock-defaults
)
643 '(change-log-font-lock-keywords t nil nil backward-paragraph
)))
645 ;; It might be nice to have a general feature to replace this. The idea I
646 ;; have is a variable giving a regexp matching text which should not be
647 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
648 ;; But I don't feel up to implementing that today.
649 (defun change-log-fill-paragraph (&optional justify
)
650 "Fill the paragraph, but preserve open parentheses at beginning of lines.
651 Prefix arg means justify as well."
653 (let ((end (progn (forward-paragraph) (point)))
654 (beg (progn (backward-paragraph) (point)))
655 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
656 (fill-region beg end justify
)
659 (defcustom add-log-current-defun-header-regexp
660 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
661 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
666 (defvar add-log-lisp-like-modes
667 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode
)
668 "*Modes that look like Lisp to `add-log-current-defun'.")
671 (defvar add-log-c-like-modes
672 '(c-mode c
++-mode c
++-c-mode objc-mode
)
673 "*Modes that look like C to `add-log-current-defun'.")
676 (defvar add-log-tex-like-modes
677 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode
)
678 "*Modes that look like TeX to `add-log-current-defun'.")
681 (defun add-log-current-defun ()
682 "Return name of function definition point is in, or nil.
684 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
685 Texinfo (@node titles) and Perl.
687 Other modes are handled by a heuristic that looks in the 10K before
688 point for uppercase headings starting in the first column or
689 identifiers followed by `:' or `='. See variables
690 `add-log-current-defun-header-regexp' and
691 `add-log-current-defun-function'.
693 Has a preference of looking backwards."
696 (let ((location (point)))
697 (cond (add-log-current-defun-function
698 (funcall add-log-current-defun-function
))
699 ((memq major-mode add-log-lisp-like-modes
)
700 ;; If we are now precisely at the beginning of a defun,
701 ;; make sure beginning-of-defun finds that one
702 ;; rather than the previous one.
703 (or (eobp) (forward-char 1))
705 ;; Make sure we are really inside the defun found,
707 (when (and (looking-at "\\s(")
708 (progn (end-of-defun)
709 (< location
(point)))
710 (progn (forward-sexp -
1)
711 (>= location
(point))))
712 (if (looking-at "\\s(")
714 ;; Skip the defining construct name, typically "defun"
717 ;; The second element is usually a symbol being defined.
718 ;; If it is not, use the first symbol in it.
719 (skip-chars-forward " \t\n'(")
720 (buffer-substring-no-properties (point)
721 (progn (forward-sexp 1)
723 ((and (memq major-mode add-log-c-like-modes
)
726 ;; Use eq instead of = here to avoid
727 ;; error when at bob and char-after
729 (while (eq (char-after (- (point) 2)) ?
\\)
731 (looking-at "[ \t]*#[ \t]*define[ \t]")))
732 ;; Handle a C macro definition.
734 (while (eq (char-after (- (point) 2)) ?
\\) ;not =; note above
736 (search-forward "define")
737 (skip-chars-forward " \t")
738 (buffer-substring-no-properties (point)
739 (progn (forward-sexp 1)
741 ((memq major-mode add-log-c-like-modes
)
743 ;; See if we are in the beginning part of a function,
744 ;; before the open brace. If so, advance forward.
745 (while (not (looking-at "{\\|\\(\\s *$\\)"))
750 (when (progn (end-of-defun)
751 (< location
(point)))
756 ;; Skip back over typedefs of arglist.
757 (while (and (not (bobp))
758 (looking-at "[ \t\n]"))
760 ;; See if this is using the DEFUN macro used in Emacs,
761 ;; or the DEFUN macro used by the C library.
762 (if (condition-case nil
765 (while (= (preceding-char) ?
\\)
770 (looking-at "DEFUN\\b"))
776 (if (= (char-after (point)) ?
\")
779 (skip-chars-forward " ,")))
780 (buffer-substring-no-properties
782 (progn (forward-sexp 1)
784 (if (looking-at "^[+-]")
785 (change-log-get-method-definition)
786 ;; Ordinary C function syntax.
789 ;; Protect against "Unbalanced parens" error.
792 (down-list 1) ; into arglist
794 (skip-chars-backward " \t")
797 ;; Verify initial pos was after
798 ;; real start of function.
801 ;; For this purpose, include the line
802 ;; that has the decl keywords. This
803 ;; may also include some of the
804 ;; comments before the function.
805 (while (and (not (bobp))
808 (looking-at "[^\n\f]")))
810 (>= location
(point)))
811 ;; Consistency check: going down and up
812 ;; shouldn't take us back before BEG.
815 ;; Don't include any final whitespace
816 ;; in the name we use.
817 (skip-chars-backward " \t\n")
820 ;; Now find the right beginning of the name.
821 ;; Include certain keywords if they
823 (setq middle
(point))
825 ;; Ignore these subparts of a class decl
826 ;; and move back to the class name itself.
827 (while (looking-at "public \\|private ")
828 (skip-chars-backward " \t:")
831 (setq middle
(point))
835 "enum \\|struct \\|union \\|class ")
836 (setq middle
(point)))
838 (when (eq (preceding-char) ?
=)
840 (skip-chars-backward " \t")
842 (buffer-substring-no-properties
844 ((memq major-mode add-log-tex-like-modes
)
845 (if (re-search-backward
846 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
849 (goto-char (match-beginning 0))
850 (buffer-substring-no-properties
851 (1+ (point)) ; without initial backslash
852 (line-end-position)))))
853 ((eq major-mode
'texinfo-mode
)
854 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t
)
855 (match-string-no-properties 1)))
856 ((memq major-mode
'(perl-mode cperl-mode
))
857 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t
)
858 (match-string-no-properties 1)))
859 ;; Emacs's autoconf-mode installs its own
860 ;; `add-log-current-defun-function'. This applies to
861 ;; a different mode apparently for editing .m4
863 ((eq major-mode
'autoconf-mode
)
864 (if (re-search-backward
865 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t
)
866 (match-string-no-properties 3)))
868 ;; If all else fails, try heuristics
869 (let (case-fold-search
872 (when (re-search-backward
873 add-log-current-defun-header-regexp
876 (setq result
(or (match-string-no-properties 1)
877 (match-string-no-properties 0)))
878 ;; Strip whitespace away
879 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
881 (setq result
(match-string-no-properties 1 result
)))
885 (defvar change-log-get-method-definition-md
)
887 ;; Subroutine used within change-log-get-method-definition.
888 ;; Add the last match in the buffer to the end of `md',
889 ;; followed by the string END; move to the end of that match.
890 (defun change-log-get-method-definition-1 (end)
891 (setq change-log-get-method-definition-md
892 (concat change-log-get-method-definition-md
895 (goto-char (match-end 0)))
897 (defun change-log-get-method-definition ()
898 "For objective C, return the method name if we are in a method."
899 (let ((change-log-get-method-definition-md "["))
901 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t
)
902 (change-log-get-method-definition-1 " ")))
905 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t
)
906 (change-log-get-method-definition-1 "")
907 (while (not (looking-at "[{;]"))
909 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
910 (change-log-get-method-definition-1 ""))
911 (concat change-log-get-method-definition-md
"]"))))))
913 (defun change-log-sortable-date-at ()
914 "Return date of log entry in a consistent form for sorting.
915 Point is assumed to be at the start of the entry."
917 (if (looking-at "^\\sw.........[0-9:+ ]*")
918 (let ((date (match-string-no-properties 0)))
920 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date
)
921 (concat (match-string 1 date
) (match-string 2 date
)
922 (match-string 3 date
))
924 (timezone-make-date-sortable date
)
928 (defun change-log-resolve-conflict ()
929 "Function to be used in `smerge-resolve-function'."
930 (let ((buf (current-buffer)))
932 (insert-buffer-substring buf
(match-beginning 1) (match-end 1))
933 (save-match-data (change-log-mode))
934 (let ((other-buf (current-buffer)))
935 (with-current-buffer buf
938 (narrow-to-region (match-beginning 0) (match-end 0))
939 (replace-match (match-string 3) t t
)
940 (change-log-merge other-buf
))))))))
943 (defun change-log-merge (other-log)
944 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
945 Both must be found in Change Log mode (since the merging depends on
946 the appropriate motion commands). OTHER-LOG can be either a file name
949 Entries are inserted in chronological order. Both the current and
950 old-style time formats for entries are supported."
951 (interactive "*fLog file name to merge: ")
952 (if (not (eq major-mode
'change-log-mode
))
953 (error "Not in Change Log mode"))
954 (let ((other-buf (if (bufferp other-log
) other-log
955 (find-file-noselect other-log
)))
956 (buf (current-buffer))
959 (goto-char (point-min))
960 (set-buffer other-buf
)
961 (goto-char (point-min))
962 (if (not (eq major-mode
'change-log-mode
))
963 (error "%s not found in Change Log mode" other-log
))
964 ;; Loop through all the entries in OTHER-LOG.
966 (setq date1
(change-log-sortable-date-at))
968 end
(progn (forward-page) (point)))
969 ;; Look for an entry in original buffer that isn't later.
970 (with-current-buffer buf
971 (while (and (not (eobp))
972 (string< date1
(change-log-sortable-date-at)))
975 (insert-buffer-substring other-buf start end
)
976 ;; At the end of the original buffer, insert a newline to
977 ;; separate entries and then the rest of the file being
980 (and (= ?
\n (char-before))
981 (or (<= (1- (point)) (point-min))
982 (= ?
\n (char-before (1- (point)))))))
984 ;; Move to the end of it to terminate outer loop.
985 (with-current-buffer other-buf
986 (goto-char (point-max)))
987 (insert-buffer-substring other-buf start
)))))))
990 (defun change-log-redate ()
991 "Fix any old-style date entries in the current log file to default format."
995 (goto-char (point-min))
996 (while (re-search-forward "^\\sw.........[0-9:+ ]*" nil t
)
997 (unless (= 12 (- (match-end 0) (match-beginning 0)))
998 (let* ((date (save-match-data
999 (timezone-fix-time (match-string 0) nil nil
)))
1000 (zone (if (consp (aref date
6))
1001 (nth 1 (aref date
6)))))
1002 (replace-match (format-time-string
1004 (encode-time (aref date
5)
1014 ;;; add-log.el ends here