1 ;;; reporter.el --- customizable bug reporting of lisp programs
3 ;; Copyright (C) 1993 1994 1995 1996 Free Software Foundation, Inc.
5 ;; Author: 1993-1996 Barry A. Warsaw
7 ;; Created: 19-Apr-1993
9 ;; Last Modified: 1996/07/02 00:39:09
10 ;; Keywords: maint mail tools
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
33 ;; The variable `mail-user-agent' contains a symbol indicating which
34 ;; Emacs mail package end users would like to use to compose outgoing
35 ;; mail. See that variable for details.
37 ;; Lisp Package Authors
38 ;; ====================
39 ;; Reporter was written primarily for Emacs Lisp package authors so
40 ;; that their users can easily report bugs. When invoked,
41 ;; reporter-submit-bug-report will set up an outgoing mail buffer with
42 ;; the appropriate bug report address, including a lisp expression the
43 ;; maintainer of the package can eval to completely reproduce the
44 ;; environment in which the bug was observed (e.g. by using
45 ;; eval-last-sexp). This package proved especially useful during my
46 ;; development of cc-mode, which is highly dependent on its
47 ;; configuration variables.
49 ;; Do a "C-h f reporter-submit-bug-report" for more information.
50 ;; Here's an example usage:
52 ;;(defconst mypkg-version "9.801")
53 ;;(defconst mypkg-maintainer-address "mypkg-help@foo.com")
54 ;;(defun mypkg-submit-bug-report ()
55 ;; "Submit via mail a bug report on mypkg"
57 ;; (reporter-submit-bug-report
58 ;; mypkg-maintainer-address
59 ;; (concat "mypkg.el " mypkg-version)
60 ;; (list 'mypkg-variable-1
63 ;; 'mypkg-variable-last)))
67 ;; I've set up a Majordomo mailing list to report bugs or suggest
68 ;; enhancements, etc. This list's intended audience is elisp package
69 ;; authors who are using reporter and want to stay current with
70 ;; releases. Here are the relevant addresses:
72 ;; Administrivia: reporter-request@python.org
73 ;; Submissions: reporter@python.org
75 ;; Packages that currently use reporter are: cc-mode, supercite, elp,
76 ;; tcl, ediff, crypt++ (crypt), dired-x, rmailgen, mode-line, vm,
77 ;; mh-e, edebug, archie, viper, w3-mode, framepop, hl319, hilit19,
78 ;; pgp, eos, hm--html, efs.
80 ;; If you know of others, please email me!
84 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
85 ;; Package author interface variables
87 (defvar reporter-prompt-for-summary-p nil
88 "Interface variable controlling prompting for problem summary.
89 When non-nil, `reporter-submit-bug-report' prompts the user for a
90 brief summary of the problem, and puts this summary on the Subject:
91 line. If this variable is a string, that string is used as the prompt
94 Default behavior is to not prompt (i.e. nil). If you want reporter to
95 prompt, you should `let' bind this variable before calling
96 `reporter-submit-bug-report'. Note that this variable is not
97 buffer-local so you should never just `setq' it.")
99 (defvar reporter-dont-compact-list nil
100 "Interface variable controlling compacting of list values.
101 When non-nil, this must be a list of variable symbols. When a
102 variable containing a list value is formatted in the bug report mail
103 buffer, it normally is compacted so that its value fits one the fewest
104 number of lines. If the variable's symbol appears in this list, its
105 value is printed in a more verbose style, specifically, one elemental
108 Note that this variable is not buffer-local so you should never just
109 `setq' it. If you want to changes its default value, you should `let'
112 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113 ;; End of editable variables
116 (defvar reporter-eval-buffer nil
117 "Buffer to retrieve variable's value from.
118 This is necessary to properly support the printing of buffer-local
119 variables. Current buffer will always be the mail buffer being
122 (defconst reporter-version
"3.3"
123 "Reporter version number.")
125 (defvar reporter-initial-text nil
126 "The automatically created initial text of a bug report.")
127 (make-variable-buffer-local 'reporter-initial-text
)
131 ;; status feedback to the user
132 (defvar reporter-status-message nil
)
133 (defvar reporter-status-count nil
)
135 (defun reporter-update-status ()
136 ;; periodically output a status message
137 (if (zerop (% reporter-status-count
10))
139 (message reporter-status-message
)
140 (setq reporter-status-message
(concat reporter-status-message
"."))))
141 (setq reporter-status-count
(1+ reporter-status-count
)))
144 ;; dumping/pretty printing of values
145 (defun reporter-beautify-list (maxwidth compact-p
)
146 ;; pretty print a list
147 (reporter-update-status)
148 (let (linebreak indent-enclosing-p indent-p here
)
149 (condition-case nil
;loop exit
152 (setq indent-enclosing-p t
)
156 (if (<= maxwidth
(current-column))
159 (goto-char linebreak
)
161 (setq linebreak nil
))
163 (setq indent-p
(reporter-beautify-list maxwidth compact-p
))
167 (newline-and-indent))
170 (setq linebreak
(point))
171 (newline-and-indent))
174 (error indent-enclosing-p
))))
176 (defun reporter-lisp-indent (indent-point state
)
177 ;; a better lisp indentation style for bug reporting
179 (goto-char (1+ (nth 1 state
)))
182 (defun reporter-dump-variable (varsym mailbuf
)
183 ;; Pretty-print the value of the variable in symbol VARSYM. MAILBUF
184 ;; is the mail buffer being composed
185 (reporter-update-status)
187 (let ((val (save-excursion
188 (set-buffer reporter-eval-buffer
)
189 (symbol-value varsym
)))
190 (sym (symbol-name varsym
))
191 (print-escape-newlines t
)
192 (maxwidth (1- (window-width)))
196 ((memq val
'(t nil
)) "")
200 (prin1-to-string val
))
202 ;; clean up lists, but only if the line as printed was long
204 (if (and val
;nil is a list, but short
206 (<= maxwidth
(current-column)))
208 (let ((compact-p (not (memq varsym reporter-dont-compact-list
)))
209 (lisp-indent-function 'reporter-lisp-indent
))
211 (reporter-beautify-list maxwidth compact-p
))))
216 (mail-position-on-field "X-Reporter-Void-Vars-Found")
218 (insert (symbol-name varsym
) " ")))
222 (defun reporter-dump-state (pkgname varlist pre-hooks post-hooks
)
223 ;; Dump the state of the mode specific variables.
224 ;; PKGNAME contains the name of the mode as it will appear in the bug
225 ;; report (you must explicitly concat any version numbers).
227 ;; VARLIST is the list of variables to dump. Each element in
228 ;; VARLIST can be a variable symbol, or a cons cell. If a symbol,
229 ;; this will be passed to `reporter-dump-variable' for insertion
230 ;; into the mail buffer. If a cons cell, the car must be a variable
231 ;; symbol and the cdr must be a function which will be `funcall'd
232 ;; with arguments the symbol and the mail buffer being composed. Use
233 ;; this to write your own custom variable value printers for
234 ;; specific variables.
236 ;; Note that the global variable `reporter-eval-buffer' will be bound to
237 ;; the buffer in which `reporter-submit-bug-report' was invoked. If you
238 ;; want to print the value of a buffer local variable, you should wrap
239 ;; the `eval' call in your custom printer inside a `set-buffer' (and
240 ;; probably a `save-excursion'). `reporter-dump-variable' handles this
243 ;; PRE-HOOKS is run after the emacs-version and PKGNAME are inserted, but
244 ;; before the VARLIST is dumped. POST-HOOKS is run after the VARLIST is
246 (let ((buffer (current-buffer)))
248 (insert "Emacs : " (emacs-version) "\n")
250 (insert "Package: " pkgname
"\n"))
251 (run-hooks 'pre-hooks
)
254 (insert "\ncurrent state:\n==============\n")
255 ;; create an emacs-lisp-mode buffer to contain the output, which
256 ;; we'll later insert into the mail buffer
257 (condition-case fault
258 (let ((mailbuf (current-buffer))
259 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
268 (lambda (varsym-or-cons-cell)
269 (let ((varsym (or (car-safe varsym-or-cons-cell
)
270 varsym-or-cons-cell
))
271 (printer (or (cdr-safe varsym-or-cons-cell
)
272 'reporter-dump-variable
)))
273 (funcall printer varsym mailbuf
)
278 (insert-buffer elbuf
))
280 (insert "State could not be dumped due to the following error:\n\n"
282 "\n\nYou should still send this bug report."))))
283 (run-hooks 'post-hooks
)
287 (defun reporter-calculate-separator ()
288 ;; returns the string regexp matching the mail separator
292 "^\\(" ;beginning of line
295 (list "[\t ]*" ;simple SMTP form
298 mail-header-separator
)) ;sendmail.el form
299 "\\|") ;or them together
302 'move
) ;search for and move
303 (buffer-substring (match-beginning 0) (match-end 0))))
306 (defun reporter-compose-outgoing ()
307 ;; compose the outgoing mail buffer, and return the selected
308 ;; paradigm, with the current-buffer tacked onto the beginning of
310 (let* ((agent mail-user-agent
)
311 (compose (get mail-user-agent
'composefunc
)))
312 ;; Sanity check. If this fails then we'll try to use the SENDMAIL
313 ;; protocol, otherwise we must signal an error.
314 (if (not (and compose
(functionp compose
)))
316 (setq agent
'sendmail-user-agent
317 compose
(get agent
'composefunc
))
318 (if (not (and compose
(functionp compose
)))
319 (error "Could not find a valid `mail-user-agent'")
321 (message "`%s' is an invalid `mail-user-agent'; using `sendmail-user-agent'"
329 (defun reporter-submit-bug-report
330 (address pkgname varlist
&optional pre-hooks post-hooks salutation
)
331 ;; Submit a bug report via mail.
333 ;; ADDRESS is the email address for the package's maintainer. PKGNAME is
334 ;; the name of the mode (you must explicitly concat any version numbers).
335 ;; VARLIST is the list of variables to dump (see `reporter-dump-state'
336 ;; for details). Optional PRE-HOOKS and POST-HOOKS are passed to
337 ;; `reporter-dump-state'. Optional SALUTATION is inserted at the top of the
338 ;; mail buffer, and point is left after the salutation.
340 ;; This function will prompt for a summary if
341 ;; reporter-prompt-for-summary-p is non-nil.
343 ;; The mailer used is described in by the variable `mail-user-agent'.
344 (let ((reporter-eval-buffer (current-buffer))
347 (reporter-status-message "Formatting bug report buffer...")
348 (reporter-status-count 0)
349 (problem (and reporter-prompt-for-summary-p
350 (read-string (if (stringp reporter-prompt-for-summary-p
)
351 reporter-prompt-for-summary-p
352 "(Very) brief summary of problem: "))))
353 (agent (reporter-compose-outgoing))
354 (mailbuf (current-buffer))
358 ;; If mailbuf did not get made visible before, make it visible now.
359 (let (same-window-buffer-names same-window-regexps
)
360 (pop-to-buffer mailbuf
)
361 ;; Just in case the original buffer is not visible now, bring it
363 (display-buffer reporter-eval-buffer
))
364 (goto-char (point-min))
365 ;; different mailers use different separators, some may not even
366 ;; use mail-header-separator, but sendmail.el stuff must have this
368 (let ((mail-header-separator (reporter-calculate-separator)))
369 (mail-position-on-field "to")
371 ;; insert problem summary if available
372 (if (and reporter-prompt-for-summary-p problem pkgname
)
374 (mail-position-on-field "subject")
375 (insert pkgname
"; " problem
)))
376 ;; move point to the body of the message
379 (setq after-sep-pos
(point))
380 (and salutation
(insert "\n" salutation
"\n\n"))
383 (setq final-resting-place
(point-marker))
385 (reporter-dump-state pkgname varlist pre-hooks post-hooks
)
386 (goto-char final-resting-place
))
387 (set-marker final-resting-place nil
)))
389 ;; save initial text and set up the `no-empty-submission' hook.
390 ;; This only works for mailers that support a pre-send hook, and
391 ;; for which the paradigm has a non-nil value for the `hookvar'
392 ;; key in its agent (i.e. sendmail.el's mail-send-hook).
394 (goto-char (point-max))
395 (skip-chars-backward " \t\n")
396 (setq reporter-initial-text
(buffer-substring after-sep-pos
(point))))
397 (if (setq hookvar
(get agent
'hookvar
))
399 (make-variable-buffer-local hookvar
)
400 (add-hook hookvar
'reporter-bug-hook
)))
402 ;; compose the minibuf message and display this.
403 (let* ((sendkey-whereis (where-is-internal
404 (get agent
'sendfunc
) nil t
))
405 (abortkey-whereis (where-is-internal
406 (get agent
'abortfunc
) nil t
))
407 (sendkey (if sendkey-whereis
408 (key-description sendkey-whereis
)
409 "C-c C-c")) ; TBD: BOGUS hardcode
410 (abortkey (if abortkey-whereis
411 (key-description abortkey-whereis
)
412 "M-x kill-buffer")) ; TBD: BOGUS hardcode
414 (message "Please enter your report. Type %s to send, %s to abort."
418 (defun reporter-bug-hook ()
419 ;; prohibit sending mail if empty bug report
422 (beginning-of-buffer)
423 (re-search-forward (reporter-calculate-separator) (point-max) 'move
)
427 (goto-char (point-max))
428 (skip-chars-backward " \t\n")
429 (if (and (= (- (point) after-sep-pos
)
430 (length reporter-initial-text
))
431 (string= (buffer-substring after-sep-pos
(point))
432 reporter-initial-text
))
433 (error "Bug report was empty--not sent"))
438 ;;; reporter.el ends here