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