]> code.delx.au - gnu-emacs/blob - lisp/add-log.el
(change-log-font-lock-keywords): Do parenthesized
[gnu-emacs] / lisp / add-log.el
1 ;;; add-log.el --- change log maintenance commands for Emacs
2
3 ;; Copyright (C) 1985, 86, 88, 93, 94, 97, 1998 Free Software Foundation, Inc.
4
5 ;; Keywords: tools
6
7 ;; This file is part of GNU Emacs.
8
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)
12 ;; any later version.
13
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.
18
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.
23
24 ;;; Commentary:
25
26 ;; This facility is documented in the Emacs Manual.
27
28 ;;; Code:
29
30 (eval-when-compile (require 'fortran))
31
32 (defgroup change-log nil
33 "Change log maintenance"
34 :group 'tools
35 :link '(custom-manual "(emacs)Change Log")
36 :prefix "change-log-"
37 :prefix "add-log-")
38
39
40 (defcustom change-log-default-name nil
41 "*Name of a change log file for \\[add-change-log-entry]."
42 :type '(choice (const :tag "default" nil)
43 string)
44 :group 'change-log)
45
46 (defcustom add-log-current-defun-function nil
47 "\
48 *If non-nil, function to guess name of current function from surrounding text.
49 \\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
50 instead) with no arguments. It returns a string or nil if it cannot guess."
51 :type 'function
52 :group 'change-log)
53
54 ;;;###autoload
55 (defcustom add-log-full-name nil
56 "*Full name of user, for inclusion in ChangeLog daily headers.
57 This defaults to the value returned by the `user-full-name' function."
58 :type '(choice (const :tag "Default" nil)
59 string)
60 :group 'change-log)
61
62 ;;;###autoload
63 (defcustom add-log-mailing-address nil
64 "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
65 This defaults to the value of `user-mail-address'."
66 :type '(choice (const :tag "Default" nil)
67 string)
68 :group 'change-log)
69
70 (defcustom add-log-time-format 'add-log-iso8601-time-string
71 "*Function that defines the time format.
72 For example, `add-log-iso8601-time-string', which gives the
73 date in international ISO 8601 format,
74 and `current-time-string' are two valid values."
75 :type '(radio (const :tag "International ISO 8601 format"
76 add-log-iso8601-time-string)
77 (const :tag "Old format, as returned by `current-time-string'"
78 current-time-string)
79 (function :tag "Other"))
80 :group 'change-log)
81
82 (defcustom add-log-keep-changes-together nil
83 "*If non-nil, normally keep day's log entries for one file together.
84
85 Log entries for a given file made with \\[add-change-log-entry] or
86 \\[add-change-log-entry-other-window] will only be added to others \
87 for that file made
88 today if this variable is non-nil or that file comes first in today's
89 entries. Otherwise another entry for that file will be started. An
90 original log:
91
92 * foo (...): ...
93 * bar (...): change 1
94
95 in the latter case, \\[add-change-log-entry-other-window] in a \
96 buffer visiting `bar', yields:
97
98 * bar (...): -!-
99 * foo (...): ...
100 * bar (...): change 1
101
102 and in the former:
103
104 * foo (...): ...
105 * bar (...): change 1
106 (...): -!-
107
108 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
109 this variable."
110 :version "20.3"
111 :type 'boolean
112 :group 'change-log)
113
114 (defvar change-log-font-lock-keywords
115 '(;;
116 ;; Date lines, new and old styles.
117 ("^\\sw.........[0-9:+ ]*"
118 (0 font-lock-string-face)
119 ;; Name and e-mail; some people put e-mail in parens, not angles.
120 ("\\([^<(]+\\)[(<]\\([A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
121 (1 font-lock-constant-face)
122 (2 font-lock-variable-name-face)))
123 ;;
124 ;; File names.
125 ("^\t\\* \\([^ ,:([\n]+\\)"
126 (1 font-lock-function-name-face)
127 ;; Possibly further names in a list:
128 ("\\=, \\([^ ,:([\n]+\\)" nil nil (1 font-lock-function-name-face))
129 ;; Possibly a parenthesized list of names:
130 ("\\= (\\([^) ,:\n]+\\)" nil nil (1 font-lock-keyword-face))
131 ("\\=, *\\([^) ,:\n]+\\)" nil nil (1 font-lock-keyword-face)))
132 ;;
133 ;; Function or variable names.
134 ("^\t(\\([^) ,:\n]+\\)"
135 (1 font-lock-keyword-face)
136 ("\\=, *\\([^) ,:\n]+\\)" nil nil (1 font-lock-keyword-face)))
137 ;;
138 ;; Conditionals.
139 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 font-lock-variable-name-face))
140 ;;
141 ;; Acknowledgements.
142 ("^\t\\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
143 1 font-lock-comment-face)
144 (" \\(From\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
145 1 font-lock-comment-face))
146 "Additional expressions to highlight in Change Log mode.")
147
148 (defvar change-log-mode-map nil
149 "Keymap for Change Log major mode.")
150 (if change-log-mode-map
151 nil
152 (setq change-log-mode-map (make-sparse-keymap)))
153
154 (defvar change-log-time-zone-rule nil
155 "Time zone used for calculating change log time stamps.
156 It takes the same format as the TZ argument of `set-time-zone-rule'.
157 If nil, use local time.")
158
159 (defvar add-log-debugging)
160
161 (defun add-log-iso8601-time-zone (time)
162 (let* ((utc-offset (or (car (current-time-zone time)) 0))
163 (sign (if (< utc-offset 0) ?- ?+))
164 (sec (abs utc-offset))
165 (ss (% sec 60))
166 (min (/ sec 60))
167 (mm (% min 60))
168 (hh (/ min 60)))
169 (format (cond ((not (zerop ss)) "%c%02d:%02d:%02d")
170 ((not (zerop mm)) "%c%02d:%02d")
171 (t "%c%02d"))
172 sign hh mm ss)))
173
174 (defun add-log-iso8601-time-string ()
175 (if change-log-time-zone-rule
176 (let ((tz (getenv "TZ"))
177 (now (current-time)))
178 (unwind-protect
179 (progn
180 (set-time-zone-rule
181 change-log-time-zone-rule)
182 (concat
183 (format-time-string "%Y-%m-%d " now)
184 (add-log-iso8601-time-zone now)))
185 (set-time-zone-rule tz)))
186 (format-time-string "%Y-%m-%d")))
187
188 (defun change-log-name ()
189 (or change-log-default-name
190 (if (eq system-type 'vax-vms)
191 "$CHANGE_LOG$.TXT"
192 "ChangeLog")))
193
194 ;;;###autoload
195 (defun prompt-for-change-log-name ()
196 "Prompt for a change log name."
197 (let* ((default (change-log-name))
198 (name (expand-file-name
199 (read-file-name (format "Log file (default %s): " default)
200 nil default))))
201 ;; Handle something that is syntactically a directory name.
202 ;; Look for ChangeLog or whatever in that directory.
203 (if (string= (file-name-nondirectory name) "")
204 (expand-file-name (file-name-nondirectory default)
205 name)
206 ;; Handle specifying a file that is a directory.
207 (if (file-directory-p name)
208 (expand-file-name (file-name-nondirectory default)
209 (file-name-as-directory name))
210 name))))
211
212 ;;;###autoload
213 (defun find-change-log (&optional file-name)
214 "Find a change log file for \\[add-change-log-entry] and return the name.
215
216 Optional arg FILE-NAME specifies the file to use.
217 If FILE-NAME is nil, use the value of `change-log-default-name'.
218 If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
219 \(or whatever we use on this operating system).
220
221 If 'change-log-default-name' contains a leading directory component, then
222 simply find it in the current directory. Otherwise, search in the current
223 directory and its successive parents for a file so named.
224
225 Once a file is found, `change-log-default-name' is set locally in the
226 current buffer to the complete file name."
227 ;; If user specified a file name or if this buffer knows which one to use,
228 ;; just use that.
229 (or file-name
230 (setq file-name (and change-log-default-name
231 (file-name-directory change-log-default-name)
232 change-log-default-name))
233 (progn
234 ;; Chase links in the source file
235 ;; and use the change log in the dir where it points.
236 (setq file-name (or (and buffer-file-name
237 (file-name-directory
238 (file-chase-links buffer-file-name)))
239 default-directory))
240 (if (file-directory-p file-name)
241 (setq file-name (expand-file-name (change-log-name) file-name)))
242 ;; Chase links before visiting the file.
243 ;; This makes it easier to use a single change log file
244 ;; for several related directories.
245 (setq file-name (file-chase-links file-name))
246 (setq file-name (expand-file-name file-name))
247 ;; Move up in the dir hierarchy till we find a change log file.
248 (let ((file1 file-name)
249 parent-dir)
250 (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
251 (progn (setq parent-dir
252 (file-name-directory
253 (directory-file-name
254 (file-name-directory file1))))
255 ;; Give up if we are already at the root dir.
256 (not (string= (file-name-directory file1)
257 parent-dir))))
258 ;; Move up to the parent dir and try again.
259 (setq file1 (expand-file-name
260 (file-name-nondirectory (change-log-name))
261 parent-dir)))
262 ;; If we found a change log in a parent, use that.
263 (if (or (get-file-buffer file1) (file-exists-p file1))
264 (setq file-name file1)))))
265 ;; Make a local variable in this buffer so we needn't search again.
266 (set (make-local-variable 'change-log-default-name) file-name)
267 file-name)
268
269 ;;;###autoload
270 (defun add-change-log-entry (&optional whoami file-name other-window new-entry)
271 "Find change log file and add an entry for today.
272 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
273 name and site.
274
275 Second arg is FILE-NAME of change log. If nil, uses `change-log-default-name'.
276 Third arg OTHER-WINDOW non-nil means visit in other window.
277 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
278 never append to an existing entry. Option `add-log-keep-changes-together'
279 otherwise affects whether a new entry is created.
280
281 Today's date is calculated according to `change-log-time-zone-rule' if
282 non-nil, otherwise in local time."
283 (interactive (list current-prefix-arg
284 (prompt-for-change-log-name)))
285 (or add-log-full-name
286 (setq add-log-full-name (user-full-name)))
287 (or add-log-mailing-address
288 (setq add-log-mailing-address user-mail-address))
289 (if whoami
290 (progn
291 (setq add-log-full-name (read-input "Full name: " add-log-full-name))
292 ;; Note that some sites have room and phone number fields in
293 ;; full name which look silly when inserted. Rather than do
294 ;; anything about that here, let user give prefix argument so that
295 ;; s/he can edit the full name field in prompter if s/he wants.
296 (setq add-log-mailing-address
297 (read-input "Mailing address: " add-log-mailing-address))))
298 (let ((defun (funcall (or add-log-current-defun-function
299 'add-log-current-defun)))
300 bound entry)
301
302 (setq file-name (expand-file-name (find-change-log file-name)))
303
304 ;; Set ENTRY to the file name to use in the new entry.
305 (and buffer-file-name
306 ;; Never want to add a change log entry for the ChangeLog file itself.
307 (not (string= buffer-file-name file-name))
308 (setq entry (if (string-match
309 (concat "^" (regexp-quote (file-name-directory
310 file-name)))
311 buffer-file-name)
312 (substring buffer-file-name (match-end 0))
313 (file-name-nondirectory buffer-file-name))))
314
315 (let ((buffer (find-buffer-visiting file-name)))
316 (setq add-log-debugging (list (gap-position) (gap-size))))
317 (if (and other-window (not (equal file-name buffer-file-name)))
318 (find-file-other-window file-name)
319 (find-file file-name))
320 (or (eq major-mode 'change-log-mode)
321 (change-log-mode))
322 (undo-boundary)
323 (goto-char (point-min))
324 (let ((new-entry (concat (funcall add-log-time-format)
325 " " add-log-full-name
326 " <" add-log-mailing-address ">")))
327 (if (looking-at (regexp-quote new-entry))
328 (forward-line 1)
329 (insert new-entry "\n\n")))
330
331 (setq bound
332 (progn
333 (if (looking-at "\n*[^\n* \t]")
334 (skip-chars-forward "\n")
335 (if add-log-keep-changes-together
336 (forward-page) ; page delimits entries for date
337 (forward-paragraph))) ; paragraph delimits entries for file
338 (point)))
339 (goto-char (point-min))
340 ;; Now insert the new line for this entry.
341 (cond ((re-search-forward "^\\s *\\*\\s *$" bound t)
342 ;; Put this file name into the existing empty entry.
343 (if entry
344 (insert entry)))
345 ((and (not new-entry)
346 (let (case-fold-search)
347 (re-search-forward
348 (concat (regexp-quote (concat "* " entry))
349 ;; Don't accept `foo.bar' when
350 ;; looking for `foo':
351 "\\(\\s \\|[(),:]\\)")
352 bound t)))
353 ;; Add to the existing entry for the same file.
354 (re-search-forward "^\\s *$\\|^\\s \\*")
355 (goto-char (match-beginning 0))
356 ;; Delete excess empty lines; make just 2.
357 (while (and (not (eobp)) (looking-at "^\\s *$"))
358 (delete-region (point) (save-excursion (forward-line 1) (point))))
359 (insert "\n\n")
360 (forward-line -2)
361 (indent-relative-maybe))
362 (t
363 ;; Make a new entry.
364 (forward-line 1)
365 (while (looking-at "\\sW")
366 (forward-line 1))
367 (while (and (not (eobp)) (looking-at "^\\s *$"))
368 (delete-region (point) (save-excursion (forward-line 1) (point))))
369 (insert "\n\n\n")
370 (forward-line -2)
371 (indent-to left-margin)
372 (insert "* " (or entry ""))))
373 ;; Now insert the function name, if we have one.
374 ;; Point is at the entry for this file,
375 ;; either at the end of the line or at the first blank line.
376 (if defun
377 (progn
378 ;; Make it easy to get rid of the function name.
379 (undo-boundary)
380 (insert (if (save-excursion
381 (beginning-of-line 1)
382 (looking-at "\\s *$"))
383 ""
384 " ")
385 "(" defun "): "))
386 ;; No function name, so put in a colon unless we have just a star.
387 (if (not (save-excursion
388 (beginning-of-line 1)
389 (looking-at "\\s *\\(\\*\\s *\\)?$")))
390 (insert ": ")))))
391
392 ;;;###autoload
393 (defun add-change-log-entry-other-window (&optional whoami file-name)
394 "Find change log file in other window and add an entry for today.
395 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
396 name and site.
397 Second optional arg FILE-NAME is file name of change log.
398 If nil, use `change-log-default-name'.
399
400 Affected by the same options as `add-change-log-entry'."
401 (interactive (if current-prefix-arg
402 (list current-prefix-arg
403 (prompt-for-change-log-name))))
404 (add-change-log-entry whoami file-name t))
405 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
406
407 ;;;###autoload
408 (defun change-log-mode ()
409 "Major mode for editing change logs; like Indented Text Mode.
410 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
411 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
412 Each entry behaves as a paragraph, and the entries for one day as a page.
413 Runs `change-log-mode-hook'."
414 (interactive)
415 (kill-all-local-variables)
416 (indented-text-mode)
417 (setq major-mode 'change-log-mode
418 mode-name "Change Log"
419 left-margin 8
420 fill-column 74
421 indent-tabs-mode t
422 tab-width 8)
423 (use-local-map change-log-mode-map)
424 (set (make-local-variable 'fill-paragraph-function)
425 'change-log-fill-paragraph)
426 ;; We really do want "^" in paragraph-start below: it is only the
427 ;; lines that begin at column 0 (despite the left-margin of 8) that
428 ;; we are looking for. Adding `* ' allows eliding the blank line
429 ;; between entries for different files.
430 (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\<")
431 (set (make-local-variable 'paragraph-separate) paragraph-start)
432 ;; Match null string on the date-line so that the date-line
433 ;; is grouped with what follows.
434 (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
435 (set (make-local-variable 'version-control) 'never)
436 (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
437 (set (make-local-variable 'font-lock-defaults)
438 '(change-log-font-lock-keywords t))
439 (run-hooks 'change-log-mode-hook))
440
441 ;; It might be nice to have a general feature to replace this. The idea I
442 ;; have is a variable giving a regexp matching text which should not be
443 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
444 ;; But I don't feel up to implementing that today.
445 (defun change-log-fill-paragraph (&optional justify)
446 "Fill the paragraph, but preserve open parentheses at beginning of lines.
447 Prefix arg means justify as well."
448 (interactive "P")
449 (let ((end (progn (forward-paragraph) (point)))
450 (beg (progn (backward-paragraph) (point)))
451 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
452 (fill-region beg end justify)
453 t))
454 \f
455 (defcustom add-log-current-defun-header-regexp
456 "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[-_a-zA-Z]+\\)[ \t]*[:=]"
457 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes."
458 :type 'regexp
459 :group 'change-log)
460
461 ;;;###autoload
462 (defvar add-log-lisp-like-modes
463 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode)
464 "*Modes that look like Lisp to `add-log-current-defun'.")
465
466 ;;;###autoload
467 (defvar add-log-c-like-modes
468 '(c-mode c++-mode c++-c-mode objc-mode)
469 "*Modes that look like C to `add-log-current-defun'.")
470
471 ;;;###autoload
472 (defvar add-log-tex-like-modes
473 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode)
474 "*Modes that look like TeX to `add-log-current-defun'.")
475
476 ;;;###autoload
477 (defun add-log-current-defun ()
478 "Return name of function definition point is in, or nil.
479
480 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
481 Texinfo (@node titles), Perl, and Fortran.
482
483 Other modes are handled by a heuristic that looks in the 10K before
484 point for uppercase headings starting in the first column or
485 identifiers followed by `:' or `=', see variable
486 `add-log-current-defun-header-regexp'.
487
488 Has a preference of looking backwards."
489 (condition-case nil
490 (save-excursion
491 (let ((location (point)))
492 (cond ((memq major-mode add-log-lisp-like-modes)
493 ;; If we are now precisely at the beginning of a defun,
494 ;; make sure beginning-of-defun finds that one
495 ;; rather than the previous one.
496 (or (eobp) (forward-char 1))
497 (beginning-of-defun)
498 ;; Make sure we are really inside the defun found, not after it.
499 (when (and (looking-at "\\s(")
500 (progn (end-of-defun)
501 (< location (point)))
502 (progn (forward-sexp -1)
503 (>= location (point))))
504 (if (looking-at "\\s(")
505 (forward-char 1))
506 ;; Skip the defining construct name, typically "defun"
507 ;; or "defvar".
508 (forward-sexp 1)
509 ;; The second element is usually a symbol being defined.
510 ;; If it is not, use the first symbol in it.
511 (skip-chars-forward " \t\n'(")
512 (buffer-substring (point)
513 (progn (forward-sexp 1)
514 (point)))))
515 ((and (memq major-mode add-log-c-like-modes)
516 (save-excursion
517 (beginning-of-line)
518 ;; Use eq instead of = here to avoid
519 ;; error when at bob and char-after
520 ;; returns nil.
521 (while (eq (char-after (- (point) 2)) ?\\)
522 (forward-line -1))
523 (looking-at "[ \t]*#[ \t]*define[ \t]")))
524 ;; Handle a C macro definition.
525 (beginning-of-line)
526 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
527 (forward-line -1))
528 (search-forward "define")
529 (skip-chars-forward " \t")
530 (buffer-substring (point)
531 (progn (forward-sexp 1) (point))))
532 ((memq major-mode add-log-c-like-modes)
533 (beginning-of-line)
534 ;; See if we are in the beginning part of a function,
535 ;; before the open brace. If so, advance forward.
536 (while (not (looking-at "{\\|\\(\\s *$\\)"))
537 (forward-line 1))
538 (or (eobp)
539 (forward-char 1))
540 (beginning-of-defun)
541 (if (progn (end-of-defun)
542 (< location (point)))
543 (progn
544 (backward-sexp 1)
545 (let (beg tem)
546
547 (forward-line -1)
548 ;; Skip back over typedefs of arglist.
549 (while (and (not (bobp))
550 (looking-at "[ \t\n]"))
551 (forward-line -1))
552 ;; See if this is using the DEFUN macro used in Emacs,
553 ;; or the DEFUN macro used by the C library.
554 (if (condition-case nil
555 (and (save-excursion
556 (end-of-line)
557 (while (= (preceding-char) ?\\)
558 (end-of-line 2))
559 (backward-sexp 1)
560 (beginning-of-line)
561 (setq tem (point))
562 (looking-at "DEFUN\\b"))
563 (>= location tem))
564 (error nil))
565 (progn
566 (goto-char tem)
567 (down-list 1)
568 (if (= (char-after (point)) ?\")
569 (progn
570 (forward-sexp 1)
571 (skip-chars-forward " ,")))
572 (buffer-substring (point)
573 (progn (forward-sexp 1) (point))))
574 (if (looking-at "^[+-]")
575 (change-log-get-method-definition)
576 ;; Ordinary C function syntax.
577 (setq beg (point))
578 (if (and (condition-case nil
579 ;; Protect against "Unbalanced parens" error.
580 (progn
581 (down-list 1) ; into arglist
582 (backward-up-list 1)
583 (skip-chars-backward " \t")
584 t)
585 (error nil))
586 ;; Verify initial pos was after
587 ;; real start of function.
588 (save-excursion
589 (goto-char beg)
590 ;; For this purpose, include the line
591 ;; that has the decl keywords. This
592 ;; may also include some of the
593 ;; comments before the function.
594 (while (and (not (bobp))
595 (save-excursion
596 (forward-line -1)
597 (looking-at "[^\n\f]")))
598 (forward-line -1))
599 (>= location (point)))
600 ;; Consistency check: going down and up
601 ;; shouldn't take us back before BEG.
602 (> (point) beg))
603 (let (end middle)
604 ;; Don't include any final newline
605 ;; in the name we use.
606 (if (= (preceding-char) ?\n)
607 (forward-char -1))
608 (setq end (point))
609 (backward-sexp 1)
610 ;; Now find the right beginning of the name.
611 ;; Include certain keywords if they
612 ;; precede the name.
613 (setq middle (point))
614 (forward-word -1)
615 ;; Ignore these subparts of a class decl
616 ;; and move back to the class name itself.
617 (while (looking-at "public \\|private ")
618 (skip-chars-backward " \t:")
619 (setq end (point))
620 (backward-sexp 1)
621 (setq middle (point))
622 (forward-word -1))
623 (and (bolp)
624 (looking-at "struct \\|union \\|class ")
625 (setq middle (point)))
626 (buffer-substring middle end)))))))))
627 ((memq major-mode add-log-tex-like-modes)
628 (if (re-search-backward
629 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t)
630 (progn
631 (goto-char (match-beginning 0))
632 (buffer-substring (1+ (point));; without initial backslash
633 (progn
634 (end-of-line)
635 (point))))))
636 ((eq major-mode 'texinfo-mode)
637 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
638 (buffer-substring (match-beginning 1)
639 (match-end 1))))
640 ((eq major-mode 'perl-mode)
641 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t)
642 (buffer-substring (match-beginning 1)
643 (match-end 1))))
644 ((or (eq major-mode 'fortran-mode)
645 ;; Needs work for f90, but better than nothing.
646 (eq major-mode 'f90-mode))
647 ;; must be inside function body for this to work
648 (beginning-of-fortran-subprogram)
649 (let ((case-fold-search t)) ; case-insensitive
650 ;; search for fortran subprogram start
651 (if (re-search-forward
652 "^[ \t]*\\(program\\|subroutine\\|function\
653 \\|[ \ta-z0-9*()]*[ \t]+function\\|\\(block[ \t]*data\\)\\)"
654 (save-excursion (end-of-fortran-subprogram)
655 (point))
656 t)
657 (or (match-string 2)
658 (progn
659 ;; move to EOL or before first left paren
660 (if (re-search-forward "[(\n]" nil t)
661 (progn (backward-char)
662 (skip-chars-backward " \t"))
663 (end-of-line))
664 ;; Use the name preceding that.
665 (buffer-substring (point)
666 (progn (backward-sexp)
667 (point)))))
668 "main")))
669 (t
670 ;; If all else fails, try heuristics
671 (let (case-fold-search)
672 (end-of-line)
673 (if (re-search-backward add-log-current-defun-header-regexp
674 (- (point) 10000)
675 t)
676 (buffer-substring (match-beginning 1)
677 (match-end 1))))))))
678 (error nil)))
679
680 (defvar change-log-get-method-definition-md)
681
682 ;; Subroutine used within change-log-get-method-definition.
683 ;; Add the last match in the buffer to the end of `md',
684 ;; followed by the string END; move to the end of that match.
685 (defun change-log-get-method-definition-1 (end)
686 (setq change-log-get-method-definition-md
687 (concat change-log-get-method-definition-md
688 (buffer-substring (match-beginning 1) (match-end 1))
689 end))
690 (goto-char (match-end 0)))
691
692 ;; For objective C, return the method name if we are in a method.
693 (defun change-log-get-method-definition ()
694 (let ((change-log-get-method-definition-md "["))
695 (save-excursion
696 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
697 (change-log-get-method-definition-1 " ")))
698 (save-excursion
699 (cond
700 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
701 (change-log-get-method-definition-1 "")
702 (while (not (looking-at "[{;]"))
703 (looking-at
704 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
705 (change-log-get-method-definition-1 ""))
706 (concat change-log-get-method-definition-md "]"))))))
707
708
709 (provide 'add-log)
710
711 ;;; add-log.el ends here