Mercurial > emacs
annotate lisp/add-log.el @ 1398:70d0cd4c5bff
mem_limits.h is now called mem-limits.h.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 12 Oct 1992 18:55:05 +0000 |
parents | e5cb5060bb51 |
children | 75fa9ad982a5 |
rev | line source |
---|---|
661 | 1 ;;; add-log.el --- change log maintenance commands for Emacs |
2 | |
678 | 3 ;; Copyright (C) 1985, 86, 87, 88, 89, 90, 91, 1992 |
4 ;; Free Software Foundation, Inc. | |
661 | 5 |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
678
diff
changeset
|
10 ;; the Free Software Foundation; either version 2, or (at your option) |
661 | 11 ;; any later version. |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
678
diff
changeset
|
22 ;;; Code: |
661 | 23 |
24 ;;;###autoload | |
25 (defvar change-log-default-name nil | |
26 "*Name of a change log file for \\[add-change-log-entry].") | |
27 | |
28 (defun change-log-name () | |
29 (or change-log-default-name | |
30 (if (eq system-type 'vax-vms) "$CHANGE_LOG$.TXT" "ChangeLog"))) | |
31 | |
32 (defun prompt-for-change-log-name () | |
33 "Prompt for a change log name." | |
34 (let ((default (change-log-name))) | |
35 (expand-file-name | |
36 (read-file-name (format "Log file (default %s): " default) | |
37 nil default)))) | |
38 | |
39 ;;;###autoload | |
40 (defun add-change-log-entry (&optional whoami file-name other-window) | |
41 "Find change log file and add an entry for today. | |
42 Optional arg (interactive prefix) non-nil means prompt for user name and site. | |
43 Second arg is file name of change log. If nil, uses `change-log-default-name'. | |
44 Third arg OTHER-WINDOW non-nil means visit in other window." | |
45 (interactive (list current-prefix-arg | |
46 (prompt-for-change-log-name))) | |
678 | 47 (let* ((full-name (if whoami |
661 | 48 (read-input "Full name: " (user-full-name)) |
49 (user-full-name))) | |
50 ;; Note that some sites have room and phone number fields in | |
51 ;; full name which look silly when inserted. Rather than do | |
52 ;; anything about that here, let user give prefix argument so that | |
53 ;; s/he can edit the full name field in prompter if s/he wants. | |
54 (login-name (if whoami | |
55 (read-input "Login name: " (user-login-name)) | |
56 (user-login-name))) | |
57 (site-name (if whoami | |
58 (read-input "Site name: " (system-name)) | |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
59 (system-name))) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
60 (defun (add-log-current-defun)) |
678 | 61 entry entry-position empty-entry) |
661 | 62 (or file-name |
63 (setq file-name (or change-log-default-name | |
64 default-directory))) | |
678 | 65 (setq file-name (if (file-directory-p file-name) |
66 (expand-file-name (change-log-name) file-name) | |
67 (expand-file-name file-name))) | |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
68 ;; Chase links before visiting the file. |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
69 ;; This makes it easier to use a single change log file |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
70 ;; for several related directories. |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
71 (setq file-name (or (file-symlink-p file-name) file-name)) |
661 | 72 (set (make-local-variable 'change-log-default-name) file-name) |
678 | 73 (if buffer-file-name |
74 (setq entry (if (string-match | |
75 (concat "^" (regexp-quote (file-name-directory | |
76 file-name))) | |
77 buffer-file-name) | |
78 (substring buffer-file-name (match-end 0)) | |
79 (file-name-nondirectory buffer-file-name)))) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
80 ;; Never want to add a change log entry for the ChangeLog file itself. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
81 (if (equal entry "ChangeLog") |
678 | 82 (setq entry nil |
83 defun nil)) | |
661 | 84 (if (and other-window (not (equal file-name buffer-file-name))) |
85 (find-file-other-window file-name) | |
86 (find-file file-name)) | |
87 (undo-boundary) | |
88 (goto-char (point-min)) | |
951 | 89 (or (looking-at (concat (substring (current-time-string) 0 10) |
90 ".* " full-name " (" login-name "@")) | |
91 (insert (current-time-string) | |
92 " " full-name | |
93 " (" login-name | |
94 "@" site-name ")\n\n")) | |
661 | 95 (goto-char (point-min)) |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
96 (setq empty-entry |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
97 (and (search-forward "\n\t* \n" nil t) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
98 (1- (point)))) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
99 (if (and entry |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
100 (not empty-entry)) |
678 | 101 ;; Look for today's entry for the same file. |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
102 ;; If there is an empty entry (just a `*'), take the hint and |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
103 ;; use it. This is so that C-x a from the ChangeLog buffer |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
104 ;; itself can be used to force the next entry to be added at |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
105 ;; the beginning, even if there are today's entries for the |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
106 ;; same file (but perhaps different revisions). |
678 | 107 (let ((entry-boundary (save-excursion |
108 (and (re-search-forward "\n[A-Z]" nil t) | |
109 (point))))) | |
110 (setq entry-position (save-excursion | |
111 (and (re-search-forward | |
112 (concat | |
113 (regexp-quote (concat "* " entry)) | |
114 ;; don't accept `foo.bar' when | |
115 ;; looking for `foo': | |
116 "[ \n\t,:]") | |
117 entry-boundary | |
118 t) | |
119 (1- (match-end 0))))))) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
120 ;; Now insert the new line for this entry. |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
121 (cond (entry-position |
678 | 122 ;; Move to the existing entry for the same file. |
123 (goto-char entry-position) | |
124 (re-search-forward "^\\s *$") | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
125 (beginning-of-line) |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
126 (while (and (not (eobp)) (looking-at "^\\s *$")) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
127 (delete-region (point) (save-excursion (forward-line 1) (point)))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
128 (insert "\n\n") |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
129 (forward-line -2) |
678 | 130 (indent-relative-maybe)) |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
131 (empty-entry |
678 | 132 ;; Put this file name into the existing empty entry. |
133 (goto-char empty-entry) | |
134 (if entry | |
135 (insert entry))) | |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
136 (t |
678 | 137 ;; Make a new entry. |
138 (forward-line 1) | |
139 (while (looking-at "\\sW") | |
140 (forward-line 1)) | |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
141 (while (and (not (eobp)) (looking-at "^\\s *$")) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
142 (delete-region (point) (save-excursion (forward-line 1) (point)))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
143 (insert "\n\n\n") |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
144 (forward-line -2) |
678 | 145 (indent-to left-margin) |
146 (insert "* " (or entry "")))) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
147 ;; Now insert the function name, if we have one. |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
148 ;; Point is at the entry for this file, |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
149 ;; either at the end of the line or at the first blank line. |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
150 (if defun |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
151 (progn |
678 | 152 ;; Make it easy to get rid of the function name. |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
153 (undo-boundary) |
678 | 154 (insert (if (save-excursion |
155 (beginning-of-line 1) | |
156 (looking-at "\\s *$")) | |
157 "" | |
158 " ") | |
159 "(" defun "): ")) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
160 ;; No function name, so put in a colon unless we have just a star. |
678 | 161 (if (not (save-excursion |
162 (beginning-of-line 1) | |
163 (looking-at "\\s *\\(\\*\\s *\\)?$"))) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
164 (insert ": "))))) |
661 | 165 |
166 ;;;###autoload | |
167 (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) | |
168 | |
169 ;;;###autoload | |
170 (defun add-change-log-entry-other-window (&optional whoami file-name) | |
171 "Find change log file in other window and add an entry for today. | |
172 First arg (interactive prefix) non-nil means prompt for user name and site. | |
173 Second arg is file name of change log. | |
174 Interactively, with a prefix argument, the file name is prompted for." | |
175 (interactive (if current-prefix-arg | |
176 (list current-prefix-arg | |
177 (prompt-for-change-log-name)))) | |
178 (add-change-log-entry whoami file-name t)) | |
179 | |
980
b62886fbf2a7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
953
diff
changeset
|
180 ;;;###autoload |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
181 (defun change-log-mode () |
678 | 182 "Major mode for editting change logs; like Indented Text Mode. |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
183 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74. |
951 | 184 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window]. |
185 Each entry behaves as a paragraph, and the entries for one day as a page. | |
186 Runs `change-log-mode-hook'." | |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
187 (interactive) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
188 (kill-all-local-variables) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
189 (indented-text-mode) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
190 (setq major-mode 'change-log-mode) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
191 (setq mode-name "Change Log") |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
678
diff
changeset
|
192 (setq left-margin 8) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
678
diff
changeset
|
193 (setq fill-column 74) |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
194 ;; Let each entry behave as one paragraph: |
678 | 195 (set (make-local-variable 'paragraph-start) "^\\s *$\\|^^L") |
196 (set (make-local-variable 'paragraph-separate) "^\\s *$\\|^^L\\|^\\sw") | |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
197 ;; Let all entries for one day behave as one page. |
1078
15b4ed20e524
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1062
diff
changeset
|
198 ;; Match null string on the date-line so that the date-line |
15b4ed20e524
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1062
diff
changeset
|
199 ;; is grouped with what follows. |
15b4ed20e524
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1062
diff
changeset
|
200 (set (make-local-variable 'page-delimiter) "^\\<\\|^") |
678 | 201 (set (make-local-variable 'version-control) 'never) |
202 (set (make-local-variable 'adaptive-fill-regexp) "\\s *") | |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
203 (run-hooks 'change-log-mode-hook)) |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
204 |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
205 (defvar add-log-current-defun-header-regexp |
1369
e5cb5060bb51
(add-log-current-defun): In normal C case,
Richard M. Stallman <rms@gnu.org>
parents:
1351
diff
changeset
|
206 "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[a-z_---A-Z]+\\)[ \t]*[:=]" |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
207 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes.") |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
208 |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
209 (defun add-log-current-defun () |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
210 "Return name of function definition point is in, or nil. |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
211 |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
212 Understands Lisp, LaTeX (\"functions\" are chapters, sections, ...), |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
213 Texinfo (@node titles), and C. |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
214 |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
215 Other modes are handled by a heuristic that looks in the 10K before |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
216 point for uppercase headings starting in the first column or |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
217 identifiers followed by `:' or `=', see variable |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
218 `add-log-current-defun-header-regexp'. |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
219 |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
220 Has a preference of looking backwards." |
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
221 (save-excursion |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
222 (let ((location (point))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
223 (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
224 ;; If we are now precisely a the beginning of a defun, |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
225 ;; make sure beginning-of-defun finds that one |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
226 ;; rather than the previous one. |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
227 (or (eobp) (forward-char 1)) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
228 (beginning-of-defun) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
229 ;; Make sure we are really inside the defun found, not after it. |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
230 (if (and (progn (end-of-defun) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
231 (< location (point))) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
232 (progn (forward-sexp -1) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
233 (>= location (point)))) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
234 (progn |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
235 (forward-word 1) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
236 (skip-chars-forward " ") |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
237 (buffer-substring (point) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
238 (progn (forward-sexp 1) (point)))))) |
951 | 239 ((and (memq major-mode '(c-mode 'c++-mode)) |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
240 (save-excursion (beginning-of-line) |
947 | 241 ;; Use eq instead of = here to avoid |
242 ;; error when at bob and char-after | |
243 ;; returns nil. | |
244 (while (eq (char-after (- (point) 2)) ?\\) | |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
245 (forward-line -1)) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
246 (looking-at "[ \t]*#[ \t]*define[ \t]"))) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
247 ;; Handle a C macro definition. |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
248 (beginning-of-line) |
1089 | 249 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
250 (forward-line -1)) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
251 (search-forward "define") |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
252 (skip-chars-forward " \t") |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
253 (buffer-substring (point) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
254 (progn (forward-sexp 1) (point)))) |
951 | 255 ((memq major-mode '(c-mode 'c++-mode)) |
1369
e5cb5060bb51
(add-log-current-defun): In normal C case,
Richard M. Stallman <rms@gnu.org>
parents:
1351
diff
changeset
|
256 (beginning-of-line) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
257 ;; See if we are in the beginning part of a function, |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
258 ;; before the open brace. If so, advance forward. |
951 | 259 (while (not (looking-at "{\\|\\(\\s *$\\)")) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
260 (forward-line 1)) |
951 | 261 (or (eobp) |
262 (forward-char 1)) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
263 (beginning-of-defun) |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
264 (if (progn (end-of-defun) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
265 (< location (point))) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
266 (progn |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
267 (backward-sexp 1) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
268 (let (beg tem) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
269 |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
270 (forward-line -1) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
271 ;; Skip back over typedefs of arglist. |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
272 (while (and (not (bobp)) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
273 (looking-at "[ \t\n]")) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
274 (forward-line -1)) |
951 | 275 ;; See if this is using the DEFUN macro used in Emacs, |
276 ;; or the DEFUN macro used by the C library. | |
1351
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
277 (if (condition-case nil |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
278 (and (save-excursion |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
279 (forward-line 1) |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
280 (backward-sexp 1) |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
281 (beginning-of-line) |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
282 (setq tem (point)) |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
283 (looking-at "DEFUN\\b")) |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
284 (>= location tem)) |
e7bc20e1b2b9
(add-log-current-defun): Catch errors checking for DEFUN.
Richard M. Stallman <rms@gnu.org>
parents:
1089
diff
changeset
|
285 (error nil)) |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
286 (progn |
1034
5cc1bd18edf7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
999
diff
changeset
|
287 (goto-char tem) |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
288 (down-list 1) |
951 | 289 (if (= (char-after (point)) ?\") |
290 (progn | |
291 (forward-sexp 1) | |
292 (skip-chars-forward " ,"))) | |
912
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
293 (buffer-substring (point) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
294 (progn (forward-sexp 1) (point)))) |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
295 ;; Ordinary C function syntax. |
1c37c99856de
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
296 (setq beg (point)) |
953 | 297 (if (condition-case nil |
298 ;; Protect against "Unbalanced parens" error. | |
299 (progn | |
300 (down-list 1) ; into arglist | |
301 (backward-up-list 1) | |
302 (skip-chars-backward " \t") | |
303 t) | |
304 (error nil)) | |
305 ;; Verify initial pos was after | |
306 ;; real start of function. | |
307 (if (and (save-excursion | |
308 (goto-char beg) | |
309 ;; For this purpose, include the line | |
310 ;; that has the decl keywords. This | |
311 ;; may also include some of the | |
312 ;; comments before the function. | |
313 (while (and (not (bobp)) | |
314 (save-excursion | |
315 (forward-line -1) | |
316 (looking-at "[^\n\f]"))) | |
317 (forward-line -1)) | |
318 (>= location (point))) | |
319 ;; Consistency check: going down and up | |
320 ;; shouldn't take us back before BEG. | |
321 (> (point) beg)) | |
322 (buffer-substring (point) | |
323 (progn (backward-sexp 1) | |
324 (point)))))))))) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
325 ((memq major-mode |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
326 '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
327 plain-tex-mode latex-mode;; cmutex.el |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
328 )) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
329 (if (re-search-backward |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
330 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
331 (progn |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
332 (goto-char (match-beginning 0)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
333 (buffer-substring (1+ (point));; without initial backslash |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
334 (progn |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
335 (end-of-line) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
336 (point)))))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
337 ((eq major-mode 'texinfo-mode) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
338 (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) |
666
7fa6b835da67
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
661
diff
changeset
|
339 (buffer-substring (match-beginning 1) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
340 (match-end 1)))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
341 (t |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
342 ;; If all else fails, try heuristics |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
343 (let (case-fold-search) |
1369
e5cb5060bb51
(add-log-current-defun): In normal C case,
Richard M. Stallman <rms@gnu.org>
parents:
1351
diff
changeset
|
344 (end-of-line) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
345 (if (re-search-backward add-log-current-defun-header-regexp |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
346 (- (point) 10000) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
347 t) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
348 (buffer-substring (match-beginning 1) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
811
diff
changeset
|
349 (match-end 1))))))))) |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
678
diff
changeset
|
350 |
999 | 351 |
352 | |
980
b62886fbf2a7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
953
diff
changeset
|
353 (provide 'add-log) |
b62886fbf2a7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
953
diff
changeset
|
354 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
678
diff
changeset
|
355 ;;; add-log.el ends here |