1 ;;; reporter.el --- customizable bug reporting of lisp programs
3 ;; Copyright (C) 1993,1994,1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: 1993-1998 Barry A. Warsaw
6 ;; Maintainer: tools-help@python.org
7 ;; Created: 19-Apr-1993
9 ;; Last Modified: 1998/03/19 17:21:16
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 (it is no longer defined in
38 ;; Lisp Package Authors
39 ;; ====================
40 ;; reporter.el was written primarily for Emacs Lisp package authors so
41 ;; that their users can more easily report bugs. When invoked,
42 ;; `reporter-submit-bug-report' will set up an outgoing mail buffer
43 ;; with the appropriate bug report address, including a lisp
44 ;; expression the maintainer of the package can evaluate to completely
45 ;; reproduce the environment in which the bug was observed (e.g. by
46 ;; using `eval-last-sexp'). This package proved especially useful
47 ;; during my development of CC Mode, which is highly dependent on its
48 ;; configuration variables.
50 ;; Do a "C-h f reporter-submit-bug-report" for more information.
51 ;; Here's an example usage:
53 ;;(defconst mypkg-version "9.801")
54 ;;(defconst mypkg-maintainer-address "mypkg-help@foo.com")
55 ;;(defun mypkg-submit-bug-report ()
56 ;; "Submit via mail a bug report on mypkg"
58 ;; (require 'reporter)
59 ;; (reporter-submit-bug-report
60 ;; mypkg-maintainer-address
61 ;; (concat "mypkg.el " mypkg-version)
62 ;; (list 'mypkg-variable-1
65 ;; 'mypkg-variable-last)))
69 ;; Packages that currently use reporter are: CC Mode, supercite, elp,
70 ;; tcl, ediff, crypt++ (crypt), dired-x, rmailgen, mode-line, vm,
71 ;; mh-e, edebug, archie, viper, w3-mode, framepop, hl319, hilit19,
72 ;; pgp, eos, hm--html, efs, webster19.
74 ;; If you know of others, please email me!
79 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
80 ;; Package author interface variables
82 (defvar reporter-prompt-for-summary-p nil
83 "Interface variable controlling prompting for problem summary.
84 When non-nil, `reporter-submit-bug-report' prompts the user for a
85 brief summary of the problem, and puts this summary on the Subject:
86 line. If this variable is a string, that string is used as the prompt
89 Default behavior is to not prompt (i.e. nil). If you want reporter to
90 prompt, you should `let' bind this variable before calling
91 `reporter-submit-bug-report'. Note that this variable is not
92 buffer-local so you should never just `setq' it.")
94 (defvar reporter-dont-compact-list nil
95 "Interface variable controlling compacting of list values.
96 When non-nil, this must be a list of variable symbols. When a
97 variable containing a list value is formatted in the bug report mail
98 buffer, it normally is compacted so that its value fits one the fewest
99 number of lines. If the variable's symbol appears in this list, its
100 value is printed in a more verbose style, specifically, one elemental
103 Note that this variable is not buffer-local so you should never just
104 `setq' it. If you want to changes its default value, you should `let'
107 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108 ;; End of editable variables
111 (defvar reporter-eval-buffer nil
112 "Buffer to retrieve variable's value from.
113 This is necessary to properly support the printing of buffer-local
114 variables. Current buffer will always be the mail buffer being
117 (defconst reporter-version
"3.34"
118 "Reporter version number.")
120 (defvar reporter-initial-text nil
121 "The automatically created initial text of a bug report.")
122 (make-variable-buffer-local 'reporter-initial-text
)
126 ;; status feedback to the user
127 (defvar reporter-status-message nil
)
128 (defvar reporter-status-count nil
)
130 (defun reporter-update-status ()
131 ;; periodically output a status message
132 (if (zerop (% reporter-status-count
10))
134 (message reporter-status-message
)
135 (setq reporter-status-message
(concat reporter-status-message
"."))))
136 (setq reporter-status-count
(1+ reporter-status-count
)))
139 ;; dumping/pretty printing of values
140 (defun reporter-beautify-list (maxwidth compact-p
)
141 ;; pretty print a list
142 (reporter-update-status)
144 linebreak indent-enclosing-p indent-p here
)
145 (condition-case nil
;loop exit
148 (setq indent-enclosing-p t
)
151 ;; The following line is how we break out of the while
152 ;; loop, in one of two ways. Either we've hit the end of
153 ;; the buffer, in which case scan-sexps returns nil, or
154 ;; we've crossed unbalanced parens and it will raise an
155 ;; error we're expecting to catch.
156 (setq move
(scan-sexps (point) 1))
158 (if (<= maxwidth
(current-column))
161 (goto-char linebreak
)
163 (setq linebreak nil
))
165 (setq indent-p
(reporter-beautify-list maxwidth compact-p
))
169 (newline-and-indent))
172 (setq linebreak
(point))
173 (newline-and-indent))
176 (error indent-enclosing-p
))))
178 (defun reporter-lisp-indent (indent-point state
)
179 ;; a better lisp indentation style for bug reporting
181 (goto-char (1+ (nth 1 state
)))
184 (defun reporter-dump-variable (varsym mailbuf
)
185 ;; Pretty-print the value of the variable in symbol VARSYM. MAILBUF
186 ;; is the mail buffer being composed
187 (reporter-update-status)
189 (let ((val (save-excursion
190 (set-buffer reporter-eval-buffer
)
191 (symbol-value varsym
)))
192 (sym (symbol-name varsym
))
193 (print-escape-newlines t
)
194 (maxwidth (1- (window-width)))
198 ((memq val
'(t nil
)) "")
202 (prin1-to-string val
))
204 ;; clean up lists, but only if the line as printed was long
206 (if (and val
;nil is a list, but short
208 (<= maxwidth
(current-column)))
210 (let ((compact-p (not (memq varsym reporter-dont-compact-list
)))
211 (lisp-indent-function 'reporter-lisp-indent
))
213 (reporter-beautify-list maxwidth compact-p
))))
218 (mail-position-on-field "X-Reporter-Void-Vars-Found")
220 (insert (symbol-name varsym
) " ")))
224 (defun reporter-dump-state (pkgname varlist pre-hooks post-hooks
)
225 ;; Dump the state of the mode specific variables.
226 ;; PKGNAME contains the name of the mode as it will appear in the bug
227 ;; report (you must explicitly concat any version numbers).
229 ;; VARLIST is the list of variables to dump. Each element in
230 ;; VARLIST can be a variable symbol, or a cons cell. If a symbol,
231 ;; this will be passed to `reporter-dump-variable' for insertion
232 ;; into the mail buffer. If a cons cell, the car must be a variable
233 ;; symbol and the cdr must be a function which will be `funcall'd
234 ;; with arguments the symbol and the mail buffer being composed. Use
235 ;; this to write your own custom variable value printers for
236 ;; specific variables.
238 ;; Note that the global variable `reporter-eval-buffer' will be bound to
239 ;; the buffer in which `reporter-submit-bug-report' was invoked. If you
240 ;; want to print the value of a buffer local variable, you should wrap
241 ;; the `eval' call in your custom printer inside a `set-buffer' (and
242 ;; probably a `save-excursion'). `reporter-dump-variable' handles this
245 ;; PRE-HOOKS is run after the emacs-version and PKGNAME are inserted, but
246 ;; before the VARLIST is dumped. POST-HOOKS is run after the VARLIST is
248 (let ((buffer (current-buffer)))
250 (insert "Emacs : " (emacs-version) "\n")
252 (insert "Package: " pkgname
"\n"))
253 (run-hooks 'pre-hooks
)
256 (insert "\ncurrent state:\n==============\n")
257 ;; create an emacs-lisp-mode buffer to contain the output, which
258 ;; we'll later insert into the mail buffer
259 (condition-case fault
260 (let ((mailbuf (current-buffer))
261 (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
270 (lambda (varsym-or-cons-cell)
271 (let ((varsym (or (car-safe varsym-or-cons-cell
)
272 varsym-or-cons-cell
))
273 (printer (or (cdr-safe varsym-or-cons-cell
)
274 'reporter-dump-variable
)))
275 (funcall printer varsym mailbuf
)
280 (insert-buffer elbuf
))
282 (insert "State could not be dumped due to the following error:\n\n"
284 "\n\nYou should still send this bug report."))))
285 (run-hooks 'post-hooks
)
289 (defun reporter-compose-outgoing ()
290 ;; compose the outgoing mail buffer, and return the selected
291 ;; paradigm, with the current-buffer tacked onto the beginning of
293 (let* ((agent mail-user-agent
)
294 (compose (get mail-user-agent
'composefunc
)))
295 ;; Sanity check. If this fails then we'll try to use the SENDMAIL
296 ;; protocol, otherwise we must signal an error.
297 (if (not (and compose
(functionp compose
)))
299 (setq agent
'sendmail-user-agent
300 compose
(get agent
'composefunc
))
301 (if (not (and compose
(functionp compose
)))
302 (error "Could not find a valid `mail-user-agent'")
304 (message "`%s' is an invalid `mail-user-agent'; using `sendmail-user-agent'"
312 (defun reporter-submit-bug-report
313 (address pkgname varlist
&optional pre-hooks post-hooks salutation
)
314 ;; Submit a bug report via mail.
316 ;; ADDRESS is the email address for the package's maintainer. PKGNAME is
317 ;; the name of the mode (you must explicitly concat any version numbers).
318 ;; VARLIST is the list of variables to dump (see `reporter-dump-state'
319 ;; for details). Optional PRE-HOOKS and POST-HOOKS are passed to
320 ;; `reporter-dump-state'. Optional SALUTATION is inserted at the top of the
321 ;; mail buffer, and point is left after the salutation.
323 ;; This function will prompt for a summary if
324 ;; reporter-prompt-for-summary-p is non-nil.
326 ;; The mailer used is described in by the variable `mail-user-agent'.
327 (let ((reporter-eval-buffer (current-buffer))
330 (reporter-status-message "Formatting bug report buffer...")
331 (reporter-status-count 0)
332 (problem (and reporter-prompt-for-summary-p
333 (read-string (if (stringp reporter-prompt-for-summary-p
)
334 reporter-prompt-for-summary-p
335 "(Very) brief summary of problem: "))))
336 (agent (reporter-compose-outgoing))
337 (mailbuf (current-buffer))
341 ;; If mailbuf did not get made visible before, make it visible now.
342 (let (same-window-buffer-names same-window-regexps
)
343 (pop-to-buffer mailbuf
)
344 ;; Just in case the original buffer is not visible now, bring it
346 (and pop-up-windows
(display-buffer reporter-eval-buffer
)))
347 (goto-char (point-min))
348 (mail-position-on-field "to")
350 ;; insert problem summary if available
351 (if (and reporter-prompt-for-summary-p problem pkgname
)
353 (mail-position-on-field "subject")
354 (insert pkgname
"; " problem
)))
355 ;; move point to the body of the message
358 (setq after-sep-pos
(point))
359 (and salutation
(insert "\n" salutation
"\n\n"))
362 (setq final-resting-place
(point-marker))
364 (reporter-dump-state pkgname varlist pre-hooks post-hooks
)
365 (goto-char final-resting-place
))
366 (set-marker final-resting-place nil
))
368 ;; save initial text and set up the `no-empty-submission' hook.
369 ;; This only works for mailers that support a pre-send hook, and
370 ;; for which the paradigm has a non-nil value for the `hookvar'
371 ;; key in its agent (i.e. sendmail.el's mail-send-hook).
373 (goto-char (point-max))
374 (skip-chars-backward " \t\n")
375 (setq reporter-initial-text
(buffer-substring after-sep-pos
(point))))
376 (if (setq hookvar
(get agent
'hookvar
))
378 (make-variable-buffer-local hookvar
)
379 (add-hook hookvar
'reporter-bug-hook
)))
381 ;; compose the minibuf message and display this.
382 (let* ((sendkey-whereis (where-is-internal
383 (get agent
'sendfunc
) nil t
))
384 (abortkey-whereis (where-is-internal
385 (get agent
'abortfunc
) nil t
))
386 (sendkey (if sendkey-whereis
387 (key-description sendkey-whereis
)
388 "C-c C-c")) ; TBD: BOGUS hardcode
389 (abortkey (if abortkey-whereis
390 (key-description abortkey-whereis
)
391 "M-x kill-buffer")) ; TBD: BOGUS hardcode
393 (message "Please enter your report. Type %s to send, %s to abort."
397 (defun reporter-bug-hook ()
398 ;; prohibit sending mail if empty bug report
405 (goto-char (point-max))
406 (skip-chars-backward " \t\n")
407 (if (and (= (- (point) after-sep-pos
)
408 (length reporter-initial-text
))
409 (string= (buffer-substring after-sep-pos
(point))
410 reporter-initial-text
))
411 (error "Empty bug report cannot be sent"))
416 ;;; reporter.el ends here