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.
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.
60 (defvar report-emacs-bug-tracker-url "http://debbugs.gnu.org/cgi/"
61 "Base URL of the GNU bugtracker.
62 Used for querying duplicates and linking to existing bugs.")
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" ())
78 (defvar message-strip-special-text-properties)
80 (defun report-emacs-bug-can-use-xdg-email ()
81 "Check if xdg-email can be used, i.e. we are on Gnome, KDE or xfce4."
82 (and (getenv "DISPLAY")
83 (executable-find "xdg-email")
84 (or (getenv "GNOME_DESKTOP_SESSION_ID")
85 ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
88 "dbus-send" nil nil nil
89 "--dest=org.gnome.SessionManager"
91 "/org/gnome/SessionManager"
92 "org.gnome.SessionManager.CanShutdown"))
94 (equal (getenv "KDE_FULL_SESSION") "true")
99 "xprop -root _DT_SAVE_MODE|grep xfce4"))
102 (defun report-emacs-bug-insert-to-mailer ()
106 (goto-char (point-min))
108 (and (looking-at "^To: \\(.*\\)")
109 (match-string-no-properties 1))))
112 (and (looking-at "^Subject: \\(.*\\)")
113 (match-string-no-properties 1))))
116 (if (> (point-max) (point))
117 (buffer-substring-no-properties (point) (point-max))))))
118 (if (and to subject body)
119 (start-process "xdg-email" nil "xdg-email"
122 (concat "mailto:" to))
123 (error "Subject, To or body not found")))))
126 (defun report-emacs-bug (topic &optional recent-keys)
127 "Report a bug in GNU Emacs.
128 Prompts for bug subject. Leaves you in a mail buffer."
129 ;; This strange form ensures that (recent-keys) is the value before
130 ;; the bug subject string is read.
131 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
132 ;; The syntax `version;' is preferred to `[version]' because the
133 ;; latter could be mistakenly stripped by mailing software.
134 (if (eq system-type 'ms-dos)
135 (setq topic (concat emacs-version "; " topic))
136 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
137 (setq topic (concat (match-string 1 emacs-version) "; " topic))))
138 (let ((from-buffer (current-buffer))
139 ;; Put these properties on semantically-void text.
140 ;; report-emacs-bug-hook deletes these regions before sending.
141 (prompt-properties '(field emacsbug-prompt
142 intangible but-helpful
144 (can-xdg-email (report-emacs-bug-can-use-xdg-email))
145 user-point message-end-point)
146 (setq message-end-point
147 (with-current-buffer (get-buffer-create "*Messages*")
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))
160 (let ((signature (buffer-substring (point) (point-max))))
161 (delete-region (point) (point-max))
163 (backward-char (length signature)))
164 (unless report-emacs-bug-no-explanations
165 ;; Insert warnings for novice users.
166 (when (string-match "@gnu\\.org$" report-emacs-bug-address)
167 (insert "This bug report will be sent to the Free Software Foundation,\n")
169 (insert "not to your local site managers!")
170 (overlay-put (make-overlay pos (point)) 'face 'highlight)))
171 (insert "\nPlease write in ")
174 (overlay-put (make-overlay pos (point)) 'face 'highlight))
175 (insert " if possible, because the Emacs maintainers
176 usually do not have translators to read other languages for them.\n\n")
177 (insert (format "Your report will be posted to the %s mailing list"
178 report-emacs-bug-address))
179 (insert "\nand the gnu.emacs.bug news group, and at http://debbugs.gnu.org.\n\n"))
181 (insert "Please describe exactly what actions triggered the bug\n"
182 "and the precise symptoms of the bug. If you can, give\n"
183 "a recipe starting from `emacs -Q':\n\n")
184 (add-text-properties (save-excursion
186 (line-beginning-position 2))
189 (setq user-point (point))
192 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
193 "please include the output from the following gdb commands:\n"
194 " `bt full' and `xbacktrace'.\n")
196 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
197 (if (file-readable-p debug-file)
198 (insert "For information about debugging Emacs, please read the file\n"
200 (add-text-properties (1+ user-point) (point) prompt-properties)
202 (insert "\n\nIn " (emacs-version) "\n")
203 (if (fboundp 'x-server-vendor)
205 ;; This is used not only for X11 but also W32 and others.
206 (insert "Windowing system distributor `" (x-server-vendor)
208 (mapconcat 'number-to-string (x-server-version) ".") "\n")
210 (if (and system-configuration-options
211 (not (equal system-configuration-options "")))
212 (insert "configured using `configure "
213 system-configuration-options "'\n\n"))
214 (insert "Important settings:\n")
217 (insert (format " value of $%s: %s\n" var (getenv var))))
218 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
219 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
220 (insert (format " locale-coding-system: %s\n" locale-coding-system))
221 (insert (format " default enable-multibyte-characters: %s\n"
222 (default-value 'enable-multibyte-characters)))
224 (insert (format "Major mode: %s\n"
226 (buffer-local-value 'mode-name from-buffer)
227 nil nil from-buffer)))
229 (insert "Minor modes in effect:\n")
230 (dolist (mode minor-mode-list)
231 (and (boundp mode) (buffer-local-value mode from-buffer)
232 (insert (format " %s: %s\n" mode
233 (buffer-local-value mode from-buffer)))))
235 (insert "Recent input:\n")
236 (let ((before-keys (point)))
237 (insert (mapconcat (lambda (key)
238 (if (or (integerp key)
241 (single-key-description key)
242 (prin1-to-string key nil)))
243 (or recent-keys (recent-keys))
246 (narrow-to-region before-keys (point))
247 (goto-char before-keys)
248 (while (progn (move-to-column 50) (not (eobp)))
249 (search-forward " " nil t)
251 (let ((message-buf (get-buffer "*Messages*")))
254 (end-pos message-end-point))
255 (with-current-buffer message-buf
258 (setq beg-pos (point)))
259 (insert "\n\nRecent messages:\n")
260 (insert-buffer-substring message-buf beg-pos end-pos))))
261 ;; After Recent messages, to avoid the messages produced by
262 ;; list-load-path-shadows.
263 (unless (looking-back "\n")
266 (insert "Load-path shadows:\n")
267 (message "Checking for load-path shadows...")
268 (let ((shadows (list-load-path-shadows t)))
269 (message "Checking for load-path shadows...done")
270 (insert (if (zerop (length shadows))
273 (insert (format "\nFeatures:\n%s\n" features))
274 (fill-region (line-beginning-position 0) (point))
275 ;; This is so the user has to type something in order to send easily.
276 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
277 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
279 (define-key (current-local-map) "\C-cm"
280 'report-emacs-bug-insert-to-mailer))
281 (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc)
282 report-emacs-bug-send-hook (get mail-user-agent 'hookvar))
283 (if report-emacs-bug-send-command
284 (setq report-emacs-bug-send-command
285 (symbol-name report-emacs-bug-send-command)))
286 (unless report-emacs-bug-no-explanations
287 (with-output-to-temp-buffer "*Bug Help*"
288 (princ "While in the mail buffer:\n\n")
289 (if report-emacs-bug-send-command
290 (princ (substitute-command-keys
291 (format " Type \\[%s] to send the bug report.\n"
292 report-emacs-bug-send-command))))
293 (princ (substitute-command-keys
294 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
296 (princ (substitute-command-keys
297 " Type \\[report-emacs-bug-insert-to-mailer] to insert text to you preferred mail program.\n")))
299 (princ (substitute-command-keys
300 " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
301 about when and how to write a bug report, and what
302 information you should include to help fix the bug.")))
303 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
304 ;; Make it less likely people will send empty messages.
305 (if report-emacs-bug-send-hook
306 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
307 (goto-char (point-max))
308 (skip-chars-backward " \t\n")
309 (make-local-variable 'report-emacs-bug-orig-text)
310 (setq report-emacs-bug-orig-text
311 (buffer-substring-no-properties (point-min) (point)))
312 (goto-char user-point)))
314 (defun report-emacs-bug-info ()
315 "Go to the Info node on reporting Emacs bugs."
317 (info "(emacs)Bugs"))
319 (defun report-emacs-bug-hook ()
320 "Do some checking before sending a bug report."
322 (goto-char (point-max))
323 (skip-chars-backward " \t\n")
324 (and (= (- (point) (point-min))
325 (length report-emacs-bug-orig-text))
326 (string-equal (buffer-substring-no-properties (point-min) (point))
327 report-emacs-bug-orig-text)
328 (error "No text entered in bug report"))
329 ;; Check the buffer contents and reject non-English letters.
330 ;; FIXME message-mode probably does this anyway.
331 (goto-char (point-min))
332 (skip-chars-forward "\0-\177")
334 (if (or report-emacs-bug-no-confirmation
335 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
336 (while (progn (skip-chars-forward "\0-\177")
338 (let ((ch (following-char)))
340 (insert (format "=%02x" ch))))))
342 ;; The last warning for novice users.
343 (unless (or report-emacs-bug-no-confirmation
345 "Send this bug report to the Emacs maintainers? "))
346 (goto-char (point-min))
347 (if (search-forward "To: ")
348 (delete-region (point) (line-end-position)))
349 (if report-emacs-bug-send-hook
350 (kill-local-variable report-emacs-bug-send-hook))
351 (with-output-to-temp-buffer "*Bug Help*"
352 (princ (substitute-command-keys
354 You invoked the command M-x report-emacs-bug,
355 but you decided not to mail the bug report to the Emacs maintainers.
357 If you want to mail it to someone else instead,
358 please insert the proper e-mail address after \"To: \",
359 and send the mail again%s."
360 (if report-emacs-bug-send-command
361 (format " using \\[%s]"
362 report-emacs-bug-send-command)
364 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
366 ;; Delete the uninteresting text that was just to help fill out the report.
369 (let ((pos (1- (point))))
370 (while (setq pos (text-property-any pos (point-max)
371 'field 'emacsbug-prompt))
372 (delete-region pos (field-end (1+ pos)))))))
375 ;; Querying the bug database
377 (defvar report-emacs-bug-bug-alist nil)
378 (make-variable-buffer-local 'report-emacs-bug-bug-alist)
379 (defvar report-emacs-bug-choice-widget nil)
380 (make-variable-buffer-local 'report-emacs-bug-choice-widget)
382 (defun report-emacs-bug-create-existing-bugs-buffer (bugs keywords)
383 (switch-to-buffer (get-buffer-create "*Existing Emacs Bugs*"))
384 (setq buffer-read-only t)
385 (let ((inhibit-read-only t))
387 (setq report-emacs-bug-bug-alist bugs)
388 (widget-insert (propertize (concat "Already known bugs ("
392 (setq report-emacs-bug-choice-widget
393 (apply 'widget-create 'radio-button-choice
399 :format (concat "Bug#" (number-to-string (nth 2 bug))
400 ": " (cadr bug) "\n %[%v%]\n")
401 ;; FIXME: Why is only the link of the
402 ;; active item clickable?
406 (widget-insert "No bugs maching your keywords found.\n"))
408 (widget-create 'push-button
409 :notify (lambda (&rest ignore)
410 ;; TODO: Do something!
411 (message "Reporting new bug!"))
415 (widget-create 'push-button
416 :notify (lambda (&rest ignore)
417 (let ((val (widget-value report-emacs-bug-choice-widget)))
418 ;; TODO: Do something!
419 (message "Appending to bug %s!"
420 (nth 2 (assoc val report-emacs-bug-bug-alist)))))
421 "Append to chosen bug"))
423 (widget-create 'push-button
424 :notify (lambda (&rest ignore)
426 "Quit reporting bug")
427 (widget-insert "\n"))
428 (use-local-map widget-keymap)
430 (goto-char (point-min)))
432 (defun report-emacs-bug-parse-query-results (status keywords)
433 (goto-char (point-min))
435 (while (re-search-forward "<a href=\"bugreport\\.cgi\\?bug=\\([[:digit:]]+\\)\">\\([^<]+\\)</a>" nil t)
436 (let ((number (match-string 1))
437 (subject (match-string 2)))
438 (when (not (string-match "^#" subject))
441 (concat report-emacs-bug-tracker-url
442 "bugreport.cgi?bug=" number)
443 ;; then the subject and number
444 subject (string-to-number number))
446 (report-emacs-bug-create-existing-bugs-buffer (nreverse buglist) keywords)))
448 (defun report-emacs-bug-query-existing-bugs (keywords)
449 "Query for KEYWORDS at `report-emacs-bug-tracker-url', and return the result.
450 The result is an alist with items of the form (URL SUBJECT NO)."
451 (interactive "sBug keywords (comma separated): ")
452 (url-retrieve (concat report-emacs-bug-tracker-url
453 "pkgreport.cgi?include=subject%3A"
454 (replace-regexp-in-string "[[:space:]]+" "+" keywords)
456 'report-emacs-bug-parse-query-results (list keywords)))
460 ;;; emacsbug.el ends here