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