]> code.delx.au - gnu-emacs/blob - lisp/vc/add-log.el
Capitalize “Universal Time” in documentation
[gnu-emacs] / lisp / vc / add-log.el
1 ;;; add-log.el --- change log maintenance commands for Emacs
2
3 ;; Copyright (C) 1985-1986, 1988, 1993-1994, 1997-1998, 2000-2016 Free
4 ;; Software Foundation, Inc.
5
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: vc tools
8
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
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) 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
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; This facility is documented in the Emacs Manual.
27
28 ;; Todo:
29
30 ;; - Find/use/create _MTN/log if there's a _MTN directory.
31 ;; - Find/use/create ++log.* if there's an {arch} directory.
32 ;; - Use an open *VC-Log* or *cvs-commit* buffer if it's related to the
33 ;; source file.
34 ;; - Don't add TAB indents (and username?) if inserting entries in those
35 ;; special places.
36
37 ;;; Code:
38
39 (defgroup change-log nil
40 "Change log maintenance."
41 :group 'tools
42 :link '(custom-manual "(emacs)Change Log")
43 :prefix "change-log-"
44 :prefix "add-log-")
45
46
47 (defcustom change-log-default-name nil
48 "Name of a change log file for \\[add-change-log-entry]."
49 :type '(choice (const :tag "default" nil)
50 string)
51 :group 'change-log)
52 ;;;###autoload
53 (put 'change-log-default-name 'safe-local-variable 'string-or-null-p)
54
55 (defcustom change-log-mode-hook nil
56 "Normal hook run by `change-log-mode'."
57 :type 'hook
58 :group 'change-log)
59
60 ;; Many modes set this variable, so avoid warnings.
61 ;;;###autoload
62 (defcustom add-log-current-defun-function nil
63 "If non-nil, function to guess name of surrounding function.
64 It is called by `add-log-current-defun' with no argument, and
65 should return the function's name as a string, or nil if point is
66 outside a function."
67 :type '(choice (const nil) function)
68 :group 'change-log)
69
70 ;;;###autoload
71 (defcustom add-log-full-name nil
72 "Full name of user, for inclusion in ChangeLog daily headers.
73 This defaults to the value returned by the function `user-full-name'."
74 :type '(choice (const :tag "Default" nil)
75 string)
76 :group 'change-log)
77
78 ;;;###autoload
79 (defcustom add-log-mailing-address nil
80 "Email addresses of user, for inclusion in ChangeLog headers.
81 This defaults to the value of `user-mail-address'. In addition to
82 being a simple string, this value can also be a list. All elements
83 will be recognized as referring to the same user; when creating a new
84 ChangeLog entry, one element will be chosen at random."
85 :type '(choice (const :tag "Default" nil)
86 (string :tag "String")
87 (repeat :tag "List of Strings" string))
88 :group 'change-log)
89
90 (defcustom add-log-time-format 'add-log-iso8601-time-string
91 "Function that defines the time format.
92 For example, `add-log-iso8601-time-string', which gives the
93 date in international ISO 8601 format,
94 and `current-time-string' are two valid values."
95 :type '(radio (const :tag "International ISO 8601 format"
96 add-log-iso8601-time-string)
97 (const :tag "Old format, as returned by `current-time-string'"
98 current-time-string)
99 (function :tag "Other"))
100 :group 'change-log)
101
102 (defcustom add-log-keep-changes-together nil
103 "If non-nil, normally keep day's log entries for one file together.
104
105 Log entries for a given file made with \\[add-change-log-entry] or
106 \\[add-change-log-entry-other-window] will only be added to others \
107 for that file made
108 today if this variable is non-nil or that file comes first in today's
109 entries. Otherwise another entry for that file will be started. An
110 original log:
111
112 * foo (...): ...
113 * bar (...): change 1
114
115 in the latter case, \\[add-change-log-entry-other-window] in a \
116 buffer visiting `bar', yields:
117
118 * bar (...): -!-
119 * foo (...): ...
120 * bar (...): change 1
121
122 and in the former:
123
124 * foo (...): ...
125 * bar (...): change 1
126 (...): -!-
127
128 The NEW-ENTRY arg to `add-change-log-entry' can override the effect of
129 this variable."
130 :version "20.3"
131 :type 'boolean
132 :group 'change-log)
133
134 (defcustom add-log-always-start-new-record nil
135 "If non-nil, `add-change-log-entry' will always start a new record."
136 :version "22.1"
137 :type 'boolean
138 :group 'change-log)
139
140 (defvar add-log-buffer-file-name-function 'buffer-file-name
141 "If non-nil, function to call to identify the full filename of a buffer.
142 This function is called with no argument. The default is to
143 use `buffer-file-name'.")
144
145 (defcustom add-log-file-name-function nil
146 "If non-nil, function to call to identify the filename for a ChangeLog entry.
147 This function is called with one argument, the value of variable
148 `buffer-file-name' in that buffer. If this is nil, the default is to
149 use the file's name relative to the directory of the change log file."
150 :type '(choice (const nil) function)
151 :group 'change-log)
152
153
154 (defcustom change-log-version-info-enabled nil
155 "If non-nil, enable recording version numbers with the changes."
156 :version "21.1"
157 :type 'boolean
158 :group 'change-log)
159
160 (defcustom change-log-version-number-regexp-list
161 (let ((re "\\([0-9]+\\.[0-9.]+\\)"))
162 (list
163 ;; (defconst ad-version "2.15"
164 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re)
165 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp
166 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re)))
167 "List of regexps to search for version number.
168 The version number must be in group 1.
169 Note: The search is conducted only within 10%, at the beginning of the file."
170 :version "21.1"
171 :type '(repeat regexp)
172 :group 'change-log)
173
174 (defface change-log-date
175 '((t (:inherit font-lock-string-face)))
176 "Face used to highlight dates in date lines."
177 :version "21.1"
178 :group 'change-log)
179 (define-obsolete-face-alias 'change-log-date-face 'change-log-date "22.1")
180
181 (defface change-log-name
182 '((t (:inherit font-lock-constant-face)))
183 "Face for highlighting author names."
184 :version "21.1"
185 :group 'change-log)
186 (define-obsolete-face-alias 'change-log-name-face 'change-log-name "22.1")
187
188 (defface change-log-email
189 '((t (:inherit font-lock-variable-name-face)))
190 "Face for highlighting author email addresses."
191 :version "21.1"
192 :group 'change-log)
193 (define-obsolete-face-alias 'change-log-email-face 'change-log-email "22.1")
194
195 (defface change-log-file
196 '((t (:inherit font-lock-function-name-face)))
197 "Face for highlighting file names."
198 :version "21.1"
199 :group 'change-log)
200 (define-obsolete-face-alias 'change-log-file-face 'change-log-file "22.1")
201
202 (defface change-log-list
203 '((t (:inherit font-lock-keyword-face)))
204 "Face for highlighting parenthesized lists of functions or variables."
205 :version "21.1"
206 :group 'change-log)
207 (define-obsolete-face-alias 'change-log-list-face 'change-log-list "22.1")
208
209 (defface change-log-conditionals
210 '((t (:inherit font-lock-variable-name-face)))
211 "Face for highlighting conditionals of the form `[...]'."
212 :version "21.1"
213 :group 'change-log)
214 (define-obsolete-face-alias 'change-log-conditionals-face
215 'change-log-conditionals "22.1")
216
217 (defface change-log-function
218 '((t (:inherit font-lock-variable-name-face)))
219 "Face for highlighting items of the form `<....>'."
220 :version "21.1"
221 :group 'change-log)
222 (define-obsolete-face-alias 'change-log-function-face
223 'change-log-function "22.1")
224
225 (defface change-log-acknowledgment
226 '((t (:inherit font-lock-comment-face)))
227 "Face for highlighting acknowledgments."
228 :version "21.1"
229 :group 'change-log)
230 (define-obsolete-face-alias 'change-log-acknowledgement
231 'change-log-acknowledgment "24.3")
232 (define-obsolete-face-alias 'change-log-acknowledgement-face
233 'change-log-acknowledgment "22.1")
234
235 (defconst change-log-file-names-re "^\\( +\\|\t\\)\\* \\([^ ,:([\n]+\\)")
236 (defconst change-log-start-entry-re "^\\sw.........[0-9:+ ]*")
237
238 (defvar change-log-font-lock-keywords
239 `(;;
240 ;; Date lines, new (2000-01-01) and old (Sat Jan 1 00:00:00 2000) styles.
241 ;; Fixme: this regexp is just an approximate one and may match
242 ;; wrongly with a non-date line existing as a random note. In
243 ;; addition, using any kind of fixed setting like this doesn't
244 ;; work if a user customizes add-log-time-format.
245 ("^[0-9-]+ +\\|^ \\{11,\\}\\|^\t \\{3,\\}\\|^\\(Sun\\|Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\) [A-z][a-z][a-z] [0-9:+ ]+"
246 (0 'change-log-date-face)
247 ;; Name and e-mail; some people put e-mail in parens, not angles.
248 ("\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" nil nil
249 (1 'change-log-name)
250 (2 'change-log-email)))
251 ;;
252 ;; File names.
253 (,change-log-file-names-re
254 (2 'change-log-file)
255 ;; Possibly further names in a list:
256 ("\\=, \\([^ ,:([\n]+\\)" nil nil (1 'change-log-file))
257 ;; Possibly a parenthesized list of names:
258 ("\\= (\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)"
259 nil nil (1 'change-log-list))
260 ("\\=, *\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)"
261 nil nil (1 'change-log-list)))
262 ;;
263 ;; Function or variable names.
264 ("^\\( +\\|\t\\)(\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)"
265 (2 'change-log-list)
266 ("\\=, *\\([^(),\n]+\\|(\\(setf\\|SETF\\) [^() ,\n]+)\\)" nil nil
267 (1 'change-log-list)))
268 ;;
269 ;; Conditionals.
270 ("\\[!?\\([^]\n]+\\)\\]\\(:\\| (\\)" (1 'change-log-conditionals))
271 ;;
272 ;; Function of change.
273 ("<\\([^>\n]+\\)>\\(:\\| (\\)" (1 'change-log-function))
274 ;;
275 ;; Acknowledgments.
276 ;; Don't include plain "From" because that is vague;
277 ;; we want to encourage people to say something more specific.
278 ;; Note that the FSF does not use "Patches by"; our convention
279 ;; is to put the name of the author of the changes at the top
280 ;; of the change log entry.
281 ("\\(^\\( +\\|\t\\)\\| \\)\\(Thanks to\\|Patch\\(es\\)? by\\|Report\\(ed by\\| from\\)\\|Suggest\\(ed by\\|ion from\\)\\)"
282 3 'change-log-acknowledgment))
283 "Additional expressions to highlight in Change Log mode.")
284
285 (defun change-log-search-file-name (where)
286 "Return the file-name for the change under point."
287 (save-excursion
288 (goto-char where)
289 (beginning-of-line 1)
290 (if (looking-at change-log-start-entry-re)
291 ;; We are at the start of an entry, search forward for a file
292 ;; name.
293 (progn
294 (re-search-forward change-log-file-names-re nil t)
295 (match-string-no-properties 2))
296 (if (looking-at change-log-file-names-re)
297 ;; We found a file name.
298 (match-string-no-properties 2)
299 ;; Look backwards for either a file name or the log entry start.
300 (if (re-search-backward
301 (concat "\\(" change-log-start-entry-re
302 "\\)\\|\\("
303 change-log-file-names-re "\\)") nil t)
304 (if (match-beginning 1)
305 ;; We got the start of the entry, look forward for a
306 ;; file name.
307 (progn
308 (re-search-forward change-log-file-names-re nil t)
309 (match-string-no-properties 2))
310 (match-string-no-properties 4))
311 ;; We must be before any file name, look forward.
312 (re-search-forward change-log-file-names-re nil t)
313 (match-string-no-properties 2))))))
314
315 (defun change-log-find-file ()
316 "Visit the file for the change under point."
317 (interactive)
318 (let ((file (change-log-search-file-name (point))))
319 (if (and file (file-exists-p file))
320 (find-file file)
321 (message "No such file or directory: %s" file))))
322
323 (defun change-log-search-tag-name-1 (&optional from)
324 "Search for a tag name within subexpression 1 of last match.
325 Optional argument FROM specifies a buffer position where the tag
326 name should be located. Return value is a cons whose car is the
327 string representing the tag and whose cdr is the position where
328 the tag was found."
329 (save-restriction
330 (narrow-to-region (match-beginning 1) (match-end 1))
331 (when from (goto-char from))
332 ;; The regexp below skips any symbol near `point' (FROM) followed by
333 ;; whitespace and another symbol. This should skip, for example,
334 ;; "struct" in a specification like "(struct buffer)" and move to
335 ;; "buffer". A leading paren is ignored.
336 (when (looking-at
337 "[(]?\\(?:\\(?:\\sw\\|\\s_\\)+\\(?:[ \t]+\\(\\sw\\|\\s_\\)+\\)\\)")
338 (goto-char (match-beginning 1)))
339 (cons (find-tag-default) (point))))
340
341 (defconst change-log-tag-re
342 "(\\(\\(?:\\sw\\|\\s_\\)+\\(?:[, \t]+\\(?:\\sw\\|\\s_\\)+\\)*\\))"
343 "Regexp matching a tag name in change log entries.")
344
345 (defun change-log-search-tag-name (&optional at)
346 "Search for a tag name near `point'.
347 Optional argument AT non-nil means search near buffer position AT.
348 Return value is a cons whose car is the string representing
349 the tag and whose cdr is the position where the tag was found."
350 (save-excursion
351 (goto-char (setq at (or at (point))))
352 (save-restriction
353 (widen)
354 (or (condition-case nil
355 ;; Within parenthesized list?
356 (save-excursion
357 (backward-up-list)
358 (when (looking-at change-log-tag-re)
359 (change-log-search-tag-name-1 at)))
360 (error nil))
361 (condition-case nil
362 ;; Before parenthesized list on same line?
363 (save-excursion
364 (when (and (skip-chars-forward " \t")
365 (looking-at change-log-tag-re))
366 (change-log-search-tag-name-1)))
367 (error nil))
368 (condition-case nil
369 ;; Near file name?
370 (save-excursion
371 (when (and (progn
372 (beginning-of-line)
373 (looking-at change-log-file-names-re))
374 (goto-char (match-end 0))
375 (skip-syntax-forward " ")
376 (looking-at change-log-tag-re))
377 (change-log-search-tag-name-1)))
378 (error nil))
379 (condition-case nil
380 ;; Anywhere else within current entry?
381 (let ((from
382 (save-excursion
383 (end-of-line)
384 (if (re-search-backward change-log-start-entry-re nil t)
385 (match-beginning 0)
386 (point-min))))
387 (to
388 (save-excursion
389 (end-of-line)
390 (if (re-search-forward change-log-start-entry-re nil t)
391 (match-beginning 0)
392 (point-max)))))
393 (when (and (< from to) (<= from at) (<= at to))
394 (save-restriction
395 ;; Narrow to current change log entry.
396 (narrow-to-region from to)
397 (cond
398 ((re-search-backward change-log-tag-re nil t)
399 (narrow-to-region (match-beginning 1) (match-end 1))
400 (goto-char (point-max))
401 (cons (find-tag-default) (point-max)))
402 ((re-search-forward change-log-tag-re nil t)
403 (narrow-to-region (match-beginning 1) (match-end 1))
404 (goto-char (point-min))
405 (cons (find-tag-default) (point-min)))))))
406 (error nil))))))
407
408 (defvar change-log-find-head nil)
409 (defvar change-log-find-tail nil)
410 (defvar change-log-find-window nil)
411
412 (defun change-log-goto-source-1 (tag regexp file buffer
413 &optional window first last)
414 "Search for tag TAG in buffer BUFFER visiting file FILE.
415 REGEXP is a regular expression for TAG. The remaining arguments
416 are optional: WINDOW denotes the window to display the results of
417 the search. FIRST is a position in BUFFER denoting the first
418 match from previous searches for TAG. LAST is the position in
419 BUFFER denoting the last match for TAG in the last search."
420 (with-current-buffer buffer
421 (save-excursion
422 (save-restriction
423 (widen)
424 (if last
425 (progn
426 ;; When LAST is set make sure we continue from the next
427 ;; line end to not find the same tag again.
428 (goto-char last)
429 (end-of-line)
430 (condition-case nil
431 ;; Try to go to the end of the current defun to avoid
432 ;; false positives within the current defun's body
433 ;; since these would match `add-log-current-defun'.
434 (end-of-defun)
435 ;; Don't fall behind when `end-of-defun' fails.
436 (error (progn (goto-char last) (end-of-line))))
437 (setq last nil))
438 ;; When LAST was not set start at beginning of BUFFER.
439 (goto-char (point-min)))
440 (let (current-defun)
441 (while (and (not last) (re-search-forward regexp nil t))
442 ;; Verify that `add-log-current-defun' invoked at the end
443 ;; of the match returns TAG. This heuristic works well
444 ;; whenever the name of the defun occurs within the first
445 ;; line of the defun.
446 (setq current-defun (add-log-current-defun))
447 (when (and current-defun (string-equal current-defun tag))
448 ;; Record this as last match.
449 (setq last (line-beginning-position))
450 ;; Record this as first match when there's none.
451 (unless first (setq first last)))))))
452 (if (or last first)
453 (with-selected-window
454 (setq change-log-find-window (or window (display-buffer buffer)))
455 (if last
456 (progn
457 (when (or (< last (point-min)) (> last (point-max)))
458 ;; Widen to show TAG.
459 (widen))
460 (push-mark)
461 (goto-char last))
462 ;; When there are no more matches go (back) to FIRST.
463 (message "No more matches for tag `%s' in file `%s'" tag file)
464 (setq last first)
465 (goto-char first))
466 ;; Return new "tail".
467 (list (selected-window) first last))
468 (message "Source location of tag `%s' not found in file `%s'" tag file)
469 nil)))
470
471 (defun change-log-goto-source ()
472 "Go to source location of \"change log tag\" near `point'.
473 A change log tag is a symbol within a parenthesized,
474 comma-separated list. If no suitable tag can be found nearby,
475 try to visit the file for the change under `point' instead."
476 (interactive)
477 (if (and (eq last-command 'change-log-goto-source)
478 change-log-find-tail)
479 (setq change-log-find-tail
480 (condition-case nil
481 (apply 'change-log-goto-source-1
482 (append change-log-find-head change-log-find-tail))
483 (error
484 (format-message
485 "Cannot find more matches for tag `%s' in file `%s'"
486 (car change-log-find-head)
487 (nth 2 change-log-find-head)))))
488 (save-excursion
489 (let* ((at (point))
490 (tag-at (change-log-search-tag-name))
491 (tag (car tag-at))
492 (file (when tag-at (change-log-search-file-name (cdr tag-at))))
493 (file-at (when file (match-beginning 2)))
494 ;; `file-2' is the file `change-log-search-file-name' finds
495 ;; at `point'. We use `file-2' as a fallback when `tag' or
496 ;; `file' are not suitable for some reason.
497 (file-2 (change-log-search-file-name at))
498 (file-2-at (when file-2 (match-beginning 2))))
499 (cond
500 ((and (or (not tag) (not file) (not (file-exists-p file)))
501 (or (not file-2) (not (file-exists-p file-2))))
502 (error "Cannot find tag or file near `point'"))
503 ((and file-2 (file-exists-p file-2)
504 (or (not tag) (not file) (not (file-exists-p file))
505 (and (or (and (< file-at file-2-at) (<= file-2-at at))
506 (and (<= at file-2-at) (< file-2-at file-at))))))
507 ;; We either have not found a suitable file name or `file-2'
508 ;; provides a "better" file name wrt `point'. Go to the
509 ;; buffer of `file-2' instead.
510 (setq change-log-find-window
511 (display-buffer (find-file-noselect file-2))))
512 (t
513 (setq change-log-find-head
514 (list tag (concat "\\_<" (regexp-quote tag) "\\_>")
515 file (find-file-noselect file)))
516 (condition-case nil
517 (setq change-log-find-tail
518 (apply 'change-log-goto-source-1 change-log-find-head))
519 (error
520 (format-message "Cannot find matches for tag `%s' in file `%s'"
521 tag file)))))))))
522
523 (defun change-log-next-error (&optional argp reset)
524 "Move to the Nth (default 1) next match in a ChangeLog buffer.
525 Compatibility function for \\[next-error] invocations."
526 (interactive "p")
527 (let* ((argp (or argp 0))
528 (count (abs argp)) ; how many cycles
529 (down (< argp 0)) ; are we going down? (is argp negative?)
530 (up (not down))
531 (search-function (if up 're-search-forward 're-search-backward)))
532
533 ;; set the starting position
534 (goto-char (cond (reset (point-min))
535 (down (line-beginning-position))
536 (up (line-end-position))
537 ((point))))
538
539 (funcall search-function change-log-file-names-re nil t count))
540
541 (beginning-of-line)
542 ;; if we found a place to visit...
543 (when (looking-at change-log-file-names-re)
544 (let (change-log-find-window)
545 (change-log-goto-source)
546 (when change-log-find-window
547 ;; Select window displaying source file.
548 (select-window change-log-find-window)))))
549
550 (defvar change-log-mode-map
551 (let ((map (make-sparse-keymap))
552 (menu-map (make-sparse-keymap)))
553 (define-key map [?\C-c ?\C-p] 'add-log-edit-prev-comment)
554 (define-key map [?\C-c ?\C-n] 'add-log-edit-next-comment)
555 (define-key map [?\C-c ?\C-f] 'change-log-find-file)
556 (define-key map [?\C-c ?\C-c] 'change-log-goto-source)
557 (define-key map [menu-bar changelog] (cons "ChangeLog" menu-map))
558 (define-key menu-map [gs]
559 '(menu-item "Go To Source" change-log-goto-source
560 :help "Go to source location of ChangeLog tag near point"))
561 (define-key menu-map [ff]
562 '(menu-item "Find File" change-log-find-file
563 :help "Visit the file for the change under point"))
564 (define-key menu-map [sep] '("--"))
565 (define-key menu-map [nx]
566 '(menu-item "Next Log-Edit Comment" add-log-edit-next-comment
567 :help "Cycle forward through Log-Edit mode comment history"))
568 (define-key menu-map [pr]
569 '(menu-item "Previous Log-Edit Comment" add-log-edit-prev-comment
570 :help "Cycle backward through Log-Edit mode comment history"))
571 map)
572 "Keymap for Change Log major mode.")
573
574 ;; It used to be called change-log-time-zone-rule but really should be
575 ;; called add-log-time-zone-rule since it's only used from add-log-* code.
576 (defvaralias 'change-log-time-zone-rule 'add-log-time-zone-rule)
577 (defvar add-log-time-zone-rule nil
578 "Time zone rule used for calculating change log time stamps.
579 If nil, use local time. If t, use Universal Time.
580 If a string, interpret as the ZONE argument of `format-time-string'.")
581 (put 'add-log-time-zone-rule 'safe-local-variable
582 (lambda (x) (or (booleanp x) (stringp x))))
583
584 (defun add-log-iso8601-time-zone (&optional time zone)
585 (let* ((utc-offset (or (car (current-time-zone time zone)) 0))
586 (sign (if (< utc-offset 0) ?- ?+))
587 (sec (abs utc-offset))
588 (ss (% sec 60))
589 (min (/ sec 60))
590 (mm (% min 60))
591 (hh (/ min 60)))
592 (format (cond ((not (zerop ss)) "%c%02d:%02d:%02d")
593 ((not (zerop mm)) "%c%02d:%02d")
594 (t "%c%02d"))
595 sign hh mm ss)))
596
597 (defvar add-log-iso8601-with-time-zone nil)
598
599 (defun add-log-iso8601-time-string (&optional time zone)
600 (let ((date (format-time-string "%Y-%m-%d" time zone)))
601 (if add-log-iso8601-with-time-zone
602 (concat date " " (add-log-iso8601-time-zone time zone))
603 date)))
604
605 (defun change-log-name ()
606 "Return (system-dependent) default name for a change log file."
607 (or change-log-default-name
608 "ChangeLog"))
609
610 (defun add-log-edit-prev-comment (arg)
611 "Cycle backward through Log-Edit mode comment history.
612 With a numeric prefix ARG, go back ARG comments."
613 (interactive "*p")
614 (save-restriction
615 (narrow-to-region (point)
616 (if (memq last-command '(add-log-edit-prev-comment
617 add-log-edit-next-comment))
618 (mark) (point)))
619 (when (fboundp 'log-edit-previous-comment)
620 (log-edit-previous-comment arg)
621 (indent-region (point-min) (point-max))
622 (goto-char (point-min))
623 (unless (save-restriction (widen) (bolp))
624 (delete-region (point) (progn (skip-chars-forward " \t\n") (point))))
625 (set-mark (point-min))
626 (goto-char (point-max))
627 (delete-region (point) (progn (skip-chars-backward " \t\n") (point))))))
628
629 (defun add-log-edit-next-comment (arg)
630 "Cycle forward through Log-Edit mode comment history.
631 With a numeric prefix ARG, go back ARG comments."
632 (interactive "*p")
633 (add-log-edit-prev-comment (- arg)))
634
635 ;;;###autoload
636 (defun prompt-for-change-log-name ()
637 "Prompt for a change log name."
638 (let* ((default (change-log-name))
639 (name (expand-file-name
640 (read-file-name (format "Log file (default %s): " default)
641 nil default))))
642 ;; Handle something that is syntactically a directory name.
643 ;; Look for ChangeLog or whatever in that directory.
644 (if (string= (file-name-nondirectory name) "")
645 (expand-file-name (file-name-nondirectory default)
646 name)
647 ;; Handle specifying a file that is a directory.
648 (if (file-directory-p name)
649 (expand-file-name (file-name-nondirectory default)
650 (file-name-as-directory name))
651 name))))
652
653 (defun change-log-version-number-search ()
654 "Return version number of current buffer's file.
655 This is the value returned by `vc-working-revision' or, if that is
656 nil, by matching `change-log-version-number-regexp-list'."
657 (let* ((size (buffer-size))
658 (limit
659 ;; The version number can be anywhere in the file, but
660 ;; restrict search to the file beginning: 10% should be
661 ;; enough to prevent some mishits.
662 ;;
663 ;; Apply percentage only if buffer size is bigger than
664 ;; approx 100 lines.
665 (if (> size (* 100 80)) (+ (point) (/ size 10)))))
666 (or (and buffer-file-name (vc-working-revision buffer-file-name))
667 (save-restriction
668 (widen)
669 (let ((regexps change-log-version-number-regexp-list)
670 version)
671 (while regexps
672 (save-excursion
673 (goto-char (point-min))
674 (when (re-search-forward (pop regexps) limit t)
675 (setq version (match-string 1)
676 regexps nil))))
677 version)))))
678
679 (declare-function diff-find-source-location "diff-mode"
680 (&optional other-file reverse noprompt))
681
682 ;;;###autoload
683 (defun find-change-log (&optional file-name buffer-file)
684 "Find a change log file for \\[add-change-log-entry] and return the name.
685
686 Optional arg FILE-NAME specifies the file to use.
687 If FILE-NAME is nil, use the value of `change-log-default-name'.
688 If `change-log-default-name' is nil, behave as though it were \"ChangeLog\"
689 \(or whatever we use on this operating system).
690
691 If `change-log-default-name' contains a leading directory component, then
692 simply find it in the current directory. Otherwise, search in the current
693 directory and its successive parents for a file so named.
694
695 Once a file is found, `change-log-default-name' is set locally in the
696 current buffer to the complete file name.
697 Optional arg BUFFER-FILE overrides `buffer-file-name'."
698 ;; If we are called from a diff, first switch to the source buffer;
699 ;; in order to respect buffer-local settings of change-log-default-name, etc.
700 (with-current-buffer (let ((buff (if (derived-mode-p 'diff-mode)
701 (car (ignore-errors
702 (diff-find-source-location))))))
703 (if (buffer-live-p buff) buff
704 (current-buffer)))
705 ;; If user specified a file name or if this buffer knows which one to use,
706 ;; just use that.
707 (or file-name
708 (setq file-name (and change-log-default-name
709 (file-name-directory change-log-default-name)
710 change-log-default-name))
711 (progn
712 ;; Chase links in the source file
713 ;; and use the change log in the dir where it points.
714 (setq file-name (or (and (or buffer-file buffer-file-name)
715 (file-name-directory
716 (file-chase-links
717 (or buffer-file buffer-file-name))))
718 default-directory))
719 (if (file-directory-p file-name)
720 (setq file-name (expand-file-name (change-log-name) file-name)))
721 ;; Chase links before visiting the file.
722 ;; This makes it easier to use a single change log file
723 ;; for several related directories.
724 (setq file-name (file-chase-links file-name))
725 (setq file-name (expand-file-name file-name))
726 ;; Move up in the dir hierarchy till we find a change log file.
727 (let ((file1 file-name)
728 parent-dir)
729 (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
730 (progn (setq parent-dir
731 (file-name-directory
732 (directory-file-name
733 (file-name-directory file1))))
734 ;; Give up if we are already at the root dir.
735 (not (string= (file-name-directory file1)
736 parent-dir))))
737 ;; Move up to the parent dir and try again.
738 (setq file1 (expand-file-name
739 (file-name-nondirectory (change-log-name))
740 parent-dir)))
741 ;; If we found a change log in a parent, use that.
742 (if (or (get-file-buffer file1) (file-exists-p file1))
743 (setq file-name file1)))))
744 ;; Make a local variable in this buffer so we needn't search again.
745 (set (make-local-variable 'change-log-default-name) file-name))
746 file-name)
747
748 (defun add-log-file-name (buffer-file log-file)
749 ;; Never want to add a change log entry for the ChangeLog file itself.
750 (unless (or (null buffer-file) (string= buffer-file log-file))
751 (if add-log-file-name-function
752 (funcall add-log-file-name-function buffer-file)
753 (setq buffer-file
754 (let* ((dir (file-name-directory log-file))
755 (rel (file-relative-name buffer-file dir)))
756 ;; Sometimes with symlinks, the two buffers may have names that
757 ;; appear to belong to different directory trees. So check the
758 ;; file-truenames, to see if we get a better result.
759 (if (not (string-match "\\`\\.\\./" rel))
760 rel
761 (let ((new (file-relative-name (file-truename buffer-file)
762 (file-truename dir))))
763 (if (< (length new) (length rel))
764 new rel)))))
765 ;; If we have a backup file, it's presumably because we're
766 ;; comparing old and new versions (e.g. for deleted
767 ;; functions) and we'll want to use the original name.
768 (if (backup-file-name-p buffer-file)
769 (file-name-sans-versions buffer-file)
770 buffer-file))))
771
772 ;;;###autoload
773 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
774 put-new-entry-on-new-line)
775 "Find change log file, and add an entry for today and an item for this file.
776 Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
777 name and email (stored in `add-log-full-name' and `add-log-mailing-address').
778
779 Second arg FILE-NAME is file name of the change log.
780 If nil, use the value of `change-log-default-name'.
781
782 Third arg OTHER-WINDOW non-nil means visit in other window.
783
784 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
785 never append to an existing entry. Option `add-log-keep-changes-together'
786 otherwise affects whether a new entry is created.
787
788 Fifth arg PUT-NEW-ENTRY-ON-NEW-LINE non-nil means that if a new
789 entry is created, put it on a new line by itself, do not put it
790 after a comma on an existing line.
791
792 Option `add-log-always-start-new-record' non-nil means always create a
793 new record, even when the last record was made on the same date and by
794 the same person.
795
796 The change log file can start with a copyright notice and a copying
797 permission notice. The first blank line indicates the end of these
798 notices.
799
800 Today's date is calculated according to `add-log-time-zone-rule' if
801 non-nil, otherwise in local time."
802 (interactive (list current-prefix-arg
803 (prompt-for-change-log-name)))
804 (let* ((defun (add-log-current-defun))
805 (version (and change-log-version-info-enabled
806 (change-log-version-number-search)))
807 (buf-file-name (funcall add-log-buffer-file-name-function))
808 (buffer-file (if buf-file-name (expand-file-name buf-file-name)))
809 (file-name (expand-file-name (find-change-log file-name buffer-file)))
810 ;; Set ITEM to the file name to use in the new item.
811 (item (add-log-file-name buffer-file file-name)))
812
813 (unless (equal file-name buffer-file-name)
814 (cond
815 ((equal file-name (buffer-file-name (window-buffer)))
816 ;; If the selected window already shows the desired buffer don't show
817 ;; it again (particularly important if other-window is true).
818 ;; This is important for diff-add-change-log-entries-other-window.
819 (set-buffer (window-buffer)))
820 ((or other-window (window-dedicated-p))
821 (find-file-other-window file-name))
822 (t (find-file file-name))))
823 (or (derived-mode-p 'change-log-mode)
824 (change-log-mode))
825 (undo-boundary)
826 (goto-char (point-min))
827
828 (let ((full-name (or add-log-full-name (user-full-name)))
829 (mailing-address (or add-log-mailing-address user-mail-address)))
830
831 (when whoami
832 (setq full-name (read-string "Full name: " full-name))
833 ;; Note that some sites have room and phone number fields in
834 ;; full name which look silly when inserted. Rather than do
835 ;; anything about that here, let user give prefix argument so that
836 ;; s/he can edit the full name field in prompter if s/he wants.
837 (setq mailing-address
838 (read-string "Mailing address: " mailing-address)))
839
840 ;; If file starts with a copyright and permission notice, skip them.
841 ;; Assume they end at first blank line.
842 (when (looking-at "Copyright")
843 (search-forward "\n\n")
844 (skip-chars-forward "\n"))
845
846 ;; Advance into first entry if it is usable; else make new one.
847 (let ((new-entries
848 (mapcar (lambda (addr)
849 (concat
850 (funcall add-log-time-format
851 nil add-log-time-zone-rule)
852 " " full-name
853 " <" addr ">"))
854 (if (consp mailing-address)
855 mailing-address
856 (list mailing-address)))))
857 (if (and (not add-log-always-start-new-record)
858 (let ((hit nil))
859 (dolist (entry new-entries hit)
860 (and (looking-at (regexp-quote entry))
861 ;; Reject multiple author entries. (Bug#8645)
862 (save-excursion
863 (forward-line 1)
864 (not (looking-at "[ \t]+.*<.*>$")))
865 (setq hit t)))))
866 (forward-line 1)
867 (insert (nth (random (length new-entries))
868 new-entries)
869 (if use-hard-newlines hard-newline "\n")
870 (if use-hard-newlines hard-newline "\n"))
871 (forward-line -1))))
872
873 ;; Determine where we should stop searching for a usable
874 ;; item to add to, within this entry.
875 (let ((bound
876 (save-excursion
877 (if (looking-at "\n*[^\n* \t]")
878 (skip-chars-forward "\n")
879 (if add-log-keep-changes-together
880 (forward-page) ; page delimits entries for date
881 (forward-paragraph))) ; paragraph delimits entries for file
882 (point))))
883
884 ;; Now insert the new line for this item.
885 (cond ((re-search-forward "^\\s *\\* *$" bound t)
886 ;; Put this file name into the existing empty item.
887 (if item
888 (insert item)))
889 ((and (not new-entry)
890 (let (case-fold-search)
891 (re-search-forward
892 (concat (regexp-quote (concat "* " item))
893 ;; Don't accept `foo.bar' when
894 ;; looking for `foo':
895 "\\(\\s \\|[(),:]\\)")
896 bound t)))
897 ;; Add to the existing item for the same file.
898 (re-search-forward "^\\s *$\\|^\\s \\*")
899 (goto-char (match-beginning 0))
900 ;; Delete excess empty lines; make just 2.
901 (while (and (not (eobp)) (looking-at "^\\s *$"))
902 (delete-region (point) (line-beginning-position 2)))
903 (insert (if use-hard-newlines hard-newline "\n")
904 (if use-hard-newlines hard-newline "\n"))
905 (forward-line -2)
906 (indent-relative-maybe))
907 (t
908 ;; Make a new item.
909 (while (looking-at "\\sW")
910 (forward-line 1))
911 (while (and (not (eobp)) (looking-at "^\\s *$"))
912 (delete-region (point) (line-beginning-position 2)))
913 (insert (if use-hard-newlines hard-newline "\n")
914 (if use-hard-newlines hard-newline "\n")
915 (if use-hard-newlines hard-newline "\n"))
916 (forward-line -2)
917 (indent-to left-margin)
918 (insert "* ")
919 (if item (insert item)))))
920 ;; Now insert the function name, if we have one.
921 ;; Point is at the item for this file,
922 ;; either at the end of the line or at the first blank line.
923 (if (not defun)
924 ;; No function name, so put in a colon unless we have just a star.
925 (unless (save-excursion
926 (beginning-of-line 1)
927 (looking-at "\\s *\\(\\* *\\)?$"))
928 (insert ": ")
929 (if version (insert version ?\s)))
930 ;; Make it easy to get rid of the function name.
931 (undo-boundary)
932 (unless (save-excursion
933 (beginning-of-line 1)
934 (looking-at "\\s *$"))
935 (insert ?\s))
936 ;; See if the prev function name has a message yet or not.
937 ;; If not, merge the two items.
938 (let ((pos (point-marker)))
939 (skip-syntax-backward " ")
940 (skip-chars-backward "):")
941 (if (and (not put-new-entry-on-new-line)
942 (looking-at "):")
943 (let ((pos (save-excursion (backward-sexp 1) (point))))
944 (when (equal (buffer-substring pos (point)) defun)
945 (delete-region pos (point)))
946 (> fill-column (+ (current-column) (length defun) 4))))
947 (progn (skip-chars-backward ", ")
948 (delete-region (point) pos)
949 (unless (memq (char-before) '(?\()) (insert ", ")))
950 (when (and (not put-new-entry-on-new-line) (looking-at "):"))
951 (delete-region (+ 1 (point)) (line-end-position)))
952 (goto-char pos)
953 (insert "("))
954 (set-marker pos nil))
955 (insert defun "): ")
956 (if version (insert version ?\s)))))
957
958 ;;;###autoload
959 (defun add-change-log-entry-other-window (&optional whoami file-name)
960 "Find change log file in other window and add entry and item.
961 This is just like `add-change-log-entry' except that it displays
962 the change log file in another window."
963 (interactive (if current-prefix-arg
964 (list current-prefix-arg
965 (prompt-for-change-log-name))))
966 (add-change-log-entry whoami file-name t))
967
968
969 (defvar change-log-indent-text 0)
970
971 (defun change-log-fill-parenthesized-list ()
972 ;; Fill parenthesized lists of names according to GNU standards.
973 ;; * file-name.ext (very-long-foo, very-long-bar, very-long-foobar):
974 ;; should be filled as
975 ;; * file-name.ext (very-long-foo, very-long-bar)
976 ;; (very-long-foobar):
977 (save-excursion
978 (end-of-line 0)
979 (skip-chars-backward " \t")
980 (when (and (equal (char-before) ?\,)
981 (> (point) (1+ (point-min))))
982 (condition-case nil
983 (when (save-excursion
984 (and (prog2
985 (up-list -1)
986 (equal (char-after) ?\()
987 (skip-chars-backward " \t"))
988 (or (bolp)
989 ;; Skip everything but a whitespace or asterisk.
990 (and (not (zerop (skip-chars-backward "^ \t\n*")))
991 (skip-chars-backward " \t")
992 ;; We want one asterisk here.
993 (= (skip-chars-backward "*") -1)
994 (skip-chars-backward " \t")
995 (bolp)))))
996 ;; Delete the comma.
997 (delete-char -1)
998 ;; Close list on previous line.
999 (insert ")")
1000 (skip-chars-forward " \t\n")
1001 ;; Start list on new line.
1002 (insert-before-markers "("))
1003 (error nil)))))
1004
1005 (defun change-log-indent ()
1006 (change-log-fill-parenthesized-list)
1007 (let* ((indent
1008 (save-excursion
1009 (beginning-of-line)
1010 (skip-chars-forward " \t")
1011 (cond
1012 ((and (looking-at "\\(.*\\) [^ \n].*[^ \n] <.*>\\(?: +(.*)\\)? *$")
1013 ;; Matching the output of add-log-time-format is difficult,
1014 ;; but I'll get it has at least two adjacent digits.
1015 (string-match "[[:digit:]][[:digit:]]" (match-string 1)))
1016 0)
1017 ((looking-at "[^*(]")
1018 (+ (current-left-margin) change-log-indent-text))
1019 (t (current-left-margin)))))
1020 (pos (save-excursion (indent-line-to indent) (point))))
1021 (if (> pos (point)) (goto-char pos))))
1022
1023
1024 (defvar smerge-resolve-function)
1025 (defvar copyright-at-end-flag)
1026
1027 ;;;###autoload
1028 (define-derived-mode change-log-mode text-mode "Change Log"
1029 "Major mode for editing change logs; like Indented Text mode.
1030 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
1031 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
1032 Each entry behaves as a paragraph, and the entries for one day as a page.
1033 Runs `change-log-mode-hook'.
1034 \n\\{change-log-mode-map}"
1035 (setq left-margin 8
1036 fill-column 74
1037 indent-tabs-mode t
1038 tab-width 8
1039 show-trailing-whitespace t)
1040 (set (make-local-variable 'fill-forward-paragraph-function)
1041 'change-log-fill-forward-paragraph)
1042 (set (make-local-variable 'comment-start) nil)
1043 ;; Make sure we call `change-log-indent' when filling.
1044 (set (make-local-variable 'fill-indent-according-to-mode) t)
1045 ;; Avoid that filling leaves behind a single "*" on a line.
1046 (add-hook 'fill-nobreak-predicate
1047 (lambda ()
1048 (looking-back "^\\s *\\*\\s *" (line-beginning-position)))
1049 nil t)
1050 (set (make-local-variable 'indent-line-function) 'change-log-indent)
1051 (set (make-local-variable 'tab-always-indent) nil)
1052 (set (make-local-variable 'copyright-at-end-flag) t)
1053 ;; We really do want "^" in paragraph-start below: it is only the
1054 ;; lines that begin at column 0 (despite the left-margin of 8) that
1055 ;; we are looking for. Adding `* ' allows eliding the blank line
1056 ;; between entries for different files.
1057 (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\<")
1058 (set (make-local-variable 'paragraph-separate) paragraph-start)
1059 ;; Match null string on the date-line so that the date-line
1060 ;; is grouped with what follows.
1061 (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
1062 (set (make-local-variable 'version-control) 'never)
1063 (set (make-local-variable 'smerge-resolve-function)
1064 'change-log-resolve-conflict)
1065 (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
1066 (set (make-local-variable 'font-lock-defaults)
1067 '(change-log-font-lock-keywords t nil nil backward-paragraph))
1068 (set (make-local-variable 'multi-isearch-next-buffer-function)
1069 'change-log-next-buffer)
1070 (set (make-local-variable 'beginning-of-defun-function)
1071 'change-log-beginning-of-defun)
1072 (set (make-local-variable 'end-of-defun-function)
1073 'change-log-end-of-defun)
1074 ;; next-error function glue
1075 (setq next-error-function 'change-log-next-error)
1076 (setq next-error-last-buffer (current-buffer)))
1077
1078 (defun change-log-next-buffer (&optional buffer wrap)
1079 "Return the next buffer in the series of ChangeLog file buffers.
1080 This function is used for multiple buffers isearch.
1081 A sequence of buffers is formed by ChangeLog files with decreasing
1082 numeric file name suffixes in the directory of the initial ChangeLog
1083 file were isearch was started."
1084 (let* ((name (change-log-name))
1085 (files (cons name (sort (file-expand-wildcards
1086 (concat name "[-.][0-9]*"))
1087 (lambda (a b)
1088 ;; The file's extension may not have a valid
1089 ;; version form (e.g. VC backup revisions).
1090 (ignore-errors
1091 (version< (substring b (length name))
1092 (substring a (length name))))))))
1093 (files (if isearch-forward files (reverse files)))
1094 (file (if wrap
1095 (car files)
1096 (cadr (member (file-name-nondirectory (buffer-file-name buffer))
1097 files)))))
1098 ;; If there are no files that match the default pattern ChangeLog.[0-9],
1099 ;; return the current buffer to force isearch wrapping to its beginning.
1100 ;; If file is nil, multi-isearch-search-fun will signal "end of multi".
1101 (if (file-exists-p file)
1102 (find-file-noselect file)
1103 (current-buffer))))
1104
1105 (defun change-log-fill-forward-paragraph (n)
1106 "Cut paragraphs so filling preserves open parentheses at beginning of lines."
1107 (let (;; Add lines starting with whitespace followed by a left paren or an
1108 ;; asterisk.
1109 (paragraph-start (concat paragraph-start "\\|\\s *\\(?:\\s(\\|\\*\\)")))
1110 (forward-paragraph n)))
1111 \f
1112 (defcustom add-log-current-defun-header-regexp
1113 "^\\([[:upper:]][[:upper:]_ ]*[[:upper:]_]\\|[-_[:alpha:]]+\\)[ \t]*[:=]"
1114 "Heuristic regexp used by `add-log-current-defun' for unknown major modes.
1115 The regexp's first submatch is placed in the ChangeLog entry, in
1116 parentheses."
1117 :type 'regexp
1118 :group 'change-log)
1119
1120 (declare-function c-cpp-define-name "cc-cmds" ())
1121 (declare-function c-defun-name "cc-cmds" ())
1122
1123 ;;;###autoload
1124 (defun add-log-current-defun ()
1125 "Return name of function definition point is in, or nil.
1126
1127 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
1128 Texinfo (@node titles) and Perl.
1129
1130 Other modes are handled by a heuristic that looks in the 10K before
1131 point for uppercase headings starting in the first column or
1132 identifiers followed by `:' or `='. See variables
1133 `add-log-current-defun-header-regexp' and
1134 `add-log-current-defun-function'.
1135
1136 Has a preference of looking backwards."
1137 (condition-case nil
1138 (save-excursion
1139 (if add-log-current-defun-function
1140 (funcall add-log-current-defun-function)
1141 ;; If all else fails, try heuristics
1142 (let (case-fold-search
1143 result)
1144 (end-of-line)
1145 (when (re-search-backward add-log-current-defun-header-regexp
1146 (- (point) 10000) t)
1147 (setq result (or (match-string-no-properties 1)
1148 (match-string-no-properties 0)))
1149 ;; Strip whitespace away
1150 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
1151 result)
1152 (setq result (match-string-no-properties 1 result)))
1153 result))))
1154 (error nil)))
1155
1156 (defvar change-log-get-method-definition-md)
1157
1158 ;; Subroutine used within change-log-get-method-definition.
1159 ;; Add the last match in the buffer to the end of `md',
1160 ;; followed by the string END; move to the end of that match.
1161 (defun change-log-get-method-definition-1 (end)
1162 (setq change-log-get-method-definition-md
1163 (concat change-log-get-method-definition-md
1164 (match-string 1)
1165 end))
1166 (goto-char (match-end 0)))
1167
1168 (defun change-log-get-method-definition ()
1169 "For Objective C, return the method name if we are in a method."
1170 (let ((change-log-get-method-definition-md "["))
1171 (save-excursion
1172 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
1173 (change-log-get-method-definition-1 " ")))
1174 (save-excursion
1175 (cond
1176 ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
1177 (change-log-get-method-definition-1 "")
1178 (while (not (looking-at "[{;]"))
1179 (looking-at
1180 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
1181 (change-log-get-method-definition-1 ""))
1182 (concat change-log-get-method-definition-md "]"))))))
1183 \f
1184 (autoload 'timezone-make-date-sortable "timezone")
1185
1186 (defun change-log-sortable-date-at ()
1187 "Return date of log entry in a consistent form for sorting.
1188 Point is assumed to be at the start of the entry."
1189 (if (looking-at change-log-start-entry-re)
1190 (let ((date (match-string-no-properties 0)))
1191 (if date
1192 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date)
1193 (concat (match-string 1 date) (match-string 2 date)
1194 (match-string 3 date))
1195 (ignore-errors (timezone-make-date-sortable date)))))
1196 (error "Bad date")))
1197
1198 (defun change-log-resolve-conflict ()
1199 "Function to be used in `smerge-resolve-function'."
1200 (save-excursion
1201 (save-restriction
1202 (narrow-to-region (match-beginning 0) (match-end 0))
1203 (let ((mb1 (match-beginning 1))
1204 (me1 (match-end 1))
1205 (mb3 (match-beginning 3))
1206 (me3 (match-end 3))
1207 (tmp1 (generate-new-buffer " *changelog-resolve-1*"))
1208 (tmp2 (generate-new-buffer " *changelog-resolve-2*")))
1209 (unwind-protect
1210 (let ((buf (current-buffer)))
1211 (with-current-buffer tmp1
1212 (change-log-mode)
1213 (insert-buffer-substring buf mb1 me1))
1214 (with-current-buffer tmp2
1215 (change-log-mode)
1216 (insert-buffer-substring buf mb3 me3)
1217 ;; Do the merge here instead of inside `buf' so as to be
1218 ;; more robust in case change-log-merge fails.
1219 (change-log-merge tmp1))
1220 (goto-char (point-max))
1221 (delete-region (point-min)
1222 (prog1 (point)
1223 (insert-buffer-substring tmp2))))
1224 (kill-buffer tmp1)
1225 (kill-buffer tmp2))))))
1226
1227 ;;;###autoload
1228 (defun change-log-merge (other-log)
1229 "Merge the contents of change log file OTHER-LOG with this buffer.
1230 Both must be found in Change Log mode (since the merging depends on
1231 the appropriate motion commands). OTHER-LOG can be either a file name
1232 or a buffer.
1233
1234 Entries are inserted in chronological order. Both the current and
1235 old-style time formats for entries are supported."
1236 (interactive "*fLog file name to merge: ")
1237 (if (not (derived-mode-p 'change-log-mode))
1238 (error "Not in Change Log mode"))
1239 (let ((other-buf (if (bufferp other-log) other-log
1240 (find-file-noselect other-log)))
1241 (buf (current-buffer))
1242 date1 start end)
1243 (save-excursion
1244 (goto-char (point-min))
1245 (set-buffer other-buf)
1246 (goto-char (point-min))
1247 (if (not (derived-mode-p 'change-log-mode))
1248 (error "%s not found in Change Log mode" other-log))
1249 ;; Loop through all the entries in OTHER-LOG.
1250 (while (not (eobp))
1251 (setq date1 (change-log-sortable-date-at))
1252 (setq start (point)
1253 end (progn (forward-page) (point)))
1254 ;; Look for an entry in original buffer that isn't later.
1255 (with-current-buffer buf
1256 (while (and (not (eobp))
1257 (string< date1 (change-log-sortable-date-at)))
1258 (forward-page))
1259 (if (not (eobp))
1260 (insert-buffer-substring other-buf start end)
1261 ;; At the end of the original buffer, insert a newline to
1262 ;; separate entries and then the rest of the file being
1263 ;; merged.
1264 (unless (or (bobp)
1265 (and (= ?\n (char-before))
1266 (or (<= (1- (point)) (point-min))
1267 (= ?\n (char-before (1- (point)))))))
1268 (insert (if use-hard-newlines hard-newline "\n")))
1269 ;; Move to the end of it to terminate outer loop.
1270 (with-current-buffer other-buf
1271 (goto-char (point-max)))
1272 (insert-buffer-substring other-buf start)))))))
1273
1274 (defun change-log-beginning-of-defun ()
1275 (re-search-backward change-log-start-entry-re nil 'move))
1276
1277 (defun change-log-end-of-defun ()
1278 ;; Look back and if there is no entry there it means we are before
1279 ;; the first ChangeLog entry, so go forward until finding one.
1280 (unless (save-excursion (re-search-backward change-log-start-entry-re nil t))
1281 (re-search-forward change-log-start-entry-re nil t))
1282
1283 ;; In case we are at the end of log entry going forward a line will
1284 ;; make us find the next entry when searching. If we are inside of
1285 ;; an entry going forward a line will still keep the point inside
1286 ;; the same entry.
1287 (forward-line 1)
1288
1289 ;; In case we are at the beginning of an entry, move past it.
1290 (when (looking-at change-log-start-entry-re)
1291 (goto-char (match-end 0))
1292 (forward-line 1))
1293
1294 ;; Search for the start of the next log entry. Go to the end of the
1295 ;; buffer if we could not find a next entry.
1296 (when (re-search-forward change-log-start-entry-re nil 'move)
1297 (goto-char (match-beginning 0))
1298 (forward-line -1)))
1299
1300 (provide 'add-log)
1301
1302 ;;; add-log.el ends here