]> code.delx.au - gnu-emacs-elpa/blob - packages/debbugs/debbugs-gnu.el
Fix last checkin
[gnu-emacs-elpa] / packages / debbugs / debbugs-gnu.el
1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker -*- lexical-binding:t -*-
2
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
8 ;; Package: debbugs
9
10 ;; This file is not part of GNU Emacs.
11
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;; This package provides an interface to bug reports which are located
28 ;; on the GNU bug tracker debbugs.gnu.org. Its main purpose is to
29 ;; show and manipulate bug reports from Emacs, but it could be used
30 ;; also for other GNU projects which use the same bug tracker.
31
32 ;; If you have `debbugs-gnu.el' in your load-path, you could enable
33 ;; the bug tracker commands by the following lines in your ~/.emacs
34 ;;
35 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
36 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
37 ;; (autoload 'debbugs-gnu-usertags "debbugs-gnu" "" 'interactive)
38 ;; (autoload 'debbugs-gnu-bugs "debbugs-gnu" "" 'interactive)
39
40 ;; The bug tracker is called interactively by
41 ;;
42 ;; M-x debbugs-gnu
43
44 ;; It asks for the severities, for which bugs shall be shown. This can
45 ;; be either just one severity, or a list of severities, separated by
46 ;; comma. Valid severities are "serious", "important", "normal",
47 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
48 ;; used, although configured on the GNU bug tracker. If no severity
49 ;; is given, all bugs are selected.
50
51 ;; There is also the pseudo severity "tagged". When it is used, the
52 ;; function will ask for user tags (a comma separated list), and shows
53 ;; just the bugs which are tagged with them. In general, user tags
54 ;; shall be strings denoting to subprojects of the package, like
55 ;; "cedet" or "tramp" of the package "emacs". If no user tag is
56 ;; given, locally tagged bugs are shown.
57
58 ;; If a prefix is given to the command, more search parameters are
59 ;; asked for, like packages (also a comma separated list, "emacs" is
60 ;; the default), whether archived bugs shall be shown, and whether
61 ;; closed bugs shall be suppressed from being retrieved.
62
63 ;; Another command is
64 ;;
65 ;; M-x debbugs-gnu-search
66
67 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
68 ;; search phrase to be used for full text search. Additionally, it
69 ;; asks for key-value pairs to filter bugs. Keys are as described in
70 ;; `debbugs-get-status', the corresponding value must be a regular
71 ;; expression to match for. The other parameters are as described in
72 ;; `debbugs-gnu'. Usually, there is just one value except for the
73 ;; attribute "date", which needs two arguments specifying a period in
74 ;; which the bug has been submitted or modified.
75
76 ;; The bug reports are downloaded from the bug tracker. In order to
77 ;; not generate too much load of the server, up to 500 bugs will be
78 ;; downloaded at once. If there are more hits, several downloads will
79 ;; be performed, until all bugs are retrieved.
80
81 ;; These default values could be changed also by customer options
82 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages'
83 ;; and `debbugs-gnu-default-suppress-bugs'.
84
85 ;; The commands create a page of bug lists. Every bug is shown in one
86 ;; line, including the bug number, the status (combining merged bug
87 ;; numbers, keywords and severities), the name of the submitter, and
88 ;; the title of the bug. On every bug line you could apply the
89 ;; following actions by the following keystrokes:
90
91 ;; RET: Show corresponding messages in Gnus/Rmail
92 ;; "C": Send a control message
93 ;; "t": Mark the bug locally as tagged
94 ;; "b": Show bugs this bug is blocked by
95 ;; "B": Show bugs this bug is blocking
96 ;; "d": Show bug attributes
97
98 ;; Furthermore, you could apply the global actions
99
100 ;; "g": Rescan bugs
101 ;; "q": Quit the buffer
102 ;; "s": Toggle bug sorting for age or for state
103 ;; "x": Toggle suppressing of bugs
104 ;; "/": Display only bugs matching a string
105 ;; "R": Display only bugs blocking the current release
106 ;; "w": Display all the currently selected bug reports
107
108 ;; When you visit the related bug messages in Gnus or Rmail, you could
109 ;; also send control messages by keystroke "C".
110
111 ;; In the header line of every bug list page, you can toggle sorting
112 ;; per column by selecting a column with the mouse. The sorting
113 ;; happens as expected for the respective column; sorting in the Title
114 ;; column is depending on whether you are the owner of a bug.
115
116 ;; Another approach for listing bugs is calling the command
117 ;;
118 ;; M-x debbugs-gnu-usertags
119
120 ;; This command shows you all existing user tags for the packages
121 ;; defined in `debbugs-gnu-default-packages'. A prefix for the
122 ;; command allows you to use other package names, or an arbitrary
123 ;; string for a user who has tagged bugs. The command returns the
124 ;; list of existing user tags for the given user(s) or package
125 ;; name(s), respectively. Applying RET on a user tag, all bugs tagged
126 ;; with this user tag are shown.
127
128 ;; Unfortunately, it is not possible with the SOAP interface to show
129 ;; all users who have tagged bugs. This list can be retrieved via
130 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi?indexon=users>.
131
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
134 ;;
135 ;; M-x debbugs-gnu-bugs
136
137 ;; The bug numbers to be shown shall be entered as comma separated list.
138
139 ;;; Code:
140
141 (require 'debbugs)
142 (require 'tabulated-list)
143 (require 'add-log)
144 (eval-when-compile (require 'subr-x))
145 (eval-when-compile (require 'cl-lib))
146
147 (autoload 'article-decode-charset "gnus-art")
148 (autoload 'diff-goto-source "diff-mode")
149 (autoload 'diff-hunk-file-names "diff-mode")
150 (autoload 'gnus-article-mime-handles "gnus-art")
151 (autoload 'gnus-fetch-field "gnus-util")
152 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
153 (autoload 'gnus-summary-article-header "gnus-sum")
154 (autoload 'gnus-summary-select-article "gnus-sum")
155 (autoload 'gnus-summary-show-article "gnus-sum")
156 (autoload 'gnus-with-article-buffer "gnus-art")
157 (autoload 'log-edit-insert-changelog "log-edit")
158 (autoload 'mail-header-subject "nnheader")
159 (autoload 'message-goto-body "message")
160 (autoload 'message-make-from "message")
161 (autoload 'rmail-get-new-mail "rmail")
162 (autoload 'rmail-show-message "rmail")
163 (autoload 'rmail-summary "rmailsum")
164 (autoload 'vc-dir-hide-up-to-date "vc-dir")
165 (autoload 'vc-dir-mark "vc-dir")
166
167 (defvar compilation-in-progress)
168 (defvar diff-file-header-re)
169 (defvar gnus-article-buffer)
170 (defvar gnus-posting-styles)
171 (defvar gnus-save-duplicate-list)
172 (defvar gnus-suppress-duplicates)
173 (defvar rmail-current-message)
174 (defvar rmail-mode-map)
175 (defvar rmail-summary-mode-map)
176 (defvar rmail-total-messages)
177
178 ;; Buffer-local variables.
179 (defvar debbugs-gnu-local-query)
180 (defvar debbugs-gnu-local-filter)
181 (defvar debbugs-gnu-local-suppress)
182 (defvar debbugs-gnu-sort-state)
183 (defvar debbugs-gnu-limit)
184
185 (defgroup debbugs-gnu ()
186 "UI for the debbugs.gnu.org bug tracker."
187 :group 'debbugs
188 :version "24.1")
189
190 (defvar debbugs-gnu-blocking-report 19759
191 "The ID of the current release report used to track blocking bug reports.")
192
193 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
194 "*The list severities bugs are searched for.
195 \"tagged\" is not a severity but marks locally tagged bugs."
196 ;; <http://debbugs.gnu.org/Developer.html#severities>
197 ;; /ssh:debbugs:/etc/debbugs/config @gSeverityList
198 ;; We don't use "critical" and "grave".
199 :group 'debbugs-gnu
200 :type '(set (const "serious")
201 (const "important")
202 (const "normal")
203 (const "minor")
204 (const "wishlist")
205 (const "tagged"))
206 :version "24.1")
207
208 (defconst debbugs-gnu-all-severities
209 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
210 "*List of all possible severities.")
211
212 (defcustom debbugs-gnu-default-packages '("emacs")
213 "*The list of packages to be searched for."
214 ;; <http://debbugs.gnu.org/Packages.html>
215 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
216 :group 'debbugs-gnu
217 :type '(set (const "adns")
218 (const "auctex")
219 (const "automake")
220 (const "cc-mode")
221 (const "coreutils")
222 (const "cppi")
223 (const "debbugs.gnu.org")
224 (const "diffutils")
225 (const "emacs")
226 (const "emacs-xwidgets")
227 (const "fm")
228 (const "gnus")
229 (const "grep")
230 (const "guile")
231 (const "guix")
232 (const "gzip")
233 (const "idutils")
234 (const "libtool")
235 (const "mh-e")
236 (const "org-mode")
237 (const "parted")
238 (const "sed")
239 (const "vc-dwim")
240 (const "woodchuck"))
241 :version "25.1")
242
243 (defconst debbugs-gnu-all-packages
244 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
245 "*List of all possible package names.")
246
247 (defcustom debbugs-gnu-default-suppress-bugs
248 '((pending . "done"))
249 "*A list of specs for bugs to be suppressed.
250 An element of this list is a cons cell \(KEY . REGEXP\), with key
251 being returned by `debbugs-get-status', and REGEXP a regular
252 expression matching the corresponding value, a string. Showing
253 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
254 :group 'debbugs-gnu
255 :type '(alist :key-type symbol :value-type regexp)
256 :version "24.1")
257
258 (defcustom debbugs-gnu-mail-backend 'gnus
259 "*The email backend to use for reading bug report email exchange.
260 If this is 'gnus, the default, use Gnus.
261 If this is 'rmail, use Rmail instead."
262 :group 'debbugs-gnu
263 :type '(choice (const :tag "Use Gnus" 'gnus)
264 (const :tag "Use Rmail" 'rmail))
265 :version "25.1")
266
267 (defface debbugs-gnu-archived '((t (:inverse-video t)))
268 "Face for archived bug reports.")
269
270 (defface debbugs-gnu-new '((t (:foreground "red")))
271 "Face for new reports that nobody has answered.")
272
273 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
274 "Face for reports that have been modified recently.")
275
276 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
277 "Face for reports that are pending.")
278
279 (defface debbugs-gnu-stale '((t (:foreground "orange")))
280 "Face for reports that have not been touched for two weeks.")
281
282 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
283 "Face for closed bug reports.")
284
285 (defface debbugs-gnu-tagged '((t (:foreground "red")))
286 "Face for reports that have been tagged locally.")
287
288 (defvar debbugs-gnu-local-tags nil
289 "List of bug numbers tagged locally, and kept persistent.")
290
291 (defvar debbugs-gnu-persistency-file
292 (expand-file-name (locate-user-emacs-file "debbugs"))
293 "File name of a persistency store for debbugs variables")
294
295 (defun debbugs-gnu-dump-persistency-file ()
296 "Function to store debbugs variables persistently."
297 (with-temp-file debbugs-gnu-persistency-file
298 (insert
299 ";; -*- emacs-lisp -*-\n"
300 ";; Debbugs tags connection history. Don't change this file.\n\n"
301 (format "(setq debbugs-gnu-local-tags '%S)"
302 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
303
304 (defvar debbugs-gnu-current-query nil
305 "The query object of the current search.
306 It will be applied server-side, when calling `debbugs-get-bugs'.
307 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
308
309 (defvar debbugs-gnu-current-filter nil
310 "The filter object for the current search.
311 It will be applied client-side, when parsing the results of
312 `debbugs-get-status'. It has a similar format as
313 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
314 a date, value is the cons cell \(BEFORE . AFTER\).")
315
316 (defvar debbugs-gnu-current-suppress nil
317 "Whether bugs shall be suppressed.
318 The specification which bugs shall be suppressed is taken from
319 `debbugs-gnu-default-suppress-bugs'.")
320
321 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
322 "Return a string read from the minibuffer.
323 Derived from `calendar-read'."
324 (let ((value (read-string prompt initial-contents)))
325 (while (not (funcall acceptable value))
326 (setq value (read-string prompt initial-contents)))
327 value))
328
329 (defconst debbugs-gnu-phrase-prompt
330 (propertize
331 "Enter search phrase: "
332 'help-echo "\
333 The search phrase contains words to be searched for, combined by
334 operators like AND, ANDNOT and OR. If there is no operator
335 between the words, AND is used by default. The phrase can also
336 be empty, in this case only the following attributes are used for
337 search."))
338
339 ;;;###autoload
340 (defun debbugs-gnu-patches ()
341 "List the bug reports that have been marked as containing a patch."
342 (interactive)
343 (debbugs-gnu nil '("emacs") nil nil "patch"))
344
345 ;;;###autoload
346 (defun debbugs-gnu-search ()
347 "Search for Emacs bugs interactively.
348 Search arguments are requested interactively. The \"search
349 phrase\" is used for full text search in the bugs database.
350 Further key-value pairs are requested until an empty key is
351 returned. If a key cannot be queried by a SOAP request, it is
352 marked as \"client-side filter\"."
353 (interactive)
354
355 (unwind-protect
356 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
357 key val1 val2 phrase severities packages archivedp)
358
359 ;; Check for the phrase.
360 (setq phrase (read-string debbugs-gnu-phrase-prompt))
361 (if (zerop (length phrase))
362 (setq phrase nil)
363 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
364 ;; We suppress closed bugs if there is no phrase.
365 (setq debbugs-gnu-current-suppress (null phrase))
366
367 ;; The other queries.
368 (catch :finished
369 (while t
370 (setq key (completing-read
371 "Enter attribute: "
372 (if phrase
373 '("severity" "package" "tags" "submitter" "date"
374 "subject" "status")
375 '("severity" "package" "archive" "src" "tag"
376 "owner" "submitter" "maint" "correspondent"
377 "date" "log_modified" "last_modified"
378 "found_date" "fixed_date" "unarchived"
379 "subject" "done" "forwarded" "msgid" "summary"))
380 nil t))
381 (cond
382 ;; Server-side queries.
383 ((equal key "severity")
384 (setq
385 severities
386 (completing-read-multiple
387 "Enter severities: " debbugs-gnu-all-severities nil t
388 (mapconcat 'identity debbugs-gnu-default-severities ","))))
389
390 ((equal key "package")
391 (setq
392 packages
393 (completing-read-multiple
394 "Enter packages: " debbugs-gnu-all-packages nil t
395 (mapconcat 'identity debbugs-gnu-default-packages ","))))
396
397 ((equal key "archive")
398 ;; We simplify, by assuming just archived bugs are requested.
399 (setq archivedp t))
400
401 ((member key '("src" "tag" "tags"))
402 (setq val1 (read-string (format "Enter %s: " key)))
403 (when (not (zerop (length val1)))
404 (add-to-list
405 'debbugs-gnu-current-query (cons (intern key) val1))))
406
407 ((member key '("owner" "submitter" "maint" "correspondent"))
408 (setq val1 (read-string "Enter email address: "))
409 (when (not (zerop (length val1)))
410 (add-to-list
411 'debbugs-gnu-current-query (cons (intern key) val1))))
412
413 ((equal key "status")
414 (setq
415 val1
416 (completing-read "Enter status: " '("done" "forwarded" "open")))
417 (when (not (zerop (length val1)))
418 (add-to-list
419 'debbugs-gnu-current-query (cons (intern key) val1))))
420
421 ;; Client-side filters.
422 ((member key '("date" "log_modified" "last_modified"
423 "found_date" "fixed_date" "unarchived"))
424 (setq val1
425 (debbugs-gnu-calendar-read
426 (format "Enter %s before YYYY-MM-DD%s: "
427 key (if phrase "" " (client-side filter)"))
428 (lambda (x)
429 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
430 (if (string-match date-format val1)
431 (setq val1 (floor
432 (float-time
433 (encode-time
434 0 0 0
435 (string-to-number (match-string 3 val1))
436 (string-to-number (match-string 2 val1))
437 (string-to-number (match-string 1 val1))))))
438 (setq val1 nil))
439 (setq val2
440 (debbugs-gnu-calendar-read
441 (format "Enter %s after YYYY-MM-DD%s: "
442 key (if phrase "" " (client-side filter)"))
443 (lambda (x)
444 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
445 (if (string-match date-format val2)
446 (setq val2 (floor
447 (float-time
448 (encode-time
449 0 0 0
450 (string-to-number (match-string 3 val2))
451 (string-to-number (match-string 2 val2))
452 (string-to-number (match-string 1 val2))))))
453 (setq val2 nil))
454 (when (or val1 val2)
455 (add-to-list
456 (if phrase
457 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
458 (cons (intern key) (cons val1 val2)))))
459
460 ((not (zerop (length key)))
461 (setq val1
462 (funcall
463 (if phrase 'read-string 'read-regexp)
464 (format "Enter %s%s"
465 key (if phrase ": " " (client-side filter)"))))
466 (when (not (zerop (length val1)))
467 (add-to-list
468 (if phrase
469 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
470 (cons (intern key) val1))))
471
472 ;; The End.
473 (t (throw :finished nil)))))
474
475 ;; Do the search.
476 (debbugs-gnu severities packages archivedp))))
477
478 ;;;###autoload
479 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
480 "List all outstanding bugs."
481 (interactive
482 (let (severities archivedp)
483 (list
484 (setq severities
485 (completing-read-multiple
486 "Severities: " debbugs-gnu-all-severities nil t
487 (mapconcat 'identity debbugs-gnu-default-severities ",")))
488 ;; The next parameters are asked only when there is a prefix.
489 (if current-prefix-arg
490 (completing-read-multiple
491 "Packages: " debbugs-gnu-all-packages nil t
492 (mapconcat 'identity debbugs-gnu-default-packages ","))
493 debbugs-gnu-default-packages)
494 (when current-prefix-arg
495 (setq archivedp (y-or-n-p "Show archived bugs?")))
496 (when (and current-prefix-arg (not archivedp))
497 (y-or-n-p "Suppress unwanted bugs?"))
498 ;; This one must be asked for severity "tagged".
499 (when (member "tagged" severities)
500 (split-string (read-string "User tag(s): ") "," t)))))
501
502 ;; Initialize variables.
503 (when (and (file-exists-p debbugs-gnu-persistency-file)
504 (not debbugs-gnu-local-tags))
505 (with-temp-buffer
506 (insert-file-contents debbugs-gnu-persistency-file)
507 (eval (read (current-buffer)))))
508 ;; Per default, we suppress retrieved unwanted bugs.
509 (when (called-interactively-p 'any)
510 (setq debbugs-gnu-current-suppress t))
511
512 ;; Add queries.
513 (dolist (severity (if (consp severities) severities (list severities)))
514 (when (not (zerop (length severity)))
515 (when (string-equal severity "tagged")
516 (setq debbugs-gnu-current-suppress nil))
517 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
518 (dolist (package (if (consp packages) packages (list packages)))
519 (when (not (zerop (length package)))
520 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
521 (when archivedp
522 (setq debbugs-gnu-current-suppress nil)
523 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
524 (when suppress
525 (setq debbugs-gnu-current-suppress t)
526 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
527 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
528 (dolist (tag (if (consp tags) tags (list tags)))
529 (when (not (zerop (length tag)))
530 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
531
532 ;; Show result.
533 (debbugs-gnu-show-reports)
534
535 ;; Reset query, filter and suppress.
536 (setq debbugs-gnu-current-query nil
537 debbugs-gnu-current-filter nil
538 debbugs-gnu-current-suppress nil))
539
540 (defun debbugs-gnu-get-bugs (query)
541 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
542 (let* ((debbugs-port "gnu.org")
543 (bugs (assoc 'bugs query))
544 (tags (assoc 'tag query))
545 (local-tags (and (member '(severity . "tagged") query) (not tags)))
546 (phrase (assoc 'phrase query))
547 args)
548 ;; Compile query arguments.
549 (unless (or query tags)
550 (dolist (elt debbugs-gnu-default-packages)
551 (setq args (append args (list :package elt)))))
552 (dolist (elt query)
553 (unless (equal elt '(severity . "tagged"))
554 (setq args
555 (append
556 args
557 (if phrase
558 (cond
559 ((eq (car elt) 'phrase)
560 (list (list :phrase (cdr elt))))
561 ((eq (car elt) 'date)
562 (list (list :date (cddr elt) (cadr elt)
563 :operator "NUMBT")))
564 (t
565 (list (list (intern (concat ":" (symbol-name (car elt))))
566 (cdr elt) :operator "ISTRINC"))))
567 (list (intern (concat ":" (symbol-name (car elt))))
568 (cdr elt)))))))
569
570 (cond
571 ;; If the query is just a list of bug numbers, we return them.
572 (bugs (cdr bugs))
573 ;; If the query contains the pseudo-severity "tagged", we return
574 ;; just the local tagged bugs.
575 (local-tags (copy-sequence debbugs-gnu-local-tags))
576 ;; A full text query.
577 (phrase
578 (mapcar
579 (lambda (x) (cdr (assoc "id" x)))
580 (apply 'debbugs-search-est args)))
581 ;; Otherwise, we retrieve the bugs from the server.
582 (t (apply 'debbugs-get-bugs args)))))
583
584 (defun debbugs-gnu-show-reports (&optional offline)
585 "Show bug reports.
586 If OFFLINE is non-nil, the query is not sent to the server. Bugs
587 are taken from the cache instead."
588 (let ((inhibit-read-only t)
589 (buffer-name "*Emacs Bugs*"))
590 ;; The tabulated mode sets several local variables. We must get
591 ;; rid of them.
592 (when (get-buffer buffer-name)
593 (kill-buffer buffer-name))
594 (switch-to-buffer (get-buffer-create buffer-name))
595 (debbugs-gnu-mode)
596
597 ;; Print bug reports.
598 (dolist (status
599 (let ((debbugs-cache-expiry (if offline nil debbugs-cache-expiry))
600 ids)
601 (apply 'debbugs-get-status
602 (if offline
603 (progn
604 (maphash (lambda (key _elem)
605 (push key ids))
606 debbugs-cache-data)
607 (sort ids '<))
608 (debbugs-gnu-get-bugs debbugs-gnu-local-query)))))
609 (let* ((id (cdr (assq 'id status)))
610 (words
611 (mapconcat
612 'identity
613 (cons (cdr (assq 'severity status))
614 (cdr (assq 'keywords status)))
615 ","))
616 (address (if (cdr (assq 'originator status))
617 (mail-header-parse-address
618 (decode-coding-string (cdr (assq 'originator status))
619 'utf-8))))
620 (owner (if (cdr (assq 'owner status))
621 (car (mail-header-parse-address
622 (decode-coding-string (cdr (assq 'owner status))
623 'utf-8)))))
624 (subject (if (cdr (assq 'subject status))
625 (decode-coding-string (cdr (assq 'subject status))
626 'utf-8)))
627 merged)
628 (unless (equal (cdr (assq 'pending status)) "pending")
629 (setq words (concat words "," (cdr (assq 'pending status)))))
630 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
631 (when packages
632 (setq words (concat words "," (mapconcat 'identity packages ",")))))
633 (when (setq merged (cdr (assq 'mergedwith status)))
634 (setq words (format "%s,%s"
635 (if (numberp merged)
636 merged
637 (mapconcat 'number-to-string merged ","))
638 words)))
639 (when (or (not merged)
640 (not (let ((found nil))
641 (dolist (id (if (listp merged)
642 merged
643 (list merged)))
644 (dolist (entry tabulated-list-entries)
645 (when (equal id (cdr (assq 'id (car entry))))
646 (setq found t))))
647 found)))
648 (add-to-list
649 'tabulated-list-entries
650 (list
651 status
652 (vector
653 (propertize
654 (format "%5d" id)
655 'face
656 ;; Mark tagged bugs.
657 (if (memq id debbugs-gnu-local-tags)
658 'debbugs-gnu-tagged
659 'default))
660 (propertize
661 ;; Mark status and age.
662 (or words "")
663 'face
664 (cond
665 ((cdr (assq 'archived status))
666 'debbugs-gnu-archived)
667 ((equal (cdr (assq 'pending status)) "done")
668 'debbugs-gnu-done)
669 ((member "pending" (cdr (assq 'keywords status)))
670 'debbugs-gnu-pending)
671 ((= (cdr (assq 'date status))
672 (cdr (assq 'log_modified status)))
673 'debbugs-gnu-new)
674 ((< (- (float-time)
675 (cdr (assq 'log_modified status)))
676 (* 60 60 24 7 2))
677 'debbugs-gnu-handled)
678 (t
679 'debbugs-gnu-stale)))
680 (propertize
681 ;; Prefer the name over the address.
682 (or (cdr address)
683 (car address)
684 "")
685 'face
686 ;; Mark own submitted bugs.
687 (if (and (stringp (car address))
688 (string-equal (car address) user-mail-address))
689 'debbugs-gnu-tagged
690 'default))
691 (propertize
692 (or subject "")
693 'face
694 ;; Mark owned bugs.
695 (if (and (stringp owner)
696 (string-equal owner user-mail-address))
697 'debbugs-gnu-tagged
698 'default))))
699 'append))))
700
701 (tabulated-list-init-header)
702 (tabulated-list-print)
703
704 (set-buffer-modified-p nil)
705 (goto-char (point-min))))
706
707 (defun debbugs-gnu-print-entry (list-id cols)
708 "Insert a debbugs entry at point.
709 Used instead of `tabulated-list-print-entry'."
710 (let ((beg (point))
711 (pos 0)
712 (case-fold-search t)
713 (id (aref cols 0))
714 (id-length (nth 1 (aref tabulated-list-format 0)))
715 (state (aref cols 1))
716 (state-length (nth 1 (aref tabulated-list-format 1)))
717 (submitter (aref cols 2))
718 (submitter-length (nth 1 (aref tabulated-list-format 2)))
719 (title (aref cols 3))
720 ;; (title-length (nth 1 (aref tabulated-list-format 3)))
721 )
722 (when (and
723 ;; We may have a narrowing in effect.
724 (or (not debbugs-gnu-limit)
725 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
726 ;; Filter suppressed bugs.
727 (or (not debbugs-gnu-local-suppress)
728 (not (catch :suppress
729 (dolist (check debbugs-gnu-default-suppress-bugs)
730 (when
731 (string-match
732 (cdr check)
733 (or (cdr (assq (car check) list-id)) ""))
734 (throw :suppress t))))))
735 ;; Filter search list.
736 (not (catch :suppress
737 (dolist (check debbugs-gnu-local-filter)
738 (let ((val (cdr (assq (car check) list-id))))
739 (if (stringp (cdr check))
740 ;; Regular expression.
741 (when (not (string-match (cdr check) (or val "")))
742 (throw :suppress t))
743 ;; Time value.
744 (when (or (and (numberp (cadr check))
745 (< (cadr check) val))
746 (and (numberp (cddr check))
747 (> (cddr check) val)))
748 (throw :suppress t))))))))
749
750 ;; Insert id.
751 (indent-to (- id-length (length id)))
752 (insert id)
753 ;; Insert state.
754 (indent-to (setq pos (+ pos id-length 1)) 1)
755 (insert (if (> (length state) state-length)
756 (propertize (substring state 0 state-length)
757 'help-echo state)
758 state))
759 ;; Insert submitter.
760 (indent-to (setq pos (+ pos state-length 1)) 1)
761 (insert "[" (if (> (length submitter) (- submitter-length 2))
762 (propertize (substring submitter 0 (- submitter-length 2))
763 'help-echo submitter)
764 submitter))
765 (indent-to (+ pos (1- submitter-length)))
766 (insert "]")
767 ;; Insert title.
768 (indent-to (setq pos (+ pos submitter-length 1)) 1)
769 (insert (propertize title 'help-echo title))
770 ;; Add properties.
771 (add-text-properties
772 beg (point)
773 `(tabulated-list-id ,list-id mouse-face highlight))
774 (insert ?\n))))
775
776 (defun debbugs-gnu-menu-map-emacs-enabled ()
777 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
778 (or ;; No package discriminator has been used.
779 (not (assq 'package debbugs-gnu-local-query))
780 ;; Package "emacs" has been selected.
781 (member '(package . "emacs") debbugs-gnu-local-query)))
782
783 (defconst debbugs-gnu-bug-triage-file
784 (expand-file-name "../admin/notes/bug-triage" data-directory)
785 "The \"bug-triage\" file.")
786
787 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
788 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
789 (and (debbugs-gnu-menu-map-emacs-enabled)
790 (stringp debbugs-gnu-bug-triage-file)
791 (file-readable-p debbugs-gnu-bug-triage-file)))
792
793 (defun debbugs-gnu-view-bug-triage ()
794 "Show \"bug-triage\" file."
795 (interactive)
796 (view-file debbugs-gnu-bug-triage-file))
797
798 (defvar debbugs-gnu-mode-map
799 (let ((map (make-sparse-keymap))
800 (menu-map (make-sparse-keymap)))
801 (set-keymap-parent map tabulated-list-mode-map)
802 (define-key map "\r" 'debbugs-gnu-select-report)
803 (define-key map [mouse-1] 'debbugs-gnu-select-report)
804 (define-key map [mouse-2] 'debbugs-gnu-select-report)
805 (define-key map "g" 'debbugs-gnu-rescan)
806 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
807 (define-key map "C" 'debbugs-gnu-send-control-message)
808
809 (define-key map "s" 'debbugs-gnu-toggle-sort)
810 (define-key map "t" 'debbugs-gnu-toggle-tag)
811 (define-key map "x" 'debbugs-gnu-toggle-suppress)
812 (define-key map "/" 'debbugs-gnu-narrow-to-status)
813 (define-key map "w" 'debbugs-gnu-widen)
814
815 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
816 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
817 (define-key map "d" 'debbugs-gnu-display-status)
818
819 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
820 (define-key menu-map [debbugs-gnu-select-report]
821 '(menu-item "Show Reports" debbugs-gnu-select-report
822 :help "Show all reports belonging to this bug"))
823 (define-key-after menu-map [debbugs-gnu-rescan]
824 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
825 :help "Refresh bug list")
826 'debbugs-gnu-select-report)
827 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
828 '(menu-item "Show Release Blocking Bugs"
829 debbugs-gnu-show-all-blocking-reports
830 :enable (debbugs-gnu-menu-map-emacs-enabled)
831 :help "Show all bugs blocking next Emacs release")
832 'debbugs-gnu-rescan)
833 (define-key-after menu-map [debbugs-gnu-send-control-message]
834 '(menu-item "Send Control Message"
835 debbugs-gnu-send-control-message
836 :help "Send control message to debbugs.gnu.org")
837 'debbugs-gnu-show-all-blocking-reports)
838
839 (define-key-after menu-map [debbugs-gnu-separator1]
840 '(menu-item "--") 'debbugs-gnu-send-control-message)
841 (define-key-after menu-map [debbugs-gnu-search]
842 '(menu-item "Search Bugs" debbugs-gnu-search
843 :help "Search bugs on debbugs.gnu.org")
844 'debbugs-gnu-separator1)
845 (define-key-after menu-map [debbugs-gnu]
846 '(menu-item "Retrieve Bugs" debbugs-gnu
847 :help "Retrieve bugs from debbugs.gnu.org")
848 'debbugs-gnu-search)
849 (define-key-after menu-map [debbugs-gnu-bugs]
850 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
851 :help "Retrieve selected bugs from debbugs.gnu.org")
852 'debbugs-gnu)
853
854 (define-key-after menu-map [debbugs-gnu-separator2]
855 '(menu-item "--") 'debbugs-gnu-bugs)
856 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
857 '(menu-item "Describe Bug Triage Procedure"
858 debbugs-gnu-view-bug-triage
859 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
860 :help "Show procedure of triaging bugs")
861 'debbugs-gnu-separator2)
862 map))
863
864 (defun debbugs-gnu-rescan ()
865 "Rescan the current set of bug reports."
866 (interactive)
867 (let ((id (debbugs-gnu-current-id))
868 (debbugs-gnu-current-query debbugs-gnu-local-query)
869 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
870 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
871 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
872 (debbugs-gnu-show-reports)
873 (when id
874 (debbugs-gnu-goto id))))
875
876 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
877 "Major mode for listing bug reports.
878
879 All normal editing commands are switched off.
880 \\<debbugs-gnu-mode-map>
881
882 The following commands are available:
883
884 \\{debbugs-gnu-mode-map}"
885 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
886 (set (make-local-variable 'debbugs-gnu-limit) nil)
887 (set (make-local-variable 'debbugs-gnu-local-query)
888 debbugs-gnu-current-query)
889 (set (make-local-variable 'debbugs-gnu-local-filter)
890 debbugs-gnu-current-filter)
891 (set (make-local-variable 'debbugs-gnu-local-suppress)
892 debbugs-gnu-current-suppress)
893 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
894 ("State" 20 debbugs-gnu-sort-state)
895 ("Submitter" 25 t)
896 ("Title" 10 debbugs-gnu-sort-title)])
897 (setq tabulated-list-sort-key (cons "Id" nil))
898 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
899 (buffer-disable-undo)
900 (setq truncate-lines t)
901 (setq buffer-read-only t))
902
903 (defun debbugs-gnu-sort-id (s1 s2)
904 (> (cdr (assq 'id (car s1)))
905 (cdr (assq 'id (car s2)))))
906
907 (defconst debbugs-gnu-state-preference
908 '((debbugs-gnu-new . 1)
909 (debbugs-gnu-stale . 2)
910 (debbugs-gnu-handled . 3)
911 (debbugs-gnu-done . 4)
912 (debbugs-gnu-pending . 5)))
913
914 (defun debbugs-gnu-get-state-preference (face-string)
915 (or (cdr (assq (get-text-property 0 'face face-string)
916 debbugs-gnu-state-preference))
917 10))
918
919 (defconst debbugs-gnu-severity-preference
920 '(("serious" . 1)
921 ("important" . 2)
922 ("normal" . 3)
923 ("minor" . 4)
924 ("wishlist" . 5)))
925
926 (defun debbugs-gnu-get-severity-preference (state)
927 (or (cdr (assoc (cdr (assq 'severity state))
928 debbugs-gnu-severity-preference))
929 10))
930
931 (defun debbugs-gnu-sort-state (s1 s2)
932 (let ((id1 (cdr (assq 'id (car s1))))
933 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
934 (id2 (cdr (assq 'id (car s2))))
935 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
936 (cond
937 ;; Tagged bugs go to the end.
938 ((and (not (memq id1 debbugs-gnu-local-tags))
939 (memq id2 debbugs-gnu-local-tags))
940 t)
941 ((and (memq id1 debbugs-gnu-local-tags)
942 (not (memq id2 debbugs-gnu-local-tags)))
943 nil)
944 ;; Then, we check the age of the bugs.
945 ((< age1 age2)
946 t)
947 ((> age1 age2)
948 nil)
949 ;; If they have the same age, we check for severity.
950 ((< (debbugs-gnu-get-severity-preference (car s1))
951 (debbugs-gnu-get-severity-preference (car s2)))
952 t)
953 (t nil))))
954
955 (defun debbugs-gnu-sort-title (s1 _s2)
956 (let ((owner (if (cdr (assq 'owner (car s1)))
957 (car (mail-header-parse-address
958 (decode-coding-string (cdr (assq 'owner (car s1)))
959 'utf-8))))))
960 (and (stringp owner)
961 (string-equal owner user-mail-address))))
962
963 (defun debbugs-gnu-toggle-sort ()
964 "Toggle sorting by age and by state."
965 (interactive)
966 (if (eq debbugs-gnu-sort-state 'number)
967 (progn
968 (setq debbugs-gnu-sort-state 'state)
969 (setq tabulated-list-sort-key (cons "Id" nil)))
970 (setq debbugs-gnu-sort-state 'number)
971 (setq tabulated-list-sort-key (cons "State" nil)))
972 (tabulated-list-init-header)
973 (tabulated-list-print))
974
975 (defun debbugs-gnu-widen ()
976 "Display all the currently selected bug reports."
977 (interactive)
978 (let ((id (debbugs-gnu-current-id t))
979 (inhibit-read-only t))
980 (setq debbugs-gnu-limit nil)
981 (tabulated-list-init-header)
982 (tabulated-list-print)
983 (when id
984 (debbugs-gnu-goto id))))
985
986 (defun debbugs-gnu-show-blocked-by-reports ()
987 "Display all bug reports this report is blocked by."
988 (interactive)
989 (let ((id (debbugs-gnu-current-id))
990 (status (debbugs-gnu-current-status)))
991 (if (null (cdr (assq 'blockedby status)))
992 (message "Bug %d is not blocked by any other bug" id)
993 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
994
995 (defun debbugs-gnu-show-blocking-reports ()
996 "Display all bug reports this report is blocking."
997 (interactive)
998 (let ((id (debbugs-gnu-current-id))
999 (status (debbugs-gnu-current-status)))
1000 (if (null (cdr (assq 'blocks status)))
1001 (message "Bug %d is not blocking any other bug" id)
1002 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
1003
1004 (defun debbugs-gnu-show-all-blocking-reports ()
1005 "Narrow the display to just the reports that are blocking a release."
1006 (interactive)
1007 (let ((blockers (cdr (assq 'blockedby
1008 (car (debbugs-get-status
1009 debbugs-gnu-blocking-report)))))
1010 (id (debbugs-gnu-current-id t))
1011 (inhibit-read-only t)
1012 status)
1013 (setq debbugs-gnu-limit nil)
1014 (goto-char (point-min))
1015 (while (not (eobp))
1016 (setq status (debbugs-gnu-current-status))
1017 (if (not (memq (cdr (assq 'id status)) blockers))
1018 (delete-region (point) (progn (forward-line 1) (point)))
1019 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1020 (forward-line 1)))
1021 (when id
1022 (debbugs-gnu-goto id))))
1023
1024 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1025 "Only display the bugs matching STRING.
1026 If STATUS-ONLY (the prefix), ignore matches in the From and
1027 Subject fields."
1028 (interactive "sNarrow to: \nP")
1029 (let ((id (debbugs-gnu-current-id t))
1030 (inhibit-read-only t)
1031 status)
1032 (setq debbugs-gnu-limit nil)
1033 (if (equal string "")
1034 (debbugs-gnu-toggle-suppress)
1035 (goto-char (point-min))
1036 (while (not (eobp))
1037 (setq status (debbugs-gnu-current-status))
1038 (if (and (not (member string (assq 'keywords status)))
1039 (not (equal string (cdr (assq 'severity status))))
1040 (or status-only
1041 (not (string-match
1042 string (cdr (assq 'originator status)))))
1043 (or status-only
1044 (not (string-match string (cdr (assq 'subject status))))))
1045 (delete-region (point) (progn (forward-line 1) (point)))
1046 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1047 (forward-line 1)))
1048 (when id
1049 (debbugs-gnu-goto id)))))
1050
1051 (defun debbugs-gnu-goto (id)
1052 "Go to the line displaying bug ID."
1053 (goto-char (point-min))
1054 (while (and (not (eobp))
1055 (not (equal (debbugs-gnu-current-id t) id)))
1056 (forward-line 1)))
1057
1058 (defun debbugs-gnu-toggle-tag ()
1059 "Toggle the local tag of the report in the current line.
1060 If a report is tagged locally, it is presumed to be of little
1061 interest to you."
1062 (interactive)
1063 (save-excursion
1064 (beginning-of-line)
1065 (let ((inhibit-read-only t)
1066 (id (debbugs-gnu-current-id)))
1067 (if (memq id debbugs-gnu-local-tags)
1068 (progn
1069 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1070 (put-text-property (point) (+ (point) 5) 'face 'default))
1071 (add-to-list 'debbugs-gnu-local-tags id)
1072 (put-text-property
1073 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1074 'face 'debbugs-gnu-tagged))
1075 (debbugs-gnu--update-tag-face id)))
1076 (debbugs-gnu-dump-persistency-file))
1077
1078 (defun debbugs-gnu--update-tag-face (id)
1079 (dolist (entry tabulated-list-entries)
1080 (when (equal (cdr (assq 'id (car entry))) id)
1081 (aset (cadr entry) 0
1082 (propertize
1083 (format "%5d" id)
1084 'face
1085 ;; Mark tagged bugs.
1086 (if (memq id debbugs-gnu-local-tags)
1087 'debbugs-gnu-tagged
1088 'default))))))
1089
1090 (defun debbugs-gnu-toggle-suppress ()
1091 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1092 (interactive)
1093 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1094 (tabulated-list-init-header)
1095 (tabulated-list-print))
1096
1097 (defvar debbugs-gnu-bug-number nil)
1098 (defvar debbugs-gnu-subject nil)
1099
1100 (defun debbugs-gnu-current-id (&optional noerror)
1101 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1102 (and (not noerror)
1103 (error "No bug on the current line"))))
1104
1105 (defun debbugs-gnu-current-status ()
1106 (get-text-property (line-beginning-position) 'tabulated-list-id))
1107
1108 (defun debbugs-gnu-display-status (query filter status)
1109 "Display the query, filter and status of the report on the current line."
1110 (interactive (list debbugs-gnu-local-query
1111 debbugs-gnu-local-filter
1112 (debbugs-gnu-current-status)))
1113 (switch-to-buffer "*Bug Status*")
1114 (let ((inhibit-read-only t))
1115 (erase-buffer)
1116 (when query
1117 (insert ";; Query\n")
1118 (pp query (current-buffer))
1119 (insert "\n"))
1120 (when filter
1121 (insert ";; Filter\n")
1122 (pp filter (current-buffer))
1123 (insert "\n"))
1124 (when status
1125 (insert ";; Status\n")
1126 (pp status (current-buffer)))
1127 (goto-char (point-min)))
1128 (set-buffer-modified-p nil)
1129 (special-mode))
1130
1131 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1132 "Read email exchange for debbugs bug ID.
1133 STATUS is the bug's status list.
1134 MERGED is the list of bugs merged with this one."
1135 (let* ((mbox-dir (make-temp-file "debbugs" t))
1136 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1137 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1138 (rmail mbox-fname)
1139 ;; Download messages of all the merged bug reports and append them
1140 ;; to the mailbox of the requested bug.
1141 (when merged
1142 (dolist (bugno merged)
1143 (let ((fn (make-temp-file "url")))
1144 (debbugs-get-mbox bugno 'mboxmaint fn)
1145 (rmail-get-new-mail fn)
1146 (delete-file fn)
1147 ;; Remove the 'unseen' attribute from all the messages we've
1148 ;; just read, so that all of them appear in the summary with
1149 ;; the same face.
1150 (while (< rmail-current-message rmail-total-messages)
1151 (rmail-show-message (1+ rmail-current-message))))))
1152 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1153 (set (make-local-variable 'debbugs-gnu-subject)
1154 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1155 (rmail-summary)
1156 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1157 (set-window-text-height nil 10)
1158 (other-window 1)
1159 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1160 (rmail-show-message 1)))
1161
1162 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1163 "Read email exchange for debbugs bug ID.
1164 STATUS is the bug's status list.
1165 MERGED is the list of bugs merged with this one."
1166 (require 'gnus-dup)
1167 (setq gnus-suppress-duplicates t
1168 gnus-save-duplicate-list t)
1169 ;; Use Gnus.
1170 (gnus-read-ephemeral-emacs-bug-group
1171 (cons id (if (listp merged) merged (list merged)))
1172 (cons (current-buffer)
1173 (current-window-configuration)))
1174 (with-current-buffer (window-buffer (selected-window))
1175 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1176 (set (make-local-variable 'debbugs-gnu-subject)
1177 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1178 (debbugs-gnu-summary-mode 1)))
1179
1180 (defun debbugs-gnu-select-report ()
1181 "Select the report on the current line."
1182 (interactive)
1183 ;; We open the report messages.
1184 (let* ((status (debbugs-gnu-current-status))
1185 (id (cdr (assq 'id status)))
1186 (merged (cdr (assq 'mergedwith status))))
1187 (setq merged (if (listp merged) merged (list merged)))
1188 (cond
1189 ((not id)
1190 (message "No bug report on the current line"))
1191 ((eq debbugs-gnu-mail-backend 'rmail)
1192 (debbugs-read-emacs-bug-with-rmail id status merged))
1193 ((eq debbugs-gnu-mail-backend 'gnus)
1194 (debbugs-read-emacs-bug-with-gnus id status merged))
1195 (t (error "No valid mail backend specified")))))
1196
1197 (defvar debbugs-gnu-summary-mode-map
1198 (let ((map (make-sparse-keymap)))
1199 (define-key map "C" 'debbugs-gnu-send-control-message)
1200 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1201 map))
1202
1203 (define-minor-mode debbugs-gnu-summary-mode
1204 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1205
1206 \\{debbugs-gnu-summary-mode-map}"
1207 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1208 (set (make-local-variable 'gnus-posting-styles)
1209 `((".*"
1210 (eval
1211 (when (buffer-live-p gnus-article-copy)
1212 (with-current-buffer gnus-article-copy
1213 (set (make-local-variable 'message-prune-recipient-rules)
1214 '((".*@debbugs.*" "emacs-pretest-bug")
1215 (".*@debbugs.*" "bug-gnu-emacs")
1216 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1217 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1218 (set (make-local-variable 'message-alter-recipients-function)
1219 (lambda (address)
1220 (if (string-match "\\([0-9]+\\)@donarmstrong"
1221 (car address))
1222 (let ((new (format "%s@debbugs.gnu.org"
1223 (match-string 1 (car address)))))
1224 (cons new new))
1225 address)))
1226 ;; `gnus-posting-styles' is eval'ed after
1227 ;; `message-simplify-subject'. So we cannot use m-s-s.
1228 (setq subject ,debbugs-gnu-subject))))))))
1229
1230 (defun debbugs-gnu-guess-current-id ()
1231 "Guess the ID based on \"#23\"."
1232 (save-excursion
1233 (beginning-of-line)
1234 (and
1235 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1236 (progn
1237 (goto-char (point-min))
1238 (re-search-forward "#\\([0-9]+\\)" nil t)))
1239 (string-to-number (match-string 1)))))
1240
1241 (defvar debbugs-gnu-send-mail-function nil
1242 "A function to send control messages from debbugs.")
1243
1244 (defun debbugs-gnu-send-control-message (message &optional reverse)
1245 "Send a control message for the current bug report.
1246 You can set the severity or add a tag, or close the report. If
1247 you use the special \"done\" MESSAGE, the report will be marked as
1248 fixed, and then closed.
1249
1250 If given a prefix, and given a tag to set, the tag will be
1251 removed instead."
1252 (interactive
1253 (list (completing-read
1254 "Control message: "
1255 '("serious" "important" "normal" "minor" "wishlist"
1256 "done" "donenotabug" "donewontfix" "doneunreproducible"
1257 "unarchive" "unmerge" "reopen" "close"
1258 "merge" "forcemerge"
1259 "block" "unblock"
1260 "owner" "noowner"
1261 "invalid"
1262 "reassign"
1263 "retitle"
1264 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1265 "pending" "help" "security" "confirmed"
1266 "usertag")
1267 nil t)
1268 current-prefix-arg))
1269 (let* ((id (or (debbugs-gnu-current-id t)
1270 debbugs-gnu-bug-number ; Set on group entry.
1271 (debbugs-gnu-guess-current-id)))
1272 (version
1273 (when (member message '("close" "done"))
1274 (read-string
1275 "Version: "
1276 (cond
1277 ;; Emacs development versions.
1278 ((string-match
1279 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1280 (format "%s.%d"
1281 (match-string 1 emacs-version)
1282 (1+ (string-to-number (match-string 2 emacs-version)))))
1283 ;; Emacs release versions.
1284 ((string-match
1285 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1286 (format "%s.%s"
1287 (match-string 1 emacs-version)
1288 (match-string 2 emacs-version)))
1289 (t emacs-version)))))
1290 (status (debbugs-gnu-current-status)))
1291 (with-temp-buffer
1292 (insert "To: control@debbugs.gnu.org\n"
1293 "From: " (message-make-from) "\n"
1294 (format "Subject: control message for bug #%d\n" id)
1295 mail-header-separator
1296 "\n"
1297 (cond
1298 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1299 (format "%s %d\n" message id))
1300 ((member message '("merge" "forcemerge"))
1301 (format "%s %d %s\n" message id
1302 (read-string "Merge with bug #: ")))
1303 ((member message '("block" "unblock"))
1304 (format
1305 "%s %d by %s\n" message id
1306 (mapconcat
1307 'identity
1308 (completing-read-multiple
1309 (format "%s with bug(s) #: " (capitalize message))
1310 (if (equal message "unblock")
1311 (mapcar 'number-to-string
1312 (cdr (assq 'blockedby status))))
1313 nil (and (equal message "unblock") status))
1314 " ")))
1315 ((equal message "owner")
1316 (format "owner %d !\n" id))
1317 ((equal message "retitle")
1318 (format "retitle %d %s\n" id (read-string "New title: ")))
1319 ((equal message "reassign")
1320 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1321 ((equal message "close")
1322 (format "close %d %s\n" id version))
1323 ((equal message "done")
1324 (format "tags %d fixed\nclose %d %s\n" id id version))
1325 ((member message '("donenotabug" "donewontfix"
1326 "doneunreproducible"))
1327 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1328 ((member message '("serious" "important" "normal"
1329 "minor" "wishlist"))
1330 (format "severity %d %s\n" id message))
1331 ((equal message "invalid")
1332 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1333 id id id))
1334 ((equal message "usertag")
1335 (format "user %s\nusertag %d %s\n"
1336 (completing-read
1337 "Package name or email address: "
1338 (append
1339 debbugs-gnu-all-packages (list user-mail-address))
1340 nil nil (car debbugs-gnu-default-packages))
1341 id (read-string "User tag: ")))
1342 (t
1343 (format "tags %d%s %s\n"
1344 id (if reverse " -" "")
1345 message))))
1346 (funcall (or debbugs-gnu-send-mail-function send-mail-function))
1347 (remhash id debbugs-cache-data)
1348 (message-goto-body)
1349 (message "Control message sent:\n%s"
1350 (buffer-substring-no-properties (point) (1- (point-max)))))))
1351
1352 (defvar debbugs-gnu-usertags-mode-map
1353 (let ((map (make-sparse-keymap)))
1354 (set-keymap-parent map tabulated-list-mode-map)
1355 (define-key map "\r" 'debbugs-gnu-select-usertag)
1356 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1357 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1358 map))
1359
1360 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1361 "Major mode for listing user tags.
1362
1363 All normal editing commands are switched off.
1364 \\<debbugs-gnu-usertags-mode-map>
1365
1366 The following commands are available:
1367
1368 \\{debbugs-gnu-usertags-mode-map}"
1369 (buffer-disable-undo)
1370 (setq truncate-lines t)
1371 (setq buffer-read-only t))
1372
1373 ;;;###autoload
1374 (defun debbugs-gnu-usertags (&rest users)
1375 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1376 (interactive
1377 (if current-prefix-arg
1378 (completing-read-multiple
1379 "Package name(s) or email address: "
1380 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1381 (mapconcat 'identity debbugs-gnu-default-packages ","))
1382 debbugs-gnu-default-packages))
1383
1384 (unwind-protect
1385 (let ((inhibit-read-only t)
1386 (debbugs-port "gnu.org")
1387 (buffer-name "*Emacs User Tags*")
1388 (user-tab-length
1389 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1390
1391 ;; Initialize variables.
1392 (when (and (file-exists-p debbugs-gnu-persistency-file)
1393 (not debbugs-gnu-local-tags))
1394 (with-temp-buffer
1395 (insert-file-contents debbugs-gnu-persistency-file)
1396 (eval (read (current-buffer)))))
1397
1398 ;; Create buffer.
1399 (when (get-buffer buffer-name)
1400 (kill-buffer buffer-name))
1401 (switch-to-buffer (get-buffer-create buffer-name))
1402 (debbugs-gnu-usertags-mode)
1403 (setq tabulated-list-format `[("User" ,user-tab-length t)
1404 ("Tag" 10 t)])
1405 (setq tabulated-list-sort-key (cons "User" nil))
1406 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1407
1408 ;; Retrieve user tags.
1409 (dolist (user users)
1410 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1411 (add-to-list
1412 'tabulated-list-entries
1413 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1414 `((("tagged") (,user) nil nil (,tag))
1415 ,(vector (propertize user 'mouse-face 'highlight)
1416 (propertize tag 'mouse-face 'highlight)))
1417 'append)))
1418
1419 ;; Add local tags.
1420 (when debbugs-gnu-local-tags
1421 (add-to-list
1422 'tabulated-list-entries
1423 `((("tagged"))
1424 ,(vector
1425 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1426
1427 ;; Show them.
1428 (tabulated-list-init-header)
1429 (tabulated-list-print)
1430
1431 (set-buffer-modified-p nil)
1432 (goto-char (point-min)))))
1433
1434 (defun debbugs-gnu-select-usertag ()
1435 "Select the user tag on the current line."
1436 (interactive)
1437 ;; We open the bug reports.
1438 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1439 (when args (apply 'debbugs-gnu args))))
1440
1441 ;;;###autoload
1442 (defun debbugs-gnu-bugs (&rest bugs)
1443 "List all BUGS, a list of bug numbers."
1444 (interactive
1445 (mapcar 'string-to-number
1446 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1447 (dolist (elt bugs)
1448 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1449 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1450 ;; We do not suppress bugs requested explicitely.
1451 (setq debbugs-gnu-current-suppress nil)
1452 (debbugs-gnu nil))
1453
1454 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1455 "The directory where the main source tree lives.")
1456
1457 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1458 "The directory where the previous source tree lives.")
1459
1460 (defun debbugs-gnu-apply-patch (&optional branch)
1461 "Apply the patch from the current message.
1462 If given a prefix, patch in the branch directory instead."
1463 (interactive "P")
1464 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1465 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1466 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1467 (let ((rej "/tmp/debbugs-gnu.rej")
1468 (output-buffer (get-buffer-create "*debbugs patch*"))
1469 (dir (if branch
1470 debbugs-gnu-branch-directory
1471 debbugs-gnu-trunk-directory))
1472 (patch-buffers nil))
1473 (when (file-exists-p rej)
1474 (delete-file rej))
1475 (with-current-buffer output-buffer
1476 (erase-buffer))
1477 (gnus-summary-select-article nil t)
1478 ;; The patches are either in MIME attachements or the main article
1479 ;; buffer. Determine which.
1480 (gnus-with-article-buffer
1481 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1482 (when (string-match "diff\\|patch\\|plain" (mm-handle-media-type handle))
1483 (push (cons (mm-handle-encoding handle)
1484 (mm-handle-buffer handle))
1485 patch-buffers))))
1486 (unless patch-buffers
1487 (gnus-summary-show-article 'raw)
1488 (article-decode-charset)
1489 (push (cons nil gnus-article-buffer) patch-buffers))
1490 (dolist (elem patch-buffers)
1491 (with-current-buffer (generate-new-buffer "*debbugs input patch*")
1492 (insert-buffer-substring (cdr elem))
1493 (cond ((eq (car elem) 'base64)
1494 (base64-decode-region (point-min) (point-max)))
1495 ((eq (car elem) 'quoted-printable)
1496 (quoted-printable-decode-region (point-min) (point-max))))
1497 (debbugs-gnu-fix-patch dir)
1498 (call-process-region (point-min) (point-max)
1499 "patch" nil output-buffer nil
1500 "-r" rej "--no-backup-if-mismatch"
1501 "-l" "-f"
1502 "-d" (expand-file-name dir)
1503 "-p1")))
1504 (set-buffer output-buffer)
1505 (when (file-exists-p rej)
1506 (goto-char (point-max))
1507 (insert-file-contents-literally rej))
1508 (goto-char (point-max))
1509 (save-some-buffers t)
1510 (require 'compile)
1511 (mapc 'kill-process compilation-in-progress)
1512 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1513 (vc-dir dir)
1514 (vc-dir-hide-up-to-date)
1515 (goto-char (point-min))
1516 (sit-for 1)
1517 (vc-diff)
1518 ;; All these commands are asynchronous, so just wait a bit. This
1519 ;; should be done properly a different way.
1520 (sit-for 2)
1521 ;; We've now done everything, so arrange the windows we need to see.
1522 (delete-other-windows)
1523 (switch-to-buffer output-buffer)
1524 (split-window)
1525 (split-window)
1526 (other-window 1)
1527 (switch-to-buffer "*compilation*")
1528 (goto-char (point-max))
1529 (other-window 1)
1530 (switch-to-buffer "*vc-diff*")
1531 (goto-char (point-min))))
1532
1533 (defun debbugs-gnu-fix-patch (dir)
1534 (setq dir (directory-file-name (expand-file-name dir)))
1535 (goto-char (point-min))
1536 (while (re-search-forward diff-file-header-re nil t)
1537 (goto-char (match-beginning 0))
1538 (let ((target-name (car (diff-hunk-file-names))))
1539 (when (and target-name
1540 (or (not (string-match "/" target-name))
1541 (and (string-match "^[ab]/" target-name)
1542 (not (file-exists-p
1543 (expand-file-name (substring target-name 2)
1544 dir))))
1545 (file-exists-p (expand-file-name target-name dir))))
1546 ;; We have a simple patch that refers to a file somewhere in the
1547 ;; tree. Find it.
1548 (when-let ((files (directory-files-recursively
1549 dir
1550 (concat "^" (regexp-quote
1551 (file-name-nondirectory target-name))
1552 "$"))))
1553 (when (re-search-forward (concat "^[+]+ "
1554 (regexp-quote target-name)
1555 "\\([ \t\n]\\)")
1556 nil t)
1557 (replace-match (concat "+++ a"
1558 (substring (car files) (length dir))
1559 (match-string 1))
1560 nil t)))))
1561 (forward-line 2)))
1562
1563 (defun debbugs-gnu-find-contributor (string)
1564 "Search through ChangeLogs to find contributors."
1565 (interactive "sContributor match: ")
1566 (let ((found 0)
1567 (match (concat "^[0-9].*" string)))
1568 (dolist (file (directory-files-recursively
1569 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1570 (with-temp-buffer
1571 (when (file-exists-p file)
1572 (insert-file-contents file))
1573 (goto-char (point-min))
1574 (while (and (re-search-forward match nil t)
1575 (not (looking-at ".*tiny change")))
1576 (cl-incf found))))
1577 (message "%s is a contributor %d times" string found)
1578 found))
1579
1580 (defvar debbugs-gnu-patch-subject nil)
1581
1582 (defun debbugs-gnu-insert-changelog ()
1583 "Add a ChangeLog from a recently applied patch from a third party."
1584 (interactive)
1585 (let (from subject patch-subject changelog)
1586 (gnus-with-article-buffer
1587 (widen)
1588 (goto-char (point-min))
1589 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1590 subject (gnus-fetch-field "subject"))
1591 ;; If it's a patch formatted the right way, extract that data.
1592 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1593 (when (string-match "diff\\|patch\\|plain"
1594 (mm-handle-media-type handle))
1595 (with-temp-buffer
1596 (insert-buffer-substring (mm-handle-buffer handle))
1597 (cond ((eq (mm-handle-encoding handle) 'base64)
1598 (base64-decode-region (point-min) (point-max)))
1599 ((eq (mm-handle-encoding handle) 'quoted-printable)
1600 (quoted-printable-decode-region (point-min) (point-max))))
1601 (setq patch-subject
1602 (or (gnus-fetch-field "subject") patch-subject))
1603 (goto-char (point-min))
1604 (when (re-search-forward "^[*] " nil t)
1605 (let ((start (match-beginning 0)))
1606 (while (and (not (eobp))
1607 (not (looking-at "---")))
1608 (forward-line 1))
1609 (setq changelog (buffer-substring
1610 start (line-end-position 0)))))))))
1611 (let ((add-log-full-name (car from))
1612 (add-log-mailing-address (cadr from)))
1613 (add-change-log-entry-other-window)
1614 (when patch-subject
1615 (setq-local debbugs-gnu-patch-subject patch-subject))
1616 (when changelog
1617 (delete-region (line-beginning-position) (point-max))
1618 (save-restriction
1619 (narrow-to-region (point) (point))
1620 (insert changelog)
1621 (indent-region (point-min) (point-max))))
1622 (let ((point (point)))
1623 (when (string-match "\\(bug#[0-9]+\\)" subject)
1624 (insert " (" (match-string 1 subject) ")."))
1625 (when (zerop (debbugs-gnu-find-contributor
1626 (let ((bits (split-string (car from))))
1627 (cond
1628 ((>= (length bits) 2)
1629 (format "%s.*%s" (car bits) (car (last bits))))
1630 ((= (length bits) 1)
1631 (car bits))
1632 ;; Fall back on the email address.
1633 (t
1634 (cadr from))))))
1635 (goto-char (point-max))
1636 (end-of-line)
1637 (when changelog
1638 (insert "\n\n"))
1639 (insert " Copyright-paperwork-exempt: yes"))
1640 (goto-char point)))))
1641
1642 (defvar debbugs-gnu-lisp-mode-map
1643 (let ((map (make-sparse-keymap)))
1644 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1645 map))
1646
1647 (define-minor-mode debbugs-gnu-lisp-mode
1648 "Minor mode for providing a debbugs interface in Lisp buffers.
1649 \\{debbugs-gnu-lisp-mode-map}"
1650 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1651
1652 (defvar debbugs-gnu-diff-mode-map
1653 (let ((map (make-sparse-keymap)))
1654 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1655 map))
1656
1657 (define-minor-mode debbugs-gnu-diff-mode
1658 "Minor mode for providing a debbugs interface in diff buffers.
1659 \\{debbugs-gnu-diff-mode-map}"
1660 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1661
1662 (defun debbugs-gnu-diff-select ()
1663 "Select the diff under point."
1664 (interactive)
1665 (delete-other-windows)
1666 (diff-goto-source))
1667
1668 (defvar debbugs-gnu-change-mode-map
1669 (let ((map (make-sparse-keymap)))
1670 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1671 map))
1672
1673 (define-minor-mode debbugs-gnu-change-mode
1674 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1675 \\{debbugs-gnu-change-mode-map}"
1676 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1677
1678 (defun debbugs-gnu-change-checkin ()
1679 "Prepare checking in the current changes."
1680 (interactive)
1681 (save-some-buffers t)
1682 (when (get-buffer "*vc-dir*")
1683 (kill-buffer (get-buffer "*vc-dir*")))
1684 (let ((patch-subject debbugs-gnu-patch-subject))
1685 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1686 (if (equal (cl-subseq default-directory 0 (length trunk))
1687 trunk)
1688 (vc-dir debbugs-gnu-trunk-directory)
1689 (vc-dir debbugs-gnu-branch-directory)))
1690 (goto-char (point-min))
1691 (while (not (search-forward "edited" nil t))
1692 (sit-for 0.01))
1693 (beginning-of-line)
1694 (while (search-forward "edited" nil t)
1695 (vc-dir-mark)
1696 (beginning-of-line))
1697 (vc-diff nil)
1698 (vc-next-action nil)
1699 (delete-region (point-min) (point-max))
1700 (log-edit-insert-changelog t)
1701 (delete-other-windows)
1702 (split-window)
1703 (other-window 1)
1704 (switch-to-buffer "*vc-diff*")
1705 (other-window 1)
1706 (when patch-subject
1707 (insert "Summary: "
1708 (replace-regexp-in-string "^ *\\[PATCH\\] *" "" patch-subject)
1709 "\n"))))
1710
1711 (defun debbugs-gnu-save-cache ()
1712 "Save the bugs cache to a file."
1713 (interactive)
1714 (unless debbugs-cache-data
1715 (error "No data to cache"))
1716 (unless (file-exists-p "~/.emacs.d/debbugs-cache")
1717 (make-directory "~/.emacs.d/debbugs-cache" t))
1718 (let ((coding-system-for-write 'utf-8))
1719 (with-temp-file "~/.emacs.d/debbugs-cache/list"
1720 (prin1 debbugs-cache-data (current-buffer)))))
1721
1722 (provide 'debbugs-gnu)
1723
1724 ;;; TODO:
1725
1726 ;; * Another random thought - is it possible to implement some local
1727 ;; cache, so only changed bugs are fetched? Glenn Morris.
1728
1729 ;;; debbugs-gnu.el ends here