1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011, 2012 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: comm, hypermedia, maint
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs 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.
17 ;; GNU Emacs 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.
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/>.
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.
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
35 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
36 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
38 ;; The bug tracker is called interactively by
42 ;; It asks for the severities, for which bugs shall be shown. This can
43 ;; be either just one severity, or a list of severities, separated by
44 ;; comma. Valid severities are "serious", "important", "normal",
45 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
46 ;; used, although configured on the GNU bug tracker. If no severity
47 ;; is given, all bugs are selected.
49 ;; There is also the pseudo severity "tagged". When it is used, the
50 ;; function will ask for user tags (a comma separated list), and shows
51 ;; just the bugs which are tagged with them. In general, user tags
52 ;; shall be strings denoting to subprojects of the package, like
53 ;; "cedet" or "tramp" of the package "emacs. If no user tag is given,
54 ;; locally tagged bugs are shown.
56 ;; If a prefix is given to the command, more search parameters are
57 ;; asked for, like packages (also a comma separated list, "emacs" is
58 ;; the default), whether archived bugs shall be shown, and whether
59 ;; closed bugs shall be shown.
63 ;; M-x debbugs-gnu-search
65 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
66 ;; search phrase to be used for full text search. Additionally, it
67 ;; asks for key-value pairs to filter bugs. Keys are as described in
68 ;; `debbugs-get-status', the corresponding value must be a regular
69 ;; expression to match for. The other parameters are as described in
70 ;; `debbugs-gnu'. Usually, there is just one value except for the
71 ;; attribute "date", which needs two arguments specifying a period in
72 ;; which the bug has been submitted or modified.
74 ;; The bug reports are downloaded from the bug tracker. In order to
75 ;; not generate too much load of the server, up to 500 bugs will be
76 ;; downloaded at once. If there are more hits, you will be asked to
77 ;; change this limit, but please don't increase this number too much.
79 ;; These default values could be changed also by customer options
80 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages',
81 ;; `debbugs-gnu-default-hits-per-page' and `debbugs-gnu-default-suppress-bugs'.
83 ;; The commands create one or more pages of bug lists. Every bug is
84 ;; shown in one line, including the bug number, the status (combining
85 ;; merged bug numbers, keywords and severities), the name of the
86 ;; submitter, and the title of the bug. On every bug line you could
87 ;; apply the following actions by the following keystrokes:
89 ;; RET: Show corresponding messages in Gnus
90 ;; "C": Send a control message
91 ;; "t": Mark the bug locally as tagged
92 ;; "d": Show bug attributes
94 ;; Furthermore, you could apply the global actions
97 ;; "q": Quit the buffer
98 ;; "s": Toggle bug sorting for age or for state
99 ;; "x": Toggle suppressing of bugs
100 ;; "/": Display only bugs matching a string
101 ;; "w": Display all the currently selected bug reports
103 ;; When you visit the related bug messages in Gnus, you could also
104 ;; send control messages by keystroke "C".
106 ;; In the header line of every bug list page, you can toggle sorting
107 ;; per column by selecting a column with the mouse. The sorting
108 ;; happens as expected for the respective column; sorting in the Title
109 ;; column is depending on whether you are the owner of a bug.
115 (require 'tabulated-list)
116 (eval-when-compile (require 'cl))
118 (autoload 'widget-convert "wid-edit.el")
119 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
120 (autoload 'mail-header-subject "nnheader")
121 (autoload 'gnus-summary-article-header "gnus-sum")
122 (autoload 'message-make-from "message")
124 (defgroup debbugs-gnu ()
125 "UI for the debbugs.gnu.org bug tracker."
129 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
130 "*The list severities bugs are searched for.
131 \"tagged\" is not a severity but marks locally tagged bugs."
132 ;; <http://debbugs.gnu.org/Developer.html#severities>
134 :type '(set (const "serious")
142 (defconst debbugs-gnu-all-severities
143 "*List of all possible severities."
144 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type))))
146 (defcustom debbugs-gnu-default-packages '("emacs")
147 "*The list of packages to be searched for."
148 ;; <http://debbugs.gnu.org/Packages.html>
150 :type '(set (const "automake")
152 (const "debbugs.gnu.org")
154 (const "emacs-xwidgets")
162 (defconst debbugs-gnu-all-packages
163 "*List of all possible package names."
164 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type))))
166 (defcustom debbugs-gnu-default-hits-per-page 500
167 "*The number of bugs shown per page."
172 (defcustom debbugs-gnu-default-suppress-bugs
173 '((pending . "done"))
174 "*A list of specs for bugs to be suppressed.
175 An element of this list is a cons cell \(KEY . REGEXP\), with key
176 being returned by `debbugs-get-status', and VAL a regular
177 expression matching the corresponding value, a string. Showing
178 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
180 :type '(alist :key-type symbol :value-type regexp)
183 (defface debbugs-gnu-new '((t (:foreground "red")))
184 "Face for new reports that nobody has answered.")
186 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
187 "Face for reports that have been modified recently.")
189 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
190 "Face for reports that are pending.")
192 (defface debbugs-gnu-stale '((t (:foreground "orange")))
193 "Face for reports that have not been touched for a week.")
195 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
196 "Face for closed bug reports.")
198 (defface debbugs-gnu-tagged '((t (:foreground "red")))
199 "Face for reports that have been tagged locally.")
201 (defvar debbugs-gnu-widgets nil)
203 (defvar debbugs-gnu-widget-map
204 (let ((map (make-sparse-keymap)))
205 (define-key map "\r" 'widget-button-press)
206 (define-key map [mouse-1] 'widget-button-press)
207 (define-key map [mouse-2] 'widget-button-press)
210 (defvar debbugs-gnu-local-tags nil
211 "List of bug numbers tagged locally, and kept persistent.")
213 (defvar debbugs-gnu-persistency-file
214 (expand-file-name (locate-user-emacs-file "debbugs"))
215 "File name of a persistency store for debbugs variables")
217 (defun debbugs-gnu-dump-persistency-file ()
218 "Function to store debbugs variables persistently."
219 (with-temp-file debbugs-gnu-persistency-file
221 ";; -*- emacs-lisp -*-\n"
222 ";; Debbugs tags connection history. Don't change this file.\n\n"
223 (format "(setq debbugs-gnu-local-tags '%S)"
224 (sort (copy-sequence debbugs-gnu-local-tags) '<)))))
226 (defvar debbugs-gnu-current-query nil
227 "The query object of the current search.
228 It will be applied server-side, when calling `debbugs-get-bugs'.
229 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
231 (defvar debbugs-gnu-current-filter nil
232 "The filter object for the current search.
233 It will be applied client-side, when parsing the results of
234 `debbugs-get-status'. It has a similar format as
235 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
236 a date, value is the cons cell \(BEFORE . AFTER\).")
238 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
239 "Return a string read from the minibuffer.
240 Derived from `calendar-read'."
241 (let ((value (read-string prompt initial-contents)))
242 (while (not (funcall acceptable value))
243 (setq value (read-string prompt initial-contents)))
246 (defconst debbugs-gnu-phrase-prompt
248 "Enter search phrase: "
250 The search phrase contains words to be searched for, combined by
251 operators like AND, ANDNOT and OR. If there is no operator
252 between the words, AND is used by default. The phrase can also
253 be empty, in this case only the following attributes are used for
257 (defun debbugs-gnu-search ()
258 "Search for Emacs bugs interactively.
259 Search arguments are requested interactively. The \"search
260 phrase\" is used for full text search in the bugs database.
261 Further key-value pairs are requested until an empty key is
262 returned. If a key cannot be queried by a SOAP request, it is
263 marked as \"client-side filter\"."
267 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
268 key val1 val2 phrase severities packages archivedp)
270 ;; Check for the phrase.
271 (setq phrase (read-string debbugs-gnu-phrase-prompt))
272 (if (zerop (length phrase))
274 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
276 ;; The other queries.
279 (setq key (completing-read
282 '("severity" "package" "tags" "submitter" "date"
284 '("severity" "package" "archive" "src" "tag"
285 "owner" "submitter" "maint" "correspondent"
286 "date" "log_modified" "last_modified"
287 "found_date" "fixed_date" "unarchived"
288 "subject" "done" "forwarded" "msgid" "summary"))
291 ;; Server-side queries.
292 ((equal key "severity")
295 (completing-read-multiple
296 "Enter severities: " debbugs-gnu-all-severities nil t
297 (mapconcat 'identity debbugs-gnu-default-severities ","))))
299 ((equal key "package")
302 (completing-read-multiple
303 "Enter packages: " debbugs-gnu-all-packages nil t
304 (mapconcat 'identity debbugs-gnu-default-packages ","))))
306 ((equal key "archive")
307 ;; We simplify, by assuming just archived bugs are requested.
310 ((member key '("src" "tag" "tags"))
311 (setq val1 (read-string (format "Enter %s: " key)))
312 (when (not (zerop (length val1)))
314 'debbugs-gnu-current-query (cons (intern key) val1))))
316 ((member key '("owner" "submitter" "maint" "correspondent"))
317 (setq val1 (read-string "Enter email address: "))
318 (when (not (zerop (length val1)))
320 'debbugs-gnu-current-query (cons (intern key) val1))))
322 ((equal key "status")
325 (completing-read "Enter status: " '("done" "forwarded" "open")))
326 (when (not (zerop (length val1)))
328 'debbugs-gnu-current-query (cons (intern key) val1))))
330 ;; Client-side filters.
331 ((member key '("date" "log_modified" "last_modified"
332 "found_date" "fixed_date" "unarchived"))
334 (debbugs-gnu-calendar-read
335 (format "Enter %s before YYYY-MM-DD%s: "
336 key (if phrase "" " (client-side filter)"))
338 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
339 (if (string-match date-format val1)
344 (string-to-number (match-string 3 val1))
345 (string-to-number (match-string 2 val1))
346 (string-to-number (match-string 1 val1))))))
349 (debbugs-gnu-calendar-read
350 (format "Enter %s after YYYY-MM-DD%s: "
351 key (if phrase "" " (client-side filter)"))
353 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
354 (if (string-match date-format val2)
359 (string-to-number (match-string 3 val2))
360 (string-to-number (match-string 2 val2))
361 (string-to-number (match-string 1 val2))))))
366 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
367 (cons (intern key) (cons val1 val2)))))
369 ((not (zerop (length key)))
372 (if phrase 'read-string 'read-regexp)
374 key (if phrase ": " " (client-side filter)"))))
375 (when (not (zerop (length val1)))
378 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
379 (cons (intern key) val1))))
382 (t (throw :finished nil)))))
385 (debbugs-gnu severities packages archivedp))
387 ;; Reset query and filter.
388 (setq debbugs-gnu-current-query nil
389 debbugs-gnu-current-filter nil)))
392 (defun debbugs-gnu (severities &optional packages archivedp suppress usertags)
393 "List all outstanding Emacs bugs."
395 (let (severities archivedp)
398 (completing-read-multiple
399 "Severities: " debbugs-gnu-all-severities nil t
400 (mapconcat 'identity debbugs-gnu-default-severities ",")))
401 ;; The next parameters are asked only when there is a prefix.
402 (if current-prefix-arg
403 (completing-read-multiple
404 "Packages: " debbugs-gnu-all-packages nil t
405 (mapconcat 'identity debbugs-gnu-default-packages ","))
406 debbugs-gnu-default-packages)
407 (when current-prefix-arg
408 (setq archivedp (y-or-n-p "Show archived bugs?")))
409 (when (and current-prefix-arg (not archivedp))
410 (y-or-n-p "Suppress unwanted bugs?"))
411 ;; This one must be asked for severity "tagged".
412 (when (member "tagged" severities)
413 (split-string (read-string "User tag(s): ") "," t)))))
415 ;; Initialize variables.
416 (when (and (file-exists-p debbugs-gnu-persistency-file)
417 (not debbugs-gnu-local-tags))
419 (insert-file-contents debbugs-gnu-persistency-file)
420 (eval (read (current-buffer)))))
421 (setq debbugs-gnu-widgets nil)
424 (dolist (severity (if (consp severities) severities (list severities)))
425 (when (not (zerop (length severity)))
426 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
427 (dolist (package (if (consp packages) packages (list packages)))
428 (when (not (zerop (length package)))
429 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
431 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
432 (dolist (usertag (if (consp usertags) usertags (list usertags)))
433 (when (not (zerop (length usertag)))
434 (add-to-list 'debbugs-gnu-current-query (cons 'usertag usertag))))
437 (let ((hits debbugs-gnu-default-hits-per-page)
438 (ids (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
440 (if (> (length ids) hits)
441 (let ((cursor-in-echo-area nil))
446 "How many reports (available %d, default %d): "
450 (number-to-string hits))))))
452 (if (> (length ids) hits)
457 curr-ids (butlast ids (- (length ids) hits)))
462 :follow-link 'mouse-face
463 :notify (lambda (widget &rest ignore)
464 (debbugs-gnu-show-reports widget))
465 :keymap debbugs-gnu-widget-map
467 :buffer-name (format "*Emacs Bugs*<%d>" i)
469 :query debbugs-gnu-current-query
470 :filter debbugs-gnu-current-filter
471 :help-echo (format "%d-%d" (car ids) (car (last curr-ids)))
473 (number-to-string i))
475 (setq ids (last ids (- (length ids) hits))))
476 (debbugs-gnu-show-reports (car debbugs-gnu-widgets)))
478 (debbugs-gnu-show-reports
482 :buffer-name "*Emacs Bugs*"
484 :query debbugs-gnu-current-query
485 :filter debbugs-gnu-current-filter))))
487 ;; Reset query and filter.
488 (setq debbugs-gnu-current-query nil
489 debbugs-gnu-current-filter nil)))
491 (defun debbugs-gnu-get-bugs (query)
492 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
493 (let ((debbugs-port "gnu.org")
494 (tagged (when (member '(severity . "tagged") query)
495 (copy-sequence debbugs-gnu-local-tags)))
496 (phrase (assoc 'phrase query))
498 ;; Compile query and usertags arguments.
500 (when (equal (car elt) 'usertag)
501 (add-to-list 'usertags (cdr elt))))
502 (unless (or query usertags)
503 (dolist (elt debbugs-gnu-default-packages)
504 (setq args (append args (list :package elt)))))
506 (unless (equal elt '(severity . "tagged"))
512 ((eq (car elt) 'phrase)
513 (list (list :phrase (cdr elt) :max 500)))
514 ((eq (car elt) 'date)
515 (list (list :date (cddr elt) (cadr elt)
518 (list (list (intern (concat ":" (symbol-name (car elt))))
519 (cdr elt) :operator "ISTRINC"))))
520 (list (intern (concat ":" (symbol-name (car elt))))
525 ;; If the query contains only the pseudo-severity "tagged", we
526 ;; return just the local tagged bugs.
527 ((and tagged (not usertags) (not (memq :severity args))) tagged)
528 ;; A full text query.
532 (lambda (x) (cdr (assoc "id" x)))
533 (apply 'debbugs-search-est args))
538 (dolist (elt packages result)
540 (append result (apply 'debbugs-get-usertag elt usertags))))))
541 ;; Otherwise, we retrieve the bugs from the server.
542 (t (append (apply 'debbugs-get-bugs args) tagged)))
546 (defvar debbugs-gnu-current-widget nil)
547 (defvar debbugs-gnu-current-limit nil)
549 (defvar widget-mouse-face)
551 (defun debbugs-gnu-show-reports (widget)
552 "Show bug reports as given in WIDGET property :bug-ids."
553 ;; The tabulated mode sets several local variables. We must get rid
555 (when (get-buffer (widget-get widget :buffer-name))
556 (kill-buffer (widget-get widget :buffer-name)))
557 (pop-to-buffer (get-buffer-create (widget-get widget :buffer-name)))
559 (let ((inhibit-read-only t)
560 (debbugs-port "gnu.org"))
562 (set (make-local-variable 'debbugs-gnu-current-widget) widget)
564 (dolist (status (apply 'debbugs-get-status (widget-get widget :bug-ids)))
565 (let* ((id (cdr (assq 'id status)))
569 (cons (cdr (assq 'severity status))
570 (cdr (assq 'keywords status)))
572 (address (mail-header-parse-address
573 (decode-coding-string (cdr (assq 'originator status))
575 (owner (if (cdr (assq 'owner status))
576 (car (mail-header-parse-address
577 (decode-coding-string (cdr (assq 'owner status))
579 (subject (decode-coding-string (cdr (assq 'subject status))
582 (unless (equal (cdr (assq 'pending status)) "pending")
584 (concat words "," (cdr (assq 'pending status)))))
585 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
587 (setq words (concat words "," (mapconcat 'identity packages ",")))))
588 (when (setq merged (cdr (assq 'mergedwith status)))
589 (setq words (format "%s,%s"
592 (mapconcat 'number-to-string merged ","))
594 (when (or (not merged)
595 (not (let ((found nil))
596 (dolist (id (if (listp merged)
599 (dolist (entry tabulated-list-entries)
600 (when (equal id (cdr (assq 'id (car entry))))
604 'tabulated-list-entries
612 (if (memq id debbugs-gnu-local-tags)
616 ;; Mark status and age.
620 ((equal (cdr (assq 'pending status)) "done")
622 ((member "pending" (cdr (assq 'keywords status)))
623 'debbugs-gnu-pending)
624 ((= (cdr (assq 'date status))
625 (cdr (assq 'log_modified status)))
628 (cdr (assq 'log_modified status)))
630 'debbugs-gnu-handled)
632 'debbugs-gnu-stale)))
634 ;; Prefer the name over the address.
638 ;; Mark own submitted bugs.
639 (if (and (stringp (car address))
640 (string-equal (car address) user-mail-address))
647 (if (and (stringp owner)
648 (string-equal owner user-mail-address))
652 (tabulated-list-init-header)
653 (tabulated-list-print)
655 (set-buffer-modified-p nil)
656 (goto-char (point-min))))
658 (defun debbugs-gnu-print-entry (list-id cols)
659 "Insert a debbugs entry at point.
660 Used instead of `tabulated-list-print-entry'."
661 ;; This shall be in `debbugs-gnu-show-reports'. But
662 ;; `tabulated-list-print' erases the buffer, therefore we do it
664 (when (and debbugs-gnu-widgets (= (point) (point-min)))
665 (widget-insert "Page:")
668 (if (eq obj debbugs-gnu-current-widget)
669 (widget-put obj :button-face 'widget-button-pressed)
670 (widget-put obj :button-face 'widget-button-face))
671 (widget-apply obj :create))
673 (widget-insert "\n\n")
675 (widget-insert "\nPage:")
676 (mapc (lambda (obj) (widget-apply obj :create)) debbugs-gnu-widgets)
683 (id-length (nth 1 (aref tabulated-list-format 0)))
684 (state (aref cols 1))
685 (state-length (nth 1 (aref tabulated-list-format 1)))
686 (submitter (aref cols 2))
687 (submitter-length (nth 1 (aref tabulated-list-format 2)))
688 (title (aref cols 3))
689 (title-length (nth 1 (aref tabulated-list-format 3))))
691 ;; We may have a narrowing in effect.
692 (or (not debbugs-gnu-current-limit)
693 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
694 ;; Filter suppressed bugs.
695 (or (not (widget-get debbugs-gnu-current-widget :suppress))
696 (not (catch :suppress
697 (dolist (check debbugs-gnu-default-suppress-bugs)
701 (or (cdr (assq (car check) list-id)) ""))
702 (throw :suppress t))))))
703 ;; Filter search list.
704 (not (catch :suppress
706 (widget-get debbugs-gnu-current-widget :filter))
707 (let ((val (cdr (assq (car check) list-id))))
708 (if (stringp (cdr check))
709 ;; Regular expression.
710 (when (not (string-match (cdr check) (or val "")))
713 (when (or (and (numberp (cadr check))
714 (< (cadr check) val))
715 (and (numberp (cddr check))
716 (> (cddr check) val)))
717 (throw :suppress t))))))))
720 (indent-to (- id-length (length id)))
723 (indent-to (setq pos (+ pos id-length 1)) 1)
724 (insert (if (> (length state) state-length)
725 (propertize (substring state 0 state-length)
729 (indent-to (setq pos (+ pos state-length 1)) 1)
730 (insert "[" (if (> (length submitter) (- submitter-length 2))
731 (propertize (substring submitter 0 (- submitter-length 2))
732 'help-echo submitter)
734 (indent-to (+ pos (1- submitter-length)))
737 (indent-to (setq pos (+ pos submitter-length 1)) 1)
738 (insert (propertize title 'help-echo title))
741 beg (point) `(tabulated-list-id ,list-id mouse-face ,widget-mouse-face))
744 (defvar debbugs-gnu-mode-map
745 (let ((map (make-sparse-keymap)))
746 (set-keymap-parent map tabulated-list-mode-map)
747 (define-key map "\r" 'debbugs-gnu-select-report)
748 (define-key map [mouse-1] 'debbugs-gnu-select-report)
749 (define-key map [mouse-2] 'debbugs-gnu-select-report)
750 (define-key map "s" 'debbugs-gnu-toggle-sort)
751 (define-key map "t" 'debbugs-gnu-toggle-tag)
752 (define-key map "d" 'debbugs-gnu-display-status)
753 (define-key map "g" 'debbugs-gnu-rescan)
754 (define-key map "x" 'debbugs-gnu-toggle-suppress)
755 (define-key map "/" 'debbugs-gnu-narrow-to-status)
756 (define-key map "w" 'debbugs-gnu-widen)
757 (define-key map "C" 'debbugs-gnu-send-control-message)
760 (defun debbugs-gnu-rescan ()
761 "Rescan the current set of bug reports."
764 ;; The last page will be provided with new bug ids.
765 ;; TODO: Do it also for the other pages.
766 (when (and debbugs-gnu-widgets
767 (eq debbugs-gnu-current-widget (car (last debbugs-gnu-widgets))))
768 (let ((first-id (car (widget-get debbugs-gnu-current-widget :bug-ids)))
770 (last (widget-get debbugs-gnu-current-widget :bug-ids))))
771 (ids (debbugs-gnu-get-bugs
772 (widget-get debbugs-gnu-current-widget :query))))
774 (while (and (<= first-id last-id) (not (memq first-id ids)))
775 (setq first-id (1+ first-id)))
777 (when (<= first-id last-id)
778 (widget-put debbugs-gnu-current-widget :bug-ids (memq first-id ids)))))
780 ;; Refresh the buffer. `save-excursion' does not work, so we
781 ;; remember the position.
783 (debbugs-gnu-show-reports debbugs-gnu-current-widget)
786 (defvar debbugs-gnu-sort-state 'number)
788 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
789 "Major mode for listing bug reports.
791 All normal editing commands are switched off.
792 \\<debbugs-gnu-mode-map>
794 The following commands are available:
796 \\{debbugs-gnu-mode-map}"
797 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
798 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
799 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
800 ("State" 20 debbugs-gnu-sort-state)
802 ("Title" 10 debbugs-gnu-sort-title)])
803 (setq tabulated-list-sort-key (cons "Id" nil))
804 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
805 (buffer-disable-undo)
806 (setq truncate-lines t)
807 (setq buffer-read-only t))
809 (defun debbugs-gnu-sort-id (s1 s2)
810 (< (cdr (assq 'id (car s1)))
811 (cdr (assq 'id (car s2)))))
813 (defconst debbugs-gnu-state-preference
814 '((debbugs-gnu-new . 1)
815 (debbugs-gnu-stale . 2)
816 (debbugs-gnu-handled . 3)
817 (debbugs-gnu-done . 4)
818 (debbugs-gnu-pending . 5)))
820 (defun debbugs-gnu-get-state-preference (face-string)
821 (or (cdr (assq (get-text-property 0 'face face-string)
822 debbugs-gnu-state-preference))
825 (defconst debbugs-gnu-severity-preference
832 (defun debbugs-gnu-get-severity-preference (state)
833 (or (cdr (assoc (cdr (assq 'severity state))
834 debbugs-gnu-severity-preference))
837 (defun debbugs-gnu-sort-state (s1 s2)
838 (let ((id1 (cdr (assq 'id (car s1))))
839 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
840 (id2 (cdr (assq 'id (car s2))))
841 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
843 ;; Tagged bugs go to the end.
844 ((and (not (memq id1 debbugs-gnu-local-tags))
845 (memq id2 debbugs-gnu-local-tags))
847 ((and (memq id1 debbugs-gnu-local-tags)
848 (not (memq id2 debbugs-gnu-local-tags)))
850 ;; Then, we check the age of the bugs.
855 ;; If they have the same age, we check for severity.
856 ((< (debbugs-gnu-get-severity-preference (car s1))
857 (debbugs-gnu-get-severity-preference (car s2)))
861 (defun debbugs-gnu-sort-title (s1 s2)
862 (let ((owner (if (cdr (assq 'owner (car s1)))
863 (car (mail-header-parse-address
864 (decode-coding-string (cdr (assq 'owner (car s1)))
867 (string-equal owner user-mail-address))))
869 (defun debbugs-gnu-toggle-sort ()
870 "Toggle sorting by age and by state."
872 (if (eq debbugs-gnu-sort-state 'number)
874 (setq debbugs-gnu-sort-state 'state)
875 (setq tabulated-list-sort-key (cons "Id" nil)))
876 (setq debbugs-gnu-sort-state 'number)
877 (setq tabulated-list-sort-key (cons "State" nil)))
878 (tabulated-list-init-header)
879 (tabulated-list-print))
881 (defun debbugs-gnu-widen ()
882 "Display all the currently selected bug reports."
884 (let ((id (debbugs-gnu-current-id t))
885 (inhibit-read-only t))
886 (setq debbugs-gnu-current-limit nil)
887 (tabulated-list-init-header)
888 (tabulated-list-print)
890 (debbugs-gnu-goto id))))
892 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
893 "Only display the bugs matching STRING.
894 If STATUS-ONLY (the prefix), ignore matches in the From and
896 (interactive "sNarrow to: \np")
897 (let ((id (debbugs-gnu-current-id t))
898 (inhibit-read-only t)
900 (setq debbugs-gnu-current-limit nil)
901 (goto-char (point-min))
903 (setq status (debbugs-gnu-current-status))
904 (if (and (not (member string (assq 'keywords status)))
905 (not (member string (assq 'severity status)))
907 (not (string-match string (cdr (assq 'originator status)))))
909 (not (string-match string (cdr (assq 'subject status))))))
910 (delete-region (point) (progn (forward-line 1) (point)))
911 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
914 (debbugs-gnu-goto id))))
916 (defun debbugs-gnu-goto (id)
917 "Go to the line displaying bug ID."
918 (goto-char (point-min))
919 (while (and (not (eobp))
920 (not (equal (debbugs-gnu-current-id t) id)))
923 (defun debbugs-gnu-toggle-tag ()
924 "Toggle tag of the report in the current line."
928 (let ((inhibit-read-only t)
929 (id (debbugs-gnu-current-id)))
930 (if (memq id debbugs-gnu-local-tags)
932 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
933 (put-text-property (point) (+ (point) 5) 'face 'default))
934 (add-to-list 'debbugs-gnu-local-tags id)
936 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
937 'face 'debbugs-gnu-tagged))))
938 (debbugs-gnu-dump-persistency-file))
940 (defun debbugs-gnu-toggle-suppress ()
941 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
943 (widget-put debbugs-gnu-current-widget :suppress
944 (not (widget-get debbugs-gnu-current-widget :suppress)))
945 (tabulated-list-init-header)
946 (tabulated-list-print))
948 (defvar debbugs-gnu-bug-number nil)
949 (defvar debbugs-gnu-subject nil)
951 (defun debbugs-gnu-current-id (&optional noerror)
952 (or (cdr (assq 'id (debbugs-gnu-current-status)))
954 (error "No bug on the current line"))))
956 (defun debbugs-gnu-current-status ()
957 (get-text-property (line-beginning-position) 'tabulated-list-id))
959 (defun debbugs-gnu-current-query ()
960 (widget-get debbugs-gnu-current-widget :query))
962 (defun debbugs-gnu-display-status (query status)
963 "Display the query and status of the report on the current line."
964 (interactive (list (debbugs-gnu-current-query)
965 (debbugs-gnu-current-status)))
966 (pop-to-buffer "*Bug Status*")
968 (when query (pp query (current-buffer)))
969 (when status (pp status (current-buffer)))
970 (goto-char (point-min))
973 (defun debbugs-gnu-select-report ()
974 "Select the report on the current line."
976 ;; We open the report messages.
977 (let* ((status (debbugs-gnu-current-status))
978 (id (cdr (assq 'id status)))
979 (merged (cdr (assq 'mergedwith status))))
980 (gnus-read-ephemeral-emacs-bug-group
981 (cons id (if (listp merged)
984 (cons (current-buffer)
985 (current-window-configuration)))
986 (with-current-buffer (window-buffer (selected-window))
987 (set (make-local-variable 'debbugs-gnu-bug-number) id)
988 (set (make-local-variable 'debbugs-gnu-subject)
989 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
990 (debbugs-gnu-summary-mode 1))))
992 (defvar debbugs-gnu-summary-mode-map
993 (let ((map (make-sparse-keymap)))
994 (define-key map "C" 'debbugs-gnu-send-control-message)
997 (defvar gnus-posting-styles)
999 (define-minor-mode debbugs-gnu-summary-mode
1000 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1002 \\{debbugs-gnu-summary-mode-map}"
1003 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1004 (set (make-local-variable 'gnus-posting-styles)
1007 (when (buffer-live-p gnus-article-copy)
1008 (with-current-buffer gnus-article-copy
1009 (set (make-local-variable 'message-prune-recipient-rules)
1010 '((".*@debbugs.*" "emacs-pretest-bug")
1011 (".*@debbugs.*" "bug-gnu-emacs")
1012 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1013 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1014 (set (make-local-variable 'message-alter-recipients-function)
1016 (if (string-match "\\([0-9]+\\)@donarmstrong"
1018 (let ((new (format "%s@debbugs.gnu.org"
1019 (match-string 1 (car address)))))
1022 ;; `gnus-posting-styles' is eval'ed after
1023 ;; `message-simplify-subject'. So we cannot use m-s-s.
1024 (setq subject ,debbugs-gnu-subject))))))))
1026 (defun debbugs-gnu-guess-current-id ()
1027 "Guess the ID based on \"#23\"."
1031 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1033 (goto-char (point-min))
1034 (re-search-forward "#\\([0-9]+\\)" nil t)))
1035 (string-to-number (match-string 1)))))
1037 (defun debbugs-gnu-send-control-message (message &optional reverse)
1038 "Send a control message for the current bug report.
1039 You can set the severity or add a tag, or close the report. If
1040 you use the special \"done\" MESSAGE, the report will be marked as
1041 fixed, and then closed.
1043 If given a prefix, and given a tag to set, the tag will be
1046 (list (completing-read
1048 '("serious" "important" "normal" "minor" "wishlist"
1049 "done" "donenotabug" "donewontfix" "doneunreproducible"
1050 "unarchive" "reopen" "close"
1051 "merge" "forcemerge"
1055 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1056 "pending" "help" "security" "confirmed")
1058 current-prefix-arg))
1059 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1060 (debbugs-gnu-guess-current-id)
1061 (debbugs-gnu-current-id)))
1063 (when (member message '("close" "done"))
1067 ;; Emacs development versions.
1069 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1071 (match-string 1 emacs-version)
1072 (1+ (string-to-number (match-string 2 emacs-version)))))
1073 ;; Emacs release versions.
1075 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1077 (match-string 1 emacs-version)
1078 (match-string 2 emacs-version)))
1079 (t emacs-version))))))
1081 (insert "To: control@debbugs.gnu.org\n"
1082 "From: " (message-make-from) "\n"
1083 (format "Subject: control message for bug #%d\n" id)
1086 ((member message '("unarchive" "reopen" "noowner"))
1087 (format "%s %d\n" message id))
1088 ((member message '("merge" "forcemerge"))
1089 (format "%s %d %s\n" message id
1090 (read-string "Merge with bug #: ")))
1091 ((equal message "owner")
1092 (format "owner %d !\n" id))
1093 ((equal message "reassign")
1094 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1095 ((equal message "close")
1096 (format "close %d %s\n" id version))
1097 ((equal message "done")
1098 (format "tags %d fixed\nclose %d %s\n" id id version))
1099 ((member message '("donenotabug" "donewontfix"
1100 "doneunreproducible"))
1101 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1102 ((member message '("serious" "important" "normal"
1103 "minor" "wishlist"))
1104 (format "severity %d %s\n" id message))
1105 ((equal message "invalid")
1106 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1109 (format "tags %d%s %s\n"
1110 id (if reverse " -" "")
1112 (funcall send-mail-function))))
1114 (provide 'debbugs-gnu)
1118 ;; * Reorganize pages after client-side filtering.
1120 ;;; debbugs-gnu.el ends here