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