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
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 (define-obsolete-variable-alias 'report-emacs-bug-pretest-address
41 'report-emacs-bug-address
"24.1")
43 (defcustom report-emacs-bug-address
"bug-gnu-emacs@gnu.org"
44 "Address of mailing list for GNU Emacs bugs."
48 (defcustom report-emacs-bug-no-confirmation nil
49 "If non-nil, suppress the confirmations asked for the sake of novice users."
53 (defcustom report-emacs-bug-no-explanations nil
54 "If non-nil, suppress the explanations given for the sake of novice users."
58 ;; User options end here.
61 (defvar report-emacs-bug-orig-text nil
62 "The automatically-created initial text of the bug report.")
64 (defvar report-emacs-bug-send-command nil
65 "Name of the command to send the bug report, as a string.")
66 (make-variable-buffer-local 'report-emacs-bug-send-command
)
68 (defvar report-emacs-bug-send-hook nil
69 "Hook run before sending the bug report.")
70 (make-variable-buffer-local 'report-emacs-bug-send-hook
)
72 (declare-function x-server-vendor
"xfns.c" (&optional terminal
))
73 (declare-function x-server-version
"xfns.c" (&optional terminal
))
74 (declare-function message-sort-headers
"message" ())
75 (defvar message-strip-special-text-properties
)
78 (defun report-emacs-bug (topic &optional recent-keys
)
79 "Report a bug in GNU Emacs.
80 Prompts for bug subject. Leaves you in a mail buffer."
81 ;; This strange form ensures that (recent-keys) is the value before
82 ;; the bug subject string is read.
83 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
84 ;; The syntax `version;' is preferred to `[version]' because the
85 ;; latter could be mistakenly stripped by mailing software.
86 (if (eq system-type
'ms-dos
)
87 (setq topic
(concat emacs-version
"; " topic
))
88 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version
)
89 (setq topic
(concat (match-string 1 emacs-version
) "; " topic
))))
90 (let ((from-buffer (current-buffer))
91 ;; Put these properties on semantically-void text.
92 ;; report-emacs-bug-hook deletes these regions before sending.
93 (prompt-properties '(field emacsbug-prompt
94 intangible but-helpful
96 user-point message-end-point
)
97 (setq message-end-point
98 (with-current-buffer (get-buffer-create "*Messages*")
100 (compose-mail report-emacs-bug-address topic
)
101 ;; The rest of this does not execute if the user was asked to
102 ;; confirm and said no.
103 (when (eq major-mode
'message-mode
)
104 ;; Message-mode sorts the headers before sending. We sort now so
105 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
106 (message-sort-headers)
107 ;; Stop message-mode stealing the properties we will add.
108 (set (make-local-variable 'message-strip-special-text-properties
) nil
))
111 (let ((signature (buffer-substring (point) (point-max))))
112 (delete-region (point) (point-max))
114 (backward-char (length signature
)))
115 (unless report-emacs-bug-no-explanations
116 ;; Insert warnings for novice users.
117 (when (string-match "@gnu\\.org$" report-emacs-bug-address
)
118 (insert "This bug report will be sent to the Free Software Foundation,\n")
120 (insert "not to your local site managers!")
121 (overlay-put (make-overlay pos
(point)) 'face
'highlight
)))
122 (insert "\nPlease write in ")
125 (overlay-put (make-overlay pos
(point)) 'face
'highlight
))
126 (insert " if possible, because the Emacs maintainers
127 usually do not have translators to read other languages for them.\n\n")
128 (insert (format "Your bug report will be posted to the %s mailing list"
129 report-emacs-bug-address
))
130 (insert ",\nand to the gnu.emacs.bug news group.\n\n"))
132 (insert "Please describe exactly what actions triggered the bug\n"
133 "and the precise symptoms of the bug. If you can, give\n"
134 "a recipe starting from `emacs -Q':\n\n")
135 (add-text-properties (save-excursion
137 (line-beginning-position 2))
140 (setq user-point
(point))
143 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
144 "please include the output from the following gdb commands:\n"
145 " `bt full' and `xbacktrace'.\n")
147 (let ((debug-file (expand-file-name "DEBUG" data-directory
)))
148 (if (file-readable-p debug-file
)
149 (insert "For information about debugging Emacs, please read the file\n"
151 (add-text-properties (1+ user-point
) (point) prompt-properties
)
153 (insert "\n\nIn " (emacs-version) "\n")
154 (if (fboundp 'x-server-vendor
)
156 ;; This is used not only for X11 but also W32 and others.
157 (insert "Windowing system distributor `" (x-server-vendor)
159 (mapconcat 'number-to-string
(x-server-version) ".") "\n")
161 (if (and system-configuration-options
162 (not (equal system-configuration-options
"")))
163 (insert "configured using `configure "
164 system-configuration-options
"'\n\n"))
165 (insert "Important settings:\n")
168 (insert (format " value of $%s: %s\n" var
(getenv var
))))
169 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
170 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
171 (insert (format " locale-coding-system: %s\n" locale-coding-system
))
172 (insert (format " default enable-multibyte-characters: %s\n"
173 (default-value 'enable-multibyte-characters
)))
175 (insert (format "Major mode: %s\n"
177 (buffer-local-value 'mode-name from-buffer
)
178 nil nil from-buffer
)))
180 (insert "Minor modes in effect:\n")
181 (dolist (mode minor-mode-list
)
182 (and (boundp mode
) (buffer-local-value mode from-buffer
)
183 (insert (format " %s: %s\n" mode
184 (buffer-local-value mode from-buffer
)))))
186 (insert "Recent input:\n")
187 (let ((before-keys (point)))
188 (insert (mapconcat (lambda (key)
189 (if (or (integerp key
)
192 (single-key-description key
)
193 (prin1-to-string key nil
)))
194 (or recent-keys
(recent-keys))
197 (narrow-to-region before-keys
(point))
198 (goto-char before-keys
)
199 (while (progn (move-to-column 50) (not (eobp)))
200 (search-forward " " nil t
)
202 (let ((message-buf (get-buffer "*Messages*")))
205 (end-pos message-end-point
))
206 (with-current-buffer message-buf
209 (setq beg-pos
(point)))
210 (insert "\n\nRecent messages:\n")
211 (insert-buffer-substring message-buf beg-pos end-pos
))))
212 ;; After Recent messages, to avoid the messages produced by
213 ;; list-load-path-shadows.
214 (unless (looking-back "\n")
217 (insert "Load-path shadows:\n")
218 (message "Checking for load-path shadows...")
219 (let ((shadows (list-load-path-shadows t
)))
220 (message "Checking for load-path shadows...done")
221 (insert (if (zerop (length shadows
))
224 (insert (format "\nFeatures:\n%s\n" features
))
225 (fill-region (line-beginning-position 0) (point))
226 ;; This is so the user has to type something in order to send easily.
227 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
228 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info
)
229 ;; Could test major-mode instead.
230 (cond ((memq mail-user-agent
'(message-user-agent gnus-user-agent
))
231 (setq report-emacs-bug-send-command
"message-send-and-exit"
232 report-emacs-bug-send-hook
'message-send-hook
))
233 ((eq mail-user-agent
'sendmail-user-agent
)
234 (setq report-emacs-bug-send-command
"mail-send-and-exit"
235 report-emacs-bug-send-hook
'mail-send-hook
))
236 ((eq mail-user-agent
'mh-e-user-agent
)
237 (setq report-emacs-bug-send-command
"mh-send-letter"
238 report-emacs-bug-send-hook
'mh-before-send-letter-hook
)))
239 (unless report-emacs-bug-no-explanations
240 (with-output-to-temp-buffer "*Bug Help*"
241 (princ "While in the mail buffer:\n\n")
242 (if report-emacs-bug-send-command
243 (princ (substitute-command-keys
244 (format " Type \\[%s] to send the bug report.\n"
245 report-emacs-bug-send-command
))))
246 (princ (substitute-command-keys
247 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
249 (princ (substitute-command-keys
250 " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
251 about when and how to write a bug report, and what
252 information you should include to help fix the bug.")))
253 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
254 ;; Make it less likely people will send empty messages.
255 (if report-emacs-bug-send-hook
256 (add-hook report-emacs-bug-send-hook
'report-emacs-bug-hook nil t
))
257 (goto-char (point-max))
258 (skip-chars-backward " \t\n")
259 (make-local-variable 'report-emacs-bug-orig-text
)
260 (setq report-emacs-bug-orig-text
261 (buffer-substring-no-properties (point-min) (point)))
262 (goto-char user-point
)))
264 (defun report-emacs-bug-info ()
265 "Go to the Info node on reporting Emacs bugs."
267 (info "(emacs)Bugs"))
269 (defun report-emacs-bug-hook ()
270 "Do some checking before sending a bug report."
272 (goto-char (point-max))
273 (skip-chars-backward " \t\n")
274 (and (= (- (point) (point-min))
275 (length report-emacs-bug-orig-text
))
276 (string-equal (buffer-substring-no-properties (point-min) (point))
277 report-emacs-bug-orig-text
)
278 (error "No text entered in bug report"))
279 ;; Check the buffer contents and reject non-English letters.
280 ;; FIXME message-mode probably does this anyway.
281 (goto-char (point-min))
282 (skip-chars-forward "\0-\177")
284 (if (or report-emacs-bug-no-confirmation
285 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
286 (while (progn (skip-chars-forward "\0-\177")
288 (let ((ch (following-char)))
290 (insert (format "=%02x" ch
))))))
292 ;; The last warning for novice users.
293 (unless (or report-emacs-bug-no-confirmation
295 "Send this bug report to the Emacs maintainers? "))
296 (goto-char (point-min))
297 (if (search-forward "To: ")
298 (delete-region (point) (line-end-position)))
299 (if report-emacs-bug-send-hook
300 (kill-local-variable report-emacs-bug-send-hook
))
301 (with-output-to-temp-buffer "*Bug Help*"
302 (princ (substitute-command-keys
304 You invoked the command M-x report-emacs-bug,
305 but you decided not to mail the bug report to the Emacs maintainers.
307 If you want to mail it to someone else instead,
308 please insert the proper e-mail address after \"To: \",
309 and send the mail again%s."
310 (if report-emacs-bug-send-command
311 (format " using \\[%s]"
312 report-emacs-bug-send-command
)
314 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
316 ;; Delete the uninteresting text that was just to help fill out the report.
319 (let ((pos (1- (point))))
320 (while (setq pos
(text-property-any pos
(point-max)
321 'field
'emacsbug-prompt
))
322 (delete-region pos
(field-end (1+ pos
)))))))
326 ;; arch-tag: 248b6523-c3b5-4fec-9a3f-0411fafa7d49
327 ;;; emacsbug.el ends here