]> code.delx.au - gnu-emacs/blob - lisp/mail/emacsbug.el
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / lisp / mail / emacsbug.el
1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
2
3 ;; Copyright (C) 1985, 1994, 1997-1998, 2000-2011
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: K. Shane Hartman
7 ;; Maintainer: FSF
8 ;; Keywords: maint mail
9 ;; Package: emacs
10
11 ;; This file is part of GNU Emacs.
12
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.
17
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.
22
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/>.
25
26 ;;; Commentary:
27
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.
32
33 ;;; Code:
34
35 (defgroup emacsbug nil
36 "Sending Emacs bug reports."
37 :group 'maint
38 :group 'mail)
39
40 (define-obsolete-variable-alias 'report-emacs-bug-pretest-address
41 'report-emacs-bug-address "24.1")
42
43 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
44 "Address of mailing list for GNU Emacs bugs."
45 :group 'emacsbug
46 :type 'string)
47
48 (defcustom report-emacs-bug-no-confirmation nil
49 "If non-nil, suppress the confirmations asked for the sake of novice users."
50 :group 'emacsbug
51 :type 'boolean)
52
53 (defcustom report-emacs-bug-no-explanations nil
54 "If non-nil, suppress the explanations given for the sake of novice users."
55 :group 'emacsbug
56 :type 'boolean)
57
58 ;; User options end here.
59
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.")
63
64 (defvar report-emacs-bug-orig-text nil
65 "The automatically-created initial text of the bug report.")
66
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)
70
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)
74
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)
79
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.
86 (condition-case nil
87 (eq 0 (call-process
88 "dbus-send" nil nil nil
89 "--dest=org.gnome.SessionManager"
90 "--print-reply"
91 "/org/gnome/SessionManager"
92 "org.gnome.SessionManager.CanShutdown"))
93 (error nil))
94 (equal (getenv "KDE_FULL_SESSION") "true")
95 (condition-case nil
96 (eq 0 (call-process
97 "/bin/sh" nil nil nil
98 "-c"
99 "xprop -root _DT_SAVE_MODE|grep xfce4"))
100 (error nil)))))
101
102 (defun report-emacs-bug-insert-to-mailer ()
103 (interactive)
104 (save-excursion
105 (let* ((to (progn
106 (goto-char (point-min))
107 (forward-line)
108 (and (looking-at "^To: \\(.*\\)")
109 (match-string-no-properties 1))))
110 (subject (progn
111 (forward-line)
112 (and (looking-at "^Subject: \\(.*\\)")
113 (match-string-no-properties 1))))
114 (body (progn
115 (forward-line 2)
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"
120 "--subject" subject
121 "--body" body
122 (concat "mailto:" to))
123 (error "Subject, To or body not found")))))
124
125 ;;;###autoload
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
143 rear-nonsticky t))
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*")
148 (point-max-marker)))
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))
158 (rfc822-goto-eoh)
159 (forward-line 1)
160 (let ((signature (buffer-substring (point) (point-max))))
161 (delete-region (point) (point-max))
162 (insert signature)
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")
168 (let ((pos (point)))
169 (insert "not to your local site managers!")
170 (overlay-put (make-overlay pos (point)) 'face 'highlight)))
171 (insert "\nPlease write in ")
172 (let ((pos (point)))
173 (insert "English")
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"))
180
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
185 (rfc822-goto-eoh)
186 (line-beginning-position 2))
187 (point)
188 prompt-properties)
189 (setq user-point (point))
190 (insert "\n\n")
191
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")
195
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"
199 debug-file ".\n")))
200 (add-text-properties (1+ user-point) (point) prompt-properties)
201
202 (insert "\n\nIn " (emacs-version) "\n")
203 (if (fboundp 'x-server-vendor)
204 (condition-case nil
205 ;; This is used not only for X11 but also W32 and others.
206 (insert "Windowing system distributor `" (x-server-vendor)
207 "', version "
208 (mapconcat 'number-to-string (x-server-version) ".") "\n")
209 (error t)))
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")
215 (mapc
216 '(lambda (var)
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)))
223 (insert "\n")
224 (insert (format "Major mode: %s\n"
225 (format-mode-line
226 (buffer-local-value 'mode-name from-buffer)
227 nil nil from-buffer)))
228 (insert "\n")
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)))))
234 (insert "\n")
235 (insert "Recent input:\n")
236 (let ((before-keys (point)))
237 (insert (mapconcat (lambda (key)
238 (if (or (integerp key)
239 (symbolp key)
240 (listp key))
241 (single-key-description key)
242 (prin1-to-string key nil)))
243 (or recent-keys (recent-keys))
244 " "))
245 (save-restriction
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)
250 (insert "\n"))))
251 (let ((message-buf (get-buffer "*Messages*")))
252 (if message-buf
253 (let (beg-pos
254 (end-pos message-end-point))
255 (with-current-buffer message-buf
256 (goto-char end-pos)
257 (forward-line -10)
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")
264 (insert "\n"))
265 (insert "\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))
271 "None found.\n"
272 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)
278 (if can-xdg-email
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"))
295 (if can-xdg-email
296 (princ (substitute-command-keys
297 " Type \\[report-emacs-bug-insert-to-mailer] to insert text to you preferred mail program.\n")))
298 (terpri)
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)))
313
314 (defun report-emacs-bug-info ()
315 "Go to the Info node on reporting Emacs bugs."
316 (interactive)
317 (info "(emacs)Bugs"))
318
319 (defun report-emacs-bug-hook ()
320 "Do some checking before sending a bug report."
321 (save-excursion
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")
333 (unless (eobp)
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")
337 (not (eobp)))
338 (let ((ch (following-char)))
339 (delete-char 1)
340 (insert (format "=%02x" ch))))))
341
342 ;; The last warning for novice users.
343 (unless (or report-emacs-bug-no-confirmation
344 (yes-or-no-p
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
353 (format "\
354 You invoked the command M-x report-emacs-bug,
355 but you decided not to mail the bug report to the Emacs maintainers.
356
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)
363 "")))))
364 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
365
366 ;; Delete the uninteresting text that was just to help fill out the report.
367 (rfc822-goto-eoh)
368 (forward-line 1)
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)))))))
373
374
375 ;; Querying the bug database
376
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)
381
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))
386 (erase-buffer)
387 (setq report-emacs-bug-bug-alist bugs)
388 (widget-insert (propertize (concat "Already known bugs ("
389 keywords "):\n\n")
390 'face 'bold))
391 (if bugs
392 (setq report-emacs-bug-choice-widget
393 (apply 'widget-create 'radio-button-choice
394 :value (caar bugs)
395 (let (items)
396 (dolist (bug bugs)
397 (push (list
398 'url-link
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?
403 (car bug))
404 items))
405 (nreverse items))))
406 (widget-insert "No bugs maching your keywords found.\n"))
407 (widget-insert "\n")
408 (widget-create 'push-button
409 :notify (lambda (&rest ignore)
410 ;; TODO: Do something!
411 (message "Reporting new bug!"))
412 "Report new bug")
413 (when bugs
414 (widget-insert " ")
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"))
422 (widget-insert " ")
423 (widget-create 'push-button
424 :notify (lambda (&rest ignore)
425 (kill-buffer))
426 "Quit reporting bug")
427 (widget-insert "\n"))
428 (use-local-map widget-keymap)
429 (widget-setup)
430 (goto-char (point-min)))
431
432 (defun report-emacs-bug-parse-query-results (status keywords)
433 (goto-char (point-min))
434 (let (buglist)
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))
439 (push (list
440 ;; first the bug URL
441 (concat report-emacs-bug-tracker-url
442 "bugreport.cgi?bug=" number)
443 ;; then the subject and number
444 subject (string-to-number number))
445 buglist))))
446 (report-emacs-bug-create-existing-bugs-buffer (nreverse buglist) keywords)))
447
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)
455 ";package=emacs")
456 'report-emacs-bug-parse-query-results (list keywords)))
457
458 (provide 'emacsbug)
459
460 ;;; emacsbug.el ends here