* calendar/todo-mode.el: Fix two bugs.
[bpt/emacs.git] / lisp / mail / emacsbug.el
CommitLineData
55535639 1;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
c0274f38 2
ba318903
PE
3;; Copyright (C) 1985, 1994, 1997-1998, 2000-2014 Free Software
4;; Foundation, Inc.
9750e079 5
e5167999 6;; Author: K. Shane Hartman
34dc21db 7;; Maintainer: emacs-devel@gnu.org
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")
9475054f
ER
233 (if (stringp emacs-repository-version)
234 (insert "Repository revision: " emacs-repository-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))
a41475e1
DC
325
326 (insert (format "\nMemory information:\n"))
327 (pp (garbage-collect) (current-buffer))
328
9656d87b 329 ;; This is so the user has to type something in order to send easily.
0a18209b 330 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
3290526d 331 (define-key (current-local-map) "\C-c\C-i" 'info-emacs-bug)
253f7d1b 332 (if can-insert-mail
e78e7e48 333 (define-key (current-local-map) "\C-c\M-i"
489cd5bd 334 'report-emacs-bug-insert-to-mailer))
e554b3f8
GM
335 (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc)
336 report-emacs-bug-send-hook (get mail-user-agent 'hookvar))
337 (if report-emacs-bug-send-command
338 (setq report-emacs-bug-send-command
339 (symbol-name report-emacs-bug-send-command)))
e9227982
RS
340 (unless report-emacs-bug-no-explanations
341 (with-output-to-temp-buffer "*Bug Help*"
3e425845 342 (princ "While in the mail buffer:\n\n")
85094855 343 (if report-emacs-bug-send-command
d8194864 344 (princ (substitute-command-keys
85094855
GM
345 (format " Type \\[%s] to send the bug report.\n"
346 report-emacs-bug-send-command))))
e9227982 347 (princ (substitute-command-keys
3e425845 348 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
253f7d1b 349 (if can-insert-mail
489cd5bd 350 (princ (substitute-command-keys
3f88cd72 351 " Type \\[report-emacs-bug-insert-to-mailer] to copy text to your preferred mail program.\n")))
e9227982
RS
352 (terpri)
353 (princ (substitute-command-keys
cb1f695c 354 " Type \\[info-emacs-bug] to visit in Info the Emacs Manual section
3e425845
CY
355 about when and how to write a bug report, and what
356 information you should include to help fix the bug.")))
357 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
0a18209b 358 ;; Make it less likely people will send empty messages.
85094855
GM
359 (if report-emacs-bug-send-hook
360 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
2f1b7dc4
GM
361 (goto-char (point-max))
362 (skip-chars-backward " \t\n")
363 (make-local-variable 'report-emacs-bug-orig-text)
364 (setq report-emacs-bug-orig-text
365 (buffer-substring-no-properties (point-min) (point)))
0a18209b 366 (goto-char user-point)))
e24ec555 367
2a1e2476 368(define-obsolete-function-alias 'report-emacs-bug-info 'info-emacs-bug "24.3")
1628adc6 369
7d15102b
GM
370;; It's the default mail mode, so it seems OK to use its features.
371(autoload 'message-bogus-recipient-p "message")
d1a5d56a 372(defvar message-send-mail-function)
7d15102b 373
e24ec555 374(defun report-emacs-bug-hook ()
85094855 375 "Do some checking before sending a bug report."
e24ec555 376 (save-excursion
85094855
GM
377 (goto-char (point-max))
378 (skip-chars-backward " \t\n")
85094855
GM
379 (and (= (- (point) (point-min))
380 (length report-emacs-bug-orig-text))
381 (string-equal (buffer-substring-no-properties (point-min) (point))
382 report-emacs-bug-orig-text)
383 (error "No text entered in bug report"))
cc26d239 384 ;; Warning for novice users.
85094855 385 (unless (or report-emacs-bug-no-confirmation
7d15102b
GM
386 (yes-or-no-p
387 "Send this bug report to the Emacs maintainers? "))
fe1d8b33
KH
388 (goto-char (point-min))
389 (if (search-forward "To: ")
85094855
GM
390 (delete-region (point) (line-end-position)))
391 (if report-emacs-bug-send-hook
392 (kill-local-variable report-emacs-bug-send-hook))
fe1d8b33 393 (with-output-to-temp-buffer "*Bug Help*"
85094855
GM
394 (princ (substitute-command-keys
395 (format "\
02f6b354
RS
396You invoked the command M-x report-emacs-bug,
397but you decided not to mail the bug report to the Emacs maintainers.
fe1d8b33 398
02f6b354
RS
399If you want to mail it to someone else instead,
400please insert the proper e-mail address after \"To: \",
85094855
GM
401and send the mail again%s."
402 (if report-emacs-bug-send-command
403 (format " using \\[%s]"
404 report-emacs-bug-send-command)
405 "")))))
d5081c1e 406 (error "M-x report-emacs-bug was canceled, please read *Bug Help* buffer"))
cc26d239
LI
407 ;; Query the user for the SMTP method, so that we can skip
408 ;; questions about From header validity if the user is going to
409 ;; use mailclient, anyway.
fbae4637 410 (when (or (and (derived-mode-p 'message-mode)
e627be4c 411 (eq message-send-mail-function 'sendmail-query-once))
fbae4637
LMI
412 (and (not (derived-mode-p 'message-mode))
413 (eq send-mail-function 'sendmail-query-once)))
cc26d239
LI
414 (sendmail-query-user-about-smtp)
415 (when (derived-mode-p 'message-mode)
416 (setq message-send-mail-function (message-default-send-mail-function))))
417 (or report-emacs-bug-no-confirmation
418 ;; mailclient.el does not need a valid From
419 (if (derived-mode-p 'message-mode)
420 (eq message-send-mail-function 'message-send-mail-with-mailclient)
421 (eq send-mail-function 'mailclient-send-it))
422 ;; Not narrowing to the headers, but that's OK.
423 (let ((from (mail-fetch-field "From")))
424 (and (or (not from)
425 (message-bogus-recipient-p from)
426 ;; This is the default user-mail-address. On today's
427 ;; systems, it seems more likely to be wrong than right,
428 ;; since most people don't run their own mail server.
429 (string-match (format "\\<%s@%s\\>"
430 (regexp-quote (user-login-name))
431 (regexp-quote (system-name)))
432 from))
433 (not (yes-or-no-p
434 (format "Is `%s' really your email address? " from)))
030f4af5 435 (error "Please edit the From address and try again"))))))
a2535589 436
614316a7 437
8e0ff8c8
ER
438(provide 'emacsbug)
439
c0274f38 440;;; emacsbug.el ends here