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