1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
11 ;; This file is not part of GNU Emacs.
13 ;; This program is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This package provides an interface to bug reports which are located
29 ;; on the GNU bug tracker debbugs.gnu.org. Its main purpose is to
30 ;; show and manipulate bug reports from Emacs, but it could be used
31 ;; also for other GNU projects which use the same bug tracker.
33 ;; If you have `debbugs-gnu.el' in your load-path, you could enable
34 ;; the bug tracker commands by the following lines in your ~/.emacs
36 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
37 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
38 ;; (autoload 'debbugs-gnu-usertags "debbugs-gnu" "" 'interactive)
39 ;; (autoload 'debbugs-gnu-bugs "debbugs-gnu" "" 'interactive)
41 ;; The bug tracker is called interactively by
45 ;; It asks for the severities, for which bugs shall be shown. This can
46 ;; be either just one severity, or a list of severities, separated by
47 ;; comma. Valid severities are "serious", "important", "normal",
48 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
49 ;; used, although configured on the GNU bug tracker. If no severity
50 ;; is given, all bugs are selected.
52 ;; There is also the pseudo severity "tagged". When it is used, the
53 ;; function will ask for user tags (a comma separated list), and shows
54 ;; just the bugs which are tagged with them. In general, user tags
55 ;; shall be strings denoting to subprojects of the package, like
56 ;; "cedet" or "tramp" of the package "emacs". If no user tag is
57 ;; given, locally tagged bugs are shown.
59 ;; If a prefix is given to the command, more search parameters are
60 ;; asked for, like packages (also a comma separated list, "emacs" is
61 ;; the default), whether archived bugs shall be shown, and whether
62 ;; closed bugs shall be shown.
66 ;; M-x debbugs-gnu-search
68 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
69 ;; search phrase to be used for full text search. Additionally, it
70 ;; asks for key-value pairs to filter bugs. Keys are as described in
71 ;; `debbugs-get-status', the corresponding value must be a regular
72 ;; expression to match for. The other parameters are as described in
73 ;; `debbugs-gnu'. Usually, there is just one value except for the
74 ;; attribute "date", which needs two arguments specifying a period in
75 ;; which the bug has been submitted or modified.
77 ;; The bug reports are downloaded from the bug tracker. In order to
78 ;; not generate too much load of the server, up to 500 bugs will be
79 ;; downloaded at once. If there are more hits, you will be asked to
80 ;; change this limit, but please don't increase this number too much.
82 ;; These default values could be changed also by customer options
83 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages',
84 ;; `debbugs-gnu-default-hits-per-page' and `debbugs-gnu-default-suppress-bugs'.
86 ;; The commands create one or more pages of bug lists. Every bug is
87 ;; shown in one line, including the bug number, the status (combining
88 ;; merged bug numbers, keywords and severities), the name of the
89 ;; submitter, and the title of the bug. On every bug line you could
90 ;; apply the following actions by the following keystrokes:
92 ;; RET: Show corresponding messages in Gnus
93 ;; "C": Send a control message
94 ;; "t": Mark the bug locally as tagged
95 ;; "d": Show bug attributes
97 ;; Furthermore, you could apply the global actions
100 ;; "q": Quit the buffer
101 ;; "s": Toggle bug sorting for age or for state
102 ;; "x": Toggle suppressing of bugs
103 ;; "/": Display only bugs matching a string
104 ;; "w": Display all the currently selected bug reports
106 ;; When you visit the related bug messages in Gnus, you could also
107 ;; send control messages by keystroke "C".
109 ;; In the header line of every bug list page, you can toggle sorting
110 ;; per column by selecting a column with the mouse. The sorting
111 ;; happens as expected for the respective column; sorting in the Title
112 ;; column is depending on whether you are the owner of a bug.
114 ;; Another approach for listing bugs is calling the command
116 ;; M-x debbugs-gnu-usertags
118 ;; This command shows you all existing user tags for the packages
119 ;; defined in `debbugs-gnu-default-packages'. A prefix for the
120 ;; command allows you to use other packe names, or an arbitrary string
121 ;; for a user who has tagged bugs. The command returns the list of
122 ;; existing user tags for the given user(s) or package name(s),
123 ;; respectively. Applying RET on a user tag, all bugs tagged with
124 ;; this user tag are shown.
126 ;; Unfortunately, it is not possible with the SOAP interface to show
127 ;; all users who have tagged bugs. This list can be retrieved via
128 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi?indexon=users>.
130 ;; Finally, if you simply want to list some bugs with known bug
131 ;; numbers, call the command
133 ;; M-x debbugs-gnu-bugs
135 ;; The bug numbers to be shown shall be entered as comma separated list.
142 (require 'tabulated-list)
143 (eval-when-compile (require 'cl))
145 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
146 (autoload 'mail-header-subject "nnheader")
147 (autoload 'gnus-summary-article-header "gnus-sum")
148 (autoload 'message-make-from "message")
150 (defgroup debbugs-gnu ()
151 "UI for the debbugs.gnu.org bug tracker."
155 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
156 "*The list severities bugs are searched for.
157 \"tagged\" is not a severity but marks locally tagged bugs."
158 ;; <http://debbugs.gnu.org/Developer.html#severities>
160 :type '(set (const "serious")
168 (defconst debbugs-gnu-all-severities
169 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
170 "*List of all possible severities.")
172 (defcustom debbugs-gnu-default-packages '("emacs")
173 "*The list of packages to be searched for."
174 ;; <http://debbugs.gnu.org/Packages.html>
175 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
177 :type '(set (const "auctex")
182 (const "debbugs.gnu.org")
185 (const "emacs-xwidgets")
201 (defconst debbugs-gnu-all-packages
202 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
203 "*List of all possible package names.")
205 (defcustom debbugs-gnu-default-hits-per-page 500
206 "*The number of bugs shown per page."
211 (defcustom debbugs-gnu-default-suppress-bugs
212 '((pending . "done"))
213 "*A list of specs for bugs to be suppressed.
214 An element of this list is a cons cell \(KEY . REGEXP\), with key
215 being returned by `debbugs-get-status', and VAL a regular
216 expression matching the corresponding value, a string. Showing
217 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
219 :type '(alist :key-type symbol :value-type regexp)
222 (defface debbugs-gnu-new '((t (:foreground "red")))
223 "Face for new reports that nobody has answered.")
225 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
226 "Face for reports that have been modified recently.")
228 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
229 "Face for reports that are pending.")
231 (defface debbugs-gnu-stale '((t (:foreground "orange")))
232 "Face for reports that have not been touched for a week.")
234 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
235 "Face for closed bug reports.")
237 (defface debbugs-gnu-tagged '((t (:foreground "red")))
238 "Face for reports that have been tagged locally.")
240 (defvar debbugs-gnu-widgets nil)
242 (defvar debbugs-gnu-widget-map
243 (let ((map (make-sparse-keymap)))
244 (define-key map "\r" 'widget-button-press)
245 (define-key map [mouse-2] 'widget-button-press)
248 (defvar debbugs-gnu-local-tags nil
249 "List of bug numbers tagged locally, and kept persistent.")
251 (defvar debbugs-gnu-persistency-file
252 (expand-file-name (locate-user-emacs-file "debbugs"))
253 "File name of a persistency store for debbugs variables")
255 (defun debbugs-gnu-dump-persistency-file ()
256 "Function to store debbugs variables persistently."
257 (with-temp-file debbugs-gnu-persistency-file
259 ";; -*- emacs-lisp -*-\n"
260 ";; Debbugs tags connection history. Don't change this file.\n\n"
261 (format "(setq debbugs-gnu-local-tags '%S)"
262 (sort (copy-sequence debbugs-gnu-local-tags) '<)))))
264 (defvar debbugs-gnu-current-query nil
265 "The query object of the current search.
266 It will be applied server-side, when calling `debbugs-get-bugs'.
267 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
269 (defvar debbugs-gnu-current-filter nil
270 "The filter object for the current search.
271 It will be applied client-side, when parsing the results of
272 `debbugs-get-status'. It has a similar format as
273 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
274 a date, value is the cons cell \(BEFORE . AFTER\).")
276 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
277 "Return a string read from the minibuffer.
278 Derived from `calendar-read'."
279 (let ((value (read-string prompt initial-contents)))
280 (while (not (funcall acceptable value))
281 (setq value (read-string prompt initial-contents)))
284 (defconst debbugs-gnu-phrase-prompt
286 "Enter search phrase: "
288 The search phrase contains words to be searched for, combined by
289 operators like AND, ANDNOT and OR. If there is no operator
290 between the words, AND is used by default. The phrase can also
291 be empty, in this case only the following attributes are used for
295 (defun debbugs-gnu-search ()
296 "Search for Emacs bugs interactively.
297 Search arguments are requested interactively. The \"search
298 phrase\" is used for full text search in the bugs database.
299 Further key-value pairs are requested until an empty key is
300 returned. If a key cannot be queried by a SOAP request, it is
301 marked as \"client-side filter\"."
305 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
306 key val1 val2 phrase severities packages archivedp)
308 ;; Check for the phrase.
309 (setq phrase (read-string debbugs-gnu-phrase-prompt))
310 (if (zerop (length phrase))
312 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
314 ;; The other queries.
317 (setq key (completing-read
320 '("severity" "package" "tags" "submitter" "date"
322 '("severity" "package" "archive" "src" "tag"
323 "owner" "submitter" "maint" "correspondent"
324 "date" "log_modified" "last_modified"
325 "found_date" "fixed_date" "unarchived"
326 "subject" "done" "forwarded" "msgid" "summary"))
329 ;; Server-side queries.
330 ((equal key "severity")
333 (completing-read-multiple
334 "Enter severities: " debbugs-gnu-all-severities nil t
335 (mapconcat 'identity debbugs-gnu-default-severities ","))))
337 ((equal key "package")
340 (completing-read-multiple
341 "Enter packages: " debbugs-gnu-all-packages nil t
342 (mapconcat 'identity debbugs-gnu-default-packages ","))))
344 ((equal key "archive")
345 ;; We simplify, by assuming just archived bugs are requested.
348 ((member key '("src" "tag" "tags"))
349 (setq val1 (read-string (format "Enter %s: " key)))
350 (when (not (zerop (length val1)))
352 'debbugs-gnu-current-query (cons (intern key) val1))))
354 ((member key '("owner" "submitter" "maint" "correspondent"))
355 (setq val1 (read-string "Enter email address: "))
356 (when (not (zerop (length val1)))
358 'debbugs-gnu-current-query (cons (intern key) val1))))
360 ((equal key "status")
363 (completing-read "Enter status: " '("done" "forwarded" "open")))
364 (when (not (zerop (length val1)))
366 'debbugs-gnu-current-query (cons (intern key) val1))))
368 ;; Client-side filters.
369 ((member key '("date" "log_modified" "last_modified"
370 "found_date" "fixed_date" "unarchived"))
372 (debbugs-gnu-calendar-read
373 (format "Enter %s before YYYY-MM-DD%s: "
374 key (if phrase "" " (client-side filter)"))
376 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
377 (if (string-match date-format val1)
382 (string-to-number (match-string 3 val1))
383 (string-to-number (match-string 2 val1))
384 (string-to-number (match-string 1 val1))))))
387 (debbugs-gnu-calendar-read
388 (format "Enter %s after YYYY-MM-DD%s: "
389 key (if phrase "" " (client-side filter)"))
391 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
392 (if (string-match date-format val2)
397 (string-to-number (match-string 3 val2))
398 (string-to-number (match-string 2 val2))
399 (string-to-number (match-string 1 val2))))))
404 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
405 (cons (intern key) (cons val1 val2)))))
407 ((not (zerop (length key)))
410 (if phrase 'read-string 'read-regexp)
412 key (if phrase ": " " (client-side filter)"))))
413 (when (not (zerop (length val1)))
416 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
417 (cons (intern key) val1))))
420 (t (throw :finished nil)))))
423 (debbugs-gnu severities packages archivedp))
425 ;; Reset query and filter.
426 (setq debbugs-gnu-current-query nil
427 debbugs-gnu-current-filter nil)))
430 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
431 "List all outstanding bugs."
433 (let (severities archivedp)
436 (completing-read-multiple
437 "Severities: " debbugs-gnu-all-severities nil t
438 (mapconcat 'identity debbugs-gnu-default-severities ",")))
439 ;; The next parameters are asked only when there is a prefix.
440 (if current-prefix-arg
441 (completing-read-multiple
442 "Packages: " debbugs-gnu-all-packages nil t
443 (mapconcat 'identity debbugs-gnu-default-packages ","))
444 debbugs-gnu-default-packages)
445 (when current-prefix-arg
446 (setq archivedp (y-or-n-p "Show archived bugs?")))
447 (when (and current-prefix-arg (not archivedp))
448 (y-or-n-p "Suppress unwanted bugs?"))
449 ;; This one must be asked for severity "tagged".
450 (when (member "tagged" severities)
451 (split-string (read-string "User tag(s): ") "," t)))))
453 ;; Initialize variables.
454 (when (and (file-exists-p debbugs-gnu-persistency-file)
455 (not debbugs-gnu-local-tags))
457 (insert-file-contents debbugs-gnu-persistency-file)
458 (eval (read (current-buffer)))))
459 (setq debbugs-gnu-widgets nil)
462 (dolist (severity (if (consp severities) severities (list severities)))
463 (when (not (zerop (length severity)))
464 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
465 (dolist (package (if (consp packages) packages (list packages)))
466 (when (not (zerop (length package)))
467 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
469 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
471 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
472 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
473 (dolist (tag (if (consp tags) tags (list tags)))
474 (when (not (zerop (length tag)))
475 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
478 (let ((hits debbugs-gnu-default-hits-per-page)
479 (ids (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
481 (if (> (length ids) hits)
482 (let ((cursor-in-echo-area nil))
487 "How many reports (available %d, default %d): "
491 (number-to-string hits))))))
493 (if (> (length ids) hits)
498 curr-ids (butlast ids (- (length ids) hits)))
503 :follow-link 'mouse-face
504 :notify (lambda (widget &rest ignore)
505 (debbugs-gnu-show-reports widget))
506 :keymap debbugs-gnu-widget-map
508 :buffer-name (format "*Emacs Bugs*<%d>" i)
510 :query debbugs-gnu-current-query
511 :filter debbugs-gnu-current-filter
512 :help-echo (format "%d-%d" (car ids) (car (last curr-ids)))
514 (number-to-string i))
516 (setq ids (last ids (- (length ids) hits))))
517 (debbugs-gnu-show-reports (car debbugs-gnu-widgets)))
519 (debbugs-gnu-show-reports
523 :buffer-name "*Emacs Bugs*"
525 :query debbugs-gnu-current-query
526 :filter debbugs-gnu-current-filter))))
528 ;; Reset query and filter.
529 (setq debbugs-gnu-current-query nil
530 debbugs-gnu-current-filter nil)))
532 (defun debbugs-gnu-get-bugs (query)
533 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
534 (let* ((debbugs-port "gnu.org")
535 (bugs (assoc 'bugs query))
536 (tags (assoc 'tag query))
537 (local-tags (and (member '(severity . "tagged") query) (not tags)))
538 (phrase (assoc 'phrase query))
540 ;; Compile query arguments.
541 (unless (or query tags)
542 (dolist (elt debbugs-gnu-default-packages)
543 (setq args (append args (list :package elt)))))
545 (unless (equal elt '(severity . "tagged"))
551 ((eq (car elt) 'phrase)
552 (list (list :phrase (cdr elt) :max 500)))
553 ((eq (car elt) 'date)
554 (list (list :date (cddr elt) (cadr elt)
557 (list (list (intern (concat ":" (symbol-name (car elt))))
558 (cdr elt) :operator "ISTRINC"))))
559 (list (intern (concat ":" (symbol-name (car elt))))
564 ;; If the query is just a list of bug numbers, we return them.
566 ;; If the query contains the pseudo-severity "tagged", we return
567 ;; just the local tagged bugs.
568 (local-tags (copy-sequence debbugs-gnu-local-tags))
569 ;; A full text query.
572 (lambda (x) (cdr (assoc "id" x)))
573 (apply 'debbugs-search-est args)))
576 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
577 (apply 'debbugs-get-usertag args))
578 ;; Otherwise, we retrieve the bugs from the server.
579 (t (apply 'debbugs-get-bugs args)))
583 (defvar debbugs-gnu-current-widget nil)
584 (defvar debbugs-gnu-current-limit nil)
586 (defun debbugs-gnu-show-reports (widget)
587 "Show bug reports as given in WIDGET property :bug-ids."
588 ;; The tabulated mode sets several local variables. We must get rid
590 (when (get-buffer (widget-get widget :buffer-name))
591 (kill-buffer (widget-get widget :buffer-name)))
592 (pop-to-buffer (get-buffer-create (widget-get widget :buffer-name)))
594 (let ((inhibit-read-only t)
595 (debbugs-port "gnu.org"))
597 (set (make-local-variable 'debbugs-gnu-current-widget) widget)
599 (dolist (status (apply 'debbugs-get-status (widget-get widget :bug-ids)))
600 (let* ((id (cdr (assq 'id status)))
604 (cons (cdr (assq 'severity status))
605 (cdr (assq 'keywords status)))
607 (address (mail-header-parse-address
608 (decode-coding-string (cdr (assq 'originator status))
610 (owner (if (cdr (assq 'owner status))
611 (car (mail-header-parse-address
612 (decode-coding-string (cdr (assq 'owner status))
614 (subject (decode-coding-string (cdr (assq 'subject status))
617 (unless (equal (cdr (assq 'pending status)) "pending")
619 (concat words "," (cdr (assq 'pending status)))))
620 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
622 (setq words (concat words "," (mapconcat 'identity packages ",")))))
623 (when (setq merged (cdr (assq 'mergedwith status)))
624 (setq words (format "%s,%s"
627 (mapconcat 'number-to-string merged ","))
629 (when (or (not merged)
630 (not (let ((found nil))
631 (dolist (id (if (listp merged)
634 (dolist (entry tabulated-list-entries)
635 (when (equal id (cdr (assq 'id (car entry))))
639 'tabulated-list-entries
647 (if (memq id debbugs-gnu-local-tags)
651 ;; Mark status and age.
655 ((equal (cdr (assq 'pending status)) "done")
657 ((member "pending" (cdr (assq 'keywords status)))
658 'debbugs-gnu-pending)
659 ((= (cdr (assq 'date status))
660 (cdr (assq 'log_modified status)))
663 (cdr (assq 'log_modified status)))
665 'debbugs-gnu-handled)
667 'debbugs-gnu-stale)))
669 ;; Prefer the name over the address.
673 ;; Mark own submitted bugs.
674 (if (and (stringp (car address))
675 (string-equal (car address) user-mail-address))
682 (if (and (stringp owner)
683 (string-equal owner user-mail-address))
687 (tabulated-list-init-header)
688 (tabulated-list-print)
690 (set-buffer-modified-p nil)
691 (goto-char (point-min))))
693 (defun debbugs-gnu-print-entry (list-id cols)
694 "Insert a debbugs entry at point.
695 Used instead of `tabulated-list-print-entry'."
696 ;; This shall be in `debbugs-gnu-show-reports'. But
697 ;; `tabulated-list-print' erases the buffer, therefore we do it
699 (when (and debbugs-gnu-widgets (= (point) (point-min)))
700 (widget-insert "Page:")
703 (if (eq obj debbugs-gnu-current-widget)
704 (widget-put obj :button-face 'widget-button-pressed)
705 (widget-put obj :button-face 'widget-button-face))
706 (widget-apply obj :create))
708 (widget-insert "\n\n")
710 (widget-insert "\nPage:")
711 (mapc (lambda (obj) (widget-apply obj :create)) debbugs-gnu-widgets)
718 (id-length (nth 1 (aref tabulated-list-format 0)))
719 (state (aref cols 1))
720 (state-length (nth 1 (aref tabulated-list-format 1)))
721 (submitter (aref cols 2))
722 (submitter-length (nth 1 (aref tabulated-list-format 2)))
723 (title (aref cols 3))
724 (title-length (nth 1 (aref tabulated-list-format 3))))
726 ;; We may have a narrowing in effect.
727 (or (not debbugs-gnu-current-limit)
728 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
729 ;; Filter suppressed bugs.
730 (or (not (widget-get debbugs-gnu-current-widget :suppress))
731 (and (not (memq (cdr (assq 'id list-id)) debbugs-gnu-local-tags))
732 (not (catch :suppress
733 (dolist (check debbugs-gnu-default-suppress-bugs)
737 (or (cdr (assq (car check) list-id)) ""))
738 (throw :suppress t)))))))
739 ;; Filter search list.
740 (not (catch :suppress
742 (widget-get debbugs-gnu-current-widget :filter))
743 (let ((val (cdr (assq (car check) list-id))))
744 (if (stringp (cdr check))
745 ;; Regular expression.
746 (when (not (string-match (cdr check) (or val "")))
749 (when (or (and (numberp (cadr check))
750 (< (cadr check) val))
751 (and (numberp (cddr check))
752 (> (cddr check) val)))
753 (throw :suppress t))))))))
756 (indent-to (- id-length (length id)))
759 (indent-to (setq pos (+ pos id-length 1)) 1)
760 (insert (if (> (length state) state-length)
761 (propertize (substring state 0 state-length)
765 (indent-to (setq pos (+ pos state-length 1)) 1)
766 (insert "[" (if (> (length submitter) (- submitter-length 2))
767 (propertize (substring submitter 0 (- submitter-length 2))
768 'help-echo submitter)
770 (indent-to (+ pos (1- submitter-length)))
773 (indent-to (setq pos (+ pos submitter-length 1)) 1)
774 (insert (propertize title 'help-echo title))
777 beg (point) `(tabulated-list-id ,list-id mouse-face ,widget-mouse-face))
780 (defvar debbugs-gnu-mode-map
781 (let ((map (make-sparse-keymap)))
782 (set-keymap-parent map tabulated-list-mode-map)
783 (define-key map "\r" 'debbugs-gnu-select-report)
784 (define-key map [mouse-1] 'debbugs-gnu-select-report)
785 (define-key map [mouse-2] 'debbugs-gnu-select-report)
786 (define-key map "s" 'debbugs-gnu-toggle-sort)
787 (define-key map "t" 'debbugs-gnu-toggle-tag)
788 (define-key map "d" 'debbugs-gnu-display-status)
789 (define-key map "g" 'debbugs-gnu-rescan)
790 (define-key map "x" 'debbugs-gnu-toggle-suppress)
791 (define-key map "/" 'debbugs-gnu-narrow-to-status)
792 (define-key map "w" 'debbugs-gnu-widen)
793 (define-key map "C" 'debbugs-gnu-send-control-message)
796 (defun debbugs-gnu-rescan ()
797 "Rescan the current set of bug reports."
800 ;; The last page will be provided with new bug ids.
801 ;; TODO: Do it also for the other pages.
802 (when (and debbugs-gnu-widgets
803 (eq debbugs-gnu-current-widget (car (last debbugs-gnu-widgets))))
804 (let ((first-id (car (widget-get debbugs-gnu-current-widget :bug-ids)))
806 (last (widget-get debbugs-gnu-current-widget :bug-ids))))
807 (ids (debbugs-gnu-get-bugs
808 (widget-get debbugs-gnu-current-widget :query))))
810 (while (and (<= first-id last-id) (not (memq first-id ids)))
811 (setq first-id (1+ first-id)))
813 (when (<= first-id last-id)
814 (widget-put debbugs-gnu-current-widget :bug-ids (memq first-id ids)))))
816 ;; Refresh the buffer. `save-excursion' does not work, so we
817 ;; remember the position.
819 (debbugs-gnu-show-reports debbugs-gnu-current-widget)
822 (defvar debbugs-gnu-sort-state 'number)
824 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
825 "Major mode for listing bug reports.
827 All normal editing commands are switched off.
828 \\<debbugs-gnu-mode-map>
830 The following commands are available:
832 \\{debbugs-gnu-mode-map}"
833 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
834 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
835 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
836 ("State" 20 debbugs-gnu-sort-state)
838 ("Title" 10 debbugs-gnu-sort-title)])
839 (setq tabulated-list-sort-key (cons "Id" nil))
840 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
841 (buffer-disable-undo)
842 (setq truncate-lines t)
843 (setq buffer-read-only t))
845 (defun debbugs-gnu-sort-id (s1 s2)
846 (< (cdr (assq 'id (car s1)))
847 (cdr (assq 'id (car s2)))))
849 (defconst debbugs-gnu-state-preference
850 '((debbugs-gnu-new . 1)
851 (debbugs-gnu-stale . 2)
852 (debbugs-gnu-handled . 3)
853 (debbugs-gnu-done . 4)
854 (debbugs-gnu-pending . 5)))
856 (defun debbugs-gnu-get-state-preference (face-string)
857 (or (cdr (assq (get-text-property 0 'face face-string)
858 debbugs-gnu-state-preference))
861 (defconst debbugs-gnu-severity-preference
868 (defun debbugs-gnu-get-severity-preference (state)
869 (or (cdr (assoc (cdr (assq 'severity state))
870 debbugs-gnu-severity-preference))
873 (defun debbugs-gnu-sort-state (s1 s2)
874 (let ((id1 (cdr (assq 'id (car s1))))
875 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
876 (id2 (cdr (assq 'id (car s2))))
877 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
879 ;; Tagged bugs go to the end.
880 ((and (not (memq id1 debbugs-gnu-local-tags))
881 (memq id2 debbugs-gnu-local-tags))
883 ((and (memq id1 debbugs-gnu-local-tags)
884 (not (memq id2 debbugs-gnu-local-tags)))
886 ;; Then, we check the age of the bugs.
891 ;; If they have the same age, we check for severity.
892 ((< (debbugs-gnu-get-severity-preference (car s1))
893 (debbugs-gnu-get-severity-preference (car s2)))
897 (defun debbugs-gnu-sort-title (s1 s2)
898 (let ((owner (if (cdr (assq 'owner (car s1)))
899 (car (mail-header-parse-address
900 (decode-coding-string (cdr (assq 'owner (car s1)))
903 (string-equal owner user-mail-address))))
905 (defun debbugs-gnu-toggle-sort ()
906 "Toggle sorting by age and by state."
908 (if (eq debbugs-gnu-sort-state 'number)
910 (setq debbugs-gnu-sort-state 'state)
911 (setq tabulated-list-sort-key (cons "Id" nil)))
912 (setq debbugs-gnu-sort-state 'number)
913 (setq tabulated-list-sort-key (cons "State" nil)))
914 (tabulated-list-init-header)
915 (tabulated-list-print))
917 (defun debbugs-gnu-widen ()
918 "Display all the currently selected bug reports."
920 (let ((id (debbugs-gnu-current-id t))
921 (inhibit-read-only t))
922 (setq debbugs-gnu-current-limit nil)
923 (tabulated-list-init-header)
924 (tabulated-list-print)
926 (debbugs-gnu-goto id))))
928 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
929 "Only display the bugs matching STRING.
930 If STATUS-ONLY (the prefix), ignore matches in the From and
932 (interactive "sNarrow to: \nP")
933 (let ((id (debbugs-gnu-current-id t))
934 (inhibit-read-only t)
936 (setq debbugs-gnu-current-limit nil)
937 (if (equal string "")
938 (debbugs-gnu-toggle-suppress)
939 (goto-char (point-min))
941 (setq status (debbugs-gnu-current-status))
942 (if (and (not (member string (assq 'keywords status)))
943 (not (member string (assq 'severity status)))
945 (not (string-match string (cdr (assq 'originator status)))))
947 (not (string-match string (cdr (assq 'subject status))))))
948 (delete-region (point) (progn (forward-line 1) (point)))
949 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
952 (debbugs-gnu-goto id)))))
954 (defun debbugs-gnu-goto (id)
955 "Go to the line displaying bug ID."
956 (goto-char (point-min))
957 (while (and (not (eobp))
958 (not (equal (debbugs-gnu-current-id t) id)))
961 (defun debbugs-gnu-toggle-tag ()
962 "Toggle the local tag of the report in the current line.
963 If a report is tagged locally, it is presumed to be of little
968 (let ((inhibit-read-only t)
969 (id (debbugs-gnu-current-id)))
970 (if (memq id debbugs-gnu-local-tags)
972 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
973 (put-text-property (point) (+ (point) 5) 'face 'default))
974 (add-to-list 'debbugs-gnu-local-tags id)
976 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
977 'face 'debbugs-gnu-tagged))
978 (debbugs-gnu--update-tag-face id)))
979 (debbugs-gnu-dump-persistency-file))
981 (defun debbugs-gnu--update-tag-face (id)
982 (dolist (entry tabulated-list-entries)
983 (when (equal (cdr (assq 'id (car entry))) id)
989 (if (memq id debbugs-gnu-local-tags)
993 (defun debbugs-gnu-toggle-suppress ()
994 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
996 (widget-put debbugs-gnu-current-widget :suppress
997 (not (widget-get debbugs-gnu-current-widget :suppress)))
998 (tabulated-list-init-header)
999 (tabulated-list-print))
1001 (defvar debbugs-gnu-bug-number nil)
1002 (defvar debbugs-gnu-subject nil)
1004 (defun debbugs-gnu-current-id (&optional noerror)
1005 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1007 (error "No bug on the current line"))))
1009 (defun debbugs-gnu-current-status ()
1010 (get-text-property (line-beginning-position) 'tabulated-list-id))
1012 (defun debbugs-gnu-current-query ()
1013 (widget-get debbugs-gnu-current-widget :query))
1015 (defun debbugs-gnu-display-status (query status)
1016 "Display the query and status of the report on the current line."
1017 (interactive (list (debbugs-gnu-current-query)
1018 (debbugs-gnu-current-status)))
1019 (pop-to-buffer "*Bug Status*")
1020 (let ((inhibit-read-only t))
1022 (when query (pp query (current-buffer)))
1023 (when status (pp status (current-buffer)))
1024 (goto-char (point-min)))
1025 (set-buffer-modified-p nil)
1028 (defun debbugs-gnu-select-report ()
1029 "Select the report on the current line."
1031 ;; We open the report messages.
1032 (let* ((status (debbugs-gnu-current-status))
1033 (id (cdr (assq 'id status)))
1034 (merged (cdr (assq 'mergedwith status))))
1035 (gnus-read-ephemeral-emacs-bug-group
1036 (cons id (if (listp merged)
1039 (cons (current-buffer)
1040 (current-window-configuration)))
1041 (with-current-buffer (window-buffer (selected-window))
1042 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1043 (set (make-local-variable 'debbugs-gnu-subject)
1044 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1045 (debbugs-gnu-summary-mode 1))))
1047 (defvar debbugs-gnu-summary-mode-map
1048 (let ((map (make-sparse-keymap)))
1049 (define-key map "C" 'debbugs-gnu-send-control-message)
1052 (defvar gnus-posting-styles)
1054 (define-minor-mode debbugs-gnu-summary-mode
1055 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1057 \\{debbugs-gnu-summary-mode-map}"
1058 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1059 (set (make-local-variable 'gnus-posting-styles)
1062 (when (buffer-live-p gnus-article-copy)
1063 (with-current-buffer gnus-article-copy
1064 (set (make-local-variable 'message-prune-recipient-rules)
1065 '((".*@debbugs.*" "emacs-pretest-bug")
1066 (".*@debbugs.*" "bug-gnu-emacs")
1067 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1068 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1069 (set (make-local-variable 'message-alter-recipients-function)
1071 (if (string-match "\\([0-9]+\\)@donarmstrong"
1073 (let ((new (format "%s@debbugs.gnu.org"
1074 (match-string 1 (car address)))))
1077 ;; `gnus-posting-styles' is eval'ed after
1078 ;; `message-simplify-subject'. So we cannot use m-s-s.
1079 (setq subject ,debbugs-gnu-subject))))))))
1081 (defun debbugs-gnu-guess-current-id ()
1082 "Guess the ID based on \"#23\"."
1086 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1088 (goto-char (point-min))
1089 (re-search-forward "#\\([0-9]+\\)" nil t)))
1090 (string-to-number (match-string 1)))))
1092 (defun debbugs-gnu-send-control-message (message &optional reverse)
1093 "Send a control message for the current bug report.
1094 You can set the severity or add a tag, or close the report. If
1095 you use the special \"done\" MESSAGE, the report will be marked as
1096 fixed, and then closed.
1098 If given a prefix, and given a tag to set, the tag will be
1101 (list (completing-read
1103 '("serious" "important" "normal" "minor" "wishlist"
1104 "done" "donenotabug" "donewontfix" "doneunreproducible"
1105 "unarchive" "reopen" "close"
1106 "merge" "forcemerge"
1110 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1111 "pending" "help" "security" "confirmed"
1114 current-prefix-arg))
1115 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1116 (debbugs-gnu-guess-current-id)
1117 (debbugs-gnu-current-id)))
1119 (when (member message '("close" "done"))
1123 ;; Emacs development versions.
1125 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1127 (match-string 1 emacs-version)
1128 (1+ (string-to-number (match-string 2 emacs-version)))))
1129 ;; Emacs release versions.
1131 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1133 (match-string 1 emacs-version)
1134 (match-string 2 emacs-version)))
1135 (t emacs-version))))))
1137 (insert "To: control@debbugs.gnu.org\n"
1138 "From: " (message-make-from) "\n"
1139 (format "Subject: control message for bug #%d\n" id)
1142 ((member message '("unarchive" "reopen" "noowner"))
1143 (format "%s %d\n" message id))
1144 ((member message '("merge" "forcemerge"))
1145 (format "%s %d %s\n" message id
1146 (read-string "Merge with bug #: ")))
1147 ((equal message "owner")
1148 (format "owner %d !\n" id))
1149 ((equal message "reassign")
1150 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1151 ((equal message "close")
1152 (format "close %d %s\n" id version))
1153 ((equal message "done")
1154 (format "tags %d fixed\nclose %d %s\n" id id version))
1155 ((member message '("donenotabug" "donewontfix"
1156 "doneunreproducible"))
1157 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1158 ((member message '("serious" "important" "normal"
1159 "minor" "wishlist"))
1160 (format "severity %d %s\n" id message))
1161 ((equal message "invalid")
1162 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1164 ((equal message "usertag")
1165 (format "user %s\nusertag %d %s\n"
1167 "Package name or email address: "
1169 debbugs-gnu-all-packages (list user-mail-address))
1170 nil nil (car debbugs-gnu-default-packages))
1171 id (read-string "User tag: ")))
1173 (format "tags %d%s %s\n"
1174 id (if reverse " -" "")
1176 (funcall send-mail-function))))
1178 (defvar debbugs-gnu-usertags-mode-map
1179 (let ((map (make-sparse-keymap)))
1180 (set-keymap-parent map tabulated-list-mode-map)
1181 (define-key map "\r" 'debbugs-gnu-select-usertag)
1182 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1183 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1186 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1187 "Major mode for listing user tags.
1189 All normal editing commands are switched off.
1190 \\<debbugs-gnu-usertags-mode-map>
1192 The following commands are available:
1194 \\{debbugs-gnu-usertags-mode-map}"
1195 (buffer-disable-undo)
1196 (setq truncate-lines t)
1197 (setq buffer-read-only t))
1200 (defun debbugs-gnu-usertags (&rest users)
1201 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1203 (if current-prefix-arg
1204 (completing-read-multiple
1205 "Package name(s) or email address: "
1206 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1207 (mapconcat 'identity debbugs-gnu-default-packages ","))
1208 debbugs-gnu-default-packages))
1211 (let ((inhibit-read-only t)
1212 (debbugs-port "gnu.org")
1213 (buffer-name "*Emacs User Tags*")
1215 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1217 ;; Initialize variables.
1218 (when (and (file-exists-p debbugs-gnu-persistency-file)
1219 (not debbugs-gnu-local-tags))
1221 (insert-file-contents debbugs-gnu-persistency-file)
1222 (eval (read (current-buffer)))))
1225 (when (get-buffer buffer-name)
1226 (kill-buffer buffer-name))
1227 (pop-to-buffer (get-buffer-create buffer-name))
1228 (debbugs-gnu-usertags-mode)
1229 (setq tabulated-list-format `[("User" ,user-tab-length t)
1231 (setq tabulated-list-sort-key (cons "User" nil))
1232 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1235 ;; Retrieve user tags.
1236 (dolist (user users)
1237 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1239 'tabulated-list-entries
1240 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1241 `((("tagged") (,user) nil nil (,tag))
1242 ,(vector (propertize user 'mouse-face widget-mouse-face)
1243 (propertize tag 'mouse-face widget-mouse-face)))
1247 (when debbugs-gnu-local-tags
1249 'tabulated-list-entries
1251 ,(vector "" (propertize "(local tags)"
1252 'mouse-face widget-mouse-face)))))
1255 (tabulated-list-init-header)
1256 (tabulated-list-print)
1258 (set-buffer-modified-p nil)
1259 (goto-char (point-min)))))
1261 (defun debbugs-gnu-select-usertag ()
1262 "Select the user tag on the current line."
1264 ;; We open the bug reports.
1265 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1266 (when args (apply 'debbugs-gnu args))))
1269 (defun debbugs-gnu-bugs (&rest bugs)
1270 "List all BUGS, a list of bug numbers."
1272 (mapcar 'string-to-number
1273 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1275 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1276 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1279 (provide 'debbugs-gnu)
1283 ;; * Reorganize pages after client-side filtering.
1285 ;;; debbugs-gnu.el ends here