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