1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011 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 command 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", which selects locally
52 ;; If a prefix is given to the command, more search parameters are
53 ;; asked for, like packages (also a comma separated list, "emacs" is
54 ;; the default), whether archived bugs shall be shown, and whether
55 ;; closed bugs shall be shown.
59 ;; M-x debbugs-gnu-search
61 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
62 ;; search phrase to be used for full text search. Additionally, it
63 ;; asks for key-value pairs to filter bugs. Keys are as described in
64 ;; `debbugs-get-status', the corresponding value must be a regular
65 ;; expression to match for. The other parameters are as described in
66 ;; `debbugs-gnu'. Usually, there is just one value except for the
67 ;; attribute "date", which needs two arguments specifying a period in
68 ;; which the bug has been submitted or modified.
70 ;; The bug reports are downloaded from the bug tracker. In order to
71 ;; not generate too much load of the server, up to 500 bugs will be
72 ;; downloaded at once. If there are more hits, you will be asked to
73 ;; change this limit, but please don't increase this number too much.
75 ;; These default values could be changed also by customer options
76 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages',
77 ;; `debbugs-gnu-default-hits-per-page' and `debbugs-gnu-default-suppress-bugs'.
79 ;; The command creates one or more pages of bug lists. Every bug is
80 ;; shown in one line, including the bug number, the status (combining
81 ;; merged bug numbers, keywords and severities), the name of the
82 ;; submitter, and the title of the bug. On every bug line you could
83 ;; apply the following actions by the following keystrokes:
85 ;; RET: Show corresponding messages in Gnus
86 ;; "C": Send a control message
87 ;; "t": Mark the bug locally as tagged
88 ;; "d": Show bug attributes
90 ;; Furthermore, you could apply the global actions
93 ;; "q": Quit the buffer
94 ;; "s": Toggle bug sorting for age or for state
95 ;; "x": Toggle suppressing of bugs
97 ;; When you visit the related bug messages in Gnus, you could also
98 ;; send control messages by keystroke "C".
100 ;; In the header line of every bug list page, you can toggle sorting
101 ;; per column by selecting a column with the mouse. The sorting
102 ;; happens as expected for the respective column; sorting in the Title
103 ;; column is depending on whether you are the owner of a bug.
109 (require 'tabulated-list)
110 (eval-when-compile (require 'cl))
112 (autoload 'widget-convert "wid-edit.el")
113 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
114 (autoload 'mail-header-subject "nnheader")
115 (autoload 'gnus-summary-article-header "gnus-sum")
116 (autoload 'message-make-from "message")
118 (defgroup debbugs-gnu ()
119 "UI for the debbugs.gnu.org bug tracker."
123 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
124 "*The list severities bugs are searched for.
125 \"tagged\" is not a severity but marks locally tagged bugs."
127 :type '(set (const "serious")
135 (defcustom debbugs-gnu-default-packages '("emacs")
136 "*The list of packages to be searched for."
138 :type '(set (const "automake")
140 (const "debbugs.gnu.org")
142 (const "emacs-xwidgets")
149 (defcustom debbugs-gnu-default-hits-per-page 500
150 "*The number of bugs shown per page."
155 (defcustom debbugs-gnu-default-suppress-bugs
156 '((pending . "done"))
157 "*A list of specs for bugs to be suppressed.
158 An element of this list is a cons cell \(KEY . REGEXP\), with key
159 being returned by `debbugs-get-status', and VAL a regular
160 expression matching the corresponding value, a string. Showing
161 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
163 :type '(alist :key-type symbol :value-type regexp)
166 (defface debbugs-gnu-new '((t (:foreground "red")))
167 "Face for new reports that nobody has answered.")
169 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
170 "Face for reports that have been modified recently.")
172 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
173 "Face for reports that are pending.")
175 (defface debbugs-gnu-stale '((t (:foreground "orange")))
176 "Face for reports that have not been touched for a week.")
178 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
179 "Face for closed bug reports.")
181 (defface debbugs-gnu-tagged '((t (:foreground "red")))
182 "Face for reports that have been tagged locally.")
184 (defvar debbugs-gnu-widgets nil)
186 (defvar debbugs-gnu-widget-map
187 (let ((map (make-sparse-keymap)))
188 (define-key map "\r" 'widget-button-press)
189 (define-key map [mouse-1] 'widget-button-press)
190 (define-key map [mouse-2] 'widget-button-press)
193 (defvar debbugs-gnu-local-tags nil
194 "List of bug numbers tagged locally, and kept persistent.")
196 (defvar debbugs-gnu-persistency-file
197 (expand-file-name (locate-user-emacs-file "debbugs"))
198 "File name of a persistency store for debbugs variables")
200 (defun debbugs-gnu-dump-persistency-file ()
201 "Function to store debbugs variables persistently."
202 (with-temp-file debbugs-gnu-persistency-file
204 ";; -*- emacs-lisp -*-\n"
205 ";; Debbugs tags connection history. Don't change this file.\n\n"
206 (format "(setq debbugs-gnu-local-tags '%S)"
207 (sort (copy-sequence debbugs-gnu-local-tags) '<)))))
209 (defvar debbugs-gnu-current-query nil
210 "The query object of the current search.
211 It will be applied server-side, when calling `debbugs-get-bugs'.
212 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
214 (defvar debbugs-gnu-current-filter nil
215 "The filter object for the current search.
216 It will be applied client-side, when parsing the results of
217 `debbugs-get-status'. It has a similar format as
218 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
219 a date, value is the cons cell \(BEFORE . AFTER\).")
221 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
222 "Return a string read from the minibuffer.
223 Derived from `calendar-read'."
224 (let ((value (read-string prompt initial-contents)))
225 (while (not (funcall acceptable value))
226 (setq value (read-string prompt initial-contents)))
229 (defconst debbugs-gnu-phrase-prompt
231 "Enter search phrase: "
233 The search phrase contains words to be searched for, combined by
234 operators like AND, ANDNOT and OR. If there is no operator
235 between the words, AND is used by default. The phrase can also
236 be empty, in this case only the following attributes are used for
240 (defun debbugs-gnu-search ()
241 "Search for Emacs bugs interactively.
242 Search arguments are requested interactively. The \"search
243 phrase\" is used for full text search in the bugs database.
244 Further key-value pairs are requested until an empty key is
245 returned. If a key cannot be queried by a SOAP request, it is
246 marked as \"client-side filter\"."
250 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
251 key val1 val2 phrase severities packages archivedp)
253 ;; Check for the phrase.
254 (setq phrase (read-string debbugs-gnu-phrase-prompt))
255 (if (zerop (length phrase))
257 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
259 ;; The other queries.
262 (setq key (completing-read
265 '("severity" "package" "tags" "submitter" "date"
267 '("severity" "package" "archive" "src" "tag"
268 "owner" "submitter" "maint" "correspondent"
269 "date" "log_modified" "last_modified"
270 "found_date" "fixed_date" "unarchived"
271 "subject" "done" "forwarded" "msgid" "summary"))
274 ;; Server-side queries.
275 ((equal key "severity")
278 (completing-read-multiple
281 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
283 (mapconcat 'identity debbugs-gnu-default-severities ","))))
285 ((equal key "package")
288 (completing-read-multiple
291 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
292 nil t (mapconcat 'identity debbugs-gnu-default-packages ","))))
294 ((equal key "archive")
295 ;; We simplify, by assuming just archived bugs are requested.
298 ((member key '("src" "tag" "tags"))
299 (setq val1 (read-string (format "Enter %s: " key)))
300 (when (not (zerop (length val1)))
302 'debbugs-gnu-current-query (cons (intern key) val1))))
304 ((member key '("owner" "submitter" "maint" "correspondent"))
305 (setq val1 (read-string "Enter email address: "))
306 (when (not (zerop (length val1)))
308 'debbugs-gnu-current-query (cons (intern key) val1))))
310 ((equal key "status")
313 (completing-read "Enter status: " '("done" "forwarded" "open")))
314 (when (not (zerop (length val1)))
316 'debbugs-gnu-current-query (cons (intern key) val1))))
318 ;; Client-side filters.
319 ((member key '("date" "log_modified" "last_modified"
320 "found_date" "fixed_date" "unarchived"))
322 (debbugs-gnu-calendar-read
323 (format "Enter %s before YYYY-MM-DD%s: "
324 key (if phrase "" " (client-side filter)"))
326 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
327 (if (string-match date-format val1)
332 (string-to-number (match-string 3 val1))
333 (string-to-number (match-string 2 val1))
334 (string-to-number (match-string 1 val1))))))
337 (debbugs-gnu-calendar-read
338 (format "Enter %s after YYYY-MM-DD%s: "
339 key (if phrase "" " (client-side filter)"))
341 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
342 (if (string-match date-format val2)
347 (string-to-number (match-string 3 val2))
348 (string-to-number (match-string 2 val2))
349 (string-to-number (match-string 1 val2))))))
354 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
355 (cons (intern key) (cons val1 val2)))))
357 ((not (zerop (length key)))
360 (if phrase 'read-string 'read-regexp)
362 key (if phrase ": " " (client-side filter)"))))
363 (when (not (zerop (length val1)))
366 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
367 (cons (intern key) val1))))
370 (t (throw :finished nil)))))
373 (debbugs-gnu severities packages archivedp))
375 ;; Reset query and filter.
376 (setq debbugs-gnu-current-query nil
377 debbugs-gnu-current-filter nil)))
380 (defun debbugs-gnu (severities &optional packages archivedp suppress)
381 "List all outstanding Emacs bugs."
385 (completing-read-multiple
387 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
388 nil t (mapconcat 'identity debbugs-gnu-default-severities ","))
389 ;; The optional parameters are asked only when there is a prefix.
390 (if current-prefix-arg
391 (completing-read-multiple
393 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
394 nil t (mapconcat 'identity debbugs-gnu-default-packages ","))
395 debbugs-gnu-default-packages)
396 (when current-prefix-arg
397 (setq archivedp (y-or-n-p "Show archived bugs?")))
398 (when (and current-prefix-arg (not archivedp))
399 (y-or-n-p "Suppress unwanted bugs?")))))
401 ;; Initialize variables.
402 (when (and (file-exists-p debbugs-gnu-persistency-file)
403 (not debbugs-gnu-local-tags))
405 (insert-file-contents debbugs-gnu-persistency-file)
406 (eval (read (current-buffer)))))
407 (setq debbugs-gnu-widgets nil)
410 (dolist (severity (if (consp severities) severities (list severities)))
411 (when (not (zerop (length severity)))
412 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
413 (dolist (package (if (consp packages) packages (list packages)))
414 (when (not (zerop (length package)))
415 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
417 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
420 (let ((hits debbugs-gnu-default-hits-per-page)
421 (ids (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
423 (if (> (length ids) hits)
424 (let ((cursor-in-echo-area nil))
429 "How many reports (available %d, default %d): "
433 (number-to-string hits))))))
435 (if (> (length ids) hits)
440 curr-ids (butlast ids (- (length ids) hits)))
445 :follow-link 'mouse-face
446 :notify (lambda (widget &rest ignore)
447 (debbugs-gnu-show-reports widget))
448 :keymap debbugs-gnu-widget-map
450 :buffer-name (format "*Emacs Bugs*<%d>" i)
452 :query debbugs-gnu-current-query
453 :filter debbugs-gnu-current-filter
454 :help-echo (format "%d-%d" (car ids) (car (last curr-ids)))
456 (number-to-string i))
458 (setq ids (last ids (- (length ids) hits))))
459 (debbugs-gnu-show-reports (car debbugs-gnu-widgets)))
461 (debbugs-gnu-show-reports
465 :buffer-name "*Emacs Bugs*"
467 :query debbugs-gnu-current-query
468 :filter debbugs-gnu-current-filter))))
470 ;; Reset query and filter.
471 (setq debbugs-gnu-current-query nil
472 debbugs-gnu-current-filter nil)))
474 (defun debbugs-gnu-get-bugs (query)
475 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
476 (let ((debbugs-port "gnu.org")
477 (tagged (when (member '(severity . "tagged") query)
478 (copy-sequence debbugs-gnu-local-tags)))
479 (phrase (assoc 'phrase query))
481 ;; Compile query arguments.
483 (dolist (elt debbugs-gnu-default-packages)
484 (setq args (append args (list :package elt)))))
486 (unless (equal elt '(severity . "tagged"))
492 ((eq (car elt) 'phrase)
493 (list (list :phrase (cdr elt) :max 500)))
494 ((eq (car elt) 'date)
495 (list (list :date (cddr elt) (cadr elt)
498 (list (list (intern (concat ":" (symbol-name (car elt))))
499 (cdr elt) :operator "ISTRINC"))))
500 (list (intern (concat ":" (symbol-name (car elt))))
504 ;; If the query contains only the pseudo-severity "tagged", we
505 ;; return just the local tagged bugs.
506 ((and tagged (not (memq :severity args)))
508 ;; A full text query.
512 (lambda (x) (cdr (assoc "id" x)))
513 (apply 'debbugs-search-est args))
515 ;; Otherwise, we retrieve the bugs from the server.
516 (t (sort (append (apply 'debbugs-get-bugs args) tagged) '<)))))
518 (defvar debbugs-gnu-current-widget nil)
520 (defvar widget-mouse-face)
522 (defun debbugs-gnu-show-reports (widget)
523 "Show bug reports as given in WIDGET property :bug-ids."
524 (pop-to-buffer (get-buffer-create (widget-get widget :buffer-name)))
526 (let ((inhibit-read-only t)
527 (debbugs-port "gnu.org"))
529 (set (make-local-variable 'debbugs-gnu-current-widget)
532 (dolist (status (apply 'debbugs-get-status (widget-get widget :bug-ids)))
533 (let* ((id (cdr (assq 'id status)))
537 (cons (cdr (assq 'severity status))
538 (cdr (assq 'keywords status)))
540 (address (mail-header-parse-address
541 (decode-coding-string (cdr (assq 'originator status))
543 (owner (if (cdr (assq 'owner status))
544 (car (mail-header-parse-address
545 (decode-coding-string (cdr (assq 'owner status))
547 (subject (decode-coding-string (cdr (assq 'subject status))
550 (unless (equal (cdr (assq 'pending status)) "pending")
552 (concat words "," (cdr (assq 'pending status)))))
553 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
555 (setq words (concat words "," (mapconcat 'identity packages ",")))))
556 (when (setq merged (cdr (assq 'mergedwith status)))
557 (setq words (format "%s,%s"
560 (mapconcat 'number-to-string merged ","))
562 (when (or (not merged)
563 (not (let ((found nil))
564 (dolist (id (if (listp merged)
567 (dolist (entry tabulated-list-entries)
568 (when (equal id (cdr (assq 'id (car entry))))
572 'tabulated-list-entries
580 (if (memq id debbugs-gnu-local-tags)
584 ;; Mark status and age.
588 ((equal (cdr (assq 'pending status)) "done")
590 ((member "pending" (cdr (assq 'keywords status)))
591 'debbugs-gnu-pending)
592 ((= (cdr (assq 'date status))
593 (cdr (assq 'log_modified status)))
596 (cdr (assq 'log_modified status)))
598 'debbugs-gnu-handled)
600 'debbugs-gnu-stale)))
602 ;; Prefer the name over the address.
606 ;; Mark own submitted bugs.
607 (if (and (stringp (car address))
608 (string-equal (car address) user-mail-address))
615 (if (and (stringp owner)
616 (string-equal owner user-mail-address))
620 (tabulated-list-init-header)
621 (tabulated-list-print)
623 (set-buffer-modified-p nil)
624 (goto-char (point-min))))
626 (defun debbugs-gnu-print-entry (list-id cols)
627 "Insert a debbugs entry at point.
628 Used instead of `tabulated-list-print-entry'."
629 ;; This shall be in `debbugs-gnu-show-reports'. But
630 ;; `tabulated-list-print' erases the buffer, therefore we do it
632 (when (and debbugs-gnu-widgets (= (point) (point-min)))
633 (widget-insert "Page:")
636 (if (eq obj debbugs-gnu-current-widget)
637 (widget-put obj :button-face 'widget-button-pressed)
638 (widget-put obj :button-face 'widget-button-face))
639 (widget-apply obj :create))
641 (widget-insert "\n\n")
643 (widget-insert "\nPage:")
644 (mapc (lambda (obj) (widget-apply obj :create)) debbugs-gnu-widgets)
651 (id-length (nth 1 (aref tabulated-list-format 0)))
652 (state (aref cols 1))
653 (state-length (nth 1 (aref tabulated-list-format 1)))
654 (submitter (aref cols 2))
655 (submitter-length (nth 1 (aref tabulated-list-format 2)))
656 (title (aref cols 3))
657 (title-length (nth 1 (aref tabulated-list-format 3))))
659 ;; We may have a narrowing in effect.
660 (or (not debbugs-gnu-current-limit)
661 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
662 ;; Filter suppressed bugs.
663 (or (not (widget-get debbugs-gnu-current-widget :suppress))
664 (not (catch :suppress
665 (dolist (check debbugs-gnu-default-suppress-bugs)
669 (or (cdr (assq (car check) list-id)) ""))
670 (throw :suppress t))))))
671 ;; Filter search list.
672 (not (catch :suppress
674 (widget-get debbugs-gnu-current-widget :filter))
675 (let ((val (cdr (assq (car check) list-id))))
676 (if (stringp (cdr check))
677 ;; Regular expression.
678 (when (not (string-match (cdr check) (or val "")))
681 (when (or (and (numberp (cadr check))
682 (< (cadr check) val))
683 (and (numberp (cddr check))
684 (> (cddr check) val)))
685 (throw :suppress t))))))))
688 (indent-to (- id-length (length id)))
691 (indent-to (setq pos (+ pos id-length 1)) 1)
692 (insert (if (> (length state) state-length)
693 (propertize (substring state 0 state-length)
697 (indent-to (setq pos (+ pos state-length 1)) 1)
698 (insert "[" (if (> (length submitter) (- submitter-length 2))
699 (propertize (substring submitter 0 (- submitter-length 2))
700 'help-echo submitter)
702 (indent-to (+ pos (1- submitter-length)))
705 (indent-to (setq pos (+ pos submitter-length 1)) 1)
706 (insert (propertize title 'help-echo title))
709 beg (point) `(tabulated-list-id ,list-id mouse-face ,widget-mouse-face))
712 (defvar debbugs-gnu-mode-map
713 (let ((map (make-sparse-keymap)))
714 (set-keymap-parent map tabulated-list-mode-map)
715 (define-key map "\r" 'debbugs-gnu-select-report)
716 (define-key map [mouse-1] 'debbugs-gnu-select-report)
717 (define-key map [mouse-2] 'debbugs-gnu-select-report)
718 (define-key map "s" 'debbugs-gnu-toggle-sort)
719 (define-key map "t" 'debbugs-gnu-toggle-tag)
720 (define-key map "d" 'debbugs-gnu-display-status)
721 (define-key map "g" 'debbugs-gnu-rescan)
722 (define-key map "x" 'debbugs-gnu-toggle-suppress)
723 (define-key map "/" 'debbugs-gnu-narrow-to-status)
724 (define-key map "w" 'debbugs-gnu-widen)
725 (define-key map "C" 'debbugs-gnu-send-control-message)
728 (defun debbugs-gnu-rescan ()
729 "Rescan the current set of bug reports."
732 ;; The last page will be provided with new bug ids.
733 ;; TODO: Do it also for the other pages.
734 (when (and debbugs-gnu-widgets
735 (eq debbugs-gnu-current-widget (car (last debbugs-gnu-widgets))))
736 (let ((first-id (car (widget-get debbugs-gnu-current-widget :bug-ids)))
738 (last (widget-get debbugs-gnu-current-widget :bug-ids))))
739 (ids (debbugs-gnu-get-bugs
740 (widget-get debbugs-gnu-current-widget :query))))
742 (while (and (<= first-id last-id) (not (memq first-id ids)))
743 (setq first-id (1+ first-id)))
745 (when (<= first-id last-id)
746 (widget-put debbugs-gnu-current-widget :bug-ids (memq first-id ids)))))
748 ;; Refresh the buffer. `save-excursion' does not work, so we
749 ;; remember the position.
751 (debbugs-gnu-show-reports debbugs-gnu-current-widget)
754 (defvar debbugs-gnu-sort-state 'number)
755 (defvar debbugs-gnu-current-limit nil)
757 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
758 "Major mode for listing bug reports.
760 All normal editing commands are switched off.
761 \\<debbugs-gnu-mode-map>
763 The following commands are available:
765 \\{debbugs-gnu-mode-map}"
766 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
767 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
768 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
769 ("State" 20 debbugs-gnu-sort-state)
771 ("Title" 10 debbugs-gnu-sort-title)])
772 (setq tabulated-list-sort-key (cons "Id" nil))
773 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
774 (buffer-disable-undo)
775 (setq truncate-lines t)
776 (setq buffer-read-only t))
778 (defun debbugs-gnu-sort-id (s1 s2)
779 (< (cdr (assq 'id (car s1)))
780 (cdr (assq 'id (car s2)))))
782 (defconst debbugs-gnu-state-preference
783 '((debbugs-gnu-new . 1)
784 (debbugs-gnu-stale . 2)
785 (debbugs-gnu-handled . 3)
786 (debbugs-gnu-done . 4)
787 (debbugs-gnu-pending . 5)))
789 (defun debbugs-gnu-get-state-preference (face-string)
790 (or (cdr (assq (get-text-property 0 'face face-string)
791 debbugs-gnu-state-preference))
794 (defconst debbugs-gnu-severity-preference
801 (defun debbugs-gnu-get-severity-preference (state)
802 (or (cdr (assoc (cdr (assq 'severity state))
803 debbugs-gnu-severity-preference))
806 (defun debbugs-gnu-sort-state (s1 s2)
807 (let ((id1 (cdr (assq 'id (car s1))))
808 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
809 (id2 (cdr (assq 'id (car s2))))
810 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
812 ;; Tagged bugs go to the end.
813 ((and (not (memq id1 debbugs-gnu-local-tags))
814 (memq id2 debbugs-gnu-local-tags))
816 ((and (memq id1 debbugs-gnu-local-tags)
817 (not (memq id2 debbugs-gnu-local-tags)))
819 ;; Then, we check the age of the bugs.
824 ;; If they have the same age, we check for severity.
825 ((< (debbugs-gnu-get-severity-preference (car s1))
826 (debbugs-gnu-get-severity-preference (car s2)))
830 (defun debbugs-gnu-sort-title (s1 s2)
831 (let ((owner (if (cdr (assq 'owner (car s1)))
832 (car (mail-header-parse-address
833 (decode-coding-string (cdr (assq 'owner (car s1)))
836 (string-equal owner user-mail-address))))
838 (defun debbugs-gnu-toggle-sort ()
839 "Toggle sorting by age and by state."
841 (if (eq debbugs-gnu-sort-state 'number)
843 (setq debbugs-gnu-sort-state 'state)
844 (setq tabulated-list-sort-key (cons "Id" nil)))
845 (setq debbugs-gnu-sort-state 'number)
846 (setq tabulated-list-sort-key (cons "State" nil)))
847 (tabulated-list-init-header)
848 (tabulated-list-print))
850 (defun debbugs-gnu-widen ()
851 "Display all the currently selected bug reports."
853 (let ((id (debbugs-gnu-current-id t))
854 (buffer-read-only nil))
855 (tabulated-list-init-header)
856 (tabulated-list-print)
857 (setq debbugs-gnu-current-limit nil)
859 (debbugs-gnu-goto id))))
861 (defun debbugs-gnu-narrow-to-status (string)
862 "Only display the bugs matching STRING."
863 (interactive "sNarrow to: ")
864 (let ((id (debbugs-gnu-current-id t))
865 (buffer-read-only nil)
868 (goto-char (point-min))
870 (setq status (debbugs-gnu-current-status))
871 (if (and (not (member string (assq 'keywords status)))
872 (not (member string (assq 'severity status)))
873 (not (string-match string (cdr (assq 'originator status))))
874 (not (string-match string (cdr (assq 'subject status)))))
875 (delete-region (point) (progn (forward-line 1) (point)))
876 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
879 (debbugs-gnu-goto id))))
881 (defun debbugs-gnu-goto (id)
882 "Go to the line displaying bug ID."
883 (goto-char (point-min))
884 (while (and (not (eobp))
885 (not (equal (debbugs-gnu-current-id t) id)))
888 (defun debbugs-gnu-toggle-tag ()
889 "Toggle tag of the report in the current line."
893 (let ((inhibit-read-only t)
894 (id (debbugs-gnu-current-id)))
895 (if (memq id debbugs-gnu-local-tags)
897 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
898 (put-text-property (point) (+ (point) 5) 'face 'default))
899 (add-to-list 'debbugs-gnu-local-tags id)
901 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
902 'face 'debbugs-gnu-tagged))))
903 (debbugs-gnu-dump-persistency-file))
905 (defun debbugs-gnu-toggle-suppress ()
906 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
908 (widget-put debbugs-gnu-current-widget :suppress
909 (not (widget-get debbugs-gnu-current-widget :suppress)))
910 (tabulated-list-init-header)
911 (tabulated-list-print))
913 (defvar debbugs-gnu-bug-number nil)
914 (defvar debbugs-gnu-subject nil)
916 (defun debbugs-gnu-current-id (&optional noerror)
917 (or (cdr (assq 'id (debbugs-gnu-current-status)))
919 (error "No bug on the current line"))))
921 (defun debbugs-gnu-current-status ()
922 (get-text-property (line-beginning-position) 'tabulated-list-id))
924 (defun debbugs-gnu-display-status (status)
925 "Display the status of the report on the current line."
926 (interactive (list (debbugs-gnu-current-status)))
927 (pop-to-buffer "*Bug Status*")
929 (pp status (current-buffer))
930 (goto-char (point-min)))
932 (defun debbugs-gnu-select-report ()
933 "Select the report on the current line."
935 ;; We open the report messages.
936 (let* ((status (debbugs-gnu-current-status))
937 (id (cdr (assq 'id status)))
938 (merged (cdr (assq 'mergedwith status))))
939 (gnus-read-ephemeral-emacs-bug-group
940 (cons id (if (listp merged)
943 (cons (current-buffer)
944 (current-window-configuration)))
945 (with-current-buffer (window-buffer (selected-window))
946 (set (make-local-variable 'debbugs-gnu-bug-number) id)
947 (set (make-local-variable 'debbugs-gnu-subject)
948 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
949 (debbugs-gnu-summary-mode 1))))
951 (defvar debbugs-gnu-summary-mode-map
952 (let ((map (make-sparse-keymap)))
953 (define-key map "C" 'debbugs-gnu-send-control-message)
956 (defvar gnus-posting-styles)
958 (define-minor-mode debbugs-gnu-summary-mode
959 "Minor mode for providing a debbugs interface in Gnus summary buffers.
961 \\{debbugs-gnu-summary-mode-map}"
962 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
963 (set (make-local-variable 'gnus-posting-styles)
966 (when (buffer-live-p gnus-article-copy)
967 (with-current-buffer gnus-article-copy
968 (set (make-local-variable 'message-prune-recipient-rules)
969 '((".*@debbugs.*" "emacs-pretest-bug")
970 (".*@debbugs.*" "bug-gnu-emacs")
971 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
972 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
973 (set (make-local-variable 'message-alter-recipients-function)
975 (if (string-match "\\([0-9]+\\)@donarmstrong"
977 (let ((new (format "%s@debbugs.gnu.org"
978 (match-string 1 (car address)))))
981 ;; `gnus-posting-styles' is eval'ed after
982 ;; `message-simplify-subject'. So we cannot use m-s-s.
983 (setq subject ,debbugs-gnu-subject))))))))
985 (defun debbugs-gnu-guess-current-id ()
986 "Guess the ID based on \"#23\"."
990 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
992 (goto-char (point-min))
993 (re-search-forward "#\\([0-9]+\\)" nil t)))
994 (string-to-number (match-string 1)))))
996 (defun debbugs-gnu-send-control-message (message &optional reverse)
997 "Send a control message for the current bug report.
998 You can set the severity or add a tag, or close the report. If
999 you use the special \"done\" MESSAGE, the report will be marked as
1000 fixed, and then closed.
1002 If given a prefix, and given a tag to set, the tag will be
1005 (list (completing-read
1007 '("serious" "important" "normal" "minor" "wishlist"
1008 "done" "donenotabug" "donewontfix" "doneunreproducible"
1009 "unarchive" "reopen" "close"
1010 "merge" "forcemerge"
1014 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1015 "pending" "help" "security" "confirmed")
1017 current-prefix-arg))
1018 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1019 (debbugs-gnu-guess-current-id)
1020 (debbugs-gnu-current-id)))
1022 (when (member message '("close" "done"))
1026 ;; Emacs development versions.
1028 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1030 (match-string 1 emacs-version)
1031 (1+ (string-to-number (match-string 2 emacs-version)))))
1032 ;; Emacs release versions.
1034 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1036 (match-string 1 emacs-version)
1037 (match-string 2 emacs-version)))
1038 (t emacs-version))))))
1040 (insert "To: control@debbugs.gnu.org\n"
1041 "From: " (message-make-from) "\n"
1042 (format "Subject: control message for bug #%d\n" id)
1045 ((member message '("unarchive" "reopen" "noowner"))
1046 (format "%s %d\n" message id))
1047 ((member message '("merge" "forcemerge"))
1048 (format "%s %d %s\n" message id
1049 (read-string "Merge with bug #: ")))
1050 ((equal message "owner")
1051 (format "owner %d !\n" id))
1052 ((equal message "reassign")
1053 (format "reassign %d %s\n" id (read-string "Package: ")))
1054 ((equal message "close")
1055 (format "close %d %s\n" id version))
1056 ((equal message "done")
1057 (format "tags %d fixed\nclose %d %s\n" id id version))
1058 ((member message '("donenotabug" "donewontfix"
1059 "doneunreproducible"))
1060 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1061 ((member message '("serious" "important" "normal"
1062 "minor" "wishlist"))
1063 (format "severity %d %s\n" id message))
1064 ((equal message "invalid")
1065 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1068 (format "tags %d%s %s\n"
1069 id (if reverse " -" "")
1071 (funcall send-mail-function))))
1073 (provide 'debbugs-gnu)
1077 ;; * Reorganize pages after client-side filtering.
1079 ;;; debbugs-gnu.el ends here