emacsbug.el 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
  2. ;; Copyright (C) 1985, 1994, 1997-1998, 2000-2017 Free Software
  3. ;; Foundation, Inc.
  4. ;; Author: K. Shane Hartman
  5. ;; Maintainer: emacs-devel@gnu.org
  6. ;; Keywords: maint mail
  7. ;; Package: emacs
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
  21. ;; describing a problem. You need to be able to send mail from Emacs
  22. ;; to complete the process. Alternatively, compose the bug report in
  23. ;; Emacs then paste it into your normal mail client.
  24. ;;; Code:
  25. (require 'sendmail)
  26. (require 'message)
  27. (defgroup emacsbug nil
  28. "Sending Emacs bug reports."
  29. :group 'maint
  30. :group 'mail)
  31. (define-obsolete-variable-alias 'report-emacs-bug-pretest-address
  32. 'report-emacs-bug-address "24.1")
  33. (defcustom report-emacs-bug-no-confirmation nil
  34. "If non-nil, suppress the confirmations asked for the sake of novice users."
  35. :group 'emacsbug
  36. :type 'boolean)
  37. (defcustom report-emacs-bug-no-explanations nil
  38. "If non-nil, suppress the explanations given for the sake of novice users."
  39. :group 'emacsbug
  40. :type 'boolean)
  41. ;; User options end here.
  42. (defvar report-emacs-bug-orig-text nil
  43. "The automatically-created initial text of the bug report.")
  44. (defvar report-emacs-bug-send-command nil
  45. "Name of the command to send the bug report, as a string.")
  46. (make-variable-buffer-local 'report-emacs-bug-send-command)
  47. (defvar report-emacs-bug-send-hook nil
  48. "Hook run before sending the bug report.")
  49. (make-variable-buffer-local 'report-emacs-bug-send-hook)
  50. (declare-function x-server-vendor "xfns.c" (&optional terminal))
  51. (declare-function x-server-version "xfns.c" (&optional terminal))
  52. (declare-function message-sort-headers "message" ())
  53. (defvar message-strip-special-text-properties)
  54. (defun report-emacs-bug-can-use-osx-open ()
  55. "Return non-nil if the macOS \"open\" command is available for mailing."
  56. (and (featurep 'ns)
  57. (equal (executable-find "open") "/usr/bin/open")
  58. (memq system-type '(darwin))))
  59. ;; FIXME this duplicates much of the logic from browse-url-can-use-xdg-open.
  60. (defun report-emacs-bug-can-use-xdg-email ()
  61. "Return non-nil if the \"xdg-email\" command can be used.
  62. xdg-email is a desktop utility that calls your preferred mail client.
  63. This requires you to be running either Gnome, KDE, or Xfce4."
  64. (and (getenv "DISPLAY")
  65. (executable-find "xdg-email")
  66. (or (getenv "GNOME_DESKTOP_SESSION_ID")
  67. ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
  68. (condition-case nil
  69. (eq 0 (call-process
  70. "dbus-send" nil nil nil
  71. "--dest=org.gnome.SessionManager"
  72. "--print-reply"
  73. "/org/gnome/SessionManager"
  74. "org.gnome.SessionManager.CanShutdown"))
  75. (error nil))
  76. (equal (getenv "KDE_FULL_SESSION") "true")
  77. ;; FIXME? browse-url-can-use-xdg-open also accepts LXDE.
  78. ;; Is that no good here, or just overlooked?
  79. (condition-case nil
  80. (eq 0 (call-process
  81. "/bin/sh" nil nil nil
  82. "-c"
  83. ;; FIXME use string-match rather than grep.
  84. "xprop -root _DT_SAVE_MODE|grep xfce4"))
  85. (error nil)))))
  86. (defun report-emacs-bug-insert-to-mailer ()
  87. "Send the message to your preferred mail client.
  88. This requires either the macOS \"open\" command, or the freedesktop
  89. \"xdg-email\" command to be available."
  90. (interactive)
  91. (save-excursion
  92. ;; FIXME? use mail-fetch-field?
  93. (let* ((to (progn
  94. (goto-char (point-min))
  95. (forward-line)
  96. (and (looking-at "^To: \\(.*\\)")
  97. (match-string-no-properties 1))))
  98. (subject (progn
  99. (forward-line)
  100. (and (looking-at "^Subject: \\(.*\\)")
  101. (match-string-no-properties 1))))
  102. (body (progn
  103. (forward-line 2)
  104. (if (> (point-max) (point))
  105. (buffer-substring-no-properties (point) (point-max))))))
  106. (if (and to subject body)
  107. (if (report-emacs-bug-can-use-osx-open)
  108. (start-process "/usr/bin/open" nil "open"
  109. (concat "mailto:" to
  110. "?subject=" (url-hexify-string subject)
  111. "&body=" (url-hexify-string body)))
  112. (start-process "xdg-email" nil "xdg-email"
  113. "--subject" subject
  114. "--body" body
  115. (concat "mailto:" to)))
  116. (error "Subject, To or body not found")))))
  117. ;; It's the default mail mode, so it seems OK to use its features.
  118. (autoload 'message-bogus-recipient-p "message")
  119. (autoload 'message-make-address "message")
  120. (defvar message-send-mail-function)
  121. (defvar message-sendmail-envelope-from)
  122. ;;;###autoload
  123. (defun report-emacs-bug (topic &optional unused)
  124. "Report a bug in GNU Emacs.
  125. Prompts for bug subject. Leaves you in a mail buffer."
  126. (declare (advertised-calling-convention (topic) "24.5"))
  127. (interactive "sBug Subject: ")
  128. ;; The syntax `version;' is preferred to `[version]' because the
  129. ;; latter could be mistakenly stripped by mailing software.
  130. (if (eq system-type 'ms-dos)
  131. (setq topic (concat emacs-version "; " topic))
  132. (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
  133. (setq topic (concat (match-string 1 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 "http://lists.gnu.org/archive/html/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 "http://debbugs.gnu.org/"))
  191. 'follow-link t)
  192. (insert ". Please check that
  193. the From: line contains a valid email address. After a delay of up
  194. to one day, you should receive an acknowledgment at that address.
  195. Please write in English if possible, as the Emacs maintainers
  196. usually do not have translators for other languages.\n\n")))
  197. (insert "Please describe exactly what actions triggered the bug, and\n"
  198. "the precise symptoms of the bug. If you can, give a recipe\n"
  199. "starting from 'emacs -Q':\n\n")
  200. (let ((txt (delete-and-extract-region
  201. (save-excursion (rfc822-goto-eoh) (line-beginning-position 2))
  202. (point))))
  203. (insert (propertize "\n" 'display txt)))
  204. (setq user-point (point))
  205. (insert "\n\n")
  206. (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
  207. "please include the output from the following gdb commands:\n"
  208. " 'bt full' and 'xbacktrace'.\n")
  209. (let ((debug-file (expand-file-name "DEBUG" data-directory)))
  210. (if (file-readable-p debug-file)
  211. (insert "For information about debugging Emacs, please read the file\n"
  212. debug-file ".\n")))
  213. (let ((txt (delete-and-extract-region (1+ user-point) (point))))
  214. (insert (propertize "\n" 'display txt)))
  215. (insert "\nIn " (emacs-version))
  216. (if emacs-build-system
  217. (insert " built on " emacs-build-system))
  218. (insert "\n")
  219. (if (stringp emacs-repository-version)
  220. (insert "Repository revision: " emacs-repository-version "\n"))
  221. (if (fboundp 'x-server-vendor)
  222. (condition-case nil
  223. ;; This is used not only for X11 but also W32 and others.
  224. (insert "Windowing system distributor '" (x-server-vendor)
  225. "', version "
  226. (mapconcat 'number-to-string (x-server-version) ".") "\n")
  227. (error t)))
  228. (let ((lsb (with-temp-buffer
  229. (if (eq 0 (ignore-errors
  230. (call-process "lsb_release" nil '(t nil)
  231. nil "-d")))
  232. (buffer-string)))))
  233. (if (stringp lsb)
  234. (insert "System " lsb "\n")))
  235. (let ((message-buf (get-buffer "*Messages*")))
  236. (if message-buf
  237. (let (beg-pos
  238. (end-pos message-end-point))
  239. (with-current-buffer message-buf
  240. (goto-char end-pos)
  241. (forward-line -10)
  242. (setq beg-pos (point)))
  243. (terpri (current-buffer) t)
  244. (insert "Recent messages:\n")
  245. (insert-buffer-substring message-buf beg-pos end-pos))))
  246. (insert "\n")
  247. (when (and system-configuration-options
  248. (not (equal system-configuration-options "")))
  249. (insert "Configured using:\n 'configure "
  250. system-configuration-options "'\n\n")
  251. (fill-region (line-beginning-position -1) (point)))
  252. (insert "Configured features:\n" system-configuration-features "\n\n")
  253. (fill-region (line-beginning-position -1) (point))
  254. (insert "Important settings:\n")
  255. (mapc
  256. (lambda (var)
  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"
  261. "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
  262. (insert (format " locale-coding-system: %s\n" locale-coding-system))
  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))))
  268. (insert "\n")
  269. (insert (format "Major mode: %s\n"
  270. (format-mode-line
  271. (buffer-local-value 'mode-name from-buffer)
  272. nil nil from-buffer)))
  273. (insert "\n")
  274. (insert "Minor modes in effect:\n")
  275. (dolist (mode minor-mode-list)
  276. (and (boundp mode) (buffer-local-value mode from-buffer)
  277. (insert (format " %s: %s\n" mode
  278. (buffer-local-value mode from-buffer)))))
  279. (insert "\n")
  280. (insert "Load-path shadows:\n")
  281. (let* ((msg "Checking for load-path shadows...")
  282. (result "done")
  283. (shadows (progn (message "%s" msg)
  284. (condition-case nil (list-load-path-shadows t)
  285. (error
  286. (setq result "error")
  287. "Error during checking")))))
  288. (message "%s%s" msg result)
  289. (insert (if (zerop (length shadows))
  290. "None found.\n"
  291. shadows)))
  292. (insert (format "\nFeatures:\n%s\n" features))
  293. (fill-region (line-beginning-position 0) (point))
  294. (insert (format "\nMemory information:\n"))
  295. (pp (garbage-collect) (current-buffer))
  296. ;; This is so the user has to type something in order to send easily.
  297. (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
  298. (define-key (current-local-map) "\C-c\C-i" 'info-emacs-bug)
  299. (if can-insert-mail
  300. (define-key (current-local-map) "\C-c\M-i"
  301. 'report-emacs-bug-insert-to-mailer))
  302. (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc)
  303. report-emacs-bug-send-hook (get mail-user-agent 'hookvar))
  304. (if report-emacs-bug-send-command
  305. (setq report-emacs-bug-send-command
  306. (symbol-name report-emacs-bug-send-command)))
  307. (unless report-emacs-bug-no-explanations
  308. (with-output-to-temp-buffer "*Bug Help*"
  309. (princ "While in the mail buffer:\n\n")
  310. (if report-emacs-bug-send-command
  311. (princ (substitute-command-keys
  312. (format " Type \\[%s] to send the bug report.\n"
  313. report-emacs-bug-send-command))))
  314. (princ (substitute-command-keys
  315. " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
  316. (if can-insert-mail
  317. (princ (substitute-command-keys
  318. " Type \\[report-emacs-bug-insert-to-mailer] to copy text to your preferred mail program.\n")))
  319. (terpri)
  320. (princ (substitute-command-keys
  321. " Type \\[info-emacs-bug] to visit in Info the Emacs Manual section
  322. about when and how to write a bug report, and what
  323. information you should include to help fix the bug.")))
  324. (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
  325. ;; Make it less likely people will send empty messages.
  326. (if report-emacs-bug-send-hook
  327. (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
  328. (goto-char (point-max))
  329. (skip-chars-backward " \t\n")
  330. (make-local-variable 'report-emacs-bug-orig-text)
  331. (setq report-emacs-bug-orig-text
  332. (buffer-substring-no-properties (point-min) (point)))
  333. (goto-char user-point)))
  334. (define-obsolete-function-alias 'report-emacs-bug-info 'info-emacs-bug "24.3")
  335. (defun report-emacs-bug-hook ()
  336. "Do some checking before sending a bug report."
  337. (save-excursion
  338. (goto-char (point-max))
  339. (skip-chars-backward " \t\n")
  340. (and (= (- (point) (point-min))
  341. (length report-emacs-bug-orig-text))
  342. (string-equal (buffer-substring-no-properties (point-min) (point))
  343. report-emacs-bug-orig-text)
  344. (error "No text entered in bug report"))
  345. ;; Warning for novice users.
  346. (unless (or report-emacs-bug-no-confirmation
  347. (yes-or-no-p
  348. "Send this bug report to the Emacs maintainers? "))
  349. (goto-char (point-min))
  350. (if (search-forward "To: ")
  351. (delete-region (point) (line-end-position)))
  352. (if report-emacs-bug-send-hook
  353. (kill-local-variable report-emacs-bug-send-hook))
  354. (with-output-to-temp-buffer "*Bug Help*"
  355. (princ (substitute-command-keys
  356. (format "\
  357. You invoked the command M-x report-emacs-bug,
  358. but you decided not to mail the bug report to the Emacs maintainers.
  359. If you want to mail it to someone else instead,
  360. please insert the proper e-mail address after \"To: \",
  361. and send the mail again%s."
  362. (if report-emacs-bug-send-command
  363. (format " using \\[%s]"
  364. report-emacs-bug-send-command)
  365. "")))))
  366. (error "M-x report-emacs-bug was canceled, please read *Bug Help* buffer"))
  367. ;; Query the user for the SMTP method, so that we can skip
  368. ;; questions about From header validity if the user is going to
  369. ;; use mailclient, anyway.
  370. (when (or (and (derived-mode-p 'message-mode)
  371. (eq message-send-mail-function 'sendmail-query-once))
  372. (and (not (derived-mode-p 'message-mode))
  373. (eq send-mail-function 'sendmail-query-once)))
  374. (sendmail-query-user-about-smtp)
  375. (when (derived-mode-p 'message-mode)
  376. (setq message-send-mail-function (message-default-send-mail-function))))
  377. (or report-emacs-bug-no-confirmation
  378. ;; mailclient.el does not need a valid From
  379. (if (derived-mode-p 'message-mode)
  380. (eq message-send-mail-function 'message-send-mail-with-mailclient)
  381. (eq send-mail-function 'mailclient-send-it))
  382. ;; Not narrowing to the headers, but that's OK.
  383. (let ((from (mail-fetch-field "From")))
  384. (and (or (not from)
  385. (message-bogus-recipient-p from)
  386. ;; This is the default user-mail-address. On today's
  387. ;; systems, it seems more likely to be wrong than right,
  388. ;; since most people don't run their own mail server.
  389. (string-match (format "\\<%s@%s\\>"
  390. (regexp-quote (user-login-name))
  391. (regexp-quote (system-name)))
  392. from))
  393. (not (yes-or-no-p
  394. (format-message "Is `%s' really your email address? "
  395. from)))
  396. (error "Please edit the From address and try again"))))))
  397. (provide 'emacsbug)
  398. ;;; emacsbug.el ends here