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