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