0
|
1 ;;; reporter.el --- customizable bug reporting of lisp programs
|
|
2
|
2
|
3 ;; Copyright (C) 1993 1994 1995 1996 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: 1993-1996 Barry A. Warsaw
|
0
|
6 ;; Created: 19-Apr-1993
|
2
|
7 ;; Version: 3.3
|
|
8 ;; Last Modified: 1996/07/02 00:39:09
|
|
9 ;; Keywords: maint mail tools
|
0
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
2
|
13 ;; XEmacs is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
0
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
2
|
18 ;; XEmacs is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
0
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
2
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
0
|
27
|
2
|
28 ;;; Synched up with: FSF 19.34.
|
0
|
29
|
|
30 ;;; Commentary:
|
2
|
31
|
|
32 ;; End User Interface
|
|
33 ;; ==================
|
|
34 ;; The variable `mail-user-agent' contains a symbol indicating which
|
|
35 ;; Emacs mail package end users would like to use to compose outgoing
|
|
36 ;; mail. See that variable for details.
|
|
37
|
|
38 ;; Mail Package Interface
|
|
39 ;; ======================
|
|
40 ;; Mail package authors can configure reporter to support their
|
|
41 ;; package by calling the function `define-mail-user-agent' See that
|
|
42 ;; function for details.
|
|
43
|
|
44 ;; Lisp Package Authors
|
|
45 ;; ====================
|
|
46 ;; Reporter was written primarily for Emacs Lisp package authors so
|
|
47 ;; that their users can easily report bugs. When invoked,
|
|
48 ;; reporter-submit-bug-report will set up an outgoing mail buffer with
|
|
49 ;; the appropriate bug report address, including a lisp expression the
|
|
50 ;; maintainer of the package can eval to completely reproduce the
|
|
51 ;; environment in which the bug was observed (e.g. by using
|
|
52 ;; eval-last-sexp). This package proved especially useful during my
|
|
53 ;; development of cc-mode, which is highly dependent on its
|
|
54 ;; configuration variables.
|
0
|
55 ;;
|
|
56 ;; Do a "C-h f reporter-submit-bug-report" for more information.
|
|
57 ;; Here's an example usage:
|
|
58 ;;
|
|
59 ;;(defconst mypkg-version "9.801")
|
|
60 ;;(defconst mypkg-maintainer-address "mypkg-help@foo.com")
|
|
61 ;;(defun mypkg-submit-bug-report ()
|
|
62 ;; "Submit via mail a bug report on mypkg"
|
|
63 ;; (interactive)
|
|
64 ;; (reporter-submit-bug-report
|
|
65 ;; mypkg-maintainer-address
|
|
66 ;; (concat "mypkg.el " mypkg-version)
|
|
67 ;; (list 'mypkg-variable-1
|
|
68 ;; 'mypkg-variable-2
|
|
69 ;; ;; ...
|
|
70 ;; 'mypkg-variable-last)))
|
|
71
|
|
72 ;; Mailing List
|
|
73 ;; ============
|
2
|
74 ;; I've set up a Majordomo mailing list to report bugs or suggest
|
|
75 ;; enhancements, etc. This list's intended audience is elisp package
|
|
76 ;; authors who are using reporter and want to stay current with
|
|
77 ;; releases. Here are the relevant addresses:
|
0
|
78 ;;
|
2
|
79 ;; Administrivia: reporter-request@python.org
|
|
80 ;; Submissions: reporter@python.org
|
0
|
81
|
|
82 ;; Packages that currently use reporter are: cc-mode, supercite, elp,
|
2
|
83 ;; tcl, ediff, crypt++ (crypt), dired-x, rmailgen, mode-line, vm,
|
|
84 ;; mh-e, edebug, archie, viper, w3-mode, framepop, hl319, hilit19,
|
|
85 ;; pgp, eos, hm--html, efs.
|
|
86 ;;
|
|
87 ;; If you know of others, please email me!
|
0
|
88
|
|
89 ;;; Code:
|
|
90
|
|
91
|
2
|
92 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
93 ;; End user interface
|
|
94
|
|
95 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
96 ;; Package author interface variables
|
0
|
97
|
|
98 (defvar reporter-prompt-for-summary-p nil
|
|
99 "Interface variable controlling prompting for problem summary.
|
|
100 When non-nil, `reporter-submit-bug-report' prompts the user for a
|
|
101 brief summary of the problem, and puts this summary on the Subject:
|
2
|
102 line. If this variable is a string, that string is used as the prompt
|
|
103 string.
|
0
|
104
|
|
105 Default behavior is to not prompt (i.e. nil). If you want reporter to
|
2
|
106 prompt, you should `let' bind this variable before calling
|
0
|
107 `reporter-submit-bug-report'. Note that this variable is not
|
|
108 buffer-local so you should never just `setq' it.")
|
|
109
|
|
110 (defvar reporter-dont-compact-list nil
|
2
|
111 "Interface variable controlling compacting of list values.
|
0
|
112 When non-nil, this must be a list of variable symbols. When a
|
|
113 variable containing a list value is formatted in the bug report mail
|
|
114 buffer, it normally is compacted so that its value fits one the fewest
|
|
115 number of lines. If the variable's symbol appears in this list, its
|
|
116 value is printed in a more verbose style, specifically, one elemental
|
|
117 sexp per line.
|
|
118
|
|
119 Note that this variable is not buffer-local so you should never just
|
|
120 `setq' it. If you want to changes its default value, you should `let'
|
|
121 bind it.")
|
|
122
|
2
|
123 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
124 ;; End of editable variables
|
0
|
125
|
2
|
126
|
0
|
127 (defvar reporter-eval-buffer nil
|
|
128 "Buffer to retrieve variable's value from.
|
|
129 This is necessary to properly support the printing of buffer-local
|
|
130 variables. Current buffer will always be the mail buffer being
|
|
131 composed.")
|
|
132
|
2
|
133 (defconst reporter-version "3.2"
|
0
|
134 "Reporter version number.")
|
|
135
|
|
136 (defvar reporter-initial-text nil
|
|
137 "The automatically created initial text of a bug report.")
|
|
138 (make-variable-buffer-local 'reporter-initial-text)
|
|
139
|
2
|
140
|
0
|
141
|
2
|
142 ;; status feedback to the user
|
0
|
143 (defvar reporter-status-message nil)
|
|
144 (defvar reporter-status-count nil)
|
|
145
|
|
146 (defun reporter-update-status ()
|
|
147 ;; periodically output a status message
|
|
148 (if (zerop (% reporter-status-count 10))
|
|
149 (progn
|
|
150 (message reporter-status-message)
|
|
151 (setq reporter-status-message (concat reporter-status-message "."))))
|
|
152 (setq reporter-status-count (1+ reporter-status-count)))
|
|
153
|
|
154
|
2
|
155 ;; dumping/pretty printing of values
|
0
|
156 (defun reporter-beautify-list (maxwidth compact-p)
|
|
157 ;; pretty print a list
|
|
158 (reporter-update-status)
|
|
159 (let (linebreak indent-enclosing-p indent-p here)
|
|
160 (condition-case nil ;loop exit
|
|
161 (progn
|
|
162 (down-list 1)
|
|
163 (setq indent-enclosing-p t)
|
|
164 (while t
|
|
165 (setq here (point))
|
|
166 (forward-sexp 1)
|
|
167 (if (<= maxwidth (current-column))
|
|
168 (if linebreak
|
|
169 (progn
|
|
170 (goto-char linebreak)
|
|
171 (newline-and-indent)
|
|
172 (setq linebreak nil))
|
|
173 (goto-char here)
|
|
174 (setq indent-p (reporter-beautify-list maxwidth compact-p))
|
|
175 (goto-char here)
|
|
176 (forward-sexp 1)
|
|
177 (if indent-p
|
|
178 (newline-and-indent))
|
|
179 t)
|
|
180 (if compact-p
|
|
181 (setq linebreak (point))
|
|
182 (newline-and-indent))
|
|
183 ))
|
|
184 t)
|
|
185 (error indent-enclosing-p))))
|
|
186
|
|
187 (defun reporter-lisp-indent (indent-point state)
|
|
188 ;; a better lisp indentation style for bug reporting
|
|
189 (save-excursion
|
|
190 (goto-char (1+ (nth 1 state)))
|
|
191 (current-column)))
|
|
192
|
|
193 (defun reporter-dump-variable (varsym mailbuf)
|
|
194 ;; Pretty-print the value of the variable in symbol VARSYM. MAILBUF
|
|
195 ;; is the mail buffer being composed
|
|
196 (reporter-update-status)
|
|
197 (condition-case nil
|
|
198 (let ((val (save-excursion
|
|
199 (set-buffer reporter-eval-buffer)
|
|
200 (symbol-value varsym)))
|
|
201 (sym (symbol-name varsym))
|
|
202 (print-escape-newlines t)
|
|
203 (maxwidth (1- (window-width)))
|
|
204 (here (point)))
|
|
205 (insert " " sym " "
|
|
206 (cond
|
|
207 ((memq val '(t nil)) "")
|
|
208 ((listp val) "'")
|
|
209 ((symbolp val) "'")
|
|
210 (t ""))
|
|
211 (prin1-to-string val))
|
|
212 (lisp-indent-line)
|
|
213 ;; clean up lists, but only if the line as printed was long
|
|
214 ;; enough to wrap
|
|
215 (if (and val ;nil is a list, but short
|
|
216 (listp val)
|
|
217 (<= maxwidth (current-column)))
|
|
218 (save-excursion
|
|
219 (let ((compact-p (not (memq varsym reporter-dont-compact-list)))
|
|
220 (lisp-indent-function 'reporter-lisp-indent))
|
|
221 (goto-char here)
|
|
222 (reporter-beautify-list maxwidth compact-p))))
|
|
223 (insert "\n"))
|
|
224 (void-variable
|
|
225 (save-excursion
|
|
226 (set-buffer mailbuf)
|
|
227 (mail-position-on-field "X-Reporter-Void-Vars-Found")
|
|
228 (end-of-line)
|
|
229 (insert (symbol-name varsym) " ")))
|
2
|
230 (error
|
|
231 (error ""))))
|
0
|
232
|
|
233 (defun reporter-dump-state (pkgname varlist pre-hooks post-hooks)
|
|
234 ;; Dump the state of the mode specific variables.
|
|
235 ;; PKGNAME contains the name of the mode as it will appear in the bug
|
|
236 ;; report (you must explicitly concat any version numbers).
|
|
237
|
|
238 ;; VARLIST is the list of variables to dump. Each element in
|
|
239 ;; VARLIST can be a variable symbol, or a cons cell. If a symbol,
|
|
240 ;; this will be passed to `reporter-dump-variable' for insertion
|
|
241 ;; into the mail buffer. If a cons cell, the car must be a variable
|
|
242 ;; symbol and the cdr must be a function which will be `funcall'd
|
|
243 ;; with arguments the symbol and the mail buffer being composed. Use
|
|
244 ;; this to write your own custom variable value printers for
|
|
245 ;; specific variables.
|
|
246
|
|
247 ;; Note that the global variable `reporter-eval-buffer' will be bound to
|
|
248 ;; the buffer in which `reporter-submit-bug-report' was invoked. If you
|
|
249 ;; want to print the value of a buffer local variable, you should wrap
|
|
250 ;; the `eval' call in your custom printer inside a `set-buffer' (and
|
|
251 ;; probably a `save-excursion'). `reporter-dump-variable' handles this
|
|
252 ;; properly.
|
|
253
|
|
254 ;; PRE-HOOKS is run after the emacs-version and PKGNAME are inserted, but
|
|
255 ;; before the VARLIST is dumped. POST-HOOKS is run after the VARLIST is
|
|
256 ;; dumped.
|
|
257 (let ((buffer (current-buffer)))
|
|
258 (set-buffer buffer)
|
|
259 (insert "Emacs : " (emacs-version) "\n")
|
|
260 (and pkgname
|
|
261 (insert "Package: " pkgname "\n"))
|
|
262 (run-hooks 'pre-hooks)
|
|
263 (if (not varlist)
|
|
264 nil
|
|
265 (insert "\ncurrent state:\n==============\n")
|
|
266 ;; create an emacs-lisp-mode buffer to contain the output, which
|
|
267 ;; we'll later insert into the mail buffer
|
|
268 (condition-case fault
|
|
269 (let ((mailbuf (current-buffer))
|
|
270 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
|
|
271 (save-excursion
|
|
272 (set-buffer elbuf)
|
|
273 (emacs-lisp-mode)
|
|
274 (erase-buffer)
|
|
275 (insert "(setq\n")
|
|
276 (lisp-indent-line)
|
|
277 (mapcar
|
|
278 (function
|
|
279 (lambda (varsym-or-cons-cell)
|
|
280 (let ((varsym (or (car-safe varsym-or-cons-cell)
|
|
281 varsym-or-cons-cell))
|
|
282 (printer (or (cdr-safe varsym-or-cons-cell)
|
|
283 'reporter-dump-variable)))
|
|
284 (funcall printer varsym mailbuf)
|
|
285 )))
|
|
286 varlist)
|
|
287 (lisp-indent-line)
|
|
288 (insert ")\n"))
|
|
289 (insert-buffer elbuf))
|
|
290 (error
|
|
291 (insert "State could not be dumped due to the following error:\n\n"
|
|
292 (format "%s" fault)
|
|
293 "\n\nYou should still send this bug report."))))
|
|
294 (run-hooks 'post-hooks)
|
|
295 ))
|
|
296
|
|
297
|
|
298 (defun reporter-calculate-separator ()
|
|
299 ;; returns the string regexp matching the mail separator
|
|
300 (save-excursion
|
|
301 (re-search-forward
|
|
302 (concat
|
|
303 "^\\(" ;beginning of line
|
|
304 (mapconcat
|
|
305 'identity
|
|
306 (list "[\t ]*" ;simple SMTP form
|
|
307 "-+" ;mh-e form
|
|
308 (regexp-quote
|
|
309 mail-header-separator)) ;sendmail.el form
|
|
310 "\\|") ;or them together
|
|
311 "\\)$") ;end of line
|
|
312 nil
|
|
313 'move) ;search for and move
|
|
314 (buffer-substring (match-beginning 0) (match-end 0))))
|
|
315
|
2
|
316
|
|
317 ;; Serves as an interface to `mail' (sendmail.el), but when the user
|
|
318 ;; answers "no" to discarding an unsent message, it gives an error.
|
0
|
319 (defun reporter-mail (&rest args)
|
|
320 (or (apply 'mail args)
|
|
321 (error "Bug report aborted")))
|
|
322
|
2
|
323 (defun reporter-compose-outgoing ()
|
|
324 ;; compose the outgoing mail buffer, and return the selected
|
|
325 ;; paradigm, with the current-buffer tacked onto the beginning of
|
|
326 ;; the list.
|
|
327 (let* ((agent mail-user-agent)
|
|
328 (compose (get mail-user-agent 'composefunc)))
|
|
329 ;; Sanity check. If this fails then we'll try to use the SENDMAIL
|
|
330 ;; protocol, otherwise we must signal an error.
|
|
331 (if (not (and compose (fboundp compose)))
|
|
332 (progn
|
|
333 (setq agent 'sendmail-user-agent
|
|
334 compose (get agent 'composefunc))
|
|
335 (if (not (and compose (fboundp compose)))
|
|
336 (error "Could not find a valid `mail-user-agent'.")
|
|
337 (ding)
|
|
338 (message "`%s' is an invalid `mail-user-agent'; using `sendmail-user-agent'."
|
|
339 mail-user-agent)
|
|
340 )))
|
|
341 (funcall compose)
|
|
342 agent))
|
|
343
|
|
344
|
0
|
345 ;;;###autoload
|
|
346 (defun reporter-submit-bug-report
|
|
347 (address pkgname varlist &optional pre-hooks post-hooks salutation)
|
|
348 ;; Submit a bug report via mail.
|
|
349
|
|
350 ;; ADDRESS is the email address for the package's maintainer. PKGNAME is
|
|
351 ;; the name of the mode (you must explicitly concat any version numbers).
|
|
352 ;; VARLIST is the list of variables to dump (see `reporter-dump-state'
|
|
353 ;; for details). Optional PRE-HOOKS and POST-HOOKS are passed to
|
|
354 ;; `reporter-dump-state'. Optional SALUTATION is inserted at the top of the
|
|
355 ;; mail buffer, and point is left after the salutation.
|
|
356
|
|
357 ;; This function will prompt for a summary if
|
|
358 ;; reporter-prompt-for-summary-p is non-nil.
|
|
359
|
2
|
360 ;; The mailer used is described in by the variable `mail-user-agent'.
|
0
|
361 (let ((reporter-eval-buffer (current-buffer))
|
|
362 final-resting-place
|
|
363 after-sep-pos
|
|
364 (reporter-status-message "Formatting bug report buffer...")
|
|
365 (reporter-status-count 0)
|
|
366 (problem (and reporter-prompt-for-summary-p
|
2
|
367 (read-string (if (stringp reporter-prompt-for-summary-p)
|
|
368 reporter-prompt-for-summary-p
|
|
369 "(Very) brief summary of problem: "))))
|
|
370 (agent (reporter-compose-outgoing))
|
|
371 (mailbuf (current-buffer))
|
|
372 hookvar)
|
|
373 ;; do the work
|
0
|
374 (require 'sendmail)
|
2
|
375 ;; If mailbuf did not get made visible before, make it visible now.
|
|
376 (let (same-window-buffer-names same-window-regexps)
|
|
377 (pop-to-buffer mailbuf)
|
|
378 ;; Just in case the original buffer is not visible now, bring it
|
|
379 ;; back somewhere
|
|
380 (display-buffer reporter-eval-buffer))
|
0
|
381 (goto-char (point-min))
|
|
382 ;; different mailers use different separators, some may not even
|
2
|
383 ;; use mail-header-separator, but sendmail.el stuff must have this
|
|
384 ;; variable bound.
|
0
|
385 (let ((mail-header-separator (reporter-calculate-separator)))
|
|
386 (mail-position-on-field "to")
|
|
387 (insert address)
|
|
388 ;; insert problem summary if available
|
|
389 (if (and reporter-prompt-for-summary-p problem pkgname)
|
|
390 (progn
|
|
391 (mail-position-on-field "subject")
|
|
392 (insert pkgname "; " problem)))
|
|
393 ;; move point to the body of the message
|
|
394 (mail-text)
|
|
395 (forward-line 1)
|
|
396 (setq after-sep-pos (point))
|
|
397 (and salutation (insert "\n" salutation "\n\n"))
|
|
398 (unwind-protect
|
|
399 (progn
|
|
400 (setq final-resting-place (point-marker))
|
|
401 (insert "\n\n")
|
|
402 (reporter-dump-state pkgname varlist pre-hooks post-hooks)
|
|
403 (goto-char final-resting-place))
|
|
404 (set-marker final-resting-place nil)))
|
|
405
|
|
406 ;; save initial text and set up the `no-empty-submission' hook.
|
2
|
407 ;; This only works for mailers that support a pre-send hook, and
|
|
408 ;; for which the paradigm has a non-nil value for the `hookvar'
|
|
409 ;; key in its agent (i.e. sendmail.el's mail-send-hook).
|
|
410 (save-excursion
|
|
411 (goto-char (point-max))
|
|
412 (skip-chars-backward " \t\n")
|
|
413 (setq reporter-initial-text (buffer-substring after-sep-pos (point))))
|
|
414 (if (setq hookvar (get agent 'hookvar))
|
0
|
415 (progn
|
2
|
416 (make-variable-buffer-local hookvar)
|
|
417 (add-hook hookvar 'reporter-bug-hook)))
|
0
|
418
|
2
|
419 ;; compose the minibuf message and display this.
|
|
420 (let* ((sendkey-whereis (where-is-internal
|
|
421 (get agent 'sendfunc) nil t))
|
|
422 (abortkey-whereis (where-is-internal
|
|
423 (get agent 'abortfunc) nil t))
|
|
424 (sendkey (if sendkey-whereis
|
|
425 (key-description sendkey-whereis)
|
|
426 "C-c C-c")) ; TBD: BOGUS hardcode
|
|
427 (abortkey (if abortkey-whereis
|
|
428 (key-description abortkey-whereis)
|
|
429 "M-x kill-buffer")) ; TBD: BOGUS hardcode
|
|
430 )
|
|
431 (message "Please enter your report. Type %s to send, %s to abort."
|
|
432 sendkey abortkey))
|
0
|
433 ))
|
|
434
|
|
435 (defun reporter-bug-hook ()
|
|
436 ;; prohibit sending mail if empty bug report
|
|
437 (let ((after-sep-pos
|
|
438 (save-excursion
|
|
439 (beginning-of-buffer)
|
|
440 (re-search-forward (reporter-calculate-separator) (point-max) 'move)
|
|
441 (forward-line 1)
|
|
442 (point))))
|
|
443 (save-excursion
|
|
444 (goto-char (point-max))
|
|
445 (skip-chars-backward " \t\n")
|
|
446 (if (and (= (- (point) after-sep-pos)
|
|
447 (length reporter-initial-text))
|
|
448 (string= (buffer-substring after-sep-pos (point))
|
|
449 reporter-initial-text))
|
2
|
450 (error "Empty bug report cannot be sent."))
|
0
|
451 )))
|
|
452
|
|
453
|
2
|
454
|
0
|
455 (provide 'reporter)
|
|
456 ;;; reporter.el ends here
|