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