1 ;;; add-log.el --- change log maintenance commands for Emacs
3 ;; Copyright (C) 1985, 86, 88, 93, 94, 97, 1998, 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.
35 (defgroup change-log nil
36 "Change log maintenance"
38 :link
'(custom-manual "(emacs)Change Log")
43 (defcustom change-log-default-name nil
44 "*Name of a change log file for \\[add-change-log-entry]."
45 :type
'(choice (const :tag
"default" nil
)
49 (defcustom change-log-mode-hook nil
50 "Normal hook run by `change-log-mode'."
54 (defcustom add-log-current-defun-function nil
56 *If non-nil, function to guess name of current function from surrounding text.
57 \\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
58 instead) with no arguments. It returns a string or nil if it cannot guess."
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 address of user, for inclusion in ChangeLog daily headers.
73 This defaults to the value of `user-mail-address'."
74 :type
'(choice (const :tag
"Default" nil
)
78 (defcustom add-log-time-format
'add-log-iso8601-time-string
79 "*Function that defines the time format.
80 For example, `add-log-iso8601-time-string', which gives the
81 date in international ISO 8601 format,
82 and `current-time-string' are two valid values."
83 :type
'(radio (const :tag
"International ISO 8601 format"
84 add-log-iso8601-time-string
)
85 (const :tag
"Old format, as returned by `current-time-string'"
87 (function :tag
"Other"))
90 (defcustom add-log-keep-changes-together nil
91 "*If non-nil, normally keep day's log entries for one file together.
93 Log entries for a given file made with \\[add-change-log-entry] or
94 \\[add-change-log-entry-other-window] will only be added to others \
96 today if this variable is non-nil or that file comes first in today's
97 entries. Otherwise another entry for that file will be started. An
101 * bar (...): change 1
103 in the latter case, \\[add-change-log-entry-other-window] in a \
104 buffer visiting `bar', yields:
108 * bar (...): change 1
113 * bar (...): change 1
116 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
122 (defcustom add-log-file-name-function nil
123 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
124 This function is called with one argument, the value of variable
125 `buffer-file-name' in that buffer. If this is nil, the default is to
126 use the file's name relative to the directory of the change log file."
131 (defcustom change-log-version-info-enabled nil
132 "*If non-nil, enable recording version numbers with the changes."
137 (defcustom change-log-version-number-regexp-list
138 (let ((re "\\([0-9]+\.[0-9.]+\\)"))
140 ;; (defconst ad-version "2.15"
141 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re
)
142 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
143 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re
)
144 ;; SCCS @(#)igrep.el 2.83
145 (concat "SCCS[ \t]+@(#).*[ \t]+" re
)
147 "*List of regexps to search for version number.
148 Note: The search is conducted only within 10%, at the beginning of the file."
150 :type
'(repeat regexp
)
154 (defvar change-log-font-lock-keywords
156 ;; Date lines, new and old styles.
157 ("^\\sw.........[0-9:+ ]*"
158 (0 font-lock-string-face
)
159 ;; Name and e-mail; some people put e-mail in parens, not angles.
160 ("\\([^<(]+\\)[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
161 (1 font-lock-constant-face
)
162 (2 font-lock-variable-name-face
)))
165 ("^\t\\* \\([^ ,:([\n]+\\)"
166 (1 font-lock-function-name-face
)
167 ;; Possibly further names in a list:
168 ("\\=, \\([^ ,:([\n]+\\)" nil nil
(1 font-lock-function-name-face
))
169 ;; Possibly a parenthesized list of names:
170 ("\\= (\\([^) ,:\n]+\\)" nil nil
(1 font-lock-keyword-face
))
171 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 font-lock-keyword-face
)))
173 ;; Function or variable names.
174 ("^\t(\\([^) ,:\n]+\\)"
175 (1 font-lock-keyword-face
)
176 ("\\=, *\\([^) ,:\n]+\\)" nil nil
(1 font-lock-keyword-face
)))
179 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 font-lock-variable-name-face
))
182 ("^\t\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
183 1 font-lock-comment-face
)
184 (" \\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
185 1 font-lock-comment-face
))
186 "Additional expressions to highlight in Change Log mode.")
188 (defvar change-log-mode-map nil
189 "Keymap for Change Log major mode.")
190 (if change-log-mode-map
192 (setq change-log-mode-map
(make-sparse-keymap)))
194 (defvar change-log-time-zone-rule nil
195 "Time zone used for calculating change log time stamps.
196 It takes the same format as the TZ argument of `set-time-zone-rule'.
197 If nil, use local time.")
199 (defun add-log-iso8601-time-zone (time)
200 (let* ((utc-offset (or (car (current-time-zone time
)) 0))
201 (sign (if (< utc-offset
0) ?- ?
+))
202 (sec (abs utc-offset
))
207 (format (cond ((not (zerop ss
)) "%c%02d:%02d:%02d")
208 ((not (zerop mm
)) "%c%02d:%02d")
212 (defun add-log-iso8601-time-string ()
213 (if change-log-time-zone-rule
214 (let ((tz (getenv "TZ"))
215 (now (current-time)))
219 change-log-time-zone-rule
)
221 (format-time-string "%Y-%m-%d " now
)
222 (add-log-iso8601-time-zone now
)))
223 (set-time-zone-rule tz
)))
224 (format-time-string "%Y-%m-%d")))
226 (defun change-log-name ()
227 "Return (system-dependent) default name for a change log file."
228 (or change-log-default-name
229 (if (eq system-type
'vax-vms
)
234 (defun prompt-for-change-log-name ()
235 "Prompt for a change log name."
236 (let* ((default (change-log-name))
237 (name (expand-file-name
238 (read-file-name (format "Log file (default %s): " default
)
240 ;; Handle something that is syntactically a directory name.
241 ;; Look for ChangeLog or whatever in that directory.
242 (if (string= (file-name-nondirectory name
) "")
243 (expand-file-name (file-name-nondirectory default
)
245 ;; Handle specifying a file that is a directory.
246 (if (file-directory-p name
)
247 (expand-file-name (file-name-nondirectory default
)
248 (file-name-as-directory name
))
251 (defun change-log-version-rcs (rcs-string &optional end
)
252 "Search for plain RCS-STRING from whole buffer up till END.
253 The surrounding $ characters fro RCS-STRING are added in this function;
254 provide argument e.g. as \"Id\"."
257 (goto-char (point-min))
258 (when (re-search-forward
259 (concat "[$]" rcs-string
":[^\n$]+[$]")
261 (setq str
(match-string 0))
262 (when (string-match "[0-9]+\.[0-9.]+" str
)
263 (match-string 0 str
))))))
265 (defun change-log-version-number-search ()
266 "Return version number for the file by searchin version control tags."
267 (let* ((size (buffer-size))
269 ;; The version number can be anywhere in the file, but restrict
270 ;; search to the file beginning: 10% should be enough to prevent
273 ;; Apply percentage only if buffer size is bigger than approx 100 lines
274 (if (> size
(* 100 80))
275 (/ (* (buffer-size) 10) 100)
279 ;; Search RCS, CVS version strings
281 (dolist (choice '("Revision" "Id"))
282 (when (setq version
(change-log-version-rcs choice end
))
286 (dolist (regexp change-log-version-number-regexp-list
)
288 (goto-char (point-min))
289 (when (re-search-forward regexp end t
)
290 (setq version
(match-string 1))
298 (defun find-change-log (&optional file-name
)
299 "Find a change log file for \\[add-change-log-entry] and return the name.
301 Optional arg FILE-NAME specifies the file to use.
302 If FILE-NAME is nil, use the value of `change-log-default-name'.
303 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
304 \(or whatever we use on this operating system).
306 If 'change-log-default-name' contains a leading directory component, then
307 simply find it in the current directory. Otherwise, search in the current
308 directory and its successive parents for a file so named.
310 Once a file is found, `change-log-default-name' is set locally in the
311 current buffer to the complete file name."
312 ;; If user specified a file name or if this buffer knows which one to use,
315 (setq file-name
(and change-log-default-name
316 (file-name-directory change-log-default-name
)
317 change-log-default-name
))
319 ;; Chase links in the source file
320 ;; and use the change log in the dir where it points.
321 (setq file-name
(or (and buffer-file-name
323 (file-chase-links buffer-file-name
)))
325 (if (file-directory-p file-name
)
326 (setq file-name
(expand-file-name (change-log-name) file-name
)))
327 ;; Chase links before visiting the file.
328 ;; This makes it easier to use a single change log file
329 ;; for several related directories.
330 (setq file-name
(file-chase-links file-name
))
331 (setq file-name
(expand-file-name file-name
))
332 ;; Move up in the dir hierarchy till we find a change log file.
333 (let ((file1 file-name
)
335 (while (and (not (or (get-file-buffer file1
) (file-exists-p file1
)))
336 (progn (setq parent-dir
339 (file-name-directory file1
))))
340 ;; Give up if we are already at the root dir.
341 (not (string= (file-name-directory file1
)
343 ;; Move up to the parent dir and try again.
344 (setq file1
(expand-file-name
345 (file-name-nondirectory (change-log-name))
347 ;; If we found a change log in a parent, use that.
348 (if (or (get-file-buffer file1
) (file-exists-p file1
))
349 (setq file-name file1
)))))
350 ;; Make a local variable in this buffer so we needn't search again.
351 (set (make-local-variable 'change-log-default-name
) file-name
)
355 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
)
356 "Find change log file and add an entry for today.
357 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
360 Second arg is FILE-NAME of change log. If nil, uses `change-log-default-name'.
361 Third arg OTHER-WINDOW non-nil means visit in other window.
362 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
363 never append to an existing entry. Option `add-log-keep-changes-together'
364 otherwise affects whether a new entry is created.
366 Today's date is calculated according to `change-log-time-zone-rule' if
367 non-nil, otherwise in local time."
368 (interactive (list current-prefix-arg
369 (prompt-for-change-log-name)))
370 (or add-log-full-name
371 (setq add-log-full-name
(user-full-name)))
372 (or add-log-mailing-address
373 (setq add-log-mailing-address user-mail-address
))
376 (setq add-log-full-name
(read-input "Full name: " add-log-full-name
))
377 ;; Note that some sites have room and phone number fields in
378 ;; full name which look silly when inserted. Rather than do
379 ;; anything about that here, let user give prefix argument so that
380 ;; s/he can edit the full name field in prompter if s/he wants.
381 (setq add-log-mailing-address
382 (read-input "Mailing address: " add-log-mailing-address
))))
383 (let ((defun (funcall (or add-log-current-defun-function
384 'add-log-current-defun
)))
385 (version (and change-log-version-info-enabled
386 (change-log-version-number-search)))
390 (setq file-name
(expand-file-name (find-change-log file-name
)))
392 ;; Set ENTRY to the file name to use in the new entry.
393 (and buffer-file-name
394 ;; Never want to add a change log entry for the ChangeLog file itself.
395 (not (string= buffer-file-name file-name
))
396 (if add-log-file-name-function
398 (funcall add-log-file-name-function buffer-file-name
))
401 (concat "^" (regexp-quote (file-name-directory
404 (substring buffer-file-name
(match-end 0))
405 (file-name-nondirectory buffer-file-name
)))
406 ;; If we have a backup file, it's presumably because we're
407 ;; comparing old and new versions (e.g. for deleted
408 ;; functions) and we'll want to use the original name.
409 (if (backup-file-name-p entry
)
410 (setq entry
(file-name-sans-versions entry
)))))
412 (if (and other-window
(not (equal file-name buffer-file-name
)))
413 (find-file-other-window file-name
)
414 (find-file file-name
))
415 (or (eq major-mode
'change-log-mode
)
418 (goto-char (point-min))
419 (let ((new-entry (concat (funcall add-log-time-format
)
420 " " add-log-full-name
421 " <" add-log-mailing-address
">")))
422 (if (looking-at (regexp-quote new-entry
))
424 (insert new-entry
"\n\n")))
428 (if (looking-at "\n*[^\n* \t]")
429 (skip-chars-forward "\n")
430 (if add-log-keep-changes-together
431 (forward-page) ; page delimits entries for date
432 (forward-paragraph))) ; paragraph delimits entries for file
434 (goto-char (point-min))
435 ;; Now insert the new line for this entry.
436 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t
)
437 ;; Put this file name into the existing empty entry.
440 ((and (not new-entry
)
441 (let (case-fold-search)
443 (concat (regexp-quote (concat "* " entry
))
444 ;; Don't accept `foo.bar' when
445 ;; looking for `foo':
446 "\\(\\s \\|[(),:]\\)")
448 ;; Add to the existing entry for the same file.
449 (re-search-forward "^\\s *$\\|^\\s \\*")
450 (goto-char (match-beginning 0))
451 ;; Delete excess empty lines; make just 2.
452 (while (and (not (eobp)) (looking-at "^\\s *$"))
453 (delete-region (point) (save-excursion (forward-line 1) (point))))
456 (indent-relative-maybe))
460 (while (looking-at "\\sW")
462 (while (and (not (eobp)) (looking-at "^\\s *$"))
463 (delete-region (point) (save-excursion (forward-line 1) (point))))
466 (indent-to left-margin
)
467 (insert "* " (or entry
""))
469 ;; Now insert the function name, if we have one.
470 ;; Point is at the entry for this file,
471 ;; either at the end of the line or at the first blank line.
474 ;; Make it easy to get rid of the function name.
476 (insert (if (save-excursion
477 (beginning-of-line 1)
478 (looking-at "\\s *$"))
485 ;; No function name, so put in a colon unless we have just a star.
486 (if (not (save-excursion
487 (beginning-of-line 1)
488 (looking-at "\\s *\\(\\*\\s *\\)?$")))
491 (concat version
" ") ""))))))
494 (defun add-change-log-entry-other-window (&optional whoami file-name
)
495 "Find change log file in other window and add an entry for today.
496 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
498 Second optional arg FILE-NAME is file name of change log.
499 If nil, use `change-log-default-name'.
501 Affected by the same options as `add-change-log-entry'."
502 (interactive (if current-prefix-arg
503 (list current-prefix-arg
504 (prompt-for-change-log-name))))
505 (add-change-log-entry whoami file-name t
))
506 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
509 (defun change-log-mode ()
510 "Major mode for editing change logs; like Indented Text Mode.
511 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
512 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
513 Each entry behaves as a paragraph, and the entries for one day as a page.
514 Runs `change-log-mode-hook'."
516 (kill-all-local-variables)
518 (setq major-mode
'change-log-mode
519 mode-name
"Change Log"
524 (use-local-map change-log-mode-map
)
525 (set (make-local-variable 'fill-paragraph-function
)
526 'change-log-fill-paragraph
)
527 ;; We really do want "^" in paragraph-start below: it is only the
528 ;; lines that begin at column 0 (despite the left-margin of 8) that
529 ;; we are looking for. Adding `* ' allows eliding the blank line
530 ;; between entries for different files.
531 (set (make-local-variable 'paragraph-start
) "\\s *$\\|\f\\|^\\<")
532 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
533 ;; Match null string on the date-line so that the date-line
534 ;; is grouped with what follows.
535 (set (make-local-variable 'page-delimiter
) "^\\<\\|^\f")
536 (set (make-local-variable 'version-control
) 'never
)
537 (set (make-local-variable 'adaptive-fill-regexp
) "\\s *")
538 (set (make-local-variable 'font-lock-defaults
)
539 '(change-log-font-lock-keywords t
))
540 (run-hooks 'change-log-mode-hook
))
542 ;; It might be nice to have a general feature to replace this. The idea I
543 ;; have is a variable giving a regexp matching text which should not be
544 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
545 ;; But I don't feel up to implementing that today.
546 (defun change-log-fill-paragraph (&optional justify
)
547 "Fill the paragraph, but preserve open parentheses at beginning of lines.
548 Prefix arg means justify as well."
550 (let ((end (progn (forward-paragraph) (point)))
551 (beg (progn (backward-paragraph) (point)))
552 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
553 (fill-region beg end justify
)
556 (defcustom add-log-current-defun-header-regexp
557 "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[-_a-zA-Z]+\\)[ \t]*[:=]"
558 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
563 (defvar add-log-lisp-like-modes
564 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode
)
565 "*Modes that look like Lisp to `add-log-current-defun'.")
568 (defvar add-log-c-like-modes
569 '(c-mode c
++-mode c
++-c-mode objc-mode
)
570 "*Modes that look like C to `add-log-current-defun'.")
573 (defvar add-log-tex-like-modes
574 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode
)
575 "*Modes that look like TeX to `add-log-current-defun'.")
578 (defun add-log-current-defun ()
579 "Return name of function definition point is in, or nil.
581 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
582 Texinfo (@node titles), Perl, and Fortran.
584 Other modes are handled by a heuristic that looks in the 10K before
585 point for uppercase headings starting in the first column or
586 identifiers followed by `:' or `=', see variables
587 `add-log-current-defun-header-regexp' and
588 `add-log-current-defun-function'
590 Has a preference of looking backwards."
593 (let ((location (point)))
594 (cond ((and (functionp add-log-current-defun-function
)
595 (funcall add-log-current-defun-function
)))
596 ((memq major-mode add-log-lisp-like-modes
)
597 ;; If we are now precisely at the beginning of a defun,
598 ;; make sure beginning-of-defun finds that one
599 ;; rather than the previous one.
600 (or (eobp) (forward-char 1))
602 ;; Make sure we are really inside the defun found, not after it.
603 (when (and (looking-at "\\s(")
604 (progn (end-of-defun)
605 (< location
(point)))
606 (progn (forward-sexp -
1)
607 (>= location
(point))))
608 (if (looking-at "\\s(")
610 ;; Skip the defining construct name, typically "defun"
613 ;; The second element is usually a symbol being defined.
614 ;; If it is not, use the first symbol in it.
615 (skip-chars-forward " \t\n'(")
616 (buffer-substring (point)
617 (progn (forward-sexp 1)
619 ((and (memq major-mode add-log-c-like-modes
)
622 ;; Use eq instead of = here to avoid
623 ;; error when at bob and char-after
625 (while (eq (char-after (- (point) 2)) ?
\\)
627 (looking-at "[ \t]*#[ \t]*define[ \t]")))
628 ;; Handle a C macro definition.
630 (while (eq (char-after (- (point) 2)) ?
\\) ;not =; note above
632 (search-forward "define")
633 (skip-chars-forward " \t")
634 (buffer-substring (point)
635 (progn (forward-sexp 1) (point))))
636 ((memq major-mode add-log-c-like-modes
)
638 ;; See if we are in the beginning part of a function,
639 ;; before the open brace. If so, advance forward.
640 (while (not (looking-at "{\\|\\(\\s *$\\)"))
645 (if (progn (end-of-defun)
646 (< location
(point)))
652 ;; Skip back over typedefs of arglist.
653 (while (and (not (bobp))
654 (looking-at "[ \t\n]"))
656 ;; See if this is using the DEFUN macro used in Emacs,
657 ;; or the DEFUN macro used by the C library.
658 (if (condition-case nil
661 (while (= (preceding-char) ?
\\)
666 (looking-at "DEFUN\\b"))
672 (if (= (char-after (point)) ?
\")
675 (skip-chars-forward " ,")))
676 (buffer-substring (point)
677 (progn (forward-sexp 1) (point))))
678 (if (looking-at "^[+-]")
679 (change-log-get-method-definition)
680 ;; Ordinary C function syntax.
682 (if (and (condition-case nil
683 ;; Protect against "Unbalanced parens" error.
685 (down-list 1) ; into arglist
687 (skip-chars-backward " \t")
690 ;; Verify initial pos was after
691 ;; real start of function.
694 ;; For this purpose, include the line
695 ;; that has the decl keywords. This
696 ;; may also include some of the
697 ;; comments before the function.
698 (while (and (not (bobp))
701 (looking-at "[^\n\f]")))
703 (>= location
(point)))
704 ;; Consistency check: going down and up
705 ;; shouldn't take us back before BEG.
708 ;; Don't include any final whitespace
709 ;; in the name we use.
710 (skip-chars-backward " \t\n")
713 ;; Now find the right beginning of the name.
714 ;; Include certain keywords if they
716 (setq middle
(point))
718 ;; Ignore these subparts of a class decl
719 ;; and move back to the class name itself.
720 (while (looking-at "public \\|private ")
721 (skip-chars-backward " \t:")
724 (setq middle
(point))
727 (looking-at "enum \\|struct \\|union \\|class ")
728 (setq middle
(point)))
730 (when (eq (preceding-char) ?
=)
732 (skip-chars-backward " \t")
734 (buffer-substring middle end
)))))))))
735 ((memq major-mode add-log-tex-like-modes
)
736 (if (re-search-backward
737 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t
)
739 (goto-char (match-beginning 0))
740 (buffer-substring (1+ (point));; without initial backslash
744 ((eq major-mode
'texinfo-mode
)
745 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t
)
746 (buffer-substring (match-beginning 1)
748 ((eq major-mode
'perl-mode
)
749 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t
)
750 (buffer-substring (match-beginning 1)
752 ((eq major-mode
'autoconf-mode
)
753 (if (re-search-backward "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t
)
754 (buffer-substring (match-beginning 3)
756 ((or (eq major-mode
'fortran-mode
)
757 ;; Needs work for f90, but better than nothing.
758 (eq major-mode
'f90-mode
))
759 ;; must be inside function body for this to work
760 (fortran-beginning-of-subprogram)
761 (let ((case-fold-search t
)) ; case-insensitive
762 ;; search for fortran subprogram start
763 (if (re-search-forward
764 "^[ \t]*\\(program\\|subroutine\\|function\
765 \\|[ \ta-z0-9*()]*[ \t]+function\\|\\(block[ \t]*data\\)\\)"
766 (save-excursion (fortran-end-of-subprogram)
771 ;; move to EOL or before first left paren
772 (if (re-search-forward "[(\n]" nil t
)
773 (progn (backward-char)
774 (skip-chars-backward " \t"))
776 ;; Use the name preceding that.
777 (buffer-substring (point)
778 (progn (backward-sexp)
782 ;; If all else fails, try heuristics
783 (let (case-fold-search
786 (when (re-search-backward
787 add-log-current-defun-header-regexp
790 (setq result
(or (buffer-substring (match-beginning 1)
792 (buffer-substring (match-beginning 0)
794 ;; Strip whitespace away
795 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
797 (setq result
(match-string 1 result
)))
801 (defvar change-log-get-method-definition-md
)
803 ;; Subroutine used within change-log-get-method-definition.
804 ;; Add the last match in the buffer to the end of `md',
805 ;; followed by the string END; move to the end of that match.
806 (defun change-log-get-method-definition-1 (end)
807 (setq change-log-get-method-definition-md
808 (concat change-log-get-method-definition-md
809 (buffer-substring (match-beginning 1) (match-end 1))
811 (goto-char (match-end 0)))
813 (defun change-log-get-method-definition ()
814 "For objective C, return the method name if we are in a method."
815 (let ((change-log-get-method-definition-md "["))
817 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t
)
818 (change-log-get-method-definition-1 " ")))
821 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t
)
822 (change-log-get-method-definition-1 "")
823 (while (not (looking-at "[{;]"))
825 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
826 (change-log-get-method-definition-1 ""))
827 (concat change-log-get-method-definition-md
"]"))))))
829 (defun change-log-sortable-date-at ()
830 "Return date of log entry in a consistent form for sorting.
831 Point is assumed to be at the start of the entry."
833 (if (looking-at "^\\sw.........[0-9:+ ]*")
834 (let ((date (match-string-no-properties 0)))
836 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date
)
837 (concat (match-string 1 date
) (match-string 2 date
)
838 (match-string 3 date
))
840 (timezone-make-date-sortable date
)
845 (defun change-log-merge (other-log)
846 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
847 Both must be found in Change Log mode (since the merging depends on
848 the appropriate motion commands).
850 Entries are inserted in chronological order.
852 Both the current and old-style time formats for entries are supported,
853 so this command could be used to convert old-style logs by merging
855 (interactive "*fLog file name to merge: ")
856 (if (not (eq major-mode
'change-log-mode
))
857 (error "Not in Change Log mode"))
858 (let ((other-buf (find-file-noselect other-log
))
859 (buf (current-buffer))
862 (goto-char (point-min))
863 (set-buffer other-buf
)
864 (goto-char (point-min))
865 (if (not (eq major-mode
'change-log-mode
))
866 (error "%s not found in Change Log mode" other-log
))
867 ;; Loop through all the entries in OTHER-LOG.
869 (setq date1
(change-log-sortable-date-at))
871 end
(progn (forward-page) (point)))
872 ;; Look for an entry in original buffer that isn't later.
873 (with-current-buffer buf
874 (while (and (not (eobp))
875 (string< date1
(change-log-sortable-date-at)))
878 (insert-buffer-substring other-buf start end
)
879 ;; At the end of the original buffer, insert a newline to
880 ;; separate entries and then the rest of the file being
881 ;; merged. Move to the end of it to terminate outer loop.
883 (insert-buffer-substring other-buf start
884 (with-current-buffer other-buf
885 (goto-char (point-max))
890 ;;; add-log.el ends here