1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
3 ;; Copyright (C) 1985, 1994, 1997-1998, 2000-2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: K. Shane Hartman
8 ;; 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.
37 (defgroup emacsbug nil
38 "Sending Emacs bug reports."
42 (define-obsolete-variable-alias 'report-emacs-bug-pretest-address
43 'report-emacs-bug-address
"24.1")
45 (defcustom report-emacs-bug-address
"bug-gnu-emacs@gnu.org"
46 "Address of mailing list for GNU Emacs bugs."
50 (defcustom report-emacs-bug-no-confirmation nil
51 "If non-nil, suppress the confirmations asked for the sake of novice users."
55 (defcustom report-emacs-bug-no-explanations nil
56 "If non-nil, suppress the explanations given for the sake of novice users."
60 ;; User options end here.
62 (defvar report-emacs-bug-tracker-url
"http://debbugs.gnu.org/cgi/"
63 "Base URL of the GNU bugtracker.
64 Used for querying duplicates and linking to existing bugs.")
66 (defvar report-emacs-bug-orig-text nil
67 "The automatically-created initial text of the bug report.")
69 (defvar report-emacs-bug-send-command nil
70 "Name of the command to send the bug report, as a string.")
71 (make-variable-buffer-local 'report-emacs-bug-send-command
)
73 (defvar report-emacs-bug-send-hook nil
74 "Hook run before sending the bug report.")
75 (make-variable-buffer-local 'report-emacs-bug-send-hook
)
77 (declare-function x-server-vendor
"xfns.c" (&optional terminal
))
78 (declare-function x-server-version
"xfns.c" (&optional terminal
))
79 (declare-function message-sort-headers
"message" ())
80 (defvar message-strip-special-text-properties
)
82 (defun report-emacs-bug-can-use-osx-open ()
83 "Check if OSX open can be used to insert bug report into mailer"
85 (equal (executable-find "open") "/usr/bin/open")
86 (memq system-type
'(darwin))))
88 (defun report-emacs-bug-can-use-xdg-email ()
89 "Check if xdg-email can be used, i.e. we are on Gnome, KDE or xfce4."
90 (and (getenv "DISPLAY")
91 (executable-find "xdg-email")
92 (or (getenv "GNOME_DESKTOP_SESSION_ID")
93 ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
96 "dbus-send" nil nil nil
97 "--dest=org.gnome.SessionManager"
99 "/org/gnome/SessionManager"
100 "org.gnome.SessionManager.CanShutdown"))
102 (equal (getenv "KDE_FULL_SESSION") "true")
105 "/bin/sh" nil nil nil
107 "xprop -root _DT_SAVE_MODE|grep xfce4"))
110 (defun report-emacs-bug-insert-to-mailer ()
114 (goto-char (point-min))
116 (and (looking-at "^To: \\(.*\\)")
117 (match-string-no-properties 1))))
120 (and (looking-at "^Subject: \\(.*\\)")
121 (match-string-no-properties 1))))
124 (if (> (point-max) (point))
125 (buffer-substring-no-properties (point) (point-max))))))
126 (if (and to subject body
)
127 (if (report-emacs-bug-can-use-osx-open)
128 (start-process "/usr/bin/open" nil
"open"
130 "?subject=" (url-hexify-string subject
)
131 "&body=" (url-hexify-string body
)))
132 (start-process "xdg-email" nil
"xdg-email"
135 (concat "mailto:" to
)))
136 (error "Subject, To or body not found")))))
139 (defun report-emacs-bug (topic &optional recent-keys
)
140 "Report a bug in GNU Emacs.
141 Prompts for bug subject. Leaves you in a mail buffer."
142 ;; This strange form ensures that (recent-keys) is the value before
143 ;; the bug subject string is read.
144 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
145 ;; The syntax `version;' is preferred to `[version]' because the
146 ;; latter could be mistakenly stripped by mailing software.
147 (if (eq system-type
'ms-dos
)
148 (setq topic
(concat emacs-version
"; " topic
))
149 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version
)
150 (setq topic
(concat (match-string 1 emacs-version
) "; " topic
))))
151 (let ((from-buffer (current-buffer))
152 ;; Put these properties on semantically-void text.
153 ;; report-emacs-bug-hook deletes these regions before sending.
154 (prompt-properties '(field emacsbug-prompt
155 intangible but-helpful
157 (can-insert-mail (or (report-emacs-bug-can-use-xdg-email)
158 (report-emacs-bug-can-use-osx-open)))
159 user-point message-end-point
)
160 (setq message-end-point
161 (with-current-buffer (get-buffer-create "*Messages*")
163 (compose-mail report-emacs-bug-address topic
)
164 ;; The rest of this does not execute if the user was asked to
165 ;; confirm and said no.
166 (when (eq major-mode
'message-mode
)
167 ;; Message-mode sorts the headers before sending. We sort now so
168 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
169 (message-sort-headers)
170 ;; Stop message-mode stealing the properties we will add.
171 (set (make-local-variable 'message-strip-special-text-properties
) nil
))
174 (let ((signature (buffer-substring (point) (point-max))))
175 (delete-region (point) (point-max))
177 (backward-char (length signature
)))
178 (unless report-emacs-bug-no-explanations
179 ;; Insert warnings for novice users.
180 (when (string-match "@gnu\\.org$" report-emacs-bug-address
)
181 (insert "This bug report will be sent to the Free Software Foundation,\n")
183 (insert "not to your local site managers!")
184 (overlay-put (make-overlay pos
(point)) 'face
'highlight
)))
185 (insert "\nPlease write in ")
188 (overlay-put (make-overlay pos
(point)) 'face
'highlight
))
189 (insert " if possible, because the Emacs maintainers
190 usually do not have translators to read other languages for them.\n\n")
191 (insert (format "Your report will be posted to the %s mailing list"
192 report-emacs-bug-address
))
193 (insert "\nand the gnu.emacs.bug news group, and at http://debbugs.gnu.org.\n\n"))
195 (insert "Please describe exactly what actions triggered the bug\n"
196 "and the precise symptoms of the bug. If you can, give\n"
197 "a recipe starting from `emacs -Q':\n\n")
198 (add-text-properties (save-excursion
200 (line-beginning-position 2))
203 (setq user-point
(point))
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")
210 (let ((debug-file (expand-file-name "DEBUG" data-directory
)))
211 (if (file-readable-p debug-file
)
212 (insert "For information about debugging Emacs, please read the file\n"
214 (add-text-properties (1+ user-point
) (point) prompt-properties
)
216 (insert "\n\nIn " (emacs-version) "\n")
217 (if (fboundp 'x-server-vendor
)
219 ;; This is used not only for X11 but also W32 and others.
220 (insert "Windowing system distributor `" (x-server-vendor)
222 (mapconcat 'number-to-string
(x-server-version) ".") "\n")
224 (if (and system-configuration-options
225 (not (equal system-configuration-options
"")))
226 (insert "configured using `configure "
227 system-configuration-options
"'\n\n"))
228 (insert "Important settings:\n")
231 (insert (format " value of $%s: %s\n" var
(getenv var
))))
232 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
233 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
234 (insert (format " locale-coding-system: %s\n" locale-coding-system
))
235 (insert (format " default enable-multibyte-characters: %s\n"
236 (default-value 'enable-multibyte-characters
)))
238 (insert (format "Major mode: %s\n"
240 (buffer-local-value 'mode-name from-buffer
)
241 nil nil from-buffer
)))
243 (insert "Minor modes in effect:\n")
244 (dolist (mode minor-mode-list
)
245 (and (boundp mode
) (buffer-local-value mode from-buffer
)
246 (insert (format " %s: %s\n" mode
247 (buffer-local-value mode from-buffer
)))))
249 (insert "Recent input:\n")
250 (let ((before-keys (point)))
251 (insert (mapconcat (lambda (key)
252 (if (or (integerp key
)
255 (single-key-description key
)
256 (prin1-to-string key nil
)))
257 (or recent-keys
(recent-keys))
260 (narrow-to-region before-keys
(point))
261 (goto-char before-keys
)
262 (while (progn (move-to-column 50) (not (eobp)))
263 (search-forward " " nil t
)
265 (let ((message-buf (get-buffer "*Messages*")))
268 (end-pos message-end-point
))
269 (with-current-buffer message-buf
272 (setq beg-pos
(point)))
273 (insert "\n\nRecent messages:\n")
274 (insert-buffer-substring message-buf beg-pos end-pos
))))
275 ;; After Recent messages, to avoid the messages produced by
276 ;; list-load-path-shadows.
277 (unless (looking-back "\n")
280 (insert "Load-path shadows:\n")
281 (message "Checking for load-path shadows...")
282 (let ((shadows (list-load-path-shadows t
)))
283 (message "Checking for load-path shadows...done")
284 (insert (if (zerop (length shadows
))
287 (insert (format "\nFeatures:\n%s\n" features
))
288 (fill-region (line-beginning-position 0) (point))
289 ;; This is so the user has to type something in order to send easily.
290 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
291 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info
)
293 (define-key (current-local-map) "\C-cm"
294 'report-emacs-bug-insert-to-mailer
))
295 (setq report-emacs-bug-send-command
(get mail-user-agent
'sendfunc
)
296 report-emacs-bug-send-hook
(get mail-user-agent
'hookvar
))
297 (if report-emacs-bug-send-command
298 (setq report-emacs-bug-send-command
299 (symbol-name report-emacs-bug-send-command
)))
300 (unless report-emacs-bug-no-explanations
301 (with-output-to-temp-buffer "*Bug Help*"
302 (princ "While in the mail buffer:\n\n")
303 (if report-emacs-bug-send-command
304 (princ (substitute-command-keys
305 (format " Type \\[%s] to send the bug report.\n"
306 report-emacs-bug-send-command
))))
307 (princ (substitute-command-keys
308 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
310 (princ (substitute-command-keys
311 " Type \\[report-emacs-bug-insert-to-mailer] to insert text to you preferred mail program.\n")))
313 (princ (substitute-command-keys
314 " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
315 about when and how to write a bug report, and what
316 information you should include to help fix the bug.")))
317 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
318 ;; Make it less likely people will send empty messages.
319 (if report-emacs-bug-send-hook
320 (add-hook report-emacs-bug-send-hook
'report-emacs-bug-hook nil t
))
321 (goto-char (point-max))
322 (skip-chars-backward " \t\n")
323 (make-local-variable 'report-emacs-bug-orig-text
)
324 (setq report-emacs-bug-orig-text
325 (buffer-substring-no-properties (point-min) (point)))
326 (goto-char user-point
)))
328 (defun report-emacs-bug-info ()
329 "Go to the Info node on reporting Emacs bugs."
331 (info "(emacs)Bugs"))
333 (defun report-emacs-bug-hook ()
334 "Do some checking before sending a bug report."
336 (goto-char (point-max))
337 (skip-chars-backward " \t\n")
338 (and (= (- (point) (point-min))
339 (length report-emacs-bug-orig-text
))
340 (string-equal (buffer-substring-no-properties (point-min) (point))
341 report-emacs-bug-orig-text
)
342 (error "No text entered in bug report"))
344 ;; The last warning for novice users.
345 (unless (or report-emacs-bug-no-confirmation
347 "Send this bug report to the Emacs maintainers? "))
348 (goto-char (point-min))
349 (if (search-forward "To: ")
350 (delete-region (point) (line-end-position)))
351 (if report-emacs-bug-send-hook
352 (kill-local-variable report-emacs-bug-send-hook
))
353 (with-output-to-temp-buffer "*Bug Help*"
354 (princ (substitute-command-keys
356 You invoked the command M-x report-emacs-bug,
357 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
)
366 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
368 ;; Delete the uninteresting text that was just to help fill out the report.
371 (let ((pos (1- (point))))
372 (while (setq pos
(text-property-any pos
(point-max)
373 'field
'emacsbug-prompt
))
374 (delete-region pos
(field-end (1+ pos
)))))))
377 ;; Querying the bug database
379 (defvar report-emacs-bug-bug-alist nil
)
380 (make-variable-buffer-local 'report-emacs-bug-bug-alist
)
381 (defvar report-emacs-bug-choice-widget nil
)
382 (make-variable-buffer-local 'report-emacs-bug-choice-widget
)
384 (defun report-emacs-bug-create-existing-bugs-buffer (bugs keywords
)
385 (switch-to-buffer (get-buffer-create "*Existing Emacs Bugs*"))
386 (setq buffer-read-only t
)
387 (let ((inhibit-read-only t
))
389 (setq report-emacs-bug-bug-alist bugs
)
390 (widget-insert (propertize (concat "Already known bugs ("
394 (setq report-emacs-bug-choice-widget
395 (apply 'widget-create
'radio-button-choice
401 :format
(concat "Bug#" (number-to-string (nth 2 bug
))
402 ": " (cadr bug
) "\n %[%v%]\n")
403 ;; FIXME: Why is only the link of the
404 ;; active item clickable?
408 (widget-insert "No bugs maching your keywords found.\n"))
410 (widget-create 'push-button
411 :notify
(lambda (&rest ignore
)
412 ;; TODO: Do something!
413 (message "Reporting new bug!"))
417 (widget-create 'push-button
418 :notify
(lambda (&rest ignore
)
419 (let ((val (widget-value report-emacs-bug-choice-widget
)))
420 ;; TODO: Do something!
421 (message "Appending to bug %s!"
422 (nth 2 (assoc val report-emacs-bug-bug-alist
)))))
423 "Append to chosen bug"))
425 (widget-create 'push-button
426 :notify
(lambda (&rest ignore
)
428 "Quit reporting bug")
429 (widget-insert "\n"))
430 (use-local-map widget-keymap
)
432 (goto-char (point-min)))
434 (defun report-emacs-bug-parse-query-results (status keywords
)
435 (goto-char (point-min))
437 (while (re-search-forward "<a href=\"bugreport\\.cgi\\?bug=\\([[:digit:]]+\\)\">\\([^<]+\\)</a>" nil t
)
438 (let ((number (match-string 1))
439 (subject (match-string 2)))
440 (when (not (string-match "^#" subject
))
443 (concat report-emacs-bug-tracker-url
444 "bugreport.cgi?bug=" number
)
445 ;; then the subject and number
446 subject
(string-to-number number
))
448 (report-emacs-bug-create-existing-bugs-buffer (nreverse buglist
) keywords
)))
450 (defun report-emacs-bug-query-existing-bugs (keywords)
451 "Query for KEYWORDS at `report-emacs-bug-tracker-url', and return the result.
452 The result is an alist with items of the form (URL SUBJECT NO)."
453 (interactive "sBug keywords (comma separated): ")
454 (url-retrieve (concat report-emacs-bug-tracker-url
455 "pkgreport.cgi?include=subject%3A"
456 (replace-regexp-in-string "[[:space:]]+" "+" keywords
)
458 'report-emacs-bug-parse-query-results
(list keywords
)))
462 ;;; emacsbug.el ends here