]> code.delx.au - gnu-emacs/blob - lisp/mail/emacsbug.el
Update docs for `customize-mode'
[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-2016 Free Software
4 ;; 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 ;; It's the default mail mode, so it seems OK to use its features.
141 (autoload 'message-bogus-recipient-p "message")
142 (autoload 'message-make-address "message")
143 (defvar message-send-mail-function)
144 (defvar message-sendmail-envelope-from)
145
146 ;;;###autoload
147 (defun report-emacs-bug (topic &optional unused)
148 "Report a bug in GNU Emacs.
149 Prompts for bug subject. Leaves you in a mail buffer."
150 (declare (advertised-calling-convention (topic) "24.5"))
151 (interactive "sBug Subject: ")
152 ;; The syntax `version;' is preferred to `[version]' because the
153 ;; latter could be mistakenly stripped by mailing software.
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))))
158 (let ((from-buffer (current-buffer))
159 (can-insert-mail (or (report-emacs-bug-can-use-xdg-email)
160 (report-emacs-bug-can-use-osx-open)))
161 user-point message-end-point)
162 (setq message-end-point
163 (with-current-buffer (messages-buffer)
164 (point-max-marker)))
165 (condition-case nil
166 ;; For the novice user make sure there's always enough space for
167 ;; the mail and the warnings buffer on this frame (Bug#10873).
168 (unless report-emacs-bug-no-explanations
169 (delete-other-windows)
170 (set-window-dedicated-p nil nil)
171 (set-frame-parameter nil 'unsplittable nil))
172 (error nil))
173 (compose-mail report-emacs-bug-address topic)
174 ;; The rest of this does not execute if the user was asked to
175 ;; confirm and said no.
176 (when (eq major-mode 'message-mode)
177 ;; Message-mode sorts the headers before sending. We sort now so
178 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
179 (message-sort-headers)
180 ;; Stop message-mode stealing the properties we will add.
181 (set (make-local-variable 'message-strip-special-text-properties) nil)
182 ;; Make sure we default to the From: address as envelope when sending
183 ;; through sendmail.
184 (when (and (not message-sendmail-envelope-from)
185 (message-bogus-recipient-p (message-make-address)))
186 (set (make-local-variable 'message-sendmail-envelope-from) 'header)))
187 (rfc822-goto-eoh)
188 (forward-line 1)
189 ;; Move the mail signature to the proper place.
190 (let ((signature (buffer-substring (point) (point-max)))
191 (inhibit-read-only t))
192 (delete-region (point) (point-max))
193 (insert signature)
194 (backward-char (length signature)))
195 (unless report-emacs-bug-no-explanations
196 ;; Insert warnings for novice users.
197 (if (not (equal "bug-gnu-emacs@gnu.org" report-emacs-bug-address))
198 (insert (format "The report will be sent to %s.\n\n"
199 report-emacs-bug-address))
200 (insert "This bug report will be sent to the ")
201 (insert-text-button
202 "Bug-GNU-Emacs"
203 'face 'link
204 'help-echo (concat "mouse-2, RET: Follow this link")
205 'action (lambda (button)
206 (browse-url "http://lists.gnu.org/archive/html/bug-gnu-emacs/"))
207 'follow-link t)
208 (insert " mailing list\nand the GNU bug tracker at ")
209 (insert-text-button
210 "debbugs.gnu.org"
211 'face 'link
212 'help-echo (concat "mouse-2, RET: Follow this link")
213 'action (lambda (button)
214 (browse-url "http://debbugs.gnu.org/"))
215 'follow-link t)
216
217 (insert ". Please check that
218 the From: line contains a valid email address. After a delay of up
219 to one day, you should receive an acknowledgment at that address.
220
221 Please write in English if possible, as the Emacs maintainers
222 usually do not have translators for other languages.\n\n")))
223
224 (insert "Please describe exactly what actions triggered the bug, and\n"
225 "the precise symptoms of the bug. If you can, give a recipe\n"
226 "starting from 'emacs -Q':\n\n")
227 (let ((txt (delete-and-extract-region
228 (save-excursion (rfc822-goto-eoh) (line-beginning-position 2))
229 (point))))
230 (insert (propertize "\n" 'display txt)))
231 (setq user-point (point))
232 (insert "\n\n")
233
234 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
235 "please include the output from the following gdb commands:\n"
236 " 'bt full' and 'xbacktrace'.\n")
237
238 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
239 (if (file-readable-p debug-file)
240 (insert "For information about debugging Emacs, please read the file\n"
241 debug-file ".\n")))
242 (let ((txt (delete-and-extract-region (1+ user-point) (point))))
243 (insert (propertize "\n" 'display txt)))
244
245 (insert "\n\nIn " (emacs-version))
246 (if emacs-build-system
247 (insert " built on " emacs-build-system))
248 (insert "\n")
249
250 (if (stringp emacs-repository-version)
251 (insert "Repository revision: " emacs-repository-version "\n"))
252 (if (fboundp 'x-server-vendor)
253 (condition-case nil
254 ;; This is used not only for X11 but also W32 and others.
255 (insert "Windowing system distributor '" (x-server-vendor)
256 "', version "
257 (mapconcat 'number-to-string (x-server-version) ".") "\n")
258 (error t)))
259 (let ((lsb (with-temp-buffer
260 (if (eq 0 (ignore-errors
261 (call-process "lsb_release" nil '(t nil)
262 nil "-d")))
263 (buffer-string)))))
264 (if (stringp lsb)
265 (insert "System " lsb "\n")))
266 (when (and system-configuration-options
267 (not (equal system-configuration-options "")))
268 (insert "Configured using:\n 'configure "
269 system-configuration-options "'\n\n")
270 (fill-region (line-beginning-position -1) (point)))
271 (insert "Configured features:\n" system-configuration-features "\n\n")
272 (fill-region (line-beginning-position -1) (point))
273 (insert "Important settings:\n")
274 (mapc
275 (lambda (var)
276 (let ((val (getenv var)))
277 (if val (insert (format " value of $%s: %s\n" var val)))))
278 '("EMACSDATA" "EMACSDOC" "EMACSLOADPATH" "EMACSPATH"
279 "LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
280 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
281 (insert (format " locale-coding-system: %s\n" locale-coding-system))
282 ;; Only ~ 0.2% of people from a sample of 3200 changed this from
283 ;; the default, t.
284 (or (default-value 'enable-multibyte-characters)
285 (insert (format " default enable-multibyte-characters: %s\n"
286 (default-value 'enable-multibyte-characters))))
287 (insert "\n")
288 (insert (format "Major mode: %s\n"
289 (format-mode-line
290 (buffer-local-value 'mode-name from-buffer)
291 nil nil from-buffer)))
292 (insert "\n")
293 (insert "Minor modes in effect:\n")
294 (dolist (mode minor-mode-list)
295 (and (boundp mode) (buffer-local-value mode from-buffer)
296 (insert (format " %s: %s\n" mode
297 (buffer-local-value mode from-buffer)))))
298 (let ((message-buf (get-buffer "*Messages*")))
299 (if message-buf
300 (let (beg-pos
301 (end-pos message-end-point))
302 (with-current-buffer message-buf
303 (goto-char end-pos)
304 (forward-line -10)
305 (setq beg-pos (point)))
306 (insert "\nRecent messages:\n")
307 (insert-buffer-substring message-buf beg-pos end-pos))))
308 ;; After Recent messages, to avoid the messages produced by
309 ;; list-load-path-shadows.
310 (unless (looking-back "\n" (1- (point)))
311 (insert "\n"))
312 (insert "\n")
313 (insert "Load-path shadows:\n")
314 (let* ((msg "Checking for load-path shadows...")
315 (result "done")
316 (shadows (progn (message "%s" msg)
317 (condition-case nil (list-load-path-shadows t)
318 (error
319 (setq result "error")
320 "Error during checking")))))
321 (message "%s%s" msg result)
322 (insert (if (zerop (length shadows))
323 "None found.\n"
324 shadows)))
325 (insert (format "\nFeatures:\n%s\n" features))
326 (fill-region (line-beginning-position 0) (point))
327
328 (insert (format "\nMemory information:\n"))
329 (pp (garbage-collect) (current-buffer))
330
331 ;; This is so the user has to type something in order to send easily.
332 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
333 (define-key (current-local-map) "\C-c\C-i" 'info-emacs-bug)
334 (if can-insert-mail
335 (define-key (current-local-map) "\C-c\M-i"
336 'report-emacs-bug-insert-to-mailer))
337 (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc)
338 report-emacs-bug-send-hook (get mail-user-agent 'hookvar))
339 (if report-emacs-bug-send-command
340 (setq report-emacs-bug-send-command
341 (symbol-name report-emacs-bug-send-command)))
342 (unless report-emacs-bug-no-explanations
343 (with-output-to-temp-buffer "*Bug Help*"
344 (princ "While in the mail buffer:\n\n")
345 (if report-emacs-bug-send-command
346 (princ (substitute-command-keys
347 (format " Type \\[%s] to send the bug report.\n"
348 report-emacs-bug-send-command))))
349 (princ (substitute-command-keys
350 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
351 (if can-insert-mail
352 (princ (substitute-command-keys
353 " Type \\[report-emacs-bug-insert-to-mailer] to copy text to your preferred mail program.\n")))
354 (terpri)
355 (princ (substitute-command-keys
356 " Type \\[info-emacs-bug] to visit in Info the Emacs Manual section
357 about when and how to write a bug report, and what
358 information you should include to help fix the bug.")))
359 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
360 ;; Make it less likely people will send empty messages.
361 (if report-emacs-bug-send-hook
362 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
363 (goto-char (point-max))
364 (skip-chars-backward " \t\n")
365 (make-local-variable 'report-emacs-bug-orig-text)
366 (setq report-emacs-bug-orig-text
367 (buffer-substring-no-properties (point-min) (point)))
368 (goto-char user-point)))
369
370 (define-obsolete-function-alias 'report-emacs-bug-info 'info-emacs-bug "24.3")
371
372 (defun report-emacs-bug-hook ()
373 "Do some checking before sending a bug report."
374 (save-excursion
375 (goto-char (point-max))
376 (skip-chars-backward " \t\n")
377 (and (= (- (point) (point-min))
378 (length report-emacs-bug-orig-text))
379 (string-equal (buffer-substring-no-properties (point-min) (point))
380 report-emacs-bug-orig-text)
381 (error "No text entered in bug report"))
382 ;; Warning for novice users.
383 (unless (or report-emacs-bug-no-confirmation
384 (yes-or-no-p
385 "Send this bug report to the Emacs maintainers? "))
386 (goto-char (point-min))
387 (if (search-forward "To: ")
388 (delete-region (point) (line-end-position)))
389 (if report-emacs-bug-send-hook
390 (kill-local-variable report-emacs-bug-send-hook))
391 (with-output-to-temp-buffer "*Bug Help*"
392 (princ (substitute-command-keys
393 (format "\
394 You invoked the command M-x report-emacs-bug,
395 but you decided not to mail the bug report to the Emacs maintainers.
396
397 If you want to mail it to someone else instead,
398 please insert the proper e-mail address after \"To: \",
399 and send the mail again%s."
400 (if report-emacs-bug-send-command
401 (format " using \\[%s]"
402 report-emacs-bug-send-command)
403 "")))))
404 (error "M-x report-emacs-bug was canceled, please read *Bug Help* buffer"))
405 ;; Query the user for the SMTP method, so that we can skip
406 ;; questions about From header validity if the user is going to
407 ;; use mailclient, anyway.
408 (when (or (and (derived-mode-p 'message-mode)
409 (eq message-send-mail-function 'sendmail-query-once))
410 (and (not (derived-mode-p 'message-mode))
411 (eq send-mail-function 'sendmail-query-once)))
412 (sendmail-query-user-about-smtp)
413 (when (derived-mode-p 'message-mode)
414 (setq message-send-mail-function (message-default-send-mail-function))))
415 (or report-emacs-bug-no-confirmation
416 ;; mailclient.el does not need a valid From
417 (if (derived-mode-p 'message-mode)
418 (eq message-send-mail-function 'message-send-mail-with-mailclient)
419 (eq send-mail-function 'mailclient-send-it))
420 ;; Not narrowing to the headers, but that's OK.
421 (let ((from (mail-fetch-field "From")))
422 (and (or (not from)
423 (message-bogus-recipient-p from)
424 ;; This is the default user-mail-address. On today's
425 ;; systems, it seems more likely to be wrong than right,
426 ;; since most people don't run their own mail server.
427 (string-match (format "\\<%s@%s\\>"
428 (regexp-quote (user-login-name))
429 (regexp-quote (system-name)))
430 from))
431 (not (yes-or-no-p
432 (format-message "Is `%s' really your email address? "
433 from)))
434 (error "Please edit the From address and try again"))))))
435
436
437 (provide 'emacsbug)
438
439 ;;; emacsbug.el ends here