(mmap_free_1): Avoid a compiler warning.
[emacs.git] / lisp / mail / emacsbug.el
blob5065a747daf8e475d4aafb63e3d8c01304f4ab8d
1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list.
3 ;; Copyright (C) 1985, 1994, 1997, 1998 Free Software Foundation, Inc.
5 ;; Author: K. Shane Hartman
6 ;; Maintainer: FSF
7 ;; Keywords: maint mail
9 ;; Not fully installed because it can work only on Internet hosts.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; `M-x report-emacs-bug ' starts an email note to the Emacs maintainers
30 ;; describing a problem. Here's how it's done...
32 ;;; Code:
34 ;; >> This should be an address which is accessible to your machine,
35 ;; >> otherwise you can't use this file. It will only work on the
36 ;; >> internet with this address.
38 (require 'sendmail)
40 (defgroup emacsbug nil
41 "Sending Emacs bug reports."
42 :group 'maint
43 :group 'mail)
45 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
46 "*Address of mailing list for GNU Emacs bugs."
47 :group 'emacsbug
48 :type 'string)
50 (defcustom report-emacs-bug-pretest-address "emacs-pretest-bug@gnu.org"
51 "*Address of mailing list for GNU Emacs pretest bugs."
52 :group 'emacsbug
53 :type 'string)
55 (defvar report-emacs-bug-orig-text nil
56 "The automatically-created initial text of bug report.")
58 (defcustom report-emacs-bug-no-confirmation nil
59 "*If non-nil, suppress the confirmations asked for the sake of novice users."
60 :group 'emacsbug
61 :type 'boolean)
63 (defcustom report-emacs-bug-no-explanations nil
64 "*If non-nil, suppress the explanations given for the sake of novice users."
65 :group 'emacsbug
66 :type 'boolean)
68 ;;;###autoload
69 (defun report-emacs-bug (topic &optional recent-keys)
70 "Report a bug in GNU Emacs.
71 Prompts for bug subject. Leaves you in a mail buffer."
72 ;; This strange form ensures that (recent-keys) is the value before
73 ;; the bug subject string is read.
74 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
75 (let (user-point message-end-point)
76 (setq message-end-point
77 (with-current-buffer (get-buffer "*Messages*")
78 (point-max-marker)))
79 (compose-mail (if (string-match "\\..*\\..*\\." emacs-version)
80 ;; If there are four numbers in emacs-version,
81 ;; this is a pretest version.
82 report-emacs-bug-pretest-address
83 report-emacs-bug-address)
84 topic)
85 ;; The rest of this does not execute
86 ;; if the user was asked to confirm and said no.
87 (rfc822-goto-eoh)
88 (forward-line 1)
90 (let ((signature (buffer-substring (point) (point-max))))
91 ;; Discourage users to write non-English text.
92 (set-buffer-multibyte nil)
93 (delete-region (point) (point-max))
94 (insert signature)
95 (backward-char (length signature)))
96 (unless report-emacs-bug-no-explanations
97 ;; Insert warnings for novice users.
98 (insert "This bug report will be sent to the Free Software Foundation,\n")
99 (let ((pos (point)))
100 (insert "not to your local site managers!")
101 (put-text-property pos (point) 'face 'highlight))
102 (insert "\nPlease write in ")
103 (let ((pos (point)))
104 (insert "English")
105 (put-text-property pos (point) 'face 'highlight))
106 (insert ", because the Emacs maintainers do not have
107 translators to read other languages for them.\n\n"))
109 (insert "In " (emacs-version) "\n")
110 (if (and system-configuration-options
111 (not (equal system-configuration-options "")))
112 (insert "configured using `configure "
113 system-configuration-options "'\n"))
114 (insert "\n")
115 (insert "Please describe exactly what actions triggered the bug\n"
116 "and the precise symptoms of the bug:\n\n")
117 (setq user-point (point))
118 (insert "\n\n\n"
119 "Recent input:\n")
120 (let ((before-keys (point)))
121 (insert (mapconcat (lambda (key)
122 (if (or (integerp key)
123 (symbolp key)
124 (listp key))
125 (single-key-description key)
126 (prin1-to-string key nil)))
127 (or recent-keys (recent-keys))
128 " "))
129 (save-restriction
130 (narrow-to-region before-keys (point))
131 (goto-char before-keys)
132 (while (progn (move-to-column 50) (not (eobp)))
133 (search-forward " " nil t)
134 (insert "\n"))))
135 (let ((message-buf (get-buffer "*Messages*")))
136 (if message-buf
137 (let (beg-pos
138 (end-pos message-end-point))
139 (with-current-buffer message-buf
140 (goto-char end-pos)
141 (forward-line -10)
142 (setq beg-pos (point)))
143 (insert "\n\nRecent messages:\n")
144 (insert-buffer-substring message-buf beg-pos end-pos))))
145 ;; This is so the user has to type something
146 ;; in order to send easily.
147 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
148 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
149 (unless report-emacs-bug-no-explanations
150 (with-output-to-temp-buffer "*Bug Help*"
151 (if (eq mail-user-agent 'sendmail-user-agent)
152 (princ (substitute-command-keys
153 "Type \\[mail-send-and-exit] to send the bug report.\n")))
154 (princ (substitute-command-keys
155 "Type \\[kill-buffer] RET to cancel (don't send it).\n"))
156 (terpri)
157 (princ (substitute-command-keys
158 "Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
159 about when and how to write a bug report,
160 and what information to supply so that the bug can be fixed.
161 Type SPC to scroll through this section and its subsections."))))
162 ;; Make it less likely people will send empty messages.
163 (make-local-variable 'mail-send-hook)
164 (add-hook 'mail-send-hook 'report-emacs-bug-hook)
165 (save-excursion
166 (goto-char (point-max))
167 (skip-chars-backward " \t\n")
168 (make-local-variable 'report-emacs-bug-orig-text)
169 (setq report-emacs-bug-orig-text (buffer-substring (point-min) (point))))
170 (goto-char user-point)))
172 (defun report-emacs-bug-info ()
173 "Go to the Info node on reporting Emacs bugs."
174 (interactive)
175 (info)
176 (Info-directory)
177 (Info-menu "emacs")
178 (Info-goto-node "Bugs"))
180 (defun report-emacs-bug-hook ()
181 (save-excursion
182 (goto-char (point-max))
183 (skip-chars-backward " \t\n")
184 (if (and (= (- (point) (point-min))
185 (length report-emacs-bug-orig-text))
186 (equal (buffer-substring (point-min) (point))
187 report-emacs-bug-orig-text))
188 (error "No text entered in bug report"))
190 ;; Check the buffer contents and reject non-English letters.
191 (save-excursion
192 (goto-char (point-min))
193 (skip-chars-forward "\0-\177")
194 (if (not (eobp))
195 (if (or report-emacs-bug-no-confirmation
196 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
197 (while (progn (skip-chars-forward "\0-\177")
198 (not (eobp)))
199 (let ((ch (following-char)))
200 (delete-char 1)
201 (insert (format "=%02x" ch)))))))
203 ;; The last warning for novice users.
204 (if (or report-emacs-bug-no-confirmation
205 (yes-or-no-p
206 "Send this bug report to the Emacs maintainers? "))
207 ;; Just send the current mail.
209 (goto-char (point-min))
210 (if (search-forward "To: ")
211 (let ((pos (point)))
212 (end-of-line)
213 (delete-region pos (point))))
214 (kill-local-variable 'mail-send-hook)
215 (with-output-to-temp-buffer "*Bug Help*"
216 (princ (substitute-command-keys "\
217 You invoked the command M-x report-emacs-bug,
218 but you decided not to mail the bug report to the Emacs maintainers.
220 If you want to mail it to someone else instead,
221 please insert the proper e-mail address after \"To: \",
222 and send the mail again using \\[mail-send-and-exit].")))
223 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
226 (provide 'emacsbug)
228 ;;; emacsbug.el ends here