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
)
77 (defun report-emacs-bug-can-use-xdg-email ()
78 "Check if xdg-email can be used, i.e. we are on Gnome, KDE or xfce4."
79 (and (getenv "DISPLAY")
80 (executable-find "xdg-email")
81 (or (getenv "GNOME_DESKTOP_SESSION_ID")
82 ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
85 "dbus-send" nil nil nil
86 "--dest=org.gnome.SessionManager"
88 "/org/gnome/SessionManager"
89 "org.gnome.SessionManager.CanShutdown"))
91 (equal (getenv "KDE_FULL_SESSION") "true")
96 "xprop -root _DT_SAVE_MODE|grep xfce4"))
99 (defun report-emacs-bug-insert-to-mailer ()
103 (goto-char (point-min))
105 (and (looking-at "^To: \\(.*\\)")
106 (match-string-no-properties 1))))
109 (and (looking-at "^Subject: \\(.*\\)")
110 (match-string-no-properties 1))))
113 (if (> (point-max) (point))
114 (buffer-substring-no-properties (point) (point-max))))))
115 (if (and to subject body
)
116 (start-process "xdg-email" nil
"xdg-email"
119 (concat "mailto:" to
))
120 (error "Subject, To or body not found")))))
124 (defun report-emacs-bug (topic &optional recent-keys
)
125 "Report a bug in GNU Emacs.
126 Prompts for bug subject. Leaves you in a mail buffer."
127 ;; This strange form ensures that (recent-keys) is the value before
128 ;; the bug subject string is read.
129 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
130 ;; The syntax `version;' is preferred to `[version]' because the
131 ;; latter could be mistakenly stripped by mailing software.
132 (if (eq system-type
'ms-dos
)
133 (setq topic
(concat emacs-version
"; " topic
))
134 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version
)
135 (setq topic
(concat (match-string 1 emacs-version
) "; " topic
))))
136 (let ((from-buffer (current-buffer))
137 ;; Put these properties on semantically-void text.
138 ;; report-emacs-bug-hook deletes these regions before sending.
139 (prompt-properties '(field emacsbug-prompt
140 intangible but-helpful
142 (can-xdg-email (report-emacs-bug-can-use-xdg-email))
143 user-point message-end-point
)
144 (setq message-end-point
145 (with-current-buffer (get-buffer-create "*Messages*")
147 (compose-mail report-emacs-bug-address topic
)
148 ;; The rest of this does not execute if the user was asked to
149 ;; confirm and said no.
150 (when (eq major-mode
'message-mode
)
151 ;; Message-mode sorts the headers before sending. We sort now so
152 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
153 (message-sort-headers)
154 ;; Stop message-mode stealing the properties we will add.
155 (set (make-local-variable 'message-strip-special-text-properties
) nil
))
158 (let ((signature (buffer-substring (point) (point-max))))
159 (delete-region (point) (point-max))
161 (backward-char (length signature
)))
162 (unless report-emacs-bug-no-explanations
163 ;; Insert warnings for novice users.
164 (when (string-match "@gnu\\.org$" report-emacs-bug-address
)
165 (insert "This bug report will be sent to the Free Software Foundation,\n")
167 (insert "not to your local site managers!")
168 (overlay-put (make-overlay pos
(point)) 'face
'highlight
)))
169 (insert "\nPlease write in ")
172 (overlay-put (make-overlay pos
(point)) 'face
'highlight
))
173 (insert " if possible, because the Emacs maintainers
174 usually do not have translators to read other languages for them.\n\n")
175 (insert (format "Your bug report will be posted to the %s mailing list"
176 report-emacs-bug-address
))
177 (insert ",\nand to the gnu.emacs.bug news group.\n\n"))
179 (insert "Please describe exactly what actions triggered the bug\n"
180 "and the precise symptoms of the bug. If you can, give\n"
181 "a recipe starting from `emacs -Q':\n\n")
182 (add-text-properties (save-excursion
184 (line-beginning-position 2))
187 (setq user-point
(point))
190 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
191 "please include the output from the following gdb commands:\n"
192 " `bt full' and `xbacktrace'.\n")
194 (let ((debug-file (expand-file-name "DEBUG" data-directory
)))
195 (if (file-readable-p debug-file
)
196 (insert "For information about debugging Emacs, please read the file\n"
198 (add-text-properties (1+ user-point
) (point) prompt-properties
)
200 (insert "\n\nIn " (emacs-version) "\n")
201 (if (fboundp 'x-server-vendor
)
203 ;; This is used not only for X11 but also W32 and others.
204 (insert "Windowing system distributor `" (x-server-vendor)
206 (mapconcat 'number-to-string
(x-server-version) ".") "\n")
208 (if (and system-configuration-options
209 (not (equal system-configuration-options
"")))
210 (insert "configured using `configure "
211 system-configuration-options
"'\n\n"))
212 (insert "Important settings:\n")
215 (insert (format " value of $%s: %s\n" var
(getenv var
))))
216 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
217 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
218 (insert (format " locale-coding-system: %s\n" locale-coding-system
))
219 (insert (format " default enable-multibyte-characters: %s\n"
220 (default-value 'enable-multibyte-characters
)))
222 (insert (format "Major mode: %s\n"
224 (buffer-local-value 'mode-name from-buffer
)
225 nil nil from-buffer
)))
227 (insert "Minor modes in effect:\n")
228 (dolist (mode minor-mode-list
)
229 (and (boundp mode
) (buffer-local-value mode from-buffer
)
230 (insert (format " %s: %s\n" mode
231 (buffer-local-value mode from-buffer
)))))
233 (insert "Recent input:\n")
234 (let ((before-keys (point)))
235 (insert (mapconcat (lambda (key)
236 (if (or (integerp key
)
239 (single-key-description key
)
240 (prin1-to-string key nil
)))
241 (or recent-keys
(recent-keys))
244 (narrow-to-region before-keys
(point))
245 (goto-char before-keys
)
246 (while (progn (move-to-column 50) (not (eobp)))
247 (search-forward " " nil t
)
249 (let ((message-buf (get-buffer "*Messages*")))
252 (end-pos message-end-point
))
253 (with-current-buffer message-buf
256 (setq beg-pos
(point)))
257 (insert "\n\nRecent messages:\n")
258 (insert-buffer-substring message-buf beg-pos end-pos
))))
259 ;; After Recent messages, to avoid the messages produced by
260 ;; list-load-path-shadows.
261 (unless (looking-back "\n")
264 (insert "Load-path shadows:\n")
265 (message "Checking for load-path shadows...")
266 (let ((shadows (list-load-path-shadows t
)))
267 (message "Checking for load-path shadows...done")
268 (insert (if (zerop (length shadows
))
271 (insert (format "\nFeatures:\n%s\n" features
))
272 (fill-region (line-beginning-position 0) (point))
273 ;; This is so the user has to type something in order to send easily.
274 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
275 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info
)
277 (define-key (current-local-map) "\C-cm"
278 'report-emacs-bug-insert-to-mailer
))
279 ;; Could test major-mode instead.
280 (cond ((memq mail-user-agent
'(message-user-agent gnus-user-agent
))
281 (setq report-emacs-bug-send-command
"message-send-and-exit"
282 report-emacs-bug-send-hook
'message-send-hook
))
283 ((eq mail-user-agent
'sendmail-user-agent
)
284 (setq report-emacs-bug-send-command
"mail-send-and-exit"
285 report-emacs-bug-send-hook
'mail-send-hook
))
286 ((eq mail-user-agent
'mh-e-user-agent
)
287 (setq report-emacs-bug-send-command
"mh-send-letter"
288 report-emacs-bug-send-hook
'mh-before-send-letter-hook
)))
289 (unless report-emacs-bug-no-explanations
290 (with-output-to-temp-buffer "*Bug Help*"
291 (princ "While in the mail buffer:\n\n")
292 (if report-emacs-bug-send-command
293 (princ (substitute-command-keys
294 (format " Type \\[%s] to send the bug report.\n"
295 report-emacs-bug-send-command
))))
296 (princ (substitute-command-keys
297 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
299 (princ (substitute-command-keys
300 " Type \\[report-emacs-bug-insert-to-mailer] to insert text to you preferred mail program.\n")))
302 (princ (substitute-command-keys
303 " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
304 about when and how to write a bug report, and what
305 information you should include to help fix the bug.")))
306 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
307 ;; Make it less likely people will send empty messages.
308 (if report-emacs-bug-send-hook
309 (add-hook report-emacs-bug-send-hook
'report-emacs-bug-hook nil t
))
310 (goto-char (point-max))
311 (skip-chars-backward " \t\n")
312 (make-local-variable 'report-emacs-bug-orig-text
)
313 (setq report-emacs-bug-orig-text
314 (buffer-substring-no-properties (point-min) (point)))
315 (goto-char user-point
)))
317 (defun report-emacs-bug-info ()
318 "Go to the Info node on reporting Emacs bugs."
320 (info "(emacs)Bugs"))
322 (defun report-emacs-bug-hook ()
323 "Do some checking before sending a bug report."
325 (goto-char (point-max))
326 (skip-chars-backward " \t\n")
327 (and (= (- (point) (point-min))
328 (length report-emacs-bug-orig-text
))
329 (string-equal (buffer-substring-no-properties (point-min) (point))
330 report-emacs-bug-orig-text
)
331 (error "No text entered in bug report"))
332 ;; Check the buffer contents and reject non-English letters.
333 ;; FIXME message-mode probably does this anyway.
334 (goto-char (point-min))
335 (skip-chars-forward "\0-\177")
337 (if (or report-emacs-bug-no-confirmation
338 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
339 (while (progn (skip-chars-forward "\0-\177")
341 (let ((ch (following-char)))
343 (insert (format "=%02x" ch
))))))
345 ;; The last warning for novice users.
346 (unless (or report-emacs-bug-no-confirmation
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
357 You invoked the command M-x report-emacs-bug,
358 but you decided not to mail the bug report to the Emacs maintainers.
360 If you want to mail it to someone else instead,
361 please insert the proper e-mail address after \"To: \",
362 and send the mail again%s."
363 (if report-emacs-bug-send-command
364 (format " using \\[%s]"
365 report-emacs-bug-send-command
)
367 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
369 ;; Delete the uninteresting text that was just to help fill out the report.
372 (let ((pos (1- (point))))
373 (while (setq pos
(text-property-any pos
(point-max)
374 'field
'emacsbug-prompt
))
375 (delete-region pos
(field-end (1+ pos
)))))))
379 ;; arch-tag: 248b6523-c3b5-4fec-9a3f-0411fafa7d49
380 ;;; emacsbug.el ends here