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