Commit | Line | Data |
---|---|---|
55535639 | 1 | ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list |
c0274f38 | 2 | |
acaf905b | 3 | ;; Copyright (C) 1985, 1994, 1997-1998, 2000-2012 |
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 | |
fbd410d6 RS |
35 | (defgroup emacsbug nil |
36 | "Sending Emacs bug reports." | |
37 | :group 'maint | |
38 | :group 'mail) | |
39 | ||
27be0364 GM |
40 | (define-obsolete-variable-alias 'report-emacs-bug-pretest-address |
41 | 'report-emacs-bug-address "24.1") | |
42 | ||
9b4e41ac | 43 | (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org" |
4d8da9a4 | 44 | "Address of mailing list for GNU Emacs bugs." |
7b27eb53 RS |
45 | :group 'emacsbug |
46 | :type 'string) | |
a85a468e | 47 | |
fbd410d6 | 48 | (defcustom report-emacs-bug-no-confirmation nil |
4d8da9a4 | 49 | "If non-nil, suppress the confirmations asked for the sake of novice users." |
fbd410d6 RS |
50 | :group 'emacsbug |
51 | :type 'boolean) | |
52 | ||
53 | (defcustom report-emacs-bug-no-explanations nil | |
4d8da9a4 | 54 | "If non-nil, suppress the explanations given for the sake of novice users." |
fbd410d6 RS |
55 | :group 'emacsbug |
56 | :type 'boolean) | |
fe1d8b33 | 57 | |
4d8da9a4 GM |
58 | ;; User options end here. |
59 | ||
614316a7 TH |
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.") | |
4d8da9a4 GM |
63 | |
64 | (defvar report-emacs-bug-orig-text nil | |
85094855 GM |
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) | |
4d8da9a4 | 74 | |
aa360da1 GM |
75 | (declare-function x-server-vendor "xfns.c" (&optional terminal)) |
76 | (declare-function x-server-version "xfns.c" (&optional terminal)) | |
a0cefee5 | 77 | (declare-function message-sort-headers "message" ()) |
27be0364 | 78 | (defvar message-strip-special-text-properties) |
aa360da1 | 79 | |
253f7d1b | 80 | (defun report-emacs-bug-can-use-osx-open () |
3f88cd72 | 81 | "Return non-nil if the OS X \"open\" command is available for mailing." |
253f7d1b JD |
82 | (and (featurep 'ns) |
83 | (equal (executable-find "open") "/usr/bin/open") | |
84 | (memq system-type '(darwin)))) | |
85 | ||
3f88cd72 | 86 | ;; FIXME this duplicates much of the logic from browse-url-can-use-xdg-open. |
489cd5bd | 87 | (defun report-emacs-bug-can-use-xdg-email () |
3f88cd72 GM |
88 | "Return non-nil if the \"xdg-email\" command can be used. |
89 | xdg-email is a desktop utility that calls your preferred mail client. | |
90 | This requires you to be running either Gnome, KDE, or Xfce4." | |
489cd5bd JD |
91 | (and (getenv "DISPLAY") |
92 | (executable-find "xdg-email") | |
93 | (or (getenv "GNOME_DESKTOP_SESSION_ID") | |
94 | ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also. | |
95 | (condition-case nil | |
96 | (eq 0 (call-process | |
97 | "dbus-send" nil nil nil | |
98 | "--dest=org.gnome.SessionManager" | |
99 | "--print-reply" | |
100 | "/org/gnome/SessionManager" | |
101 | "org.gnome.SessionManager.CanShutdown")) | |
102 | (error nil)) | |
103 | (equal (getenv "KDE_FULL_SESSION") "true") | |
3f88cd72 GM |
104 | ;; FIXME? browse-url-can-use-xdg-open also accepts LXDE. |
105 | ;; Is that no good here, or just overlooked? | |
489cd5bd JD |
106 | (condition-case nil |
107 | (eq 0 (call-process | |
108 | "/bin/sh" nil nil nil | |
109 | "-c" | |
3f88cd72 | 110 | ;; FIXME use string-match rather than grep. |
489cd5bd JD |
111 | "xprop -root _DT_SAVE_MODE|grep xfce4")) |
112 | (error nil))))) | |
113 | ||
114 | (defun report-emacs-bug-insert-to-mailer () | |
3f88cd72 GM |
115 | "Send the message to your preferred mail client. |
116 | This requires either the OS X \"open\" command, or the freedesktop | |
117 | \"xdg-email\" command to be available." | |
489cd5bd JD |
118 | (interactive) |
119 | (save-excursion | |
3f88cd72 | 120 | ;; FIXME? use mail-fetch-field? |
489cd5bd JD |
121 | (let* ((to (progn |
122 | (goto-char (point-min)) | |
123 | (forward-line) | |
124 | (and (looking-at "^To: \\(.*\\)") | |
125 | (match-string-no-properties 1)))) | |
126 | (subject (progn | |
127 | (forward-line) | |
128 | (and (looking-at "^Subject: \\(.*\\)") | |
129 | (match-string-no-properties 1)))) | |
130 | (body (progn | |
131 | (forward-line 2) | |
132 | (if (> (point-max) (point)) | |
133 | (buffer-substring-no-properties (point) (point-max)))))) | |
134 | (if (and to subject body) | |
253f7d1b JD |
135 | (if (report-emacs-bug-can-use-osx-open) |
136 | (start-process "/usr/bin/open" nil "open" | |
7d15102b | 137 | (concat "mailto:" to |
253f7d1b JD |
138 | "?subject=" (url-hexify-string subject) |
139 | "&body=" (url-hexify-string body))) | |
140 | (start-process "xdg-email" nil "xdg-email" | |
141 | "--subject" subject | |
142 | "--body" body | |
143 | (concat "mailto:" to))) | |
489cd5bd JD |
144 | (error "Subject, To or body not found"))))) |
145 | ||
aa228418 | 146 | ;;;###autoload |
01753e63 | 147 | (defun report-emacs-bug (topic &optional recent-keys) |
aa228418 | 148 | "Report a bug in GNU Emacs. |
a2535589 | 149 | Prompts for bug subject. Leaves you in a mail buffer." |
01753e63 EN |
150 | ;; This strange form ensures that (recent-keys) is the value before |
151 | ;; the bug subject string is read. | |
152 | (interactive (reverse (list (recent-keys) (read-string "Bug Subject: ")))) | |
a722966c MC |
153 | ;; The syntax `version;' is preferred to `[version]' because the |
154 | ;; latter could be mistakenly stripped by mailing software. | |
ef77dde4 MC |
155 | (if (eq system-type 'ms-dos) |
156 | (setq topic (concat emacs-version "; " topic)) | |
157 | (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version) | |
158 | (setq topic (concat (match-string 1 emacs-version) "; " topic)))) | |
27be0364 GM |
159 | (let ((from-buffer (current-buffer)) |
160 | ;; Put these properties on semantically-void text. | |
161 | ;; report-emacs-bug-hook deletes these regions before sending. | |
162 | (prompt-properties '(field emacsbug-prompt | |
1176868d CY |
163 | intangible but-helpful |
164 | rear-nonsticky t)) | |
253f7d1b JD |
165 | (can-insert-mail (or (report-emacs-bug-can-use-xdg-email) |
166 | (report-emacs-bug-can-use-osx-open))) | |
27be0364 | 167 | user-point message-end-point) |
0a18209b | 168 | (setq message-end-point |
5e11c425 | 169 | (with-current-buffer (get-buffer-create "*Messages*") |
0a18209b | 170 | (point-max-marker))) |
27be0364 | 171 | (compose-mail report-emacs-bug-address topic) |
2f1b7dc4 GM |
172 | ;; The rest of this does not execute if the user was asked to |
173 | ;; confirm and said no. | |
27be0364 GM |
174 | (when (eq major-mode 'message-mode) |
175 | ;; Message-mode sorts the headers before sending. We sort now so | |
176 | ;; that report-emacs-bug-orig-text remains valid. (Bug#5178) | |
177 | (message-sort-headers) | |
178 | ;; Stop message-mode stealing the properties we will add. | |
179 | (set (make-local-variable 'message-strip-special-text-properties) nil)) | |
9e68869b RS |
180 | (rfc822-goto-eoh) |
181 | (forward-line 1) | |
9e68869b | 182 | (let ((signature (buffer-substring (point) (point-max)))) |
9e68869b | 183 | (delete-region (point) (point-max)) |
518adca2 RS |
184 | (insert signature) |
185 | (backward-char (length signature))) | |
fbd410d6 RS |
186 | (unless report-emacs-bug-no-explanations |
187 | ;; Insert warnings for novice users. | |
1176868d CY |
188 | (if (not (equal "bug-gnu-emacs@gnu.org" report-emacs-bug-address)) |
189 | (insert (format "The report will be sent to %s.\n\n" | |
190 | report-emacs-bug-address)) | |
191 | (insert "This bug report will be sent to the ") | |
192 | (insert-button | |
193 | "Bug-GNU-Emacs" | |
194 | 'face 'link | |
195 | 'help-echo (concat "mouse-2, RET: Follow this link") | |
196 | 'action (lambda (button) | |
197 | (browse-url "http://lists.gnu.org/archive/html/bug-gnu-emacs/")) | |
198 | 'follow-link t) | |
199 | (insert " mailing list\nand the GNU bug tracker at ") | |
200 | (insert-button | |
201 | "debbugs.gnu.org" | |
202 | 'face 'link | |
203 | 'help-echo (concat "mouse-2, RET: Follow this link") | |
204 | 'action (lambda (button) | |
205 | (browse-url "http://debbugs.gnu.org/")) | |
206 | 'follow-link t) | |
207 | ||
208 | (insert ". Please check that | |
209 | the From: line contains a valid email address. After a delay of up | |
210 | to one day, you should receive an acknowledgement at that address. | |
211 | ||
212 | Please write in English if possible, as the Emacs maintainers | |
213 | usually do not have translators for other languages.\n\n"))) | |
214 | ||
215 | (insert "Please describe exactly what actions triggered the bug, and\n" | |
216 | "the precise symptoms of the bug. If you can, give a recipe\n" | |
217 | "starting from `emacs -Q':\n\n") | |
85094855 GM |
218 | (add-text-properties (save-excursion |
219 | (rfc822-goto-eoh) | |
220 | (line-beginning-position 2)) | |
221 | (point) | |
9888f112 | 222 | prompt-properties) |
515ced27 | 223 | (setq user-point (point)) |
3a7f4c18 KS |
224 | (insert "\n\n") |
225 | ||
fca615d5 | 226 | (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n" |
3a7f4c18 KS |
227 | "please include the output from the following gdb commands:\n" |
228 | " `bt full' and `xbacktrace'.\n") | |
229 | ||
230 | (let ((debug-file (expand-file-name "DEBUG" data-directory))) | |
231 | (if (file-readable-p debug-file) | |
00006066 CY |
232 | (insert "For information about debugging Emacs, please read the file\n" |
233 | debug-file ".\n"))) | |
9888f112 | 234 | (add-text-properties (1+ user-point) (point) prompt-properties) |
515ced27 | 235 | |
3a7f4c18 | 236 | (insert "\n\nIn " (emacs-version) "\n") |
f4982064 | 237 | (if (fboundp 'x-server-vendor) |
6f8a2742 | 238 | (condition-case nil |
951c155f SM |
239 | ;; This is used not only for X11 but also W32 and others. |
240 | (insert "Windowing system distributor `" (x-server-vendor) | |
241 | "', version " | |
6f8a2742 JD |
242 | (mapconcat 'number-to-string (x-server-version) ".") "\n") |
243 | (error t))) | |
4d4ec1f8 EZ |
244 | (when (and system-configuration-options |
245 | (not (equal system-configuration-options ""))) | |
246 | (insert "Configured using:\n `configure " | |
247 | system-configuration-options "'\n\n") | |
248 | (fill-region (line-beginning-position -1) (point))) | |
dc81f8a2 | 249 | (insert "Important settings:\n") |
1daad47d | 250 | (mapc |
4f91a816 SM |
251 | (lambda (var) |
252 | (insert (format " value of $%s: %s\n" var (getenv var)))) | |
249dd409 | 253 | '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES" |
5dae4230 | 254 | "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS")) |
dc81f8a2 | 255 | (insert (format " locale-coding-system: %s\n" locale-coding-system)) |
597e2240 GM |
256 | (insert (format " default enable-multibyte-characters: %s\n" |
257 | (default-value 'enable-multibyte-characters))) | |
0a18209b | 258 | (insert "\n") |
3c3ba27b | 259 | (insert (format "Major mode: %s\n" |
48d33090 SM |
260 | (format-mode-line |
261 | (buffer-local-value 'mode-name from-buffer) | |
262 | nil nil from-buffer))) | |
e927088b RS |
263 | (insert "\n") |
264 | (insert "Minor modes in effect:\n") | |
265 | (dolist (mode minor-mode-list) | |
3c3ba27b RS |
266 | (and (boundp mode) (buffer-local-value mode from-buffer) |
267 | (insert (format " %s: %s\n" mode | |
268 | (buffer-local-value mode from-buffer))))) | |
e927088b | 269 | (insert "\n") |
515ced27 | 270 | (insert "Recent input:\n") |
0a18209b KH |
271 | (let ((before-keys (point))) |
272 | (insert (mapconcat (lambda (key) | |
273 | (if (or (integerp key) | |
274 | (symbolp key) | |
275 | (listp key)) | |
276 | (single-key-description key) | |
277 | (prin1-to-string key nil))) | |
278 | (or recent-keys (recent-keys)) | |
279 | " ")) | |
280 | (save-restriction | |
281 | (narrow-to-region before-keys (point)) | |
282 | (goto-char before-keys) | |
283 | (while (progn (move-to-column 50) (not (eobp))) | |
284 | (search-forward " " nil t) | |
285 | (insert "\n")))) | |
286 | (let ((message-buf (get-buffer "*Messages*"))) | |
287 | (if message-buf | |
288 | (let (beg-pos | |
289 | (end-pos message-end-point)) | |
290 | (with-current-buffer message-buf | |
291 | (goto-char end-pos) | |
292 | (forward-line -10) | |
293 | (setq beg-pos (point))) | |
294 | (insert "\n\nRecent messages:\n") | |
295 | (insert-buffer-substring message-buf beg-pos end-pos)))) | |
0b952197 GM |
296 | ;; After Recent messages, to avoid the messages produced by |
297 | ;; list-load-path-shadows. | |
298 | (unless (looking-back "\n") | |
299 | (insert "\n")) | |
300 | (insert "\n") | |
301 | (insert "Load-path shadows:\n") | |
302 | (message "Checking for load-path shadows...") | |
303 | (let ((shadows (list-load-path-shadows t))) | |
304 | (message "Checking for load-path shadows...done") | |
305 | (insert (if (zerop (length shadows)) | |
306 | "None found.\n" | |
307 | shadows))) | |
9656d87b GM |
308 | (insert (format "\nFeatures:\n%s\n" features)) |
309 | (fill-region (line-beginning-position 0) (point)) | |
310 | ;; This is so the user has to type something in order to send easily. | |
0a18209b KH |
311 | (use-local-map (nconc (make-sparse-keymap) (current-local-map))) |
312 | (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info) | |
253f7d1b | 313 | (if can-insert-mail |
bd78fa1d | 314 | (define-key (current-local-map) "\C-cm" |
489cd5bd | 315 | 'report-emacs-bug-insert-to-mailer)) |
e554b3f8 GM |
316 | (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc) |
317 | report-emacs-bug-send-hook (get mail-user-agent 'hookvar)) | |
318 | (if report-emacs-bug-send-command | |
319 | (setq report-emacs-bug-send-command | |
320 | (symbol-name report-emacs-bug-send-command))) | |
e9227982 RS |
321 | (unless report-emacs-bug-no-explanations |
322 | (with-output-to-temp-buffer "*Bug Help*" | |
3e425845 | 323 | (princ "While in the mail buffer:\n\n") |
85094855 | 324 | (if report-emacs-bug-send-command |
d8194864 | 325 | (princ (substitute-command-keys |
85094855 GM |
326 | (format " Type \\[%s] to send the bug report.\n" |
327 | report-emacs-bug-send-command)))) | |
e9227982 | 328 | (princ (substitute-command-keys |
3e425845 | 329 | " Type \\[kill-buffer] RET to cancel (don't send it).\n")) |
253f7d1b | 330 | (if can-insert-mail |
489cd5bd | 331 | (princ (substitute-command-keys |
3f88cd72 | 332 | " Type \\[report-emacs-bug-insert-to-mailer] to copy text to your preferred mail program.\n"))) |
e9227982 RS |
333 | (terpri) |
334 | (princ (substitute-command-keys | |
3e425845 CY |
335 | " Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section |
336 | about when and how to write a bug report, and what | |
337 | information you should include to help fix the bug."))) | |
338 | (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*"))) | |
0a18209b | 339 | ;; Make it less likely people will send empty messages. |
85094855 GM |
340 | (if report-emacs-bug-send-hook |
341 | (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t)) | |
2f1b7dc4 GM |
342 | (goto-char (point-max)) |
343 | (skip-chars-backward " \t\n") | |
344 | (make-local-variable 'report-emacs-bug-orig-text) | |
345 | (setq report-emacs-bug-orig-text | |
346 | (buffer-substring-no-properties (point-min) (point))) | |
0a18209b | 347 | (goto-char user-point))) |
e24ec555 | 348 | |
1628adc6 KH |
349 | (defun report-emacs-bug-info () |
350 | "Go to the Info node on reporting Emacs bugs." | |
351 | (interactive) | |
4d8da9a4 | 352 | (info "(emacs)Bugs")) |
1628adc6 | 353 | |
7d15102b GM |
354 | ;; It's the default mail mode, so it seems OK to use its features. |
355 | (autoload 'message-bogus-recipient-p "message") | |
d1a5d56a | 356 | (defvar message-send-mail-function) |
7d15102b | 357 | |
e24ec555 | 358 | (defun report-emacs-bug-hook () |
85094855 | 359 | "Do some checking before sending a bug report." |
e24ec555 | 360 | (save-excursion |
85094855 GM |
361 | (goto-char (point-max)) |
362 | (skip-chars-backward " \t\n") | |
85094855 GM |
363 | (and (= (- (point) (point-min)) |
364 | (length report-emacs-bug-orig-text)) | |
365 | (string-equal (buffer-substring-no-properties (point-min) (point)) | |
366 | report-emacs-bug-orig-text) | |
367 | (error "No text entered in bug report")) | |
7d15102b | 368 | (or report-emacs-bug-no-confirmation |
d1a5d56a | 369 | ;; mailclient.el does not handle From (at present). |
67a0931d | 370 | (if (derived-mode-p 'message-mode) |
d1a5d56a GM |
371 | (eq message-send-mail-function 'message-send-mail-with-mailclient) |
372 | (eq send-mail-function 'mailclient-send-it)) | |
7d15102b GM |
373 | ;; Not narrowing to the headers, but that's OK. |
374 | (let ((from (mail-fetch-field "From"))) | |
375 | (and (or (not from) | |
376 | (message-bogus-recipient-p from) | |
377 | ;; This is the default user-mail-address. On today's | |
378 | ;; systems, it seems more likely to be wrong than right, | |
379 | ;; since most people don't run their own mail server. | |
fc6c2727 GM |
380 | (string-match (format "\\<%s@%s\\>" |
381 | (regexp-quote (user-login-name)) | |
382 | (regexp-quote (system-name))) | |
7d15102b | 383 | from)) |
e4245494 GM |
384 | (not (yes-or-no-p |
385 | (format "Is `%s' really your email address? " from))) | |
7d15102b | 386 | (error "Please edit the From address and try again")))) |
fe1d8b33 | 387 | ;; The last warning for novice users. |
85094855 | 388 | (unless (or report-emacs-bug-no-confirmation |
7d15102b GM |
389 | (yes-or-no-p |
390 | "Send this bug report to the Emacs maintainers? ")) | |
fe1d8b33 KH |
391 | (goto-char (point-min)) |
392 | (if (search-forward "To: ") | |
85094855 GM |
393 | (delete-region (point) (line-end-position))) |
394 | (if report-emacs-bug-send-hook | |
395 | (kill-local-variable report-emacs-bug-send-hook)) | |
fe1d8b33 | 396 | (with-output-to-temp-buffer "*Bug Help*" |
85094855 GM |
397 | (princ (substitute-command-keys |
398 | (format "\ | |
02f6b354 RS |
399 | You invoked the command M-x report-emacs-bug, |
400 | but you decided not to mail the bug report to the Emacs maintainers. | |
fe1d8b33 | 401 | |
02f6b354 RS |
402 | If you want to mail it to someone else instead, |
403 | please insert the proper e-mail address after \"To: \", | |
85094855 GM |
404 | and send the mail again%s." |
405 | (if report-emacs-bug-send-command | |
406 | (format " using \\[%s]" | |
407 | report-emacs-bug-send-command) | |
408 | ""))))) | |
02f6b354 | 409 | (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer")) |
ea33ba73 | 410 | |
85094855 GM |
411 | ;; Delete the uninteresting text that was just to help fill out the report. |
412 | (rfc822-goto-eoh) | |
413 | (forward-line 1) | |
9888f112 TTN |
414 | (let ((pos (1- (point)))) |
415 | (while (setq pos (text-property-any pos (point-max) | |
416 | 'field 'emacsbug-prompt)) | |
417 | (delete-region pos (field-end (1+ pos))))))) | |
a2535589 | 418 | |
614316a7 TH |
419 | |
420 | ;; Querying the bug database | |
421 | ||
e554b3f8 GM |
422 | (defvar report-emacs-bug-bug-alist nil) |
423 | (make-variable-buffer-local 'report-emacs-bug-bug-alist) | |
424 | (defvar report-emacs-bug-choice-widget nil) | |
425 | (make-variable-buffer-local 'report-emacs-bug-choice-widget) | |
426 | ||
7dcd777e | 427 | (defun report-emacs-bug-create-existing-bugs-buffer (bugs keywords) |
614316a7 TH |
428 | (switch-to-buffer (get-buffer-create "*Existing Emacs Bugs*")) |
429 | (setq buffer-read-only t) | |
430 | (let ((inhibit-read-only t)) | |
431 | (erase-buffer) | |
e554b3f8 | 432 | (setq report-emacs-bug-bug-alist bugs) |
7dcd777e TH |
433 | (widget-insert (propertize (concat "Already known bugs (" |
434 | keywords "):\n\n") | |
435 | 'face 'bold)) | |
614316a7 | 436 | (if bugs |
e554b3f8 | 437 | (setq report-emacs-bug-choice-widget |
614316a7 | 438 | (apply 'widget-create 'radio-button-choice |
a140ec5f | 439 | :value (caar bugs) |
614316a7 TH |
440 | (let (items) |
441 | (dolist (bug bugs) | |
442 | (push (list | |
443 | 'url-link | |
f62f063d | 444 | :format (concat "Bug#" (number-to-string (nth 2 bug)) |
a140ec5f | 445 | ": " (cadr bug) "\n %[%v%]\n") |
614316a7 TH |
446 | ;; FIXME: Why is only the link of the |
447 | ;; active item clickable? | |
f62f063d | 448 | (car bug)) |
614316a7 TH |
449 | items)) |
450 | (nreverse items)))) | |
333f9019 | 451 | (widget-insert "No bugs matching your keywords found.\n")) |
614316a7 TH |
452 | (widget-insert "\n") |
453 | (widget-create 'push-button | |
454 | :notify (lambda (&rest ignore) | |
455 | ;; TODO: Do something! | |
456 | (message "Reporting new bug!")) | |
457 | "Report new bug") | |
458 | (when bugs | |
459 | (widget-insert " ") | |
460 | (widget-create 'push-button | |
461 | :notify (lambda (&rest ignore) | |
e554b3f8 | 462 | (let ((val (widget-value report-emacs-bug-choice-widget))) |
614316a7 TH |
463 | ;; TODO: Do something! |
464 | (message "Appending to bug %s!" | |
e554b3f8 | 465 | (nth 2 (assoc val report-emacs-bug-bug-alist))))) |
614316a7 TH |
466 | "Append to chosen bug")) |
467 | (widget-insert " ") | |
468 | (widget-create 'push-button | |
469 | :notify (lambda (&rest ignore) | |
470 | (kill-buffer)) | |
471 | "Quit reporting bug") | |
472 | (widget-insert "\n")) | |
473 | (use-local-map widget-keymap) | |
474 | (widget-setup) | |
475 | (goto-char (point-min))) | |
476 | ||
7dcd777e | 477 | (defun report-emacs-bug-parse-query-results (status keywords) |
614316a7 TH |
478 | (goto-char (point-min)) |
479 | (let (buglist) | |
480 | (while (re-search-forward "<a href=\"bugreport\\.cgi\\?bug=\\([[:digit:]]+\\)\">\\([^<]+\\)</a>" nil t) | |
481 | (let ((number (match-string 1)) | |
482 | (subject (match-string 2))) | |
483 | (when (not (string-match "^#" subject)) | |
484 | (push (list | |
485 | ;; first the bug URL | |
486 | (concat report-emacs-bug-tracker-url | |
487 | "bugreport.cgi?bug=" number) | |
488 | ;; then the subject and number | |
489 | subject (string-to-number number)) | |
490 | buglist)))) | |
7dcd777e | 491 | (report-emacs-bug-create-existing-bugs-buffer (nreverse buglist) keywords))) |
614316a7 | 492 | |
19c38752 | 493 | ;;;###autoload |
614316a7 TH |
494 | (defun report-emacs-bug-query-existing-bugs (keywords) |
495 | "Query for KEYWORDS at `report-emacs-bug-tracker-url', and return the result. | |
496 | The result is an alist with items of the form (URL SUBJECT NO)." | |
331460ac | 497 | (interactive "sBug keywords (comma separated): ") |
614316a7 TH |
498 | (url-retrieve (concat report-emacs-bug-tracker-url |
499 | "pkgreport.cgi?include=subject%3A" | |
500 | (replace-regexp-in-string "[[:space:]]+" "+" keywords) | |
501 | ";package=emacs") | |
7dcd777e | 502 | 'report-emacs-bug-parse-query-results (list keywords))) |
614316a7 | 503 | |
8e0ff8c8 ER |
504 | (provide 'emacsbug) |
505 | ||
c0274f38 | 506 | ;;; emacsbug.el ends here |