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