(re_match_2_internal) [emacs]: Use PT, not point.
[bpt/emacs.git] / lisp / add-log.el
CommitLineData
84fc2cfa
ER
1;;; add-log.el --- change log maintenance commands for Emacs
2
e332f80b 3;; Copyright (C) 1985, 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
84fc2cfa 4
e9571d2a
ER
5;; Keywords: maint
6
84fc2cfa
ER
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
fd7fa35a 11;; the Free Software Foundation; either version 2, or (at your option)
84fc2cfa
ER
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
b578f267
EN
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.
84fc2cfa 23
e41b2db1
ER
24;;; Commentary:
25
26;; This facility is documented in the Emacs Manual.
27
fd7fa35a 28;;; Code:
84fc2cfa 29
84fc2cfa
ER
30(defvar change-log-default-name nil
31 "*Name of a change log file for \\[add-change-log-entry].")
32
6258d3af
RM
33(defvar add-log-current-defun-function nil
34 "\
35*If non-nil, function to guess name of current function from surrounding text.
36\\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
37instead) with no arguments. It returns a string or nil if it cannot guess.")
38
29db528b 39;;;###autoload
59ac2ce6 40(defvar add-log-full-name nil
02ec1592
BF
41 "*Full name of user, for inclusion in ChangeLog daily headers.
42This defaults to the value returned by the `user-full-name' function.")
43
29db528b 44;;;###autoload
59ac2ce6 45(defvar add-log-mailing-address nil
02ec1592 46 "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
fb38ca86 47This defaults to the value of `user-mail-address'.")
02ec1592 48
5f562719 49(defvar change-log-font-lock-keywords
51bd1843 50 '(("^[12].+" . font-lock-function-name-face) ; Date line.
5f562719 51 ("^\t\\* \\([^ :\n]+\\)" 1 font-lock-comment-face) ; File name.
6ad1cbf5 52 ("(\\([^)\n]+\\)):" 1 font-lock-keyword-face)) ; Function name.
5f562719
RS
53 "Additional expressions to highlight in Change Log mode.")
54
45c50c5d
KH
55(defvar change-log-mode-map nil
56 "Keymap for Change Log major mode.")
57(if change-log-mode-map
58 nil
59 (setq change-log-mode-map (make-sparse-keymap)))
60
51bd1843
EN
61(defvar change-log-time-zone-rule nil
62 "Time zone used for calculating change log time stamps.
63It takes the same format as the TZ argument of `set-time-zone-rule'.
64If nil, use local time.")
65
66(defun iso8601-time-zone (time)
67 (let* ((utc-offset (or (car (current-time-zone time)) 0))
68 (sign (if (< utc-offset 0) ?- ?+))
69 (sec (abs utc-offset))
70 (ss (% sec 60))
71 (min (/ sec 60))
72 (mm (% min 60))
73 (hh (/ min 60)))
74 (format (cond ((not (zerop ss)) "%c%02d:%02d:%02d")
75 ((not (zerop mm)) "%c%02d:%02d")
76 (t "%c%02d"))
77 sign hh mm ss)))
78
84fc2cfa
ER
79(defun change-log-name ()
80 (or change-log-default-name
8afc29f0
RS
81 (if (eq system-type 'vax-vms)
82 "$CHANGE_LOG$.TXT"
3912227e 83 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
5675b1e4 84 "changelo"
8afc29f0 85 "ChangeLog"))))
84fc2cfa 86
287d149f 87;;;###autoload
84fc2cfa
ER
88(defun prompt-for-change-log-name ()
89 "Prompt for a change log name."
117aaf60
KH
90 (let* ((default (change-log-name))
91 (name (expand-file-name
92 (read-file-name (format "Log file (default %s): " default)
93 nil default))))
94 ;; Handle something that is syntactically a directory name.
95 ;; Look for ChangeLog or whatever in that directory.
96 (if (string= (file-name-nondirectory name) "")
97 (expand-file-name (file-name-nondirectory default)
98 name)
99 ;; Handle specifying a file that is a directory.
100 (if (file-directory-p name)
101 (expand-file-name (file-name-nondirectory default)
102 (file-name-as-directory name))
103 name))))
84fc2cfa 104
45a13f0d
RM
105;;;###autoload
106(defun find-change-log (&optional file-name)
107 "Find a change log file for \\[add-change-log-entry] and return the name.
a82e2ed5
RS
108
109Optional arg FILE-NAME specifies the file to use.
de98fcaf
RS
110If FILE-NAME is nil, use the value of `change-log-default-name'.
111If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
112\(or whatever we use on this operating system).
113
114If 'change-log-default-name' contains a leading directory component, then
115simply find it in the current directory. Otherwise, search in the current
116directory and its successive parents for a file so named.
45a13f0d
RM
117
118Once a file is found, `change-log-default-name' is set locally in the
119current buffer to the complete file name."
a82e2ed5
RS
120 ;; If user specified a file name or if this buffer knows which one to use,
121 ;; just use that.
45a13f0d 122 (or file-name
de98fcaf
RS
123 (setq file-name (and change-log-default-name
124 (file-name-directory change-log-default-name)
125 change-log-default-name))
a82e2ed5
RS
126 (progn
127 ;; Chase links in the source file
128 ;; and use the change log in the dir where it points.
129 (setq file-name (or (and buffer-file-name
130 (file-name-directory
131 (file-chase-links buffer-file-name)))
132 default-directory))
133 (if (file-directory-p file-name)
134 (setq file-name (expand-file-name (change-log-name) file-name)))
135 ;; Chase links before visiting the file.
136 ;; This makes it easier to use a single change log file
137 ;; for several related directories.
138 (setq file-name (file-chase-links file-name))
139 (setq file-name (expand-file-name file-name))
140 ;; Move up in the dir hierarchy till we find a change log file.
141 (let ((file1 file-name)
142 parent-dir)
143 (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
144 (progn (setq parent-dir
145 (file-name-directory
146 (directory-file-name
147 (file-name-directory file1))))
148 ;; Give up if we are already at the root dir.
149 (not (string= (file-name-directory file1)
150 parent-dir))))
151 ;; Move up to the parent dir and try again.
152 (setq file1 (expand-file-name
153 (file-name-nondirectory (change-log-name))
154 parent-dir)))
155 ;; If we found a change log in a parent, use that.
156 (if (or (get-file-buffer file1) (file-exists-p file1))
157 (setq file-name file1)))))
158 ;; Make a local variable in this buffer so we needn't search again.
159 (set (make-local-variable 'change-log-default-name) file-name)
160 file-name)
45a13f0d 161
84fc2cfa 162;;;###autoload
287d149f 163(defun add-change-log-entry (&optional whoami file-name other-window new-entry)
84fc2cfa
ER
164 "Find change log file and add an entry for today.
165Optional arg (interactive prefix) non-nil means prompt for user name and site.
166Second arg is file name of change log. If nil, uses `change-log-default-name'.
287d149f
RM
167Third arg OTHER-WINDOW non-nil means visit in other window.
168Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
51bd1843
EN
169never append to an existing entry. Today's date is calculated according to
170`change-log-time-zone-rule' if non-nil, otherwise in local time."
84fc2cfa
ER
171 (interactive (list current-prefix-arg
172 (prompt-for-change-log-name)))
550d8777
RS
173 (or add-log-full-name
174 (setq add-log-full-name (user-full-name)))
175 (or add-log-mailing-address
176 (setq add-log-mailing-address user-mail-address))
02ec1592
BF
177 (if whoami
178 (progn
179 (setq add-log-full-name (read-input "Full name: " add-log-full-name))
84fc2cfa
ER
180 ;; Note that some sites have room and phone number fields in
181 ;; full name which look silly when inserted. Rather than do
182 ;; anything about that here, let user give prefix argument so that
183 ;; s/he can edit the full name field in prompter if s/he wants.
02ec1592
BF
184 (setq add-log-mailing-address
185 (read-input "Mailing address: " add-log-mailing-address))))
186 (let ((defun (funcall (or add-log-current-defun-function
187 'add-log-current-defun)))
188 paragraph-end entry)
45a13f0d 189
3e1c918b 190 (setq file-name (expand-file-name (find-change-log file-name)))
82f4acaf
RM
191
192 ;; Set ENTRY to the file name to use in the new entry.
193 (and buffer-file-name
194 ;; Never want to add a change log entry for the ChangeLog file itself.
195 (not (string= buffer-file-name file-name))
196 (setq entry (if (string-match
197 (concat "^" (regexp-quote (file-name-directory
198 file-name)))
199 buffer-file-name)
200 (substring buffer-file-name (match-end 0))
201 (file-name-nondirectory buffer-file-name))))
202
84fc2cfa
ER
203 (if (and other-window (not (equal file-name buffer-file-name)))
204 (find-file-other-window file-name)
205 (find-file file-name))
675a998f
RS
206 (or (eq major-mode 'change-log-mode)
207 (change-log-mode))
84fc2cfa
ER
208 (undo-boundary)
209 (goto-char (point-min))
51bd1843
EN
210 (let ((new-entry (concat (if change-log-time-zone-rule
211 (let ((tz (getenv "TZ"))
212 (now (current-time)))
213 (unwind-protect
214 (progn
215 (set-time-zone-rule
216 change-log-time-zone-rule)
217 (concat
218 (format-time-string "%Y-%m-%d " now)
219 (iso8601-time-zone now)))
220 (set-time-zone-rule tz)))
221 (format-time-string "%Y-%m-%d"))
222 " " add-log-full-name
223 " <" add-log-mailing-address ">")))
224 (if (looking-at (regexp-quote new-entry))
225 (forward-line 1)
226 (insert new-entry "\n\n")))
82f4acaf 227
74046d00 228 ;; Search only within the first paragraph.
716a781e
RS
229 (if (looking-at "\n*[^\n* \t]")
230 (skip-chars-forward "\n")
231 (forward-paragraph 1))
82f4acaf 232 (setq paragraph-end (point))
84fc2cfa 233 (goto-char (point-min))
82f4acaf 234
1832dbd1 235 ;; Now insert the new line for this entry.
82f4acaf
RM
236 (cond ((re-search-forward "^\\s *\\*\\s *$" paragraph-end t)
237 ;; Put this file name into the existing empty entry.
238 (if entry
239 (insert entry)))
287d149f 240 ((and (not new-entry)
e172f546
KH
241 (let (case-fold-search)
242 (re-search-forward
243 (concat (regexp-quote (concat "* " entry))
244 ;; Don't accept `foo.bar' when
245 ;; looking for `foo':
246 "\\(\\s \\|[(),:]\\)")
247 paragraph-end t)))
82f4acaf
RM
248 ;; Add to the existing entry for the same file.
249 (re-search-forward "^\\s *$\\|^\\s \\*")
e172f546
KH
250 (goto-char (match-beginning 0))
251 ;; Delete excess empty lines; make just 2.
09b389d0 252 (while (and (not (eobp)) (looking-at "^\\s *$"))
1832dbd1
RS
253 (delete-region (point) (save-excursion (forward-line 1) (point))))
254 (insert "\n\n")
255 (forward-line -2)
dd309224 256 (indent-relative-maybe))
21d7e080 257 (t
dd309224
RM
258 ;; Make a new entry.
259 (forward-line 1)
260 (while (looking-at "\\sW")
261 (forward-line 1))
09b389d0 262 (while (and (not (eobp)) (looking-at "^\\s *$"))
1832dbd1
RS
263 (delete-region (point) (save-excursion (forward-line 1) (point))))
264 (insert "\n\n\n")
265 (forward-line -2)
dd309224
RM
266 (indent-to left-margin)
267 (insert "* " (or entry ""))))
1832dbd1 268 ;; Now insert the function name, if we have one.
21d7e080
ER
269 ;; Point is at the entry for this file,
270 ;; either at the end of the line or at the first blank line.
271 (if defun
272 (progn
dd309224 273 ;; Make it easy to get rid of the function name.
21d7e080 274 (undo-boundary)
dd309224
RM
275 (insert (if (save-excursion
276 (beginning-of-line 1)
277 (looking-at "\\s *$"))
278 ""
279 " ")
280 "(" defun "): "))
1832dbd1 281 ;; No function name, so put in a colon unless we have just a star.
dd309224
RM
282 (if (not (save-excursion
283 (beginning-of-line 1)
284 (looking-at "\\s *\\(\\*\\s *\\)?$")))
1832dbd1 285 (insert ": ")))))
84fc2cfa 286
84fc2cfa
ER
287;;;###autoload
288(defun add-change-log-entry-other-window (&optional whoami file-name)
289 "Find change log file in other window and add an entry for today.
6258d3af
RM
290Optional arg (interactive prefix) non-nil means prompt for user name and site.
291Second arg is file name of change log. \
292If nil, uses `change-log-default-name'."
84fc2cfa
ER
293 (interactive (if current-prefix-arg
294 (list current-prefix-arg
295 (prompt-for-change-log-name))))
296 (add-change-log-entry whoami file-name t))
82f4acaf 297;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
84fc2cfa 298
1da56800 299;;;###autoload
21d7e080 300(defun change-log-mode ()
eb8c3be9 301 "Major mode for editing change logs; like Indented Text Mode.
09b389d0 302Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
5516387c
RM
303New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
304Each entry behaves as a paragraph, and the entries for one day as a page.
305Runs `change-log-mode-hook'."
21d7e080
ER
306 (interactive)
307 (kill-all-local-variables)
308 (indented-text-mode)
82f4acaf
RM
309 (setq major-mode 'change-log-mode
310 mode-name "Change Log"
311 left-margin 8
4f675a8c 312 fill-column 74
60f10a06
KH
313 indent-tabs-mode t
314 tab-width 8)
45c50c5d 315 (use-local-map change-log-mode-map)
60f10a06
KH
316 (set (make-local-variable 'fill-paragraph-function)
317 'change-log-fill-paragraph)
21d7e080 318 ;; Let each entry behave as one paragraph:
14ee1953
RS
319 ;; We really do want "^" in paragraph-start below: it is only the lines that
320 ;; begin at column 0 (despite the left-margin of 8) that we are looking for.
51bd1843
EN
321 (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\<")
322 (set (make-local-variable 'paragraph-separate) "\\s *$\\|\f\\|^\\<")
21d7e080 323 ;; Let all entries for one day behave as one page.
2c91c85c
RS
324 ;; Match null string on the date-line so that the date-line
325 ;; is grouped with what follows.
964141f2 326 (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
dd309224
RM
327 (set (make-local-variable 'version-control) 'never)
328 (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
4b286eca
SM
329 (set (make-local-variable 'font-lock-defaults)
330 '(change-log-font-lock-keywords t))
21d7e080
ER
331 (run-hooks 'change-log-mode-hook))
332
287d149f
RM
333;; It might be nice to have a general feature to replace this. The idea I
334;; have is a variable giving a regexp matching text which should not be
335;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
336;; But I don't feel up to implementing that today.
337(defun change-log-fill-paragraph (&optional justify)
338 "Fill the paragraph, but preserve open parentheses at beginning of lines.
339Prefix arg means justify as well."
340 (interactive "P")
14ee1953
RS
341 (let ((end (save-excursion (forward-paragraph) (point)))
342 (beg (save-excursion (backward-paragraph)(point)))
343 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
344 (fill-region beg end justify)))
287d149f 345\f
21d7e080 346(defvar add-log-current-defun-header-regexp
26add1bf 347 "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[-_a-zA-Z]+\\)[ \t]*[:=]"
21d7e080
ER
348 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes.")
349
e332f80b 350;;;###autoload
21d7e080
ER
351(defun add-log-current-defun ()
352 "Return name of function definition point is in, or nil.
353
63314951 354Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
64bd2d51 355Texinfo (@node titles), Perl, and Fortran.
21d7e080
ER
356
357Other modes are handled by a heuristic that looks in the 10K before
358point for uppercase headings starting in the first column or
359identifiers followed by `:' or `=', see variable
360`add-log-current-defun-header-regexp'.
361
362Has a preference of looking backwards."
2cc0b765
RS
363 (condition-case nil
364 (save-excursion
365 (let ((location (point)))
3fec4c1b
RS
366 (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode
367 lisp-interaction-mode))
a0151877 368 ;; If we are now precisely at the beginning of a defun,
2cc0b765
RS
369 ;; make sure beginning-of-defun finds that one
370 ;; rather than the previous one.
371 (or (eobp) (forward-char 1))
372 (beginning-of-defun)
373 ;; Make sure we are really inside the defun found, not after it.
947b2743
RS
374 (if (and (looking-at "\\s(")
375 (progn (end-of-defun)
2cc0b765
RS
376 (< location (point)))
377 (progn (forward-sexp -1)
378 (>= location (point))))
379 (progn
0e933219
JB
380 (if (looking-at "\\s(")
381 (forward-char 1))
382 (forward-sexp 1)
a0151877 383 (skip-chars-forward " '")
2cc0b765
RS
384 (buffer-substring (point)
385 (progn (forward-sexp 1) (point))))))
32e986d4 386 ((and (memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
2cc0b765
RS
387 (save-excursion (beginning-of-line)
388 ;; Use eq instead of = here to avoid
389 ;; error when at bob and char-after
390 ;; returns nil.
391 (while (eq (char-after (- (point) 2)) ?\\)
36e6631c 392 (forward-line -1))
2cc0b765
RS
393 (looking-at "[ \t]*#[ \t]*define[ \t]")))
394 ;; Handle a C macro definition.
395 (beginning-of-line)
396 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
397 (forward-line -1))
398 (search-forward "define")
399 (skip-chars-forward " \t")
400 (buffer-substring (point)
401 (progn (forward-sexp 1) (point))))
32e986d4 402 ((memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
2cc0b765
RS
403 (beginning-of-line)
404 ;; See if we are in the beginning part of a function,
405 ;; before the open brace. If so, advance forward.
406 (while (not (looking-at "{\\|\\(\\s *$\\)"))
407 (forward-line 1))
408 (or (eobp)
409 (forward-char 1))
410 (beginning-of-defun)
411 (if (progn (end-of-defun)
412 (< location (point)))
413 (progn
414 (backward-sexp 1)
415 (let (beg tem)
fd7fa35a 416
2cc0b765
RS
417 (forward-line -1)
418 ;; Skip back over typedefs of arglist.
419 (while (and (not (bobp))
420 (looking-at "[ \t\n]"))
421 (forward-line -1))
422 ;; See if this is using the DEFUN macro used in Emacs,
423 ;; or the DEFUN macro used by the C library.
424 (if (condition-case nil
425 (and (save-excursion
019644ee
RS
426 (end-of-line)
427 (while (= (preceding-char) ?\\)
428 (end-of-line 2))
2cc0b765
RS
429 (backward-sexp 1)
430 (beginning-of-line)
431 (setq tem (point))
432 (looking-at "DEFUN\\b"))
433 (>= location tem))
434 (error nil))
435 (progn
436 (goto-char tem)
437 (down-list 1)
438 (if (= (char-after (point)) ?\")
439 (progn
440 (forward-sexp 1)
441 (skip-chars-forward " ,")))
442 (buffer-substring (point)
443 (progn (forward-sexp 1) (point))))
32e986d4
RS
444 (if (looking-at "^[+-]")
445 (get-method-definition)
446 ;; Ordinary C function syntax.
447 (setq beg (point))
e172f546
KH
448 (if (and (condition-case nil
449 ;; Protect against "Unbalanced parens" error.
450 (progn
451 (down-list 1) ; into arglist
452 (backward-up-list 1)
453 (skip-chars-backward " \t")
454 t)
455 (error nil))
456 ;; Verify initial pos was after
457 ;; real start of function.
458 (save-excursion
459 (goto-char beg)
460 ;; For this purpose, include the line
461 ;; that has the decl keywords. This
462 ;; may also include some of the
463 ;; comments before the function.
464 (while (and (not (bobp))
465 (save-excursion
466 (forward-line -1)
467 (looking-at "[^\n\f]")))
468 (forward-line -1))
469 (>= location (point)))
32e986d4
RS
470 ;; Consistency check: going down and up
471 ;; shouldn't take us back before BEG.
472 (> (point) beg))
e172f546
KH
473 (let (end middle)
474 ;; Don't include any final newline
475 ;; in the name we use.
476 (if (= (preceding-char) ?\n)
477 (forward-char -1))
478 (setq end (point))
479 (backward-sexp 1)
480 ;; Now find the right beginning of the name.
481 ;; Include certain keywords if they
482 ;; precede the name.
483 (setq middle (point))
484 (forward-word -1)
6dfa1d83
RS
485 ;; Ignore these subparts of a class decl
486 ;; and move back to the class name itself.
487 (while (looking-at "public \\|private ")
488 (skip-chars-backward " \t:")
489 (setq end (point))
490 (backward-sexp 1)
491 (setq middle (point))
492 (forward-word -1))
e172f546
KH
493 (and (bolp)
494 (looking-at "struct \\|union \\|class ")
495 (setq middle (point)))
496 (buffer-substring middle end)))))))))
2cc0b765
RS
497 ((memq major-mode
498 '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el
499 plain-tex-mode latex-mode;; cmutex.el
500 ))
501 (if (re-search-backward
502 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t)
503 (progn
504 (goto-char (match-beginning 0))
505 (buffer-substring (1+ (point));; without initial backslash
506 (progn
507 (end-of-line)
508 (point))))))
509 ((eq major-mode 'texinfo-mode)
3071ee28 510 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
2cc0b765
RS
511 (buffer-substring (match-beginning 1)
512 (match-end 1))))
64bd2d51
RS
513 ((eq major-mode 'perl-mode)
514 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t)
515 (buffer-substring (match-beginning 1)
516 (match-end 1))))
a9e2a7f2
RS
517 ((eq major-mode 'fortran-mode)
518 ;; must be inside function body for this to work
519 (beginning-of-fortran-subprogram)
520 (let ((case-fold-search t)) ; case-insensitive
521 ;; search for fortran subprogram start
522 (if (re-search-forward
523 "^[ \t]*\\(program\\|subroutine\\|function\
524\\|[ \ta-z0-9*]*[ \t]+function\\)"
63314951 525 nil t)
a9e2a7f2
RS
526 (progn
527 ;; move to EOL or before first left paren
528 (if (re-search-forward "[(\n]" nil t)
529 (progn (forward-char -1)
530 (skip-chars-backward " \t"))
531 (end-of-line))
532 ;; Use the name preceding that.
533 (buffer-substring (point)
534 (progn (forward-sexp -1)
535 (point)))))))
2cc0b765
RS
536 (t
537 ;; If all else fails, try heuristics
538 (let (case-fold-search)
539 (end-of-line)
540 (if (re-search-backward add-log-current-defun-header-regexp
541 (- (point) 10000)
542 t)
543 (buffer-substring (match-beginning 1)
544 (match-end 1))))))))
545 (error nil)))
ef15f270 546
15319a8f
RS
547(defvar get-method-definition-md)
548
59c1a7de
RS
549;; Subroutine used within get-method-definition.
550;; Add the last match in the buffer to the end of `md',
551;; followed by the string END; move to the end of that match.
552(defun get-method-definition-1 (end)
15319a8f
RS
553 (setq get-method-definition-md
554 (concat get-method-definition-md
555 (buffer-substring (match-beginning 1) (match-end 1))
556 end))
59c1a7de
RS
557 (goto-char (match-end 0)))
558
559;; For objective C, return the method name if we are in a method.
560(defun get-method-definition ()
15319a8f 561 (let ((get-method-definition-md "["))
59c1a7de 562 (save-excursion
f27f16ed 563 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
59c1a7de
RS
564 (get-method-definition-1 " ")))
565 (save-excursion
566 (cond
f27f16ed 567 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
59c1a7de
RS
568 (get-method-definition-1 "")
569 (while (not (looking-at "[{;]"))
570 (looking-at
f27f16ed 571 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
59c1a7de 572 (get-method-definition-1 ""))
15319a8f 573 (concat get-method-definition-md "]"))))))
59c1a7de 574
ef15f270 575
1da56800
RS
576(provide 'add-log)
577
fd7fa35a 578;;; add-log.el ends here