Don't quote lambda expressions with `quote'.
[bpt/emacs.git] / lisp / mail / emacsbug.el
CommitLineData
55535639 1;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
c0274f38 2
73b0cd50 3;; Copyright (C) 1985, 1994, 1997-1998, 2000-2011
893db5bc 4;; Free Software Foundation, Inc.
9750e079 5
e5167999 6;; Author: K. Shane Hartman
2f14b48d 7;; Maintainer: FSF
fbd410d6 8;; Keywords: maint mail
bd78fa1d 9;; Package: emacs
2f14b48d 10
a2535589
JA
11;; This file is part of GNU Emacs.
12
b1fc2b50 13;; GNU Emacs is free software: you can redistribute it and/or modify
a2535589 14;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
a2535589
JA
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
b1fc2b50 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a2535589 25
e41b2db1
ER
26;;; Commentary:
27
b92a07e0 28;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
4d8da9a4
GM
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.
e41b2db1 32
2f14b48d 33;;; Code:
a2535589 34
253f7d1b
JD
35(require 'url-util)
36
fbd410d6
RS
37(defgroup emacsbug nil
38 "Sending Emacs bug reports."
39 :group 'maint
40 :group 'mail)
41
27be0364
GM
42(define-obsolete-variable-alias 'report-emacs-bug-pretest-address
43 'report-emacs-bug-address "24.1")
44
9b4e41ac 45(defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
4d8da9a4 46 "Address of mailing list for GNU Emacs bugs."
7b27eb53
RS
47 :group 'emacsbug
48 :type 'string)
a85a468e 49
fbd410d6 50(defcustom report-emacs-bug-no-confirmation nil
4d8da9a4 51 "If non-nil, suppress the confirmations asked for the sake of novice users."
fbd410d6
RS
52 :group 'emacsbug
53 :type 'boolean)
54
55(defcustom report-emacs-bug-no-explanations nil
4d8da9a4 56 "If non-nil, suppress the explanations given for the sake of novice users."
fbd410d6
RS
57 :group 'emacsbug
58 :type 'boolean)
fe1d8b33 59
4d8da9a4
GM
60;; User options end here.
61
614316a7
TH
62(defvar report-emacs-bug-tracker-url "http://debbugs.gnu.org/cgi/"
63 "Base URL of the GNU bugtracker.
64Used for querying duplicates and linking to existing bugs.")
4d8da9a4
GM
65
66(defvar report-emacs-bug-orig-text nil
85094855
GM
67 "The automatically-created initial text of the bug report.")
68
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)
72
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)
4d8da9a4 76
aa360da1
GM
77(declare-function x-server-vendor "xfns.c" (&optional terminal))
78(declare-function x-server-version "xfns.c" (&optional terminal))
a0cefee5 79(declare-function message-sort-headers "message" ())
27be0364 80(defvar message-strip-special-text-properties)
aa360da1 81
253f7d1b
JD
82(defun report-emacs-bug-can-use-osx-open ()
83 "Check if OSX open can be used to insert bug report into mailer"
84 (and (featurep 'ns)
85 (equal (executable-find "open") "/usr/bin/open")
86 (memq system-type '(darwin))))
87
489cd5bd
JD
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.
94 (condition-case nil
95 (eq 0 (call-process
96 "dbus-send" nil nil nil
97 "--dest=org.gnome.SessionManager"
98 "--print-reply"
99 "/org/gnome/SessionManager"
100 "org.gnome.SessionManager.CanShutdown"))
101 (error nil))
102 (equal (getenv "KDE_FULL_SESSION") "true")
103 (condition-case nil
104 (eq 0 (call-process
105 "/bin/sh" nil nil nil
106 "-c"
107 "xprop -root _DT_SAVE_MODE|grep xfce4"))
108 (error nil)))))
109
110(defun report-emacs-bug-insert-to-mailer ()
111 (interactive)
112 (save-excursion
113 (let* ((to (progn
114 (goto-char (point-min))
115 (forward-line)
116 (and (looking-at "^To: \\(.*\\)")
117 (match-string-no-properties 1))))
118 (subject (progn
119 (forward-line)
120 (and (looking-at "^Subject: \\(.*\\)")
121 (match-string-no-properties 1))))
122 (body (progn
123 (forward-line 2)
124 (if (> (point-max) (point))
125 (buffer-substring-no-properties (point) (point-max))))))
126 (if (and to subject body)
253f7d1b
JD
127 (if (report-emacs-bug-can-use-osx-open)
128 (start-process "/usr/bin/open" nil "open"
129 (concat "mailto:" to
130 "?subject=" (url-hexify-string subject)
131 "&body=" (url-hexify-string body)))
132 (start-process "xdg-email" nil "xdg-email"
133 "--subject" subject
134 "--body" body
135 (concat "mailto:" to)))
489cd5bd
JD
136 (error "Subject, To or body not found")))))
137
aa228418 138;;;###autoload
01753e63 139(defun report-emacs-bug (topic &optional recent-keys)
aa228418 140 "Report a bug in GNU Emacs.
a2535589 141Prompts for bug subject. Leaves you in a mail buffer."
01753e63
EN
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: "))))
a722966c
MC
145 ;; The syntax `version;' is preferred to `[version]' because the
146 ;; latter could be mistakenly stripped by mailing software.
ef77dde4
MC
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))))
27be0364
GM
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
156 rear-nonsticky t))
253f7d1b
JD
157 (can-insert-mail (or (report-emacs-bug-can-use-xdg-email)
158 (report-emacs-bug-can-use-osx-open)))
27be0364 159 user-point message-end-point)
0a18209b 160 (setq message-end-point
5e11c425 161 (with-current-buffer (get-buffer-create "*Messages*")
0a18209b 162 (point-max-marker)))
27be0364 163 (compose-mail report-emacs-bug-address topic)
2f1b7dc4
GM
164 ;; The rest of this does not execute if the user was asked to
165 ;; confirm and said no.
27be0364
GM
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))
9e68869b
RS
172 (rfc822-goto-eoh)
173 (forward-line 1)
9e68869b 174 (let ((signature (buffer-substring (point) (point-max))))
9e68869b 175 (delete-region (point) (point-max))
518adca2
RS
176 (insert signature)
177 (backward-char (length signature)))
fbd410d6
RS
178 (unless report-emacs-bug-no-explanations
179 ;; Insert warnings for novice users.
27be0364 180 (when (string-match "@gnu\\.org$" report-emacs-bug-address)
53dab082
EZ
181 (insert "This bug report will be sent to the Free Software Foundation,\n")
182 (let ((pos (point)))
183 (insert "not to your local site managers!")
85094855 184 (overlay-put (make-overlay pos (point)) 'face 'highlight)))
a722966c 185 (insert "\nPlease write in ")
fbd410d6
RS
186 (let ((pos (point)))
187 (insert "English")
85094855 188 (overlay-put (make-overlay pos (point)) 'face 'highlight))
9210027b
RS
189 (insert " if possible, because the Emacs maintainers
190usually do not have translators to read other languages for them.\n\n")
7163badd 191 (insert (format "Your report will be posted to the %s mailing list"
27be0364 192 report-emacs-bug-address))
220d91b8 193 (insert "\nand the gnu.emacs.bug news group, and at http://debbugs.gnu.org.\n\n"))
fe1d8b33 194
515ced27 195 (insert "Please describe exactly what actions triggered the bug\n"
31c615e4
GM
196 "and the precise symptoms of the bug. If you can, give\n"
197 "a recipe starting from `emacs -Q':\n\n")
85094855
GM
198 (add-text-properties (save-excursion
199 (rfc822-goto-eoh)
200 (line-beginning-position 2))
201 (point)
9888f112 202 prompt-properties)
515ced27 203 (setq user-point (point))
3a7f4c18
KS
204 (insert "\n\n")
205
fca615d5 206 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
3a7f4c18
KS
207 "please include the output from the following gdb commands:\n"
208 " `bt full' and `xbacktrace'.\n")
209
210 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
211 (if (file-readable-p debug-file)
00006066
CY
212 (insert "For information about debugging Emacs, please read the file\n"
213 debug-file ".\n")))
9888f112 214 (add-text-properties (1+ user-point) (point) prompt-properties)
515ced27 215
3a7f4c18 216 (insert "\n\nIn " (emacs-version) "\n")
f4982064 217 (if (fboundp 'x-server-vendor)
6f8a2742 218 (condition-case nil
951c155f
SM
219 ;; This is used not only for X11 but also W32 and others.
220 (insert "Windowing system distributor `" (x-server-vendor)
221 "', version "
6f8a2742
JD
222 (mapconcat 'number-to-string (x-server-version) ".") "\n")
223 (error t)))
0a18209b
KH
224 (if (and system-configuration-options
225 (not (equal system-configuration-options "")))
226 (insert "configured using `configure "
515ced27 227 system-configuration-options "'\n\n"))
dc81f8a2 228 (insert "Important settings:\n")
1daad47d 229 (mapc
4f91a816
SM
230 (lambda (var)
231 (insert (format " value of $%s: %s\n" var (getenv var))))
249dd409 232 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
5dae4230 233 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
dc81f8a2 234 (insert (format " locale-coding-system: %s\n" locale-coding-system))
597e2240
GM
235 (insert (format " default enable-multibyte-characters: %s\n"
236 (default-value 'enable-multibyte-characters)))
0a18209b 237 (insert "\n")
3c3ba27b 238 (insert (format "Major mode: %s\n"
48d33090
SM
239 (format-mode-line
240 (buffer-local-value 'mode-name from-buffer)
241 nil nil from-buffer)))
e927088b
RS
242 (insert "\n")
243 (insert "Minor modes in effect:\n")
244 (dolist (mode minor-mode-list)
3c3ba27b
RS
245 (and (boundp mode) (buffer-local-value mode from-buffer)
246 (insert (format " %s: %s\n" mode
247 (buffer-local-value mode from-buffer)))))
e927088b 248 (insert "\n")
515ced27 249 (insert "Recent input:\n")
0a18209b
KH
250 (let ((before-keys (point)))
251 (insert (mapconcat (lambda (key)
252 (if (or (integerp key)
253 (symbolp key)
254 (listp key))
255 (single-key-description key)
256 (prin1-to-string key nil)))
257 (or recent-keys (recent-keys))
258 " "))
259 (save-restriction
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)
264 (insert "\n"))))
265 (let ((message-buf (get-buffer "*Messages*")))
266 (if message-buf
267 (let (beg-pos
268 (end-pos message-end-point))
269 (with-current-buffer message-buf
270 (goto-char end-pos)
271 (forward-line -10)
272 (setq beg-pos (point)))
273 (insert "\n\nRecent messages:\n")
274 (insert-buffer-substring message-buf beg-pos end-pos))))
0b952197
GM
275 ;; After Recent messages, to avoid the messages produced by
276 ;; list-load-path-shadows.
277 (unless (looking-back "\n")
278 (insert "\n"))
279 (insert "\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))
285 "None found.\n"
286 shadows)))
9656d87b
GM
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.
0a18209b
KH
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)
253f7d1b 292 (if can-insert-mail
bd78fa1d 293 (define-key (current-local-map) "\C-cm"
489cd5bd 294 'report-emacs-bug-insert-to-mailer))
e554b3f8
GM
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)))
e9227982
RS
300 (unless report-emacs-bug-no-explanations
301 (with-output-to-temp-buffer "*Bug Help*"
3e425845 302 (princ "While in the mail buffer:\n\n")
85094855 303 (if report-emacs-bug-send-command
d8194864 304 (princ (substitute-command-keys
85094855
GM
305 (format " Type \\[%s] to send the bug report.\n"
306 report-emacs-bug-send-command))))
e9227982 307 (princ (substitute-command-keys
3e425845 308 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
253f7d1b 309 (if can-insert-mail
489cd5bd
JD
310 (princ (substitute-command-keys
311 " Type \\[report-emacs-bug-insert-to-mailer] to insert text to you preferred mail program.\n")))
e9227982
RS
312 (terpri)
313 (princ (substitute-command-keys
3e425845
CY
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*")))
0a18209b 318 ;; Make it less likely people will send empty messages.
85094855
GM
319 (if report-emacs-bug-send-hook
320 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
2f1b7dc4
GM
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)))
0a18209b 326 (goto-char user-point)))
e24ec555 327
1628adc6
KH
328(defun report-emacs-bug-info ()
329 "Go to the Info node on reporting Emacs bugs."
330 (interactive)
4d8da9a4 331 (info "(emacs)Bugs"))
1628adc6 332
e24ec555 333(defun report-emacs-bug-hook ()
85094855 334 "Do some checking before sending a bug report."
e24ec555 335 (save-excursion
85094855
GM
336 (goto-char (point-max))
337 (skip-chars-backward " \t\n")
85094855
GM
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"))
fe1d8b33
KH
343
344 ;; The last warning for novice users.
85094855
GM
345 (unless (or report-emacs-bug-no-confirmation
346 (yes-or-no-p
347 "Send this bug report to the Emacs maintainers? "))
fe1d8b33
KH
348 (goto-char (point-min))
349 (if (search-forward "To: ")
85094855
GM
350 (delete-region (point) (line-end-position)))
351 (if report-emacs-bug-send-hook
352 (kill-local-variable report-emacs-bug-send-hook))
fe1d8b33 353 (with-output-to-temp-buffer "*Bug Help*"
85094855
GM
354 (princ (substitute-command-keys
355 (format "\
02f6b354
RS
356You invoked the command M-x report-emacs-bug,
357but you decided not to mail the bug report to the Emacs maintainers.
fe1d8b33 358
02f6b354
RS
359If you want to mail it to someone else instead,
360please insert the proper e-mail address after \"To: \",
85094855
GM
361and send the mail again%s."
362 (if report-emacs-bug-send-command
363 (format " using \\[%s]"
364 report-emacs-bug-send-command)
365 "")))))
02f6b354 366 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
ea33ba73 367
85094855
GM
368 ;; Delete the uninteresting text that was just to help fill out the report.
369 (rfc822-goto-eoh)
370 (forward-line 1)
9888f112
TTN
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)))))))
a2535589 375
614316a7
TH
376
377;; Querying the bug database
378
e554b3f8
GM
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)
383
7dcd777e 384(defun report-emacs-bug-create-existing-bugs-buffer (bugs keywords)
614316a7
TH
385 (switch-to-buffer (get-buffer-create "*Existing Emacs Bugs*"))
386 (setq buffer-read-only t)
387 (let ((inhibit-read-only t))
388 (erase-buffer)
e554b3f8 389 (setq report-emacs-bug-bug-alist bugs)
7dcd777e
TH
390 (widget-insert (propertize (concat "Already known bugs ("
391 keywords "):\n\n")
392 'face 'bold))
614316a7 393 (if bugs
e554b3f8 394 (setq report-emacs-bug-choice-widget
614316a7 395 (apply 'widget-create 'radio-button-choice
a140ec5f 396 :value (caar bugs)
614316a7
TH
397 (let (items)
398 (dolist (bug bugs)
399 (push (list
400 'url-link
f62f063d 401 :format (concat "Bug#" (number-to-string (nth 2 bug))
a140ec5f 402 ": " (cadr bug) "\n %[%v%]\n")
614316a7
TH
403 ;; FIXME: Why is only the link of the
404 ;; active item clickable?
f62f063d 405 (car bug))
614316a7
TH
406 items))
407 (nreverse items))))
408 (widget-insert "No bugs maching your keywords found.\n"))
409 (widget-insert "\n")
410 (widget-create 'push-button
411 :notify (lambda (&rest ignore)
412 ;; TODO: Do something!
413 (message "Reporting new bug!"))
414 "Report new bug")
415 (when bugs
416 (widget-insert " ")
417 (widget-create 'push-button
418 :notify (lambda (&rest ignore)
e554b3f8 419 (let ((val (widget-value report-emacs-bug-choice-widget)))
614316a7
TH
420 ;; TODO: Do something!
421 (message "Appending to bug %s!"
e554b3f8 422 (nth 2 (assoc val report-emacs-bug-bug-alist)))))
614316a7
TH
423 "Append to chosen bug"))
424 (widget-insert " ")
425 (widget-create 'push-button
426 :notify (lambda (&rest ignore)
427 (kill-buffer))
428 "Quit reporting bug")
429 (widget-insert "\n"))
430 (use-local-map widget-keymap)
431 (widget-setup)
432 (goto-char (point-min)))
433
7dcd777e 434(defun report-emacs-bug-parse-query-results (status keywords)
614316a7
TH
435 (goto-char (point-min))
436 (let (buglist)
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))
441 (push (list
442 ;; first the bug URL
443 (concat report-emacs-bug-tracker-url
444 "bugreport.cgi?bug=" number)
445 ;; then the subject and number
446 subject (string-to-number number))
447 buglist))))
7dcd777e 448 (report-emacs-bug-create-existing-bugs-buffer (nreverse buglist) keywords)))
614316a7
TH
449
450(defun report-emacs-bug-query-existing-bugs (keywords)
451 "Query for KEYWORDS at `report-emacs-bug-tracker-url', and return the result.
452The result is an alist with items of the form (URL SUBJECT NO)."
331460ac 453 (interactive "sBug keywords (comma separated): ")
614316a7
TH
454 (url-retrieve (concat report-emacs-bug-tracker-url
455 "pkgreport.cgi?include=subject%3A"
456 (replace-regexp-in-string "[[:space:]]+" "+" keywords)
457 ";package=emacs")
7dcd777e 458 'report-emacs-bug-parse-query-results (list keywords)))
614316a7 459
8e0ff8c8
ER
460(provide 'emacsbug)
461
c0274f38 462;;; emacsbug.el ends here