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