home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / reporter.el < prev    next >
Encoding:
Text File  |  1993-05-17  |  6.1 KB  |  163 lines

  1. ;;; reporter.el --- customizable bug reporting of lisp programs
  2.  
  3. ;; Author: 1993 Barry A. Warsaw, Century Computing Inc. <bwarsaw@cen.com>
  4. ;; Maintainer:      bwarsaw@cen.com
  5. ;; Created:         19-Apr-1993
  6. ;; Version:         1.10
  7. ;; Last Modified:   1993/05/17 00:07:37
  8. ;; Keywords: bug reports lisp
  9.  
  10. ;; LCD Archive Entry:
  11. ;; reporter|Barry A. Warsaw|warsaw@anthem.nlm.nih.gov|
  12. ;; Customizable bug reporting of lisp programs.|
  13. ;; 17-May-1993||~/misc/reporter.el.Z|
  14.  
  15. ;; Copyright (C) 1993 Barry A. Warsaw
  16.  
  17. ;; This file is not yet part of GNU Emacs.
  18. ;;
  19. ;; This program is free software; you can redistribute it and/or modify
  20. ;; it under the terms of the GNU General Public License as published by
  21. ;; the Free Software Foundation; either version 2 of the License, or
  22. ;; (at your option) any later version.
  23. ;; 
  24. ;; This program is distributed in the hope that it will be useful,
  25. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. ;; GNU General Public License for more details.
  28. ;; 
  29. ;; You should have received a copy of the GNU General Public License
  30. ;; along with this program; if not, write to the Free Software
  31. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32.  
  33. ;; Introduction
  34. ;; ============
  35. ;; This program is for lisp package authors and is used to ease
  36. ;; reporting of bugs.  When envoked, reporter-submit-bug-report will
  37. ;; set up a mail buffer with the appropriate bug report address,
  38. ;; including a lisp expression the maintainer of the package can use
  39. ;; to completely reproduce the environment in which the bug was
  40. ;; observed (e.g. by using eval-last-sexp). This package is especially
  41. ;; useful for my development of c++-mode.el, which is highly dependent
  42. ;; on its configuration variables.
  43. ;;
  44. ;; Do a "C-h f reporter-submit-bug-report" for more information.
  45.  
  46. ;;; Code:
  47.  
  48.  
  49. ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  50. ;; user defined variables
  51.  
  52. (defvar reporter-mailer 'mail
  53.   "*Mail package to use to generate bug report buffer.")
  54.  
  55. ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  56. ;; end of user defined variables
  57.  
  58.  
  59. (defun reporter-dump-variable (varsym)
  60.   "Pretty-print the value of the variable in symbol VARSYM."
  61.   (let ((val (eval varsym))
  62.     (sym (symbol-name varsym))
  63.     (print-escape-newlines t))
  64.     (insert "     " sym " "
  65.         (if (or (listp val) (symbolp val)) "'" "")
  66.         (prin1-to-string val)
  67.         "\n")))
  68.  
  69. (defun reporter-dump-state (pkgname varlist pre-hooks post-hooks)
  70.   "Dump the state of the mode specific variables.
  71. PKGNAME contains the name of the mode as it will appear in the bug
  72. report (you must explicitly add any version numbers).
  73.  
  74. VARLIST is the list of variables to dump.  Each element in VARLIST can
  75. be a variable symbol, or a cons cell.  If a symbol, this will be
  76. passed to reporter-dump-variable for insertion into the mail buffer.
  77. If a cons cell, the car must be a variable symbol and the cdr must be
  78. a function which will be funcall'd with the symbol. Use this to write
  79. your own custom variable value printers for specific variables.
  80.  
  81. PRE-HOOKS is run after the emacs-version and PKGNAME are inserted, but
  82. before the VARLIST is dumped.  POST-HOOKS is run after the VARLIST is
  83. dumped."
  84.   (let ((buffer (current-buffer)))
  85.     (set-buffer buffer)
  86.     (insert "Emacs  : " (emacs-version) "\nPackage: " pkgname "\n")
  87.     (run-hooks 'pre-hooks)
  88.     (insert "\ncurrent state:\n==============\n(setq\n")
  89.     (mapcar
  90.      (function
  91.       (lambda (varsym-or-cons-cell)
  92.     (let ((varsym (or (car-safe varsym-or-cons-cell)
  93.               varsym-or-cons-cell))
  94.           (printer (or (cdr-safe varsym-or-cons-cell)
  95.                'reporter-dump-variable)))
  96.       (funcall printer varsym)
  97.       )))
  98.      varlist)
  99.     (insert "     )\n")
  100.     (run-hooks 'post-hooks)
  101.     ))
  102.  
  103. (defun reporter-submit-bug-report
  104.   (address pkgname varlist &optional pre-hooks post-hooks salutation)
  105.   "Submit a bug report via mail.
  106.  
  107. ADDRESS is the email address for the package's maintainer. PKGNAME is
  108. the name of the mode (you must explicitly add any version numbers).
  109. VARLIST is the list of variables to dump (do a \"\\[describe-function] reporter-dump-state\"
  110. for details). Optional PRE-HOOKS and POST-HOOKS are passed to
  111. reporter-dump-state. Optional SALUTATION is inserted at the top of the
  112. mail buffer, and point is left after the saluation.
  113.  
  114. The mailer used is described in the variable reporter-mailer."
  115.  
  116.   (let ((curbuf (current-buffer))
  117.     (mailbuf (progn (call-interactively reporter-mailer)
  118.             (current-buffer))))
  119.     (require 'sendmail)
  120.     (pop-to-buffer curbuf)
  121.     (pop-to-buffer mailbuf)
  122.     ;; different mailers use different separators, some may not even
  123.     ;; use m-h-s, but sendmail.el stuff must have m-h-s bound.
  124.     (let ((mail-header-separator
  125.            (save-excursion
  126.              (re-search-forward
  127.               (concat
  128.                "^\\("            ;beginning of line
  129.                (mapconcat
  130.                 'identity
  131.                 (list "[        ]*"          ;simple SMTP form
  132.                       "-+"                   ;mh-e form
  133.                       mail-header-separator) ;sendmail.el form
  134.                 "\\|")                 ;or them together
  135.                "\\)$")                 ;end of line
  136.               nil
  137.               'move)            ;search for and move
  138.              (buffer-substring (match-beginning 0) (match-end 0)))))
  139.       (mail-position-on-field "to")
  140.       (insert address)
  141.       (mail-position-on-field "subject")
  142.       (insert "Report on package " pkgname)
  143.       (re-search-forward mail-header-separator (point-max) 'move)
  144.       (forward-line 1)
  145.       (insert "\nDear " (or salutation address) ",\n\n")
  146.       (set-mark (point))                ;user should see mark change
  147.       (insert "\n\n")
  148.       (reporter-dump-state pkgname varlist pre-hooks post-hooks)
  149.       (exchange-point-and-mark))
  150.     (let* ((sendkey "C-c C-c")        ;can this be generalized like below?
  151.        (killkey-whereis (where-is-internal 'kill-buffer nil t))
  152.        (killkey (if killkey-whereis
  153.             (key-description killkey-whereis)
  154.               "M-x kill-buffer")))
  155.       (message "Please type in your report. Hit %s to send, %s to abort."
  156.            sendkey killkey))
  157.     ))
  158.  
  159. ;; this is useful
  160. (provide 'reporter)
  161.  
  162. ;;; reporter.el ends here
  163.