Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / mail / emacsbug.el
CommitLineData
55535639 1;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
c0274f38 2
597e2240 3;; Copyright (C) 1985, 1994, 1997, 1998, 2000, 2001, 2002, 2003, 2004,
5df4f04c 4;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
893db5bc 5;; Free Software Foundation, Inc.
9750e079 6
e5167999 7;; Author: K. Shane Hartman
2f14b48d 8;; Maintainer: FSF
fbd410d6 9;; Keywords: maint mail
2f14b48d 10
a2535589
JA
11;; This file is part of GNU Emacs.
12
b1fc2b50 13;; GNU Emacs is free software: you can redistribute it and/or modify
a2535589 14;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
a2535589
JA
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
b1fc2b50 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a2535589 25
e41b2db1
ER
26;;; Commentary:
27
b92a07e0 28;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
4d8da9a4
GM
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.
e41b2db1 32
2f14b48d 33;;; Code:
a2535589 34
fbd410d6
RS
35(defgroup emacsbug nil
36 "Sending Emacs bug reports."
37 :group 'maint
38 :group 'mail)
39
9b4e41ac 40(defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
4d8da9a4 41 "Address of mailing list for GNU Emacs bugs."
7b27eb53
RS
42 :group 'emacsbug
43 :type 'string)
a85a468e 44
893db5bc 45(defcustom report-emacs-bug-pretest-address "bug-gnu-emacs@gnu.org"
4d8da9a4 46 "Address of mailing list for GNU Emacs pretest bugs."
7b27eb53 47 :group 'emacsbug
893db5bc
GM
48 :type 'string
49 :version "23.2") ; emacs-pretest-bug -> bug-gnu-emacs
a2535589 50
fbd410d6 51(defcustom report-emacs-bug-no-confirmation nil
4d8da9a4 52 "If non-nil, suppress the confirmations asked for the sake of novice users."
fbd410d6
RS
53 :group 'emacsbug
54 :type 'boolean)
55
56(defcustom report-emacs-bug-no-explanations nil
4d8da9a4 57 "If non-nil, suppress the explanations given for the sake of novice users."
fbd410d6
RS
58 :group 'emacsbug
59 :type 'boolean)
fe1d8b33 60
4d8da9a4
GM
61;; User options end here.
62
63
64(defvar report-emacs-bug-orig-text nil
85094855
GM
65 "The automatically-created initial text of the bug report.")
66
67(defvar report-emacs-bug-send-command nil
68 "Name of the command to send the bug report, as a string.")
69(make-variable-buffer-local 'report-emacs-bug-send-command)
70
71(defvar report-emacs-bug-send-hook nil
72 "Hook run before sending the bug report.")
73(make-variable-buffer-local 'report-emacs-bug-send-hook)
4d8da9a4 74
aa360da1
GM
75(declare-function x-server-vendor "xfns.c" (&optional terminal))
76(declare-function x-server-version "xfns.c" (&optional terminal))
a0cefee5 77(declare-function message-sort-headers "message" ())
aa360da1 78
aa228418 79;;;###autoload
01753e63 80(defun report-emacs-bug (topic &optional recent-keys)
aa228418 81 "Report a bug in GNU Emacs.
a2535589 82Prompts for bug subject. Leaves you in a mail buffer."
01753e63
EN
83 ;; This strange form ensures that (recent-keys) is the value before
84 ;; the bug subject string is read.
85 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
a722966c
MC
86 ;; The syntax `version;' is preferred to `[version]' because the
87 ;; latter could be mistakenly stripped by mailing software.
ef77dde4
MC
88 (if (eq system-type 'ms-dos)
89 (setq topic (concat emacs-version "; " topic))
90 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
91 (setq topic (concat (match-string 1 emacs-version) "; " topic))))
92 ;; If there are four numbers in emacs-version (three for MS-DOS),
93 ;; this is a pretest version.
94 (let* ((pretest-p (string-match (if (eq system-type 'ms-dos)
95 "\\..*\\."
96 "\\..*\\..*\\.")
97 emacs-version))
a722966c
MC
98 (from-buffer (current-buffer))
99 (reporting-address (if pretest-p
100 report-emacs-bug-pretest-address
101 report-emacs-bug-address))
102 ;; Put these properties on semantically-void text.
85094855 103 ;; report-emacs-bug-hook deletes these regions before sending.
a722966c
MC
104 (prompt-properties '(field emacsbug-prompt
105 intangible but-helpful
106 rear-nonsticky t))
107 user-point message-end-point)
0a18209b 108 (setq message-end-point
5e11c425 109 (with-current-buffer (get-buffer-create "*Messages*")
0a18209b 110 (point-max-marker)))
85094855 111 (compose-mail reporting-address topic)
2f1b7dc4
GM
112 ;; The rest of this does not execute if the user was asked to
113 ;; confirm and said no.
114 ;; Message-mode sorts the headers before sending. We sort now so
115 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
116 (if (eq major-mode 'message-mode)
117 (message-sort-headers))
9e68869b
RS
118 (rfc822-goto-eoh)
119 (forward-line 1)
9e68869b 120 (let ((signature (buffer-substring (point) (point-max))))
9e68869b 121 (delete-region (point) (point-max))
518adca2
RS
122 (insert signature)
123 (backward-char (length signature)))
fbd410d6
RS
124 (unless report-emacs-bug-no-explanations
125 ;; Insert warnings for novice users.
85094855 126 (when (string-match "@gnu\\.org$" reporting-address)
53dab082
EZ
127 (insert "This bug report will be sent to the Free Software Foundation,\n")
128 (let ((pos (point)))
129 (insert "not to your local site managers!")
85094855 130 (overlay-put (make-overlay pos (point)) 'face 'highlight)))
a722966c 131 (insert "\nPlease write in ")
fbd410d6
RS
132 (let ((pos (point)))
133 (insert "English")
85094855 134 (overlay-put (make-overlay pos (point)) 'face 'highlight))
9210027b
RS
135 (insert " if possible, because the Emacs maintainers
136usually do not have translators to read other languages for them.\n\n")
7163badd 137 (insert (format "Your report will be posted to the %s mailing list"
53dab082 138 reporting-address))
85094855
GM
139 ;; Nowadays all bug reports end up there.
140;;; (if pretest-p (insert ".\n\n")
7163badd 141 (insert "\nand the gnu.emacs.bug news group, and at http://debbugs.gnu.org.\n\n"))
fe1d8b33 142
515ced27 143 (insert "Please describe exactly what actions triggered the bug\n"
31c615e4
GM
144 "and the precise symptoms of the bug. If you can, give\n"
145 "a recipe starting from `emacs -Q':\n\n")
85094855
GM
146 ;; Stop message-mode stealing the properties we are about to add.
147 (if (boundp 'message-strip-special-text-properties)
148 (set (make-local-variable 'message-strip-special-text-properties) nil))
149 (add-text-properties (save-excursion
150 (rfc822-goto-eoh)
151 (line-beginning-position 2))
152 (point)
9888f112 153 prompt-properties)
515ced27 154 (setq user-point (point))
3a7f4c18
KS
155 (insert "\n\n")
156
fca615d5 157 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
3a7f4c18
KS
158 "please include the output from the following gdb commands:\n"
159 " `bt full' and `xbacktrace'.\n")
160
161 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
162 (if (file-readable-p debug-file)
00006066
CY
163 (insert "For information about debugging Emacs, please read the file\n"
164 debug-file ".\n")))
9888f112 165 (add-text-properties (1+ user-point) (point) prompt-properties)
515ced27 166
3a7f4c18 167 (insert "\n\nIn " (emacs-version) "\n")
f4982064 168 (if (fboundp 'x-server-vendor)
6f8a2742 169 (condition-case nil
951c155f
SM
170 ;; This is used not only for X11 but also W32 and others.
171 (insert "Windowing system distributor `" (x-server-vendor)
172 "', version "
6f8a2742
JD
173 (mapconcat 'number-to-string (x-server-version) ".") "\n")
174 (error t)))
0a18209b
KH
175 (if (and system-configuration-options
176 (not (equal system-configuration-options "")))
177 (insert "configured using `configure "
515ced27 178 system-configuration-options "'\n\n"))
dc81f8a2 179 (insert "Important settings:\n")
1daad47d 180 (mapc
249dd409
EZ
181 '(lambda (var)
182 (insert (format " value of $%s: %s\n" var (getenv var))))
183 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
5dae4230 184 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
dc81f8a2 185 (insert (format " locale-coding-system: %s\n" locale-coding-system))
597e2240
GM
186 (insert (format " default enable-multibyte-characters: %s\n"
187 (default-value 'enable-multibyte-characters)))
0a18209b 188 (insert "\n")
3c3ba27b 189 (insert (format "Major mode: %s\n"
48d33090
SM
190 (format-mode-line
191 (buffer-local-value 'mode-name from-buffer)
192 nil nil from-buffer)))
e927088b
RS
193 (insert "\n")
194 (insert "Minor modes in effect:\n")
195 (dolist (mode minor-mode-list)
3c3ba27b
RS
196 (and (boundp mode) (buffer-local-value mode from-buffer)
197 (insert (format " %s: %s\n" mode
198 (buffer-local-value mode from-buffer)))))
e927088b 199 (insert "\n")
515ced27 200 (insert "Recent input:\n")
0a18209b
KH
201 (let ((before-keys (point)))
202 (insert (mapconcat (lambda (key)
203 (if (or (integerp key)
204 (symbolp key)
205 (listp key))
206 (single-key-description key)
207 (prin1-to-string key nil)))
208 (or recent-keys (recent-keys))
209 " "))
210 (save-restriction
211 (narrow-to-region before-keys (point))
212 (goto-char before-keys)
213 (while (progn (move-to-column 50) (not (eobp)))
214 (search-forward " " nil t)
215 (insert "\n"))))
216 (let ((message-buf (get-buffer "*Messages*")))
217 (if message-buf
218 (let (beg-pos
219 (end-pos message-end-point))
220 (with-current-buffer message-buf
221 (goto-char end-pos)
222 (forward-line -10)
223 (setq beg-pos (point)))
224 (insert "\n\nRecent messages:\n")
225 (insert-buffer-substring message-buf beg-pos end-pos))))
0b952197
GM
226 ;; After Recent messages, to avoid the messages produced by
227 ;; list-load-path-shadows.
228 (unless (looking-back "\n")
229 (insert "\n"))
230 (insert "\n")
231 (insert "Load-path shadows:\n")
232 (message "Checking for load-path shadows...")
233 (let ((shadows (list-load-path-shadows t)))
234 (message "Checking for load-path shadows...done")
235 (insert (if (zerop (length shadows))
236 "None found.\n"
237 shadows)))
9656d87b
GM
238 (insert (format "\nFeatures:\n%s\n" features))
239 (fill-region (line-beginning-position 0) (point))
240 ;; This is so the user has to type something in order to send easily.
0a18209b
KH
241 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
242 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
85094855
GM
243 ;; Could test major-mode instead.
244 (cond ((memq mail-user-agent '(message-user-agent gnus-user-agent))
245 (setq report-emacs-bug-send-command "message-send-and-exit"
246 report-emacs-bug-send-hook 'message-send-hook))
247 ((eq mail-user-agent 'sendmail-user-agent)
248 (setq report-emacs-bug-send-command "mail-send-and-exit"
249 report-emacs-bug-send-hook 'mail-send-hook))
250 ((eq mail-user-agent 'mh-e-user-agent)
251 (setq report-emacs-bug-send-command "mh-send-letter"
252 report-emacs-bug-send-hook 'mh-before-send-letter-hook)))
e9227982
RS
253 (unless report-emacs-bug-no-explanations
254 (with-output-to-temp-buffer "*Bug Help*"
3e425845 255 (princ "While in the mail buffer:\n\n")
85094855 256 (if report-emacs-bug-send-command
d8194864 257 (princ (substitute-command-keys
85094855
GM
258 (format " Type \\[%s] to send the bug report.\n"
259 report-emacs-bug-send-command))))
e9227982 260 (princ (substitute-command-keys
3e425845 261 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
e9227982
RS
262 (terpri)
263 (princ (substitute-command-keys
3e425845
CY
264 " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
265 about when and how to write a bug report, and what
266 information you should include to help fix the bug.")))
267 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
0a18209b 268 ;; Make it less likely people will send empty messages.
85094855
GM
269 (if report-emacs-bug-send-hook
270 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
2f1b7dc4
GM
271 (goto-char (point-max))
272 (skip-chars-backward " \t\n")
273 (make-local-variable 'report-emacs-bug-orig-text)
274 (setq report-emacs-bug-orig-text
275 (buffer-substring-no-properties (point-min) (point)))
0a18209b 276 (goto-char user-point)))
e24ec555 277
1628adc6
KH
278(defun report-emacs-bug-info ()
279 "Go to the Info node on reporting Emacs bugs."
280 (interactive)
4d8da9a4 281 (info "(emacs)Bugs"))
1628adc6 282
e24ec555 283(defun report-emacs-bug-hook ()
85094855 284 "Do some checking before sending a bug report."
e24ec555 285 (save-excursion
85094855
GM
286 (goto-char (point-max))
287 (skip-chars-backward " \t\n")
85094855
GM
288 (and (= (- (point) (point-min))
289 (length report-emacs-bug-orig-text))
290 (string-equal (buffer-substring-no-properties (point-min) (point))
291 report-emacs-bug-orig-text)
292 (error "No text entered in bug report"))
fe1d8b33 293 ;; Check the buffer contents and reject non-English letters.
85094855
GM
294 ;; FIXME message-mode probably does this anyway.
295 (goto-char (point-min))
296 (skip-chars-forward "\0-\177")
297 (unless (eobp)
298 (if (or report-emacs-bug-no-confirmation
299 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
300 (while (progn (skip-chars-forward "\0-\177")
301 (not (eobp)))
302 (let ((ch (following-char)))
303 (delete-char 1)
304 (insert (format "=%02x" ch))))))
fe1d8b33
KH
305
306 ;; The last warning for novice users.
85094855
GM
307 (unless (or report-emacs-bug-no-confirmation
308 (yes-or-no-p
309 "Send this bug report to the Emacs maintainers? "))
fe1d8b33
KH
310 (goto-char (point-min))
311 (if (search-forward "To: ")
85094855
GM
312 (delete-region (point) (line-end-position)))
313 (if report-emacs-bug-send-hook
314 (kill-local-variable report-emacs-bug-send-hook))
fe1d8b33 315 (with-output-to-temp-buffer "*Bug Help*"
85094855
GM
316 (princ (substitute-command-keys
317 (format "\
02f6b354
RS
318You invoked the command M-x report-emacs-bug,
319but you decided not to mail the bug report to the Emacs maintainers.
fe1d8b33 320
02f6b354
RS
321If you want to mail it to someone else instead,
322please insert the proper e-mail address after \"To: \",
85094855
GM
323and send the mail again%s."
324 (if report-emacs-bug-send-command
325 (format " using \\[%s]"
326 report-emacs-bug-send-command)
327 "")))))
02f6b354 328 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
ea33ba73 329
85094855
GM
330 ;; Delete the uninteresting text that was just to help fill out the report.
331 (rfc822-goto-eoh)
332 (forward-line 1)
9888f112
TTN
333 (let ((pos (1- (point))))
334 (while (setq pos (text-property-any pos (point-max)
335 'field 'emacsbug-prompt))
336 (delete-region pos (field-end (1+ pos)))))))
a2535589 337
8e0ff8c8
ER
338(provide 'emacsbug)
339
c0274f38 340;;; emacsbug.el ends here