Commit | Line | Data |
---|---|---|
5abdc915 | 1 | ;;; add-log.el --- change log maintenance commands for Emacs |
84fc2cfa | 2 | |
171c707b LK |
3 | ;; Copyright (C) 1985, 1986, 1988, 1993, 1994, 1997, 1998, 2000, 2003, |
4 | ;; 2004, 2005 Free Software Foundation, Inc. | |
84fc2cfa | 5 | |
6228c05b | 6 | ;; Maintainer: FSF |
df63ae66 | 7 | ;; Keywords: tools |
e9571d2a | 8 | |
84fc2cfa ER |
9 | ;; This file is part of GNU Emacs. |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
fd7fa35a | 13 | ;; the Free Software Foundation; either version 2, or (at your option) |
84fc2cfa ER |
14 | ;; any later version. |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
84fc2cfa | 25 | |
e41b2db1 ER |
26 | ;;; Commentary: |
27 | ||
28 | ;; This facility is documented in the Emacs Manual. | |
29 | ||
fd7fa35a | 30 | ;;; Code: |
84fc2cfa | 31 | |
776d8e16 | 32 | (eval-when-compile |
5960adc7 | 33 | (require 'timezone)) |
3697b807 | 34 | |
fcad5199 RS |
35 | (defgroup change-log nil |
36 | "Change log maintenance" | |
37 | :group 'tools | |
3697b807 | 38 | :link '(custom-manual "(emacs)Change Log") |
fcad5199 RS |
39 | :prefix "change-log-" |
40 | :prefix "add-log-") | |
84fc2cfa | 41 | |
fcad5199 RS |
42 | |
43 | (defcustom change-log-default-name nil | |
44 | "*Name of a change log file for \\[add-change-log-entry]." | |
45 | :type '(choice (const :tag "default" nil) | |
46 | string) | |
47 | :group 'change-log) | |
48 | ||
c3979f12 DL |
49 | (defcustom change-log-mode-hook nil |
50 | "Normal hook run by `change-log-mode'." | |
51 | :type 'hook | |
52 | :group 'change-log) | |
53 | ||
c882e115 RS |
54 | ;; Many modes set this variable, so avoid warnings. |
55 | ;;;###autoload | |
fcad5199 | 56 | (defcustom add-log-current-defun-function nil |
5960adc7 DL |
57 | "*If non-nil, function to guess name of surrounding function. |
58 | It is used by `add-log-current-defun' in preference to built-in rules. | |
59 | Returns function's name as a string, or nil if outside a function." | |
cea3855a | 60 | :type '(choice (const nil) function) |
fcad5199 | 61 | :group 'change-log) |
6258d3af | 62 | |
29db528b | 63 | ;;;###autoload |
fcad5199 | 64 | (defcustom add-log-full-name nil |
02ec1592 | 65 | "*Full name of user, for inclusion in ChangeLog daily headers. |
075a6629 | 66 | This defaults to the value returned by the function `user-full-name'." |
fcad5199 RS |
67 | :type '(choice (const :tag "Default" nil) |
68 | string) | |
69 | :group 'change-log) | |
02ec1592 | 70 | |
29db528b | 71 | ;;;###autoload |
fcad5199 | 72 | (defcustom add-log-mailing-address nil |
c1b3ae42 CW |
73 | "*Electronic mail addresses of user, for inclusion in ChangeLog headers. |
74 | This defaults to the value of `user-mail-address'. In addition to | |
75 | being a simple string, this value can also be a list. All elements | |
76 | will be recognized as referring to the same user; when creating a new | |
77 | ChangeLog entry, one element will be chosen at random." | |
fcad5199 | 78 | :type '(choice (const :tag "Default" nil) |
24f4201f MR |
79 | (string :tag "String") |
80 | (repeat :tag "List of Strings" string)) | |
fcad5199 RS |
81 | :group 'change-log) |
82 | ||
df63ae66 RS |
83 | (defcustom add-log-time-format 'add-log-iso8601-time-string |
84 | "*Function that defines the time format. | |
85 | For example, `add-log-iso8601-time-string', which gives the | |
86 | date in international ISO 8601 format, | |
87 | and `current-time-string' are two valid values." | |
88 | :type '(radio (const :tag "International ISO 8601 format" | |
89 | add-log-iso8601-time-string) | |
90 | (const :tag "Old format, as returned by `current-time-string'" | |
91 | current-time-string) | |
92 | (function :tag "Other")) | |
93 | :group 'change-log) | |
02ec1592 | 94 | |
83afd62c | 95 | (defcustom add-log-keep-changes-together nil |
3697b807 DL |
96 | "*If non-nil, normally keep day's log entries for one file together. |
97 | ||
98 | Log entries for a given file made with \\[add-change-log-entry] or | |
99 | \\[add-change-log-entry-other-window] will only be added to others \ | |
100 | for that file made | |
101 | today if this variable is non-nil or that file comes first in today's | |
102 | entries. Otherwise another entry for that file will be started. An | |
103 | original log: | |
104 | ||
105 | * foo (...): ... | |
106 | * bar (...): change 1 | |
83afd62c | 107 | |
3697b807 DL |
108 | in the latter case, \\[add-change-log-entry-other-window] in a \ |
109 | buffer visiting `bar', yields: | |
83afd62c | 110 | |
3697b807 DL |
111 | * bar (...): -!- |
112 | * foo (...): ... | |
113 | * bar (...): change 1 | |
83afd62c | 114 | |
3697b807 | 115 | and in the former: |
83afd62c | 116 | |
3697b807 DL |
117 | * foo (...): ... |
118 | * bar (...): change 1 | |
119 | (...): -!- | |
83afd62c | 120 | |
3697b807 DL |
121 | The NEW-ENTRY arg to `add-change-log-entry' can override the effect of |
122 | this variable." | |
123 | :version "20.3" | |
83afd62c KH |
124 | :type 'boolean |
125 | :group 'change-log) | |
126 | ||
598f34fa SS |
127 | (defcustom add-log-always-start-new-record nil |
128 | "*If non-nil, `add-change-log-entry' will always start a new record." | |
bf247b6e | 129 | :version "22.1" |
598f34fa SS |
130 | :type 'boolean |
131 | :group 'change-log) | |
132 | ||
d68f7f1b SM |
133 | (defcustom add-log-buffer-file-name-function nil |
134 | "*If non-nil, function to call to identify the full filename of a buffer. | |
135 | This function is called with no argument. If this is nil, the default is to | |
136 | use `buffer-file-name'." | |
cea3855a | 137 | :type '(choice (const nil) function) |
d68f7f1b SM |
138 | :group 'change-log) |
139 | ||
666f4056 RS |
140 | (defcustom add-log-file-name-function nil |
141 | "*If non-nil, function to call to identify the filename for a ChangeLog entry. | |
075a6629 DL |
142 | This function is called with one argument, the value of variable |
143 | `buffer-file-name' in that buffer. If this is nil, the default is to | |
144 | use the file's name relative to the directory of the change log file." | |
cea3855a | 145 | :type '(choice (const nil) function) |
666f4056 RS |
146 | :group 'change-log) |
147 | ||
776d8e16 GM |
148 | |
149 | (defcustom change-log-version-info-enabled nil | |
150 | "*If non-nil, enable recording version numbers with the changes." | |
151 | :version "21.1" | |
152 | :type 'boolean | |
153 | :group 'change-log) | |
154 | ||
155 | (defcustom change-log-version-number-regexp-list | |
156 | (let ((re "\\([0-9]+\.[0-9.]+\\)")) | |
157 | (list | |
158 | ;; (defconst ad-version "2.15" | |
159 | (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re) | |
160 | ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp | |
5960adc7 | 161 | (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re))) |
776d8e16 | 162 | "*List of regexps to search for version number. |
5960adc7 | 163 | The version number must be in group 1. |
776d8e16 GM |
164 | Note: The search is conducted only within 10%, at the beginning of the file." |
165 | :version "21.1" | |
166 | :type '(repeat regexp) | |
167 | :group 'change-log) | |
168 | ||
163f7b71 GM |
169 | (defface change-log-date-face |
170 | '((t (:inherit font-lock-string-face))) | |
171 | "Face used to highlight dates in date lines." | |
172 | :version "21.1" | |
173 | :group 'change-log) | |
174 | ||
175 | (defface change-log-name-face | |
176 | '((t (:inherit font-lock-constant-face))) | |
177 | "Face for highlighting author names." | |
178 | :version "21.1" | |
179 | :group 'change-log) | |
180 | ||
181 | (defface change-log-email-face | |
182 | '((t (:inherit font-lock-variable-name-face))) | |
183 | "Face for highlighting author email addresses." | |
184 | :version "21.1" | |
185 | :group 'change-log) | |
186 | ||
187 | (defface change-log-file-face | |
188 | '((t (:inherit font-lock-function-name-face))) | |
189 | "Face for highlighting file names." | |
190 | :version "21.1" | |
191 | :group 'change-log) | |
192 | ||
193 | (defface change-log-list-face | |
194 | '((t (:inherit font-lock-keyword-face))) | |
195 | "Face for highlighting parenthesized lists of functions or variables." | |
196 | :version "21.1" | |
197 | :group 'change-log) | |
598f34fa | 198 | |
163f7b71 GM |
199 | (defface change-log-conditionals-face |
200 | '((t (:inherit font-lock-variable-name-face))) | |
201 | "Face for highlighting conditionals of the form `[...]'." | |
202 | :version "21.1" | |
203 | :group 'change-log) | |
204 | ||
205 | (defface change-log-function-face | |
206 | '((t (:inherit font-lock-variable-name-face))) | |
207 | "Face for highlighting items of the form `<....>'." | |
208 | :version "21.1" | |
209 | :group 'change-log) | |
210 | ||
211 | (defface change-log-acknowledgement-face | |
212 | '((t (:inherit font-lock-comment-face))) | |
213 | "Face for highlighting acknowledgments." | |
214 | :version "21.1" | |
215 | :group 'change-log) | |
776d8e16 | 216 | |
5f562719 | 217 | (defvar change-log-font-lock-keywords |
5572c1d1 SM |
218 | '(;; |
219 | ;; Date lines, new and old styles. | |
3307b0ca | 220 | ("^\\sw.........[0-9:+ ]*" |
163f7b71 | 221 | (0 'change-log-date-face) |
97a3278b | 222 | ;; Name and e-mail; some people put e-mail in parens, not angles. |
7397a79f | 223 | ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil |
163f7b71 GM |
224 | (1 'change-log-name-face) |
225 | (2 'change-log-email-face))) | |
5572c1d1 SM |
226 | ;; |
227 | ;; File names. | |
9e4b54a0 LK |
228 | ("^\\( +\\|\t\\)\\* \\([^ ,:([\n]+\\)" |
229 | (2 'change-log-file-face) | |
97a3278b | 230 | ;; Possibly further names in a list: |
163f7b71 | 231 | ("\\=, \\([^ ,:([\n]+\\)" nil nil (1 'change-log-file-face)) |
97a3278b | 232 | ;; Possibly a parenthesized list of names: |
171c707b | 233 | ("\\= (\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)" |
bc071f64 | 234 | nil nil (1 'change-log-list-face)) |
171c707b | 235 | ("\\=, *\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)" |
bc071f64 | 236 | nil nil (1 'change-log-list-face))) |
5572c1d1 SM |
237 | ;; |
238 | ;; Function or variable names. | |
9e4b54a0 LK |
239 | ("^\\( +\\|\t\\)(\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)" |
240 | (2 'change-log-list-face) | |
171c707b | 241 | ("\\=, *\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)" nil nil |
bc071f64 | 242 | (1 'change-log-list-face))) |
5572c1d1 SM |
243 | ;; |
244 | ;; Conditionals. | |
163f7b71 | 245 | ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals-face)) |
5572c1d1 | 246 | ;; |
a8d693d8 | 247 | ;; Function of change. |
163f7b71 | 248 | ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function-face)) |
a8d693d8 | 249 | ;; |
a3cab9f0 | 250 | ;; Acknowledgements. |
a8e10524 RS |
251 | ;; Don't include plain "From" because that is vague; |
252 | ;; we want to encourage people to say something more specific. | |
c50089c9 RS |
253 | ;; Note that the FSF does not use "Patches by"; our convention |
254 | ;; is to put the name of the author of the changes at the top | |
255 | ;; of the change log entry. | |
9e4b54a0 LK |
256 | ("\\(^\\( +\\|\t\\)\\| \\)\\(Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)" |
257 | 3 'change-log-acknowledgement-face)) | |
5f562719 RS |
258 | "Additional expressions to highlight in Change Log mode.") |
259 | ||
3066d4ad SM |
260 | (defvar change-log-mode-map |
261 | (let ((map (make-sparse-keymap))) | |
262 | (define-key map [?\C-c ?\C-p] 'add-log-edit-prev-comment) | |
263 | (define-key map [?\C-c ?\C-n] 'add-log-edit-next-comment) | |
264 | map) | |
45c50c5d | 265 | "Keymap for Change Log major mode.") |
45c50c5d | 266 | |
51bd1843 EN |
267 | (defvar change-log-time-zone-rule nil |
268 | "Time zone used for calculating change log time stamps. | |
269 | It takes the same format as the TZ argument of `set-time-zone-rule'. | |
270 | If nil, use local time.") | |
271 | ||
df63ae66 | 272 | (defun add-log-iso8601-time-zone (time) |
51bd1843 EN |
273 | (let* ((utc-offset (or (car (current-time-zone time)) 0)) |
274 | (sign (if (< utc-offset 0) ?- ?+)) | |
275 | (sec (abs utc-offset)) | |
276 | (ss (% sec 60)) | |
277 | (min (/ sec 60)) | |
278 | (mm (% min 60)) | |
279 | (hh (/ min 60))) | |
280 | (format (cond ((not (zerop ss)) "%c%02d:%02d:%02d") | |
281 | ((not (zerop mm)) "%c%02d:%02d") | |
282 | (t "%c%02d")) | |
283 | sign hh mm ss))) | |
284 | ||
df63ae66 RS |
285 | (defun add-log-iso8601-time-string () |
286 | (if change-log-time-zone-rule | |
287 | (let ((tz (getenv "TZ")) | |
288 | (now (current-time))) | |
289 | (unwind-protect | |
290 | (progn | |
918f4ac3 | 291 | (set-time-zone-rule change-log-time-zone-rule) |
df63ae66 RS |
292 | (concat |
293 | (format-time-string "%Y-%m-%d " now) | |
294 | (add-log-iso8601-time-zone now))) | |
295 | (set-time-zone-rule tz))) | |
296 | (format-time-string "%Y-%m-%d"))) | |
297 | ||
84fc2cfa | 298 | (defun change-log-name () |
075a6629 | 299 | "Return (system-dependent) default name for a change log file." |
84fc2cfa | 300 | (or change-log-default-name |
513063cf | 301 | (if (eq system-type 'vax-vms) |
4a047d23 RS |
302 | "$CHANGE_LOG$.TXT" |
303 | "ChangeLog"))) | |
84fc2cfa | 304 | |
3066d4ad SM |
305 | (defun add-log-edit-prev-comment (arg) |
306 | "Cycle backward through Log-Edit mode comment history. | |
307 | With a numeric prefix ARG, go back ARG comments." | |
308 | (interactive "*p") | |
309 | (save-restriction | |
310 | (narrow-to-region (point) | |
311 | (if (memq last-command '(add-log-edit-prev-comment | |
312 | add-log-edit-next-comment)) | |
313 | (mark) (point))) | |
314 | (when (fboundp 'log-edit-previous-comment) | |
315 | (log-edit-previous-comment arg) | |
316 | (indent-region (point-min) (point-max)) | |
317 | (goto-char (point-min)) | |
318 | (unless (save-restriction (widen) (bolp)) | |
319 | (delete-region (point) (progn (skip-chars-forward " \t\n") (point)))) | |
320 | (set-mark (point-min)) | |
321 | (goto-char (point-max)) | |
322 | (delete-region (point) (progn (skip-chars-backward " \t\n") (point)))))) | |
323 | ||
324 | (defun add-log-edit-next-comment (arg) | |
325 | "Cycle forward through Log-Edit mode comment history. | |
326 | With a numeric prefix ARG, go back ARG comments." | |
327 | (interactive "*p") | |
328 | (add-log-edit-prev-comment (- arg))) | |
329 | ||
287d149f | 330 | ;;;###autoload |
84fc2cfa ER |
331 | (defun prompt-for-change-log-name () |
332 | "Prompt for a change log name." | |
117aaf60 KH |
333 | (let* ((default (change-log-name)) |
334 | (name (expand-file-name | |
335 | (read-file-name (format "Log file (default %s): " default) | |
336 | nil default)))) | |
337 | ;; Handle something that is syntactically a directory name. | |
338 | ;; Look for ChangeLog or whatever in that directory. | |
339 | (if (string= (file-name-nondirectory name) "") | |
340 | (expand-file-name (file-name-nondirectory default) | |
341 | name) | |
342 | ;; Handle specifying a file that is a directory. | |
343 | (if (file-directory-p name) | |
344 | (expand-file-name (file-name-nondirectory default) | |
345 | (file-name-as-directory name)) | |
346 | name)))) | |
84fc2cfa | 347 | |
776d8e16 | 348 | (defun change-log-version-number-search () |
5960adc7 DL |
349 | "Return version number of current buffer's file. |
350 | This is the value returned by `vc-workfile-version' or, if that is | |
351 | nil, by matching `change-log-version-number-regexp-list'." | |
776d8e16 | 352 | (let* ((size (buffer-size)) |
fc9b0554 | 353 | (limit |
5960adc7 DL |
354 | ;; The version number can be anywhere in the file, but |
355 | ;; restrict search to the file beginning: 10% should be | |
356 | ;; enough to prevent some mishits. | |
776d8e16 | 357 | ;; |
5960adc7 DL |
358 | ;; Apply percentage only if buffer size is bigger than |
359 | ;; approx 100 lines. | |
fc9b0554 | 360 | (if (> size (* 100 80)) (+ (point) (/ size 10))))) |
d68f7f1b | 361 | (or (and buffer-file-name (vc-workfile-version buffer-file-name)) |
5960adc7 DL |
362 | (save-restriction |
363 | (widen) | |
fc9b0554 SM |
364 | (let ((regexps change-log-version-number-regexp-list) |
365 | version) | |
5960adc7 DL |
366 | (while regexps |
367 | (save-excursion | |
368 | (goto-char (point-min)) | |
fc9b0554 | 369 | (when (re-search-forward (pop regexps) limit t) |
5960adc7 | 370 | (setq version (match-string 1) |
fc9b0554 SM |
371 | regexps nil)))) |
372 | version))))) | |
776d8e16 GM |
373 | |
374 | ||
45a13f0d | 375 | ;;;###autoload |
d68f7f1b | 376 | (defun find-change-log (&optional file-name buffer-file) |
45a13f0d | 377 | "Find a change log file for \\[add-change-log-entry] and return the name. |
a82e2ed5 RS |
378 | |
379 | Optional arg FILE-NAME specifies the file to use. | |
de98fcaf | 380 | If FILE-NAME is nil, use the value of `change-log-default-name'. |
218cf475 | 381 | If `change-log-default-name' is nil, behave as though it were 'ChangeLog' |
de98fcaf RS |
382 | \(or whatever we use on this operating system). |
383 | ||
218cf475 | 384 | If `change-log-default-name' contains a leading directory component, then |
513063cf | 385 | simply find it in the current directory. Otherwise, search in the current |
de98fcaf | 386 | directory and its successive parents for a file so named. |
45a13f0d RM |
387 | |
388 | Once a file is found, `change-log-default-name' is set locally in the | |
d68f7f1b SM |
389 | current buffer to the complete file name. |
390 | Optional arg BUFFER-FILE overrides `buffer-file-name'." | |
a82e2ed5 RS |
391 | ;; If user specified a file name or if this buffer knows which one to use, |
392 | ;; just use that. | |
45a13f0d | 393 | (or file-name |
de98fcaf RS |
394 | (setq file-name (and change-log-default-name |
395 | (file-name-directory change-log-default-name) | |
396 | change-log-default-name)) | |
a82e2ed5 RS |
397 | (progn |
398 | ;; Chase links in the source file | |
399 | ;; and use the change log in the dir where it points. | |
d68f7f1b | 400 | (setq file-name (or (and (or buffer-file buffer-file-name) |
a82e2ed5 | 401 | (file-name-directory |
d68f7f1b SM |
402 | (file-chase-links |
403 | (or buffer-file buffer-file-name)))) | |
a82e2ed5 RS |
404 | default-directory)) |
405 | (if (file-directory-p file-name) | |
406 | (setq file-name (expand-file-name (change-log-name) file-name))) | |
407 | ;; Chase links before visiting the file. | |
408 | ;; This makes it easier to use a single change log file | |
409 | ;; for several related directories. | |
410 | (setq file-name (file-chase-links file-name)) | |
411 | (setq file-name (expand-file-name file-name)) | |
412 | ;; Move up in the dir hierarchy till we find a change log file. | |
413 | (let ((file1 file-name) | |
414 | parent-dir) | |
415 | (while (and (not (or (get-file-buffer file1) (file-exists-p file1))) | |
416 | (progn (setq parent-dir | |
417 | (file-name-directory | |
418 | (directory-file-name | |
419 | (file-name-directory file1)))) | |
420 | ;; Give up if we are already at the root dir. | |
421 | (not (string= (file-name-directory file1) | |
422 | parent-dir)))) | |
423 | ;; Move up to the parent dir and try again. | |
513063cf | 424 | (setq file1 (expand-file-name |
a82e2ed5 RS |
425 | (file-name-nondirectory (change-log-name)) |
426 | parent-dir))) | |
427 | ;; If we found a change log in a parent, use that. | |
428 | (if (or (get-file-buffer file1) (file-exists-p file1)) | |
429 | (setq file-name file1))))) | |
430 | ;; Make a local variable in this buffer so we needn't search again. | |
431 | (set (make-local-variable 'change-log-default-name) file-name) | |
432 | file-name) | |
45a13f0d | 433 | |
2eb7ccf4 SM |
434 | (defun add-log-file-name (buffer-file log-file) |
435 | ;; Never want to add a change log entry for the ChangeLog file itself. | |
436 | (unless (or (null buffer-file) (string= buffer-file log-file)) | |
d68f7f1b SM |
437 | (if add-log-file-name-function |
438 | (funcall add-log-file-name-function buffer-file) | |
439 | (setq buffer-file | |
440 | (if (string-match | |
441 | (concat "^" (regexp-quote (file-name-directory log-file))) | |
442 | buffer-file) | |
443 | (substring buffer-file (match-end 0)) | |
444 | (file-name-nondirectory buffer-file))) | |
445 | ;; If we have a backup file, it's presumably because we're | |
446 | ;; comparing old and new versions (e.g. for deleted | |
447 | ;; functions) and we'll want to use the original name. | |
448 | (if (backup-file-name-p buffer-file) | |
449 | (file-name-sans-versions buffer-file) | |
450 | buffer-file)))) | |
2eb7ccf4 | 451 | |
84fc2cfa | 452 | ;;;###autoload |
287d149f | 453 | (defun add-change-log-entry (&optional whoami file-name other-window new-entry) |
d882f144 | 454 | "Find change log file, and add an entry for today and an item for this file. |
83afd62c | 455 | Optional arg WHOAMI (interactive prefix) non-nil means prompt for user |
d9ee5172 | 456 | name and email (stored in `add-log-full-name' and `add-log-mailing-address'). |
83afd62c | 457 | |
d882f144 RS |
458 | Second arg FILE-NAME is file name of the change log. |
459 | If nil, use the value of `change-log-default-name'. | |
460 | ||
287d149f | 461 | Third arg OTHER-WINDOW non-nil means visit in other window. |
d882f144 | 462 | |
287d149f | 463 | Fourth arg NEW-ENTRY non-nil means always create a new entry at the front; |
3697b807 DL |
464 | never append to an existing entry. Option `add-log-keep-changes-together' |
465 | otherwise affects whether a new entry is created. | |
466 | ||
598f34fa SS |
467 | Option `add-log-always-start-new-record' non-nil means always create a |
468 | new record, even when the last record was made on the same date and by | |
469 | the same person. | |
470 | ||
d882f144 RS |
471 | The change log file can start with a copyright notice and a copying |
472 | permission notice. The first blank line indicates the end of these | |
473 | notices. | |
474 | ||
3697b807 DL |
475 | Today's date is calculated according to `change-log-time-zone-rule' if |
476 | non-nil, otherwise in local time." | |
84fc2cfa ER |
477 | (interactive (list current-prefix-arg |
478 | (prompt-for-change-log-name))) | |
d68f7f1b SM |
479 | (let* ((defun (add-log-current-defun)) |
480 | (version (and change-log-version-info-enabled | |
481 | (change-log-version-number-search))) | |
8f530b95 SM |
482 | (buf-file-name (if add-log-buffer-file-name-function |
483 | (funcall add-log-buffer-file-name-function) | |
484 | buffer-file-name)) | |
485 | (buffer-file (if buf-file-name (expand-file-name buf-file-name))) | |
dd816e0d | 486 | (file-name (expand-file-name (find-change-log file-name buffer-file))) |
d882f144 RS |
487 | ;; Set ITEM to the file name to use in the new item. |
488 | (item (add-log-file-name buffer-file file-name)) | |
563631fe RS |
489 | bound |
490 | (full-name (or add-log-full-name (user-full-name))) | |
491 | (mailing-address (or add-log-mailing-address user-mail-address))) | |
492 | ||
493 | (if whoami | |
494 | (progn | |
3981e5b5 | 495 | (setq full-name (read-string "Full name: " full-name)) |
563631fe RS |
496 | ;; Note that some sites have room and phone number fields in |
497 | ;; full name which look silly when inserted. Rather than do | |
498 | ;; anything about that here, let user give prefix argument so that | |
499 | ;; s/he can edit the full name field in prompter if s/he wants. | |
500 | (setq mailing-address | |
3981e5b5 | 501 | (read-string "Mailing address: " mailing-address)))) |
2eb7ccf4 | 502 | |
7cd017ba SM |
503 | (unless (equal file-name buffer-file-name) |
504 | (if (or other-window (window-dedicated-p (selected-window))) | |
505 | (find-file-other-window file-name) | |
506 | (find-file file-name))) | |
675a998f RS |
507 | (or (eq major-mode 'change-log-mode) |
508 | (change-log-mode)) | |
84fc2cfa ER |
509 | (undo-boundary) |
510 | (goto-char (point-min)) | |
d882f144 RS |
511 | |
512 | ;; If file starts with a copyright and permission notice, skip them. | |
513 | ;; Assume they end at first blank line. | |
514 | (when (looking-at "Copyright") | |
515 | (search-forward "\n\n") | |
516 | (skip-chars-forward "\n")) | |
517 | ||
518 | ;; Advance into first entry if it is usable; else make new one. | |
c1b3ae42 CW |
519 | (let ((new-entries (mapcar (lambda (addr) |
520 | (concat (funcall add-log-time-format) | |
563631fe | 521 | " " full-name |
c1b3ae42 | 522 | " <" addr ">")) |
563631fe RS |
523 | (if (consp mailing-address) |
524 | mailing-address | |
525 | (list mailing-address))))) | |
598f34fa | 526 | (if (and (not add-log-always-start-new-record) |
c1b3ae42 CW |
527 | (let ((hit nil)) |
528 | (dolist (entry new-entries hit) | |
529 | (when (looking-at (regexp-quote entry)) | |
530 | (setq hit t))))) | |
51bd1843 | 531 | (forward-line 1) |
c1b3ae42 CW |
532 | (insert (nth (random (length new-entries)) |
533 | new-entries) | |
534 | "\n\n") | |
d882f144 | 535 | (forward-line -1))) |
82f4acaf | 536 | |
d882f144 RS |
537 | ;; Determine where we should stop searching for a usable |
538 | ;; item to add to, within this entry. | |
3697b807 | 539 | (setq bound |
d882f144 | 540 | (save-excursion |
3697b807 DL |
541 | (if (looking-at "\n*[^\n* \t]") |
542 | (skip-chars-forward "\n") | |
543 | (if add-log-keep-changes-together | |
544 | (forward-page) ; page delimits entries for date | |
545 | (forward-paragraph))) ; paragraph delimits entries for file | |
546 | (point))) | |
d882f144 RS |
547 | |
548 | ;; Now insert the new line for this item. | |
3697b807 | 549 | (cond ((re-search-forward "^\\s *\\*\\s *$" bound t) |
d882f144 RS |
550 | ;; Put this file name into the existing empty item. |
551 | (if item | |
552 | (insert item))) | |
287d149f | 553 | ((and (not new-entry) |
e172f546 KH |
554 | (let (case-fold-search) |
555 | (re-search-forward | |
d882f144 | 556 | (concat (regexp-quote (concat "* " item)) |
e172f546 KH |
557 | ;; Don't accept `foo.bar' when |
558 | ;; looking for `foo': | |
559 | "\\(\\s \\|[(),:]\\)") | |
3697b807 | 560 | bound t))) |
d882f144 | 561 | ;; Add to the existing item for the same file. |
82f4acaf | 562 | (re-search-forward "^\\s *$\\|^\\s \\*") |
e172f546 | 563 | (goto-char (match-beginning 0)) |
3697b807 DL |
564 | ;; Delete excess empty lines; make just 2. |
565 | (while (and (not (eobp)) (looking-at "^\\s *$")) | |
5960adc7 | 566 | (delete-region (point) (line-beginning-position 2))) |
918f4ac3 | 567 | (insert-char ?\n 2) |
3697b807 DL |
568 | (forward-line -2) |
569 | (indent-relative-maybe)) | |
21d7e080 | 570 | (t |
d882f144 | 571 | ;; Make a new item. |
dd309224 RM |
572 | (while (looking-at "\\sW") |
573 | (forward-line 1)) | |
09b389d0 | 574 | (while (and (not (eobp)) (looking-at "^\\s *$")) |
5960adc7 | 575 | (delete-region (point) (line-beginning-position 2))) |
918f4ac3 | 576 | (insert-char ?\n 3) |
1832dbd1 | 577 | (forward-line -2) |
dd309224 | 578 | (indent-to left-margin) |
918f4ac3 | 579 | (insert "* ") |
d882f144 | 580 | (if item (insert item)))) |
1832dbd1 | 581 | ;; Now insert the function name, if we have one. |
d882f144 | 582 | ;; Point is at the item for this file, |
21d7e080 | 583 | ;; either at the end of the line or at the first blank line. |
5a9ac14b SM |
584 | (if (not defun) |
585 | ;; No function name, so put in a colon unless we have just a star. | |
586 | (unless (save-excursion | |
587 | (beginning-of-line 1) | |
588 | (looking-at "\\s *\\(\\*\\s *\\)?$")) | |
589 | (insert ": ") | |
590 | (if version (insert version ?\ ))) | |
591 | ;; Make it easy to get rid of the function name. | |
592 | (undo-boundary) | |
5960adc7 DL |
593 | (unless (save-excursion |
594 | (beginning-of-line 1) | |
5a9ac14b SM |
595 | (looking-at "\\s *$")) |
596 | (insert ?\ )) | |
597 | ;; See if the prev function name has a message yet or not. | |
598 | ;; If not, merge the two items. | |
599 | (let ((pos (point-marker))) | |
600 | (skip-syntax-backward " ") | |
601 | (skip-chars-backward "):") | |
602 | (if (and (looking-at "):") | |
fc9b0554 SM |
603 | (let ((pos (save-excursion (backward-sexp 1) (point)))) |
604 | (when (equal (buffer-substring pos (point)) defun) | |
605 | (delete-region pos (point))) | |
606 | (> fill-column (+ (current-column) (length defun) 4)))) | |
607 | (progn (skip-chars-backward ", ") | |
608 | (delete-region (point) pos) | |
609 | (unless (memq (char-before) '(?\()) (insert ", "))) | |
5a9ac14b SM |
610 | (if (looking-at "):") |
611 | (delete-region (+ 1 (point)) (line-end-position))) | |
612 | (goto-char pos) | |
613 | (insert "(")) | |
614 | (set-marker pos nil)) | |
615 | (insert defun "): ") | |
616 | (if version (insert version ?\ ))))) | |
84fc2cfa | 617 | |
84fc2cfa ER |
618 | ;;;###autoload |
619 | (defun add-change-log-entry-other-window (&optional whoami file-name) | |
d882f144 RS |
620 | "Find change log file in other window and add entry and item. |
621 | This is just like `add-change-log-entry' except that it displays | |
622 | the change log file in another window." | |
84fc2cfa ER |
623 | (interactive (if current-prefix-arg |
624 | (list current-prefix-arg | |
625 | (prompt-for-change-log-name)))) | |
626 | (add-change-log-entry whoami file-name t)) | |
82f4acaf | 627 | ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) |
84fc2cfa | 628 | |
fc9b0554 SM |
629 | (defvar add-log-indent-text 0) |
630 | ||
631 | (defun add-log-indent () | |
632 | (let* ((indent | |
633 | (save-excursion | |
634 | (beginning-of-line) | |
635 | (skip-chars-forward " \t") | |
636 | (cond | |
637 | ((and (looking-at "\\(.*\\) [^ \n].*[^ \n] <.*>$") | |
638 | ;; Matching the output of add-log-time-format is difficult, | |
639 | ;; but I'll get it has at least two adjacent digits. | |
640 | (string-match "[[:digit:]][[:digit:]]" (match-string 1))) | |
641 | 0) | |
642 | ((looking-at "[^*(]") | |
643 | (+ (current-left-margin) add-log-indent-text)) | |
644 | (t (current-left-margin))))) | |
645 | (pos (save-excursion (indent-line-to indent) (point)))) | |
646 | (if (> pos (point)) (goto-char pos)))) | |
647 | ||
648 | ||
3066d4ad SM |
649 | (defvar smerge-resolve-function) |
650 | ||
1da56800 | 651 | ;;;###autoload |
7cd017ba | 652 | (define-derived-mode change-log-mode text-mode "Change Log" |
eb8c3be9 | 653 | "Major mode for editing change logs; like Indented Text Mode. |
09b389d0 | 654 | Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74. |
3697b807 | 655 | New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window]. |
5516387c | 656 | Each entry behaves as a paragraph, and the entries for one day as a page. |
3066d4ad SM |
657 | Runs `change-log-mode-hook'. |
658 | \\{change-log-mode-map}" | |
7cd017ba | 659 | (setq left-margin 8 |
4f675a8c | 660 | fill-column 74 |
60f10a06 KH |
661 | indent-tabs-mode t |
662 | tab-width 8) | |
663 | (set (make-local-variable 'fill-paragraph-function) | |
664 | 'change-log-fill-paragraph) | |
fc9b0554 SM |
665 | (set (make-local-variable 'indent-line-function) 'add-log-indent) |
666 | (set (make-local-variable 'tab-always-indent) nil) | |
4b7d4d0d DL |
667 | ;; We really do want "^" in paragraph-start below: it is only the |
668 | ;; lines that begin at column 0 (despite the left-margin of 8) that | |
669 | ;; we are looking for. Adding `* ' allows eliding the blank line | |
670 | ;; between entries for different files. | |
c9cfb0f2 | 671 | (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\<") |
4b7d4d0d | 672 | (set (make-local-variable 'paragraph-separate) paragraph-start) |
2c91c85c RS |
673 | ;; Match null string on the date-line so that the date-line |
674 | ;; is grouped with what follows. | |
964141f2 | 675 | (set (make-local-variable 'page-delimiter) "^\\<\\|^\f") |
dd309224 | 676 | (set (make-local-variable 'version-control) 'never) |
7cd017ba SM |
677 | (set (make-local-variable 'smerge-resolve-function) |
678 | 'change-log-resolve-conflict) | |
dd309224 | 679 | (set (make-local-variable 'adaptive-fill-regexp) "\\s *") |
4b286eca | 680 | (set (make-local-variable 'font-lock-defaults) |
7cd017ba | 681 | '(change-log-font-lock-keywords t nil nil backward-paragraph))) |
21d7e080 | 682 | |
287d149f RM |
683 | ;; It might be nice to have a general feature to replace this. The idea I |
684 | ;; have is a variable giving a regexp matching text which should not be | |
685 | ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(". | |
686 | ;; But I don't feel up to implementing that today. | |
687 | (defun change-log-fill-paragraph (&optional justify) | |
688 | "Fill the paragraph, but preserve open parentheses at beginning of lines. | |
689 | Prefix arg means justify as well." | |
690 | (interactive "P") | |
8d6467a4 RS |
691 | (let ((end (progn (forward-paragraph) (point))) |
692 | (beg (progn (backward-paragraph) (point))) | |
14ee1953 | 693 | (paragraph-start (concat paragraph-start "\\|\\s *\\s("))) |
8d6467a4 RS |
694 | (fill-region beg end justify) |
695 | t)) | |
287d149f | 696 | \f |
fcad5199 | 697 | (defcustom add-log-current-defun-header-regexp |
a8d693d8 | 698 | "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]" |
fcad5199 RS |
699 | "*Heuristic regexp used by `add-log-current-defun' for unknown major modes." |
700 | :type 'regexp | |
701 | :group 'change-log) | |
21d7e080 | 702 | |
fb644f48 EN |
703 | ;;;###autoload |
704 | (defvar add-log-lisp-like-modes | |
3697b807 | 705 | '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode) |
fb644f48 EN |
706 | "*Modes that look like Lisp to `add-log-current-defun'.") |
707 | ||
708 | ;;;###autoload | |
709 | (defvar add-log-c-like-modes | |
710 | '(c-mode c++-mode c++-c-mode objc-mode) | |
711 | "*Modes that look like C to `add-log-current-defun'.") | |
712 | ||
713 | ;;;###autoload | |
714 | (defvar add-log-tex-like-modes | |
715 | '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode) | |
716 | "*Modes that look like TeX to `add-log-current-defun'.") | |
717 | ||
e332f80b | 718 | ;;;###autoload |
21d7e080 ER |
719 | (defun add-log-current-defun () |
720 | "Return name of function definition point is in, or nil. | |
721 | ||
63314951 | 722 | Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...), |
5960adc7 | 723 | Texinfo (@node titles) and Perl. |
21d7e080 ER |
724 | |
725 | Other modes are handled by a heuristic that looks in the 10K before | |
726 | point for uppercase headings starting in the first column or | |
5960adc7 | 727 | identifiers followed by `:' or `='. See variables |
c1356086 | 728 | `add-log-current-defun-header-regexp' and |
5ef08021 | 729 | `add-log-current-defun-function'. |
21d7e080 ER |
730 | |
731 | Has a preference of looking backwards." | |
2cc0b765 RS |
732 | (condition-case nil |
733 | (save-excursion | |
734 | (let ((location (point))) | |
5960adc7 DL |
735 | (cond (add-log-current-defun-function |
736 | (funcall add-log-current-defun-function)) | |
c1356086 | 737 | ((memq major-mode add-log-lisp-like-modes) |
a0151877 | 738 | ;; If we are now precisely at the beginning of a defun, |
2cc0b765 RS |
739 | ;; make sure beginning-of-defun finds that one |
740 | ;; rather than the previous one. | |
741 | (or (eobp) (forward-char 1)) | |
742 | (beginning-of-defun) | |
5960adc7 DL |
743 | ;; Make sure we are really inside the defun found, |
744 | ;; not after it. | |
42b1fc29 RS |
745 | (when (and (looking-at "\\s(") |
746 | (progn (end-of-defun) | |
747 | (< location (point))) | |
748 | (progn (forward-sexp -1) | |
749 | (>= location (point)))) | |
750 | (if (looking-at "\\s(") | |
751 | (forward-char 1)) | |
752 | ;; Skip the defining construct name, typically "defun" | |
753 | ;; or "defvar". | |
754 | (forward-sexp 1) | |
755 | ;; The second element is usually a symbol being defined. | |
756 | ;; If it is not, use the first symbol in it. | |
63c7727f | 757 | (skip-chars-forward " \t\n'(") |
5960adc7 DL |
758 | (buffer-substring-no-properties (point) |
759 | (progn (forward-sexp 1) | |
760 | (point))))) | |
fb644f48 EN |
761 | ((and (memq major-mode add-log-c-like-modes) |
762 | (save-excursion | |
763 | (beginning-of-line) | |
764 | ;; Use eq instead of = here to avoid | |
765 | ;; error when at bob and char-after | |
766 | ;; returns nil. | |
767 | (while (eq (char-after (- (point) 2)) ?\\) | |
768 | (forward-line -1)) | |
769 | (looking-at "[ \t]*#[ \t]*define[ \t]"))) | |
2cc0b765 RS |
770 | ;; Handle a C macro definition. |
771 | (beginning-of-line) | |
772 | (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above | |
773 | (forward-line -1)) | |
774 | (search-forward "define") | |
775 | (skip-chars-forward " \t") | |
5960adc7 DL |
776 | (buffer-substring-no-properties (point) |
777 | (progn (forward-sexp 1) | |
778 | (point)))) | |
fb644f48 | 779 | ((memq major-mode add-log-c-like-modes) |
2cc0b765 RS |
780 | (beginning-of-line) |
781 | ;; See if we are in the beginning part of a function, | |
782 | ;; before the open brace. If so, advance forward. | |
783 | (while (not (looking-at "{\\|\\(\\s *$\\)")) | |
784 | (forward-line 1)) | |
785 | (or (eobp) | |
786 | (forward-char 1)) | |
8eca85ef RS |
787 | (let (maybe-beg) |
788 | ;; Try to find the containing defun. | |
789 | (beginning-of-defun) | |
790 | (end-of-defun) | |
791 | ;; If the defun we found ends before the desired position, | |
792 | ;; see if there's a DEFUN construct | |
793 | ;; between that end and the desired position. | |
794 | (when (save-excursion | |
795 | (and (> location (point)) | |
bf247b6e | 796 | (re-search-forward "^DEFUN" |
8eca85ef RS |
797 | (save-excursion |
798 | (goto-char location) | |
799 | (line-end-position)) | |
800 | t) | |
801 | (re-search-forward "^{" nil t) | |
802 | (setq maybe-beg (point)))) | |
803 | ;; If so, go to the end of that instead. | |
804 | (goto-char maybe-beg) | |
805 | (end-of-defun))) | |
806 | ;; If the desired position is within the defun we found, | |
807 | ;; find the function name. | |
808 | (when (< location (point)) | |
5960adc7 DL |
809 | (backward-sexp 1) |
810 | (let (beg tem) | |
811 | ||
812 | (forward-line -1) | |
813 | ;; Skip back over typedefs of arglist. | |
814 | (while (and (not (bobp)) | |
815 | (looking-at "[ \t\n]")) | |
816 | (forward-line -1)) | |
817 | ;; See if this is using the DEFUN macro used in Emacs, | |
568ec09d | 818 | ;; or the DEFUN macro used by the C library: |
5960adc7 DL |
819 | (if (condition-case nil |
820 | (and (save-excursion | |
821 | (end-of-line) | |
822 | (while (= (preceding-char) ?\\) | |
823 | (end-of-line 2)) | |
824 | (backward-sexp 1) | |
825 | (beginning-of-line) | |
826 | (setq tem (point)) | |
827 | (looking-at "DEFUN\\b")) | |
828 | (>= location tem)) | |
829 | (error nil)) | |
568ec09d SS |
830 | ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory |
831 | ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK | |
5960adc7 DL |
832 | (progn |
833 | (goto-char tem) | |
834 | (down-list 1) | |
568ec09d SS |
835 | (when (= (char-after (point)) ?\") |
836 | (forward-sexp 1) | |
837 | (search-forward ",")) | |
838 | (skip-syntax-forward " ") | |
5960adc7 DL |
839 | (buffer-substring-no-properties |
840 | (point) | |
568ec09d SS |
841 | (progn (search-forward ",") |
842 | (forward-char -1) | |
843 | (skip-syntax-backward " ") | |
5960adc7 DL |
844 | (point)))) |
845 | (if (looking-at "^[+-]") | |
846 | (change-log-get-method-definition) | |
847 | ;; Ordinary C function syntax. | |
848 | (setq beg (point)) | |
849 | (if (and | |
850 | ;; Protect against "Unbalanced parens" error. | |
851 | (condition-case nil | |
852 | (progn | |
853 | (down-list 1) ; into arglist | |
854 | (backward-up-list 1) | |
855 | (skip-chars-backward " \t") | |
856 | t) | |
857 | (error nil)) | |
858 | ;; Verify initial pos was after | |
859 | ;; real start of function. | |
860 | (save-excursion | |
861 | (goto-char beg) | |
862 | ;; For this purpose, include the line | |
863 | ;; that has the decl keywords. This | |
864 | ;; may also include some of the | |
865 | ;; comments before the function. | |
866 | (while (and (not (bobp)) | |
867 | (save-excursion | |
868 | (forward-line -1) | |
869 | (looking-at "[^\n\f]"))) | |
870 | (forward-line -1)) | |
871 | (>= location (point))) | |
872 | ;; Consistency check: going down and up | |
873 | ;; shouldn't take us back before BEG. | |
874 | (> (point) beg)) | |
875 | (let (end middle) | |
876 | ;; Don't include any final whitespace | |
877 | ;; in the name we use. | |
878 | (skip-chars-backward " \t\n") | |
879 | (setq end (point)) | |
880 | (backward-sexp 1) | |
881 | ;; Now find the right beginning of the name. | |
882 | ;; Include certain keywords if they | |
883 | ;; precede the name. | |
884 | (setq middle (point)) | |
885 | (forward-word -1) | |
886 | ;; Ignore these subparts of a class decl | |
887 | ;; and move back to the class name itself. | |
888 | (while (looking-at "public \\|private ") | |
889 | (skip-chars-backward " \t:") | |
890 | (setq end (point)) | |
891 | (backward-sexp 1) | |
892 | (setq middle (point)) | |
893 | (forward-word -1)) | |
894 | (and (bolp) | |
895 | (looking-at | |
896 | "enum \\|struct \\|union \\|class ") | |
897 | (setq middle (point))) | |
898 | (goto-char end) | |
899 | (when (eq (preceding-char) ?=) | |
900 | (forward-char -1) | |
901 | (skip-chars-backward " \t") | |
902 | (setq end (point))) | |
903 | (buffer-substring-no-properties | |
904 | middle end)))))))) | |
fb644f48 | 905 | ((memq major-mode add-log-tex-like-modes) |
2cc0b765 | 906 | (if (re-search-backward |
5960adc7 DL |
907 | "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" |
908 | nil t) | |
2cc0b765 RS |
909 | (progn |
910 | (goto-char (match-beginning 0)) | |
5960adc7 DL |
911 | (buffer-substring-no-properties |
912 | (1+ (point)) ; without initial backslash | |
913 | (line-end-position))))) | |
2cc0b765 | 914 | ((eq major-mode 'texinfo-mode) |
3071ee28 | 915 | (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t) |
5960adc7 | 916 | (match-string-no-properties 1))) |
c06e9d8b | 917 | ((memq major-mode '(perl-mode cperl-mode)) |
5a9ac14b | 918 | (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t) |
5960adc7 DL |
919 | (match-string-no-properties 1))) |
920 | ;; Emacs's autoconf-mode installs its own | |
921 | ;; `add-log-current-defun-function'. This applies to | |
922 | ;; a different mode apparently for editing .m4 | |
923 | ;; autoconf source. | |
f654865f | 924 | ((eq major-mode 'autoconf-mode) |
5960adc7 DL |
925 | (if (re-search-backward |
926 | "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t) | |
927 | (match-string-no-properties 3))) | |
2cc0b765 RS |
928 | (t |
929 | ;; If all else fails, try heuristics | |
c1356086 GM |
930 | (let (case-fold-search |
931 | result) | |
2cc0b765 | 932 | (end-of-line) |
c1356086 GM |
933 | (when (re-search-backward |
934 | add-log-current-defun-header-regexp | |
935 | (- (point) 10000) | |
936 | t) | |
5960adc7 DL |
937 | (setq result (or (match-string-no-properties 1) |
938 | (match-string-no-properties 0))) | |
c1356086 GM |
939 | ;; Strip whitespace away |
940 | (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)" | |
941 | result) | |
5960adc7 | 942 | (setq result (match-string-no-properties 1 result))) |
c1356086 | 943 | result)))))) |
2cc0b765 | 944 | (error nil))) |
ef15f270 | 945 | |
83afd62c | 946 | (defvar change-log-get-method-definition-md) |
15319a8f | 947 | |
83afd62c | 948 | ;; Subroutine used within change-log-get-method-definition. |
59c1a7de RS |
949 | ;; Add the last match in the buffer to the end of `md', |
950 | ;; followed by the string END; move to the end of that match. | |
83afd62c KH |
951 | (defun change-log-get-method-definition-1 (end) |
952 | (setq change-log-get-method-definition-md | |
953 | (concat change-log-get-method-definition-md | |
5960adc7 | 954 | (match-string 1) |
15319a8f | 955 | end)) |
59c1a7de RS |
956 | (goto-char (match-end 0))) |
957 | ||
83afd62c | 958 | (defun change-log-get-method-definition () |
075a6629 | 959 | "For objective C, return the method name if we are in a method." |
83afd62c | 960 | (let ((change-log-get-method-definition-md "[")) |
59c1a7de | 961 | (save-excursion |
f27f16ed | 962 | (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t) |
83afd62c | 963 | (change-log-get-method-definition-1 " "))) |
59c1a7de RS |
964 | (save-excursion |
965 | (cond | |
f27f16ed | 966 | ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t) |
83afd62c | 967 | (change-log-get-method-definition-1 "") |
59c1a7de RS |
968 | (while (not (looking-at "[{;]")) |
969 | (looking-at | |
f27f16ed | 970 | "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*") |
83afd62c KH |
971 | (change-log-get-method-definition-1 "")) |
972 | (concat change-log-get-method-definition-md "]")))))) | |
075a6629 DL |
973 | \f |
974 | (defun change-log-sortable-date-at () | |
975 | "Return date of log entry in a consistent form for sorting. | |
976 | Point is assumed to be at the start of the entry." | |
977 | (require 'timezone) | |
978 | (if (looking-at "^\\sw.........[0-9:+ ]*") | |
979 | (let ((date (match-string-no-properties 0))) | |
980 | (if date | |
981 | (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date) | |
982 | (concat (match-string 1 date) (match-string 2 date) | |
983 | (match-string 3 date)) | |
984 | (condition-case nil | |
985 | (timezone-make-date-sortable date) | |
986 | (error nil))))) | |
987 | (error "Bad date"))) | |
59c1a7de | 988 | |
7cd017ba SM |
989 | (defun change-log-resolve-conflict () |
990 | "Function to be used in `smerge-resolve-function'." | |
991 | (let ((buf (current-buffer))) | |
992 | (with-temp-buffer | |
993 | (insert-buffer-substring buf (match-beginning 1) (match-end 1)) | |
994 | (save-match-data (change-log-mode)) | |
995 | (let ((other-buf (current-buffer))) | |
996 | (with-current-buffer buf | |
997 | (save-excursion | |
998 | (save-restriction | |
999 | (narrow-to-region (match-beginning 0) (match-end 0)) | |
1000 | (replace-match (match-string 3) t t) | |
1001 | (change-log-merge other-buf)))))))) | |
1002 | ||
075a6629 DL |
1003 | ;;;###autoload |
1004 | (defun change-log-merge (other-log) | |
1005 | "Merge the contents of ChangeLog file OTHER-LOG with this buffer. | |
1006 | Both must be found in Change Log mode (since the merging depends on | |
7cd017ba SM |
1007 | the appropriate motion commands). OTHER-LOG can be either a file name |
1008 | or a buffer. | |
075a6629 | 1009 | |
918f4ac3 DL |
1010 | Entries are inserted in chronological order. Both the current and |
1011 | old-style time formats for entries are supported." | |
075a6629 DL |
1012 | (interactive "*fLog file name to merge: ") |
1013 | (if (not (eq major-mode 'change-log-mode)) | |
1014 | (error "Not in Change Log mode")) | |
7cd017ba SM |
1015 | (let ((other-buf (if (bufferp other-log) other-log |
1016 | (find-file-noselect other-log))) | |
075a6629 DL |
1017 | (buf (current-buffer)) |
1018 | date1 start end) | |
1019 | (save-excursion | |
1020 | (goto-char (point-min)) | |
1021 | (set-buffer other-buf) | |
1022 | (goto-char (point-min)) | |
1023 | (if (not (eq major-mode 'change-log-mode)) | |
1024 | (error "%s not found in Change Log mode" other-log)) | |
1025 | ;; Loop through all the entries in OTHER-LOG. | |
1026 | (while (not (eobp)) | |
1027 | (setq date1 (change-log-sortable-date-at)) | |
1028 | (setq start (point) | |
1029 | end (progn (forward-page) (point))) | |
1030 | ;; Look for an entry in original buffer that isn't later. | |
1031 | (with-current-buffer buf | |
1032 | (while (and (not (eobp)) | |
1033 | (string< date1 (change-log-sortable-date-at))) | |
1034 | (forward-page)) | |
1035 | (if (not (eobp)) | |
1036 | (insert-buffer-substring other-buf start end) | |
1037 | ;; At the end of the original buffer, insert a newline to | |
1038 | ;; separate entries and then the rest of the file being | |
7cd017ba SM |
1039 | ;; merged. |
1040 | (unless (or (bobp) | |
1041 | (and (= ?\n (char-before)) | |
1042 | (or (<= (1- (point)) (point-min)) | |
1043 | (= ?\n (char-before (1- (point))))))) | |
1044 | (insert "\n")) | |
1045 | ;; Move to the end of it to terminate outer loop. | |
1046 | (with-current-buffer other-buf | |
1047 | (goto-char (point-max))) | |
1048 | (insert-buffer-substring other-buf start))))))) | |
ef15f270 | 1049 | |
918f4ac3 DL |
1050 | ;;;###autoload |
1051 | (defun change-log-redate () | |
1052 | "Fix any old-style date entries in the current log file to default format." | |
1053 | (interactive) | |
1054 | (require 'timezone) | |
1055 | (save-excursion | |
1056 | (goto-char (point-min)) | |
1057 | (while (re-search-forward "^\\sw.........[0-9:+ ]*" nil t) | |
1058 | (unless (= 12 (- (match-end 0) (match-beginning 0))) | |
1059 | (let* ((date (save-match-data | |
1060 | (timezone-fix-time (match-string 0) nil nil))) | |
1061 | (zone (if (consp (aref date 6)) | |
1062 | (nth 1 (aref date 6))))) | |
1063 | (replace-match (format-time-string | |
1064 | "%Y-%m-%d " | |
1065 | (encode-time (aref date 5) | |
1066 | (aref date 4) | |
1067 | (aref date 3) | |
1068 | (aref date 2) | |
1069 | (aref date 1) | |
1070 | (aref date 0) | |
1071 | zone)))))))) | |
1072 | ||
1da56800 RS |
1073 | (provide 'add-log) |
1074 | ||
ab5796a9 | 1075 | ;;; arch-tag: 81eee6fc-088f-4372-a37f-80ad9620e762 |
fd7fa35a | 1076 | ;;; add-log.el ends here |