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