1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
3 ;; Copyright (C) 1985, 1994, 1997, 1998, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
5 ;; Free Software Foundation, Inc.
7 ;; Author: K. Shane Hartman
9 ;; Keywords: maint mail
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 <http://www.gnu.org/licenses/>.
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.
35 (defgroup emacsbug nil
36 "Sending Emacs bug reports."
40 (defcustom report-emacs-bug-address
"bug-gnu-emacs@gnu.org"
41 "Address of mailing list for GNU Emacs bugs."
45 (defcustom report-emacs-bug-pretest-address
"bug-gnu-emacs@gnu.org"
46 "Address of mailing list for GNU Emacs pretest bugs."
49 :version
"23.2") ; emacs-pretest-bug -> bug-gnu-emacs
51 (defcustom report-emacs-bug-no-confirmation nil
52 "If non-nil, suppress the confirmations asked for the sake of novice users."
56 (defcustom report-emacs-bug-no-explanations nil
57 "If non-nil, suppress the explanations given for the sake of novice users."
61 ;; User options end here.
64 (defvar report-emacs-bug-orig-text nil
65 "The automatically-created initial text of the bug report.")
67 (defvar report-emacs-bug-send-command nil
68 "Name of the command to send the bug report, as a string.")
69 (make-variable-buffer-local 'report-emacs-bug-send-command
)
71 (defvar report-emacs-bug-send-hook nil
72 "Hook run before sending the bug report.")
73 (make-variable-buffer-local 'report-emacs-bug-send-hook
)
75 (declare-function x-server-vendor
"xfns.c" (&optional terminal
))
76 (declare-function x-server-version
"xfns.c" (&optional terminal
))
77 (declare-function message-sort-headers
"message" ())
80 (defun report-emacs-bug (topic &optional recent-keys
)
81 "Report a bug in GNU Emacs.
82 Prompts for bug subject. Leaves you in a mail buffer."
83 ;; This strange form ensures that (recent-keys) is the value before
84 ;; the bug subject string is read.
85 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
86 ;; The syntax `version;' is preferred to `[version]' because the
87 ;; latter could be mistakenly stripped by mailing software.
88 (if (eq system-type
'ms-dos
)
89 (setq topic
(concat emacs-version
"; " topic
))
90 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version
)
91 (setq topic
(concat (match-string 1 emacs-version
) "; " topic
))))
92 ;; If there are four numbers in emacs-version (three for MS-DOS),
93 ;; this is a pretest version.
94 (let* ((pretest-p (string-match (if (eq system-type
'ms-dos
)
98 (from-buffer (current-buffer))
99 (reporting-address (if pretest-p
100 report-emacs-bug-pretest-address
101 report-emacs-bug-address
))
102 ;; Put these properties on semantically-void text.
103 ;; report-emacs-bug-hook deletes these regions before sending.
104 (prompt-properties '(field emacsbug-prompt
105 intangible but-helpful
107 user-point message-end-point
)
108 (setq message-end-point
109 (with-current-buffer (get-buffer-create "*Messages*")
111 (compose-mail reporting-address topic
)
112 ;; The rest of this does not execute if the user was asked to
113 ;; confirm and said no.
114 ;; Message-mode sorts the headers before sending. We sort now so
115 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
116 (if (eq major-mode
'message-mode
)
117 (message-sort-headers))
120 (let ((signature (buffer-substring (point) (point-max))))
121 (delete-region (point) (point-max))
123 (backward-char (length signature
)))
124 (unless report-emacs-bug-no-explanations
125 ;; Insert warnings for novice users.
126 (when (string-match "@gnu\\.org$" reporting-address
)
127 (insert "This bug report will be sent to the Free Software Foundation,\n")
129 (insert "not to your local site managers!")
130 (overlay-put (make-overlay pos
(point)) 'face
'highlight
)))
131 (insert "\nPlease write in ")
134 (overlay-put (make-overlay pos
(point)) 'face
'highlight
))
135 (insert " if possible, because the Emacs maintainers
136 usually do not have translators to read other languages for them.\n\n")
137 (insert (format "Your report will be posted to the %s mailing list"
139 ;; Nowadays all bug reports end up there.
140 ;;; (if pretest-p (insert ".\n\n")
141 (insert "\nand the gnu.emacs.bug news group, and at http://debbugs.gnu.org.\n\n"))
143 (insert "Please describe exactly what actions triggered the bug\n"
144 "and the precise symptoms of the bug. If you can, give\n"
145 "a recipe starting from `emacs -Q':\n\n")
146 ;; Stop message-mode stealing the properties we are about to add.
147 (if (boundp 'message-strip-special-text-properties
)
148 (set (make-local-variable 'message-strip-special-text-properties
) nil
))
149 (add-text-properties (save-excursion
151 (line-beginning-position 2))
154 (setq user-point
(point))
157 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
158 "please include the output from the following gdb commands:\n"
159 " `bt full' and `xbacktrace'.\n")
161 (let ((debug-file (expand-file-name "DEBUG" data-directory
)))
162 (if (file-readable-p debug-file
)
163 (insert "For information about debugging Emacs, please read the file\n"
165 (add-text-properties (1+ user-point
) (point) prompt-properties
)
167 (insert "\n\nIn " (emacs-version) "\n")
168 (if (fboundp 'x-server-vendor
)
170 ;; This is used not only for X11 but also W32 and others.
171 (insert "Windowing system distributor `" (x-server-vendor)
173 (mapconcat 'number-to-string
(x-server-version) ".") "\n")
175 (if (and system-configuration-options
176 (not (equal system-configuration-options
"")))
177 (insert "configured using `configure "
178 system-configuration-options
"'\n\n"))
179 (insert "Important settings:\n")
182 (insert (format " value of $%s: %s\n" var
(getenv var
))))
183 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
184 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
185 (insert (format " locale-coding-system: %s\n" locale-coding-system
))
186 (insert (format " default enable-multibyte-characters: %s\n"
187 (default-value 'enable-multibyte-characters
)))
189 (insert (format "Major mode: %s\n"
191 (buffer-local-value 'mode-name from-buffer
)
192 nil nil from-buffer
)))
194 (insert "Minor modes in effect:\n")
195 (dolist (mode minor-mode-list
)
196 (and (boundp mode
) (buffer-local-value mode from-buffer
)
197 (insert (format " %s: %s\n" mode
198 (buffer-local-value mode from-buffer
)))))
200 (insert "Recent input:\n")
201 (let ((before-keys (point)))
202 (insert (mapconcat (lambda (key)
203 (if (or (integerp key
)
206 (single-key-description key
)
207 (prin1-to-string key nil
)))
208 (or recent-keys
(recent-keys))
211 (narrow-to-region before-keys
(point))
212 (goto-char before-keys
)
213 (while (progn (move-to-column 50) (not (eobp)))
214 (search-forward " " nil t
)
216 (let ((message-buf (get-buffer "*Messages*")))
219 (end-pos message-end-point
))
220 (with-current-buffer message-buf
223 (setq beg-pos
(point)))
224 (insert "\n\nRecent messages:\n")
225 (insert-buffer-substring message-buf beg-pos end-pos
))))
226 ;; After Recent messages, to avoid the messages produced by
227 ;; list-load-path-shadows.
228 (unless (looking-back "\n")
231 (insert "Load-path shadows:\n")
232 (message "Checking for load-path shadows...")
233 (let ((shadows (list-load-path-shadows t
)))
234 (message "Checking for load-path shadows...done")
235 (insert (if (zerop (length shadows
))
238 (insert (format "\nFeatures:\n%s\n" features
))
239 (fill-region (line-beginning-position 0) (point))
240 ;; This is so the user has to type something in order to send easily.
241 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
242 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info
)
243 ;; Could test major-mode instead.
244 (cond ((memq mail-user-agent
'(message-user-agent gnus-user-agent
))
245 (setq report-emacs-bug-send-command
"message-send-and-exit"
246 report-emacs-bug-send-hook
'message-send-hook
))
247 ((eq mail-user-agent
'sendmail-user-agent
)
248 (setq report-emacs-bug-send-command
"mail-send-and-exit"
249 report-emacs-bug-send-hook
'mail-send-hook
))
250 ((eq mail-user-agent
'mh-e-user-agent
)
251 (setq report-emacs-bug-send-command
"mh-send-letter"
252 report-emacs-bug-send-hook
'mh-before-send-letter-hook
)))
253 (unless report-emacs-bug-no-explanations
254 (with-output-to-temp-buffer "*Bug Help*"
255 (princ "While in the mail buffer:\n\n")
256 (if report-emacs-bug-send-command
257 (princ (substitute-command-keys
258 (format " Type \\[%s] to send the bug report.\n"
259 report-emacs-bug-send-command
))))
260 (princ (substitute-command-keys
261 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
263 (princ (substitute-command-keys
264 " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
265 about when and how to write a bug report, and what
266 information you should include to help fix the bug.")))
267 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
268 ;; Make it less likely people will send empty messages.
269 (if report-emacs-bug-send-hook
270 (add-hook report-emacs-bug-send-hook
'report-emacs-bug-hook nil t
))
271 (goto-char (point-max))
272 (skip-chars-backward " \t\n")
273 (make-local-variable 'report-emacs-bug-orig-text
)
274 (setq report-emacs-bug-orig-text
275 (buffer-substring-no-properties (point-min) (point)))
276 (goto-char user-point
)))
278 (defun report-emacs-bug-info ()
279 "Go to the Info node on reporting Emacs bugs."
281 (info "(emacs)Bugs"))
283 (defun report-emacs-bug-hook ()
284 "Do some checking before sending a bug report."
286 (goto-char (point-max))
287 (skip-chars-backward " \t\n")
288 (and (= (- (point) (point-min))
289 (length report-emacs-bug-orig-text
))
290 (string-equal (buffer-substring-no-properties (point-min) (point))
291 report-emacs-bug-orig-text
)
292 (error "No text entered in bug report"))
293 ;; Check the buffer contents and reject non-English letters.
294 ;; FIXME message-mode probably does this anyway.
295 (goto-char (point-min))
296 (skip-chars-forward "\0-\177")
298 (if (or report-emacs-bug-no-confirmation
299 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
300 (while (progn (skip-chars-forward "\0-\177")
302 (let ((ch (following-char)))
304 (insert (format "=%02x" ch
))))))
306 ;; The last warning for novice users.
307 (unless (or report-emacs-bug-no-confirmation
309 "Send this bug report to the Emacs maintainers? "))
310 (goto-char (point-min))
311 (if (search-forward "To: ")
312 (delete-region (point) (line-end-position)))
313 (if report-emacs-bug-send-hook
314 (kill-local-variable report-emacs-bug-send-hook
))
315 (with-output-to-temp-buffer "*Bug Help*"
316 (princ (substitute-command-keys
318 You invoked the command M-x report-emacs-bug,
319 but you decided not to mail the bug report to the Emacs maintainers.
321 If you want to mail it to someone else instead,
322 please insert the proper e-mail address after \"To: \",
323 and send the mail again%s."
324 (if report-emacs-bug-send-command
325 (format " using \\[%s]"
326 report-emacs-bug-send-command
)
328 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
330 ;; Delete the uninteresting text that was just to help fill out the report.
333 (let ((pos (1- (point))))
334 (while (setq pos
(text-property-any pos
(point-max)
335 'field
'emacsbug-prompt
))
336 (delete-region pos
(field-end (1+ pos
)))))))
340 ;;; emacsbug.el ends here