]> code.delx.au - gnu-emacs/blob - lisp/mail/emacsbug.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / mail / emacsbug.el
1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
2
3 ;; Copyright (C) 1985, 1994, 1997, 1998, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: K. Shane Hartman
7 ;; Maintainer: FSF
8 ;; Keywords: maint mail
9
10 ;; Not fully installed because it can work only on Internet hosts.
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs 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.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
31 ;; describing a problem. Here's how it's done...
32
33 ;;; Code:
34
35 ;; >> This should be an address which is accessible to your machine,
36 ;; >> otherwise you can't use this file. It will only work on the
37 ;; >> internet with this address.
38
39 (require 'sendmail)
40
41 (defgroup emacsbug nil
42 "Sending Emacs bug reports."
43 :group 'maint
44 :group 'mail)
45
46 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
47 "*Address of mailing list for GNU Emacs bugs."
48 :group 'emacsbug
49 :type 'string)
50
51 (defcustom report-emacs-bug-pretest-address "emacs-pretest-bug@gnu.org"
52 "*Address of mailing list for GNU Emacs pretest bugs."
53 :group 'emacsbug
54 :type 'string)
55
56 (defvar report-emacs-bug-orig-text nil
57 "The automatically-created initial text of bug report.")
58
59 (defcustom report-emacs-bug-no-confirmation nil
60 "*If non-nil, suppress the confirmations asked for the sake of novice users."
61 :group 'emacsbug
62 :type 'boolean)
63
64 (defcustom report-emacs-bug-no-explanations nil
65 "*If non-nil, suppress the explanations given for the sake of novice users."
66 :group 'emacsbug
67 :type 'boolean)
68
69 ;;;###autoload
70 (defun report-emacs-bug (topic &optional recent-keys)
71 "Report a bug in GNU Emacs.
72 Prompts for bug subject. Leaves you in a mail buffer."
73 ;; This strange form ensures that (recent-keys) is the value before
74 ;; the bug subject string is read.
75 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
76 ;; If there are four numbers in emacs-version, this is a pretest
77 ;; version.
78 (let* ((pretest-p (string-match "\\..*\\..*\\." emacs-version))
79 (from-buffer (current-buffer))
80 (reporting-address (if pretest-p
81 report-emacs-bug-pretest-address
82 report-emacs-bug-address))
83 ;; Put these properties on semantically-void text.
84 (prompt-properties '(field emacsbug-prompt
85 intangible but-helpful
86 rear-nonsticky t))
87 user-point message-end-point)
88 (setq message-end-point
89 (with-current-buffer (get-buffer-create "*Messages*")
90 (point-max-marker)))
91 (compose-mail reporting-address
92 topic)
93 ;; The rest of this does not execute
94 ;; if the user was asked to confirm and said no.
95 (rfc822-goto-eoh)
96 (forward-line 1)
97
98 (let ((signature (buffer-substring (point) (point-max))))
99 (delete-region (point) (point-max))
100 (insert signature)
101 (backward-char (length signature)))
102 (unless report-emacs-bug-no-explanations
103 ;; Insert warnings for novice users.
104 (when (string-match "@gnu\\.org^" reporting-address)
105 (insert "This bug report will be sent to the Free Software Foundation,\n")
106 (let ((pos (point)))
107 (insert "not to your local site managers!")
108 (put-text-property pos (point) 'face 'highlight)))
109 (insert "\nPlease write in ")
110 (let ((pos (point)))
111 (insert "English")
112 (put-text-property pos (point) 'face 'highlight))
113 (insert " if possible, because the Emacs maintainers
114 usually do not have translators to read other languages for them.\n\n")
115 (insert (format "Your bug report will be posted to the %s mailing list"
116 reporting-address))
117 (if pretest-p
118 (insert ".\n\n")
119 (insert ",\nand to the gnu.emacs.bug news group.\n\n")))
120
121 (insert "Please describe exactly what actions triggered the bug\n"
122 "and the precise symptoms of the bug:\n\n")
123 (add-text-properties (point) (save-excursion (mail-text) (point))
124 prompt-properties)
125
126 (setq user-point (point))
127 (insert "\n\n")
128
129 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
130 "please include the output from the following gdb commands:\n"
131 " `bt full' and `xbacktrace'.\n")
132
133 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
134 (if (file-readable-p debug-file)
135 (insert "If you would like to further debug the crash, please read the file\n"
136 debug-file " for instructions.\n")))
137 (add-text-properties (1+ user-point) (point) prompt-properties)
138
139 (insert "\n\nIn " (emacs-version) "\n")
140 (if (fboundp 'x-server-vendor)
141 (condition-case nil
142 (insert "X server distributor `" (x-server-vendor) "', version "
143 (mapconcat 'number-to-string (x-server-version) ".") "\n")
144 (error t)))
145 (if (and system-configuration-options
146 (not (equal system-configuration-options "")))
147 (insert "configured using `configure "
148 system-configuration-options "'\n\n"))
149 (insert "Important settings:\n")
150 (mapcar
151 '(lambda (var)
152 (insert (format " value of $%s: %s\n" var (getenv var))))
153 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
154 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
155 (insert (format " locale-coding-system: %s\n" locale-coding-system))
156 (insert (format " default-enable-multibyte-characters: %s\n"
157 default-enable-multibyte-characters))
158 (insert "\n")
159 (insert (format "Major mode: %s\n"
160 (buffer-local-value 'mode-name from-buffer)))
161 (insert "\n")
162 (insert "Minor modes in effect:\n")
163 (dolist (mode minor-mode-list)
164 (and (boundp mode) (buffer-local-value mode from-buffer)
165 (insert (format " %s: %s\n" mode
166 (buffer-local-value mode from-buffer)))))
167 (insert "\n")
168 (insert "Recent input:\n")
169 (let ((before-keys (point)))
170 (insert (mapconcat (lambda (key)
171 (if (or (integerp key)
172 (symbolp key)
173 (listp key))
174 (single-key-description key)
175 (prin1-to-string key nil)))
176 (or recent-keys (recent-keys))
177 " "))
178 (save-restriction
179 (narrow-to-region before-keys (point))
180 (goto-char before-keys)
181 (while (progn (move-to-column 50) (not (eobp)))
182 (search-forward " " nil t)
183 (insert "\n"))))
184 (let ((message-buf (get-buffer "*Messages*")))
185 (if message-buf
186 (let (beg-pos
187 (end-pos message-end-point))
188 (with-current-buffer message-buf
189 (goto-char end-pos)
190 (forward-line -10)
191 (setq beg-pos (point)))
192 (insert "\n\nRecent messages:\n")
193 (insert-buffer-substring message-buf beg-pos end-pos))))
194 ;; This is so the user has to type something
195 ;; in order to send easily.
196 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
197 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
198 (unless report-emacs-bug-no-explanations
199 (with-output-to-temp-buffer "*Bug Help*"
200 (if (eq mail-user-agent 'sendmail-user-agent)
201 (princ (substitute-command-keys
202 "Type \\[mail-send-and-exit] to send the bug report.\n")))
203 (princ (substitute-command-keys
204 "Type \\[kill-buffer] RET to cancel (don't send it).\n"))
205 (terpri)
206 (princ (substitute-command-keys
207 "Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
208 about when and how to write a bug report,
209 and what information to supply so that the bug can be fixed.
210 Type SPC to scroll through this section and its subsections."))))
211 ;; Make it less likely people will send empty messages.
212 (make-local-variable 'mail-send-hook)
213 (add-hook 'mail-send-hook 'report-emacs-bug-hook)
214 (save-excursion
215 (goto-char (point-max))
216 (skip-chars-backward " \t\n")
217 (make-local-variable 'report-emacs-bug-orig-text)
218 (setq report-emacs-bug-orig-text (buffer-substring (point-min) (point))))
219 (goto-char user-point)))
220
221 (defun report-emacs-bug-info ()
222 "Go to the Info node on reporting Emacs bugs."
223 (interactive)
224 (info)
225 (Info-directory)
226 (Info-menu "emacs")
227 (Info-goto-node "Bugs"))
228
229 (defun report-emacs-bug-hook ()
230 (save-excursion
231 (save-excursion
232 (goto-char (point-max))
233 (skip-chars-backward " \t\n")
234 (if (and (= (- (point) (point-min))
235 (length report-emacs-bug-orig-text))
236 (equal (buffer-substring (point-min) (point))
237 report-emacs-bug-orig-text))
238 (error "No text entered in bug report")))
239
240 ;; Check the buffer contents and reject non-English letters.
241 (save-excursion
242 (goto-char (point-min))
243 (skip-chars-forward "\0-\177")
244 (if (not (eobp))
245 (if (or report-emacs-bug-no-confirmation
246 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
247 (while (progn (skip-chars-forward "\0-\177")
248 (not (eobp)))
249 (let ((ch (following-char)))
250 (delete-char 1)
251 (insert (format "=%02x" ch)))))))
252
253 ;; The last warning for novice users.
254 (if (or report-emacs-bug-no-confirmation
255 (yes-or-no-p
256 "Send this bug report to the Emacs maintainers? "))
257 ;; Just send the current mail.
258 nil
259 (goto-char (point-min))
260 (if (search-forward "To: ")
261 (let ((pos (point)))
262 (end-of-line)
263 (delete-region pos (point))))
264 (kill-local-variable 'mail-send-hook)
265 (with-output-to-temp-buffer "*Bug Help*"
266 (princ (substitute-command-keys "\
267 You invoked the command M-x report-emacs-bug,
268 but you decided not to mail the bug report to the Emacs maintainers.
269
270 If you want to mail it to someone else instead,
271 please insert the proper e-mail address after \"To: \",
272 and send the mail again using \\[mail-send-and-exit].")))
273 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
274
275 ;; Unclutter
276 (mail-text)
277 (let ((pos (1- (point))))
278 (while (setq pos (text-property-any pos (point-max)
279 'field 'emacsbug-prompt))
280 (delete-region pos (field-end (1+ pos)))))))
281
282 (provide 'emacsbug)
283
284 ;;; arch-tag: 248b6523-c3b5-4fec-9a3f-0411fafa7d49
285 ;;; emacsbug.el ends here