* lisp/mail/emacsbug.el (report-emacs-bug):
[bpt/emacs.git] / lisp / mail / emacsbug.el
CommitLineData
55535639 1;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
c0274f38 2
90582f05
GM
3;; Copyright (C) 1985, 1994, 1997-1998, 2000-2013
4;; Free Software Foundation, Inc.
9750e079 5
e5167999 6;; Author: K. Shane Hartman
2f14b48d 7;; Maintainer: FSF
fbd410d6 8;; Keywords: maint mail
bd78fa1d 9;; Package: emacs
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
cc26d239
LI
35(require 'sendmail)
36(require 'message)
37
fbd410d6
RS
38(defgroup emacsbug nil
39 "Sending Emacs bug reports."
40 :group 'maint
41 :group 'mail)
42
27be0364
GM
43(define-obsolete-variable-alias 'report-emacs-bug-pretest-address
44 'report-emacs-bug-address "24.1")
45
9b4e41ac 46(defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
4d8da9a4 47 "Address of mailing list for GNU Emacs bugs."
7b27eb53
RS
48 :group 'emacsbug
49 :type 'string)
a85a468e 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
4d8da9a4 63(defvar report-emacs-bug-orig-text nil
85094855
GM
64 "The automatically-created initial text of the bug report.")
65
66(defvar report-emacs-bug-send-command nil
67 "Name of the command to send the bug report, as a string.")
68(make-variable-buffer-local 'report-emacs-bug-send-command)
69
70(defvar report-emacs-bug-send-hook nil
71 "Hook run before sending the bug report.")
72(make-variable-buffer-local 'report-emacs-bug-send-hook)
4d8da9a4 73
aa360da1
GM
74(declare-function x-server-vendor "xfns.c" (&optional terminal))
75(declare-function x-server-version "xfns.c" (&optional terminal))
a0cefee5 76(declare-function message-sort-headers "message" ())
27be0364 77(defvar message-strip-special-text-properties)
aa360da1 78
253f7d1b 79(defun report-emacs-bug-can-use-osx-open ()
3f88cd72 80 "Return non-nil if the OS X \"open\" command is available for mailing."
253f7d1b
JD
81 (and (featurep 'ns)
82 (equal (executable-find "open") "/usr/bin/open")
83 (memq system-type '(darwin))))
84
3f88cd72 85;; FIXME this duplicates much of the logic from browse-url-can-use-xdg-open.
489cd5bd 86(defun report-emacs-bug-can-use-xdg-email ()
3f88cd72
GM
87 "Return non-nil if the \"xdg-email\" command can be used.
88xdg-email is a desktop utility that calls your preferred mail client.
89This requires you to be running either Gnome, KDE, or Xfce4."
489cd5bd
JD
90 (and (getenv "DISPLAY")
91 (executable-find "xdg-email")
92 (or (getenv "GNOME_DESKTOP_SESSION_ID")
93 ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
94 (condition-case nil
95 (eq 0 (call-process
96 "dbus-send" nil nil nil
97 "--dest=org.gnome.SessionManager"
98 "--print-reply"
99 "/org/gnome/SessionManager"
100 "org.gnome.SessionManager.CanShutdown"))
101 (error nil))
102 (equal (getenv "KDE_FULL_SESSION") "true")
3f88cd72
GM
103 ;; FIXME? browse-url-can-use-xdg-open also accepts LXDE.
104 ;; Is that no good here, or just overlooked?
489cd5bd
JD
105 (condition-case nil
106 (eq 0 (call-process
107 "/bin/sh" nil nil nil
108 "-c"
3f88cd72 109 ;; FIXME use string-match rather than grep.
489cd5bd
JD
110 "xprop -root _DT_SAVE_MODE|grep xfce4"))
111 (error nil)))))
112
113(defun report-emacs-bug-insert-to-mailer ()
3f88cd72
GM
114 "Send the message to your preferred mail client.
115This requires either the OS X \"open\" command, or the freedesktop
116\"xdg-email\" command to be available."
489cd5bd
JD
117 (interactive)
118 (save-excursion
3f88cd72 119 ;; FIXME? use mail-fetch-field?
489cd5bd
JD
120 (let* ((to (progn
121 (goto-char (point-min))
122 (forward-line)
123 (and (looking-at "^To: \\(.*\\)")
124 (match-string-no-properties 1))))
125 (subject (progn
126 (forward-line)
127 (and (looking-at "^Subject: \\(.*\\)")
128 (match-string-no-properties 1))))
129 (body (progn
130 (forward-line 2)
131 (if (> (point-max) (point))
132 (buffer-substring-no-properties (point) (point-max))))))
133 (if (and to subject body)
253f7d1b
JD
134 (if (report-emacs-bug-can-use-osx-open)
135 (start-process "/usr/bin/open" nil "open"
7d15102b 136 (concat "mailto:" to
253f7d1b
JD
137 "?subject=" (url-hexify-string subject)
138 "&body=" (url-hexify-string body)))
139 (start-process "xdg-email" nil "xdg-email"
140 "--subject" subject
141 "--body" body
142 (concat "mailto:" to)))
489cd5bd
JD
143 (error "Subject, To or body not found")))))
144
aa228418 145;;;###autoload
01753e63 146(defun report-emacs-bug (topic &optional recent-keys)
aa228418 147 "Report a bug in GNU Emacs.
a2535589 148Prompts for bug subject. Leaves you in a mail buffer."
01753e63
EN
149 ;; This strange form ensures that (recent-keys) is the value before
150 ;; the bug subject string is read.
151 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
a722966c
MC
152 ;; The syntax `version;' is preferred to `[version]' because the
153 ;; latter could be mistakenly stripped by mailing software.
ef77dde4
MC
154 (if (eq system-type 'ms-dos)
155 (setq topic (concat emacs-version "; " topic))
156 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
157 (setq topic (concat (match-string 1 emacs-version) "; " topic))))
27be0364 158 (let ((from-buffer (current-buffer))
253f7d1b
JD
159 (can-insert-mail (or (report-emacs-bug-can-use-xdg-email)
160 (report-emacs-bug-can-use-osx-open)))
27be0364 161 user-point message-end-point)
0a18209b 162 (setq message-end-point
90582f05 163 (with-current-buffer (messages-buffer)
0a18209b 164 (point-max-marker)))
27be0364 165 (compose-mail report-emacs-bug-address topic)
2f1b7dc4
GM
166 ;; The rest of this does not execute if the user was asked to
167 ;; confirm and said no.
27be0364
GM
168 (when (eq major-mode 'message-mode)
169 ;; Message-mode sorts the headers before sending. We sort now so
170 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
171 (message-sort-headers)
172 ;; Stop message-mode stealing the properties we will add.
173 (set (make-local-variable 'message-strip-special-text-properties) nil))
9e68869b
RS
174 (rfc822-goto-eoh)
175 (forward-line 1)
4443f204
RS
176 ;; Move the mail signature to the proper place.
177 (let ((signature (buffer-substring (point) (point-max)))
178 (inhibit-read-only t))
9e68869b 179 (delete-region (point) (point-max))
518adca2
RS
180 (insert signature)
181 (backward-char (length signature)))
fbd410d6
RS
182 (unless report-emacs-bug-no-explanations
183 ;; Insert warnings for novice users.
1176868d
CY
184 (if (not (equal "bug-gnu-emacs@gnu.org" report-emacs-bug-address))
185 (insert (format "The report will be sent to %s.\n\n"
186 report-emacs-bug-address))
187 (insert "This bug report will be sent to the ")
030f4af5 188 (insert-text-button
1176868d
CY
189 "Bug-GNU-Emacs"
190 'face 'link
191 'help-echo (concat "mouse-2, RET: Follow this link")
192 'action (lambda (button)
193 (browse-url "http://lists.gnu.org/archive/html/bug-gnu-emacs/"))
194 'follow-link t)
195 (insert " mailing list\nand the GNU bug tracker at ")
030f4af5 196 (insert-text-button
1176868d
CY
197 "debbugs.gnu.org"
198 'face 'link
199 'help-echo (concat "mouse-2, RET: Follow this link")
200 'action (lambda (button)
201 (browse-url "http://debbugs.gnu.org/"))
202 'follow-link t)
203
204 (insert ". Please check that
205the From: line contains a valid email address. After a delay of up
09ae5da1 206to one day, you should receive an acknowledgment at that address.
1176868d
CY
207
208Please write in English if possible, as the Emacs maintainers
209usually do not have translators for other languages.\n\n")))
210
211 (insert "Please describe exactly what actions triggered the bug, and\n"
212 "the precise symptoms of the bug. If you can, give a recipe\n"
213 "starting from `emacs -Q':\n\n")
030f4af5
SM
214 (let ((txt (delete-and-extract-region
215 (save-excursion (rfc822-goto-eoh) (line-beginning-position 2))
216 (point))))
217 (insert (propertize "\n" 'display txt)))
515ced27 218 (setq user-point (point))
3a7f4c18
KS
219 (insert "\n\n")
220
fca615d5 221 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
3a7f4c18
KS
222 "please include the output from the following gdb commands:\n"
223 " `bt full' and `xbacktrace'.\n")
224
225 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
226 (if (file-readable-p debug-file)
00006066
CY
227 (insert "For information about debugging Emacs, please read the file\n"
228 debug-file ".\n")))
030f4af5
SM
229 (let ((txt (delete-and-extract-region (1+ user-point) (point))))
230 (insert (propertize "\n" 'display txt)))
515ced27 231
3a7f4c18 232 (insert "\n\nIn " (emacs-version) "\n")
a1ed8b05
GM
233 (if (stringp emacs-bzr-version)
234 (insert "Bzr revision: " emacs-bzr-version "\n"))
f4982064 235 (if (fboundp 'x-server-vendor)
6f8a2742 236 (condition-case nil
951c155f
SM
237 ;; This is used not only for X11 but also W32 and others.
238 (insert "Windowing system distributor `" (x-server-vendor)
239 "', version "
6f8a2742
JD
240 (mapconcat 'number-to-string (x-server-version) ".") "\n")
241 (error t)))
bcc0adbf
GM
242 (let ((lsb (with-temp-buffer
243 (if (eq 0 (ignore-errors
244 (call-process "lsb_release" nil '(t nil)
245 nil "-d")))
246 (buffer-string)))))
247 (if (stringp lsb)
1feca5a2 248 (insert "System " lsb "\n")))
4d4ec1f8
EZ
249 (when (and system-configuration-options
250 (not (equal system-configuration-options "")))
251 (insert "Configured using:\n `configure "
252 system-configuration-options "'\n\n")
253 (fill-region (line-beginning-position -1) (point)))
dc81f8a2 254 (insert "Important settings:\n")
1daad47d 255 (mapc
4f91a816 256 (lambda (var)
2b48d721
GM
257 (let ((val (getenv var)))
258 (if val (insert (format " value of $%s: %s\n" var val)))))
259 '("EMACSDATA" "EMACSDOC" "EMACSLOADPATH" "EMACSPATH"
260 "LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
5dae4230 261 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
dc81f8a2 262 (insert (format " locale-coding-system: %s\n" locale-coding-system))
ccc9f6dc
GM
263 ;; Only ~ 0.2% of people from a sample of 3200 changed this from
264 ;; the default, t.
265 (or (default-value 'enable-multibyte-characters)
266 (insert (format " default enable-multibyte-characters: %s\n"
267 (default-value 'enable-multibyte-characters))))
0a18209b 268 (insert "\n")
3c3ba27b 269 (insert (format "Major mode: %s\n"
48d33090
SM
270 (format-mode-line
271 (buffer-local-value 'mode-name from-buffer)
272 nil nil from-buffer)))
e927088b
RS
273 (insert "\n")
274 (insert "Minor modes in effect:\n")
275 (dolist (mode minor-mode-list)
3c3ba27b
RS
276 (and (boundp mode) (buffer-local-value mode from-buffer)
277 (insert (format " %s: %s\n" mode
278 (buffer-local-value mode from-buffer)))))
e927088b 279 (insert "\n")
515ced27 280 (insert "Recent input:\n")
0a18209b
KH
281 (let ((before-keys (point)))
282 (insert (mapconcat (lambda (key)
283 (if (or (integerp key)
284 (symbolp key)
285 (listp key))
286 (single-key-description key)
287 (prin1-to-string key nil)))
288 (or recent-keys (recent-keys))
289 " "))
290 (save-restriction
291 (narrow-to-region before-keys (point))
292 (goto-char before-keys)
293 (while (progn (move-to-column 50) (not (eobp)))
294 (search-forward " " nil t)
295 (insert "\n"))))
296 (let ((message-buf (get-buffer "*Messages*")))
297 (if message-buf
298 (let (beg-pos
299 (end-pos message-end-point))
300 (with-current-buffer message-buf
301 (goto-char end-pos)
302 (forward-line -10)
303 (setq beg-pos (point)))
304 (insert "\n\nRecent messages:\n")
305 (insert-buffer-substring message-buf beg-pos end-pos))))
0b952197
GM
306 ;; After Recent messages, to avoid the messages produced by
307 ;; list-load-path-shadows.
308 (unless (looking-back "\n")
309 (insert "\n"))
310 (insert "\n")
311 (insert "Load-path shadows:\n")
fa05bfe0
GM
312 (let* ((msg "Checking for load-path shadows...")
313 (result "done")
314 (shadows (progn (message "%s" msg)
315 (condition-case nil (list-load-path-shadows t)
316 (error
317 (setq result "error")
318 "Error during checking")))))
319 (message "%s%s" msg result)
0b952197
GM
320 (insert (if (zerop (length shadows))
321 "None found.\n"
322 shadows)))
9656d87b
GM
323 (insert (format "\nFeatures:\n%s\n" features))
324 (fill-region (line-beginning-position 0) (point))
325 ;; This is so the user has to type something in order to send easily.
0a18209b 326 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
3290526d 327 (define-key (current-local-map) "\C-c\C-i" 'info-emacs-bug)
253f7d1b 328 (if can-insert-mail
e78e7e48 329 (define-key (current-local-map) "\C-c\M-i"
489cd5bd 330 'report-emacs-bug-insert-to-mailer))
e554b3f8
GM
331 (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc)
332 report-emacs-bug-send-hook (get mail-user-agent 'hookvar))
333 (if report-emacs-bug-send-command
334 (setq report-emacs-bug-send-command
335 (symbol-name report-emacs-bug-send-command)))
e9227982
RS
336 (unless report-emacs-bug-no-explanations
337 (with-output-to-temp-buffer "*Bug Help*"
3e425845 338 (princ "While in the mail buffer:\n\n")
85094855 339 (if report-emacs-bug-send-command
d8194864 340 (princ (substitute-command-keys
85094855
GM
341 (format " Type \\[%s] to send the bug report.\n"
342 report-emacs-bug-send-command))))
e9227982 343 (princ (substitute-command-keys
3e425845 344 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
253f7d1b 345 (if can-insert-mail
489cd5bd 346 (princ (substitute-command-keys
3f88cd72 347 " Type \\[report-emacs-bug-insert-to-mailer] to copy text to your preferred mail program.\n")))
e9227982
RS
348 (terpri)
349 (princ (substitute-command-keys
cb1f695c 350 " Type \\[info-emacs-bug] to visit in Info the Emacs Manual section
3e425845
CY
351 about when and how to write a bug report, and what
352 information you should include to help fix the bug.")))
353 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
0a18209b 354 ;; Make it less likely people will send empty messages.
85094855
GM
355 (if report-emacs-bug-send-hook
356 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
2f1b7dc4
GM
357 (goto-char (point-max))
358 (skip-chars-backward " \t\n")
359 (make-local-variable 'report-emacs-bug-orig-text)
360 (setq report-emacs-bug-orig-text
361 (buffer-substring-no-properties (point-min) (point)))
0a18209b 362 (goto-char user-point)))
e24ec555 363
2a1e2476 364(define-obsolete-function-alias 'report-emacs-bug-info 'info-emacs-bug "24.3")
1628adc6 365
7d15102b
GM
366;; It's the default mail mode, so it seems OK to use its features.
367(autoload 'message-bogus-recipient-p "message")
d1a5d56a 368(defvar message-send-mail-function)
7d15102b 369
e24ec555 370(defun report-emacs-bug-hook ()
85094855 371 "Do some checking before sending a bug report."
e24ec555 372 (save-excursion
85094855
GM
373 (goto-char (point-max))
374 (skip-chars-backward " \t\n")
85094855
GM
375 (and (= (- (point) (point-min))
376 (length report-emacs-bug-orig-text))
377 (string-equal (buffer-substring-no-properties (point-min) (point))
378 report-emacs-bug-orig-text)
379 (error "No text entered in bug report"))
cc26d239 380 ;; Warning for novice users.
85094855 381 (unless (or report-emacs-bug-no-confirmation
7d15102b
GM
382 (yes-or-no-p
383 "Send this bug report to the Emacs maintainers? "))
fe1d8b33
KH
384 (goto-char (point-min))
385 (if (search-forward "To: ")
85094855
GM
386 (delete-region (point) (line-end-position)))
387 (if report-emacs-bug-send-hook
388 (kill-local-variable report-emacs-bug-send-hook))
fe1d8b33 389 (with-output-to-temp-buffer "*Bug Help*"
85094855
GM
390 (princ (substitute-command-keys
391 (format "\
02f6b354
RS
392You invoked the command M-x report-emacs-bug,
393but you decided not to mail the bug report to the Emacs maintainers.
fe1d8b33 394
02f6b354
RS
395If you want to mail it to someone else instead,
396please insert the proper e-mail address after \"To: \",
85094855
GM
397and send the mail again%s."
398 (if report-emacs-bug-send-command
399 (format " using \\[%s]"
400 report-emacs-bug-send-command)
401 "")))))
02f6b354 402 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
cc26d239
LI
403 ;; Query the user for the SMTP method, so that we can skip
404 ;; questions about From header validity if the user is going to
405 ;; use mailclient, anyway.
fbae4637 406 (when (or (and (derived-mode-p 'message-mode)
e627be4c 407 (eq message-send-mail-function 'sendmail-query-once))
fbae4637
LMI
408 (and (not (derived-mode-p 'message-mode))
409 (eq send-mail-function 'sendmail-query-once)))
cc26d239
LI
410 (sendmail-query-user-about-smtp)
411 (when (derived-mode-p 'message-mode)
412 (setq message-send-mail-function (message-default-send-mail-function))))
413 (or report-emacs-bug-no-confirmation
414 ;; mailclient.el does not need a valid From
415 (if (derived-mode-p 'message-mode)
416 (eq message-send-mail-function 'message-send-mail-with-mailclient)
417 (eq send-mail-function 'mailclient-send-it))
418 ;; Not narrowing to the headers, but that's OK.
419 (let ((from (mail-fetch-field "From")))
420 (and (or (not from)
421 (message-bogus-recipient-p from)
422 ;; This is the default user-mail-address. On today's
423 ;; systems, it seems more likely to be wrong than right,
424 ;; since most people don't run their own mail server.
425 (string-match (format "\\<%s@%s\\>"
426 (regexp-quote (user-login-name))
427 (regexp-quote (system-name)))
428 from))
429 (not (yes-or-no-p
430 (format "Is `%s' really your email address? " from)))
030f4af5 431 (error "Please edit the From address and try again"))))))
a2535589 432
614316a7 433
8e0ff8c8
ER
434(provide 'emacsbug)
435
c0274f38 436;;; emacsbug.el ends here