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