]> code.delx.au - gnu-emacs-elpa/blob - packages/debbugs/debbugs-gnu.el
Make an empty `/' command display all the bugs
[gnu-emacs-elpa] / packages / debbugs / debbugs-gnu.el
1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
2
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
8 ;; Package: debbugs
9 ;; Version: 0.6
10
11 ;; This file is not part of GNU Emacs.
12
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.
17
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.
22
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/>.
25
26 ;;; Commentary:
27
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.
32
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
35 ;;
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)
40
41 ;; The bug tracker is called interactively by
42 ;;
43 ;; M-x debbugs-gnu
44
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.
51
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.
58
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.
63
64 ;; Another command is
65 ;;
66 ;; M-x debbugs-gnu-search
67
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.
76
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.
81
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'.
85
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:
91
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
96
97 ;; Furthermore, you could apply the global actions
98
99 ;; "g": Rescan bugs
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
105
106 ;; When you visit the related bug messages in Gnus, you could also
107 ;; send control messages by keystroke "C".
108
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.
113
114 ;; Another approach for listing bugs is calling the command
115 ;;
116 ;; M-x debbugs-gnu-usertags
117
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.
125
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>.
129
130 ;; Finally, if you simply want to list some bugs with known bug
131 ;; numbers, call the command
132 ;;
133 ;; M-x debbugs-gnu-bugs
134
135 ;; The bug numbers to be shown shall be entered as comma separated list.
136
137 ;;; Code:
138
139 (require 'debbugs)
140 (require 'widget)
141 (require 'wid-edit)
142 (require 'tabulated-list)
143 (eval-when-compile (require 'cl))
144
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")
149
150 (defgroup debbugs-gnu ()
151 "UI for the debbugs.gnu.org bug tracker."
152 :group 'debbugs
153 :version "24.1")
154
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>
159 :group 'debbugs-gnu
160 :type '(set (const "serious")
161 (const "important")
162 (const "normal")
163 (const "minor")
164 (const "wishlist")
165 (const "tagged"))
166 :version "24.1")
167
168 (defconst debbugs-gnu-all-severities
169 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
170 "*List of all possible severities.")
171
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>
176 :group 'debbugs-gnu
177 :type '(set (const "auctex")
178 (const "automake")
179 (const "cc-mode")
180 (const "coreutils")
181 (const "cppi")
182 (const "debbugs.gnu.org")
183 (const "diffutils")
184 (const "emacs")
185 (const "emacs-xwidgets")
186 (const "fm")
187 (const "gnus")
188 (const "grep")
189 (const "guile")
190 (const "guix")
191 (const "gzip")
192 (const "idutils")
193 (const "libtool")
194 (const "mh-e")
195 (const "org-mode")
196 (const "parted")
197 (const "vc-dwim")
198 (const "woodchuck"))
199 :version "24.4")
200
201 (defconst debbugs-gnu-all-packages
202 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
203 "*List of all possible package names.")
204
205 (defcustom debbugs-gnu-default-hits-per-page 500
206 "*The number of bugs shown per page."
207 :group 'debbugs-gnu
208 :type 'integer
209 :version "24.1")
210
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'."
218 :group 'debbugs-gnu
219 :type '(alist :key-type symbol :value-type regexp)
220 :version "24.1")
221
222 (defface debbugs-gnu-new '((t (:foreground "red")))
223 "Face for new reports that nobody has answered.")
224
225 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
226 "Face for reports that have been modified recently.")
227
228 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
229 "Face for reports that are pending.")
230
231 (defface debbugs-gnu-stale '((t (:foreground "orange")))
232 "Face for reports that have not been touched for a week.")
233
234 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
235 "Face for closed bug reports.")
236
237 (defface debbugs-gnu-tagged '((t (:foreground "red")))
238 "Face for reports that have been tagged locally.")
239
240 (defvar debbugs-gnu-widgets nil)
241
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)
246 map))
247
248 (defvar debbugs-gnu-local-tags nil
249 "List of bug numbers tagged locally, and kept persistent.")
250
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")
254
255 (defun debbugs-gnu-dump-persistency-file ()
256 "Function to store debbugs variables persistently."
257 (with-temp-file debbugs-gnu-persistency-file
258 (insert
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) '<)))))
263
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'.")
268
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\).")
275
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)))
282 value))
283
284 (defconst debbugs-gnu-phrase-prompt
285 (propertize
286 "Enter search phrase: "
287 'help-echo "\
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
292 search."))
293
294 ;;;###autoload
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\"."
302 (interactive)
303
304 (unwind-protect
305 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
306 key val1 val2 phrase severities packages archivedp)
307
308 ;; Check for the phrase.
309 (setq phrase (read-string debbugs-gnu-phrase-prompt))
310 (if (zerop (length phrase))
311 (setq phrase nil)
312 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
313
314 ;; The other queries.
315 (catch :finished
316 (while t
317 (setq key (completing-read
318 "Enter attribute: "
319 (if phrase
320 '("severity" "package" "tags" "submitter" "date"
321 "subject" "status")
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"))
327 nil t))
328 (cond
329 ;; Server-side queries.
330 ((equal key "severity")
331 (setq
332 severities
333 (completing-read-multiple
334 "Enter severities: " debbugs-gnu-all-severities nil t
335 (mapconcat 'identity debbugs-gnu-default-severities ","))))
336
337 ((equal key "package")
338 (setq
339 packages
340 (completing-read-multiple
341 "Enter packages: " debbugs-gnu-all-packages nil t
342 (mapconcat 'identity debbugs-gnu-default-packages ","))))
343
344 ((equal key "archive")
345 ;; We simplify, by assuming just archived bugs are requested.
346 (setq archivedp t))
347
348 ((member key '("src" "tag" "tags"))
349 (setq val1 (read-string (format "Enter %s: " key)))
350 (when (not (zerop (length val1)))
351 (add-to-list
352 'debbugs-gnu-current-query (cons (intern key) val1))))
353
354 ((member key '("owner" "submitter" "maint" "correspondent"))
355 (setq val1 (read-string "Enter email address: "))
356 (when (not (zerop (length val1)))
357 (add-to-list
358 'debbugs-gnu-current-query (cons (intern key) val1))))
359
360 ((equal key "status")
361 (setq
362 val1
363 (completing-read "Enter status: " '("done" "forwarded" "open")))
364 (when (not (zerop (length val1)))
365 (add-to-list
366 'debbugs-gnu-current-query (cons (intern key) val1))))
367
368 ;; Client-side filters.
369 ((member key '("date" "log_modified" "last_modified"
370 "found_date" "fixed_date" "unarchived"))
371 (setq val1
372 (debbugs-gnu-calendar-read
373 (format "Enter %s before YYYY-MM-DD%s: "
374 key (if phrase "" " (client-side filter)"))
375 (lambda (x)
376 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
377 (if (string-match date-format val1)
378 (setq val1 (floor
379 (float-time
380 (encode-time
381 0 0 0
382 (string-to-number (match-string 3 val1))
383 (string-to-number (match-string 2 val1))
384 (string-to-number (match-string 1 val1))))))
385 (setq val1 nil))
386 (setq val2
387 (debbugs-gnu-calendar-read
388 (format "Enter %s after YYYY-MM-DD%s: "
389 key (if phrase "" " (client-side filter)"))
390 (lambda (x)
391 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
392 (if (string-match date-format val2)
393 (setq val2 (floor
394 (float-time
395 (encode-time
396 0 0 0
397 (string-to-number (match-string 3 val2))
398 (string-to-number (match-string 2 val2))
399 (string-to-number (match-string 1 val2))))))
400 (setq val2 nil))
401 (when (or val1 val2)
402 (add-to-list
403 (if phrase
404 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
405 (cons (intern key) (cons val1 val2)))))
406
407 ((not (zerop (length key)))
408 (setq val1
409 (funcall
410 (if phrase 'read-string 'read-regexp)
411 (format "Enter %s%s"
412 key (if phrase ": " " (client-side filter)"))))
413 (when (not (zerop (length val1)))
414 (add-to-list
415 (if phrase
416 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
417 (cons (intern key) val1))))
418
419 ;; The End.
420 (t (throw :finished nil)))))
421
422 ;; Do the search.
423 (debbugs-gnu severities packages archivedp))
424
425 ;; Reset query and filter.
426 (setq debbugs-gnu-current-query nil
427 debbugs-gnu-current-filter nil)))
428
429 ;;;###autoload
430 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
431 "List all outstanding bugs."
432 (interactive
433 (let (severities archivedp)
434 (list
435 (setq severities
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)))))
452
453 ;; Initialize variables.
454 (when (and (file-exists-p debbugs-gnu-persistency-file)
455 (not debbugs-gnu-local-tags))
456 (with-temp-buffer
457 (insert-file-contents debbugs-gnu-persistency-file)
458 (eval (read (current-buffer)))))
459 (setq debbugs-gnu-widgets nil)
460
461 ;; Add queries.
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))))
468 (when archivedp
469 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
470 (when suppress
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))))
476
477 (unwind-protect
478 (let ((hits debbugs-gnu-default-hits-per-page)
479 (ids (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
480
481 (if (> (length ids) hits)
482 (let ((cursor-in-echo-area nil))
483 (setq hits
484 (string-to-number
485 (read-string
486 (format
487 "How many reports (available %d, default %d): "
488 (length ids) hits)
489 nil
490 nil
491 (number-to-string hits))))))
492
493 (if (> (length ids) hits)
494 (let ((i 0)
495 curr-ids)
496 (while ids
497 (setq i (1+ i)
498 curr-ids (butlast ids (- (length ids) hits)))
499 (add-to-list
500 'debbugs-gnu-widgets
501 (widget-convert
502 'push-button
503 :follow-link 'mouse-face
504 :notify (lambda (widget &rest ignore)
505 (debbugs-gnu-show-reports widget))
506 :keymap debbugs-gnu-widget-map
507 :suppress suppress
508 :buffer-name (format "*Emacs Bugs*<%d>" i)
509 :bug-ids curr-ids
510 :query debbugs-gnu-current-query
511 :filter debbugs-gnu-current-filter
512 :help-echo (format "%d-%d" (car ids) (car (last curr-ids)))
513 :format " %[%v%]"
514 (number-to-string i))
515 'append)
516 (setq ids (last ids (- (length ids) hits))))
517 (debbugs-gnu-show-reports (car debbugs-gnu-widgets)))
518
519 (debbugs-gnu-show-reports
520 (widget-convert
521 'const
522 :suppress suppress
523 :buffer-name "*Emacs Bugs*"
524 :bug-ids ids
525 :query debbugs-gnu-current-query
526 :filter debbugs-gnu-current-filter))))
527
528 ;; Reset query and filter.
529 (setq debbugs-gnu-current-query nil
530 debbugs-gnu-current-filter nil)))
531
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))
539 args)
540 ;; Compile query arguments.
541 (unless (or query tags)
542 (dolist (elt debbugs-gnu-default-packages)
543 (setq args (append args (list :package elt)))))
544 (dolist (elt query)
545 (unless (equal elt '(severity . "tagged"))
546 (setq args
547 (append
548 args
549 (if phrase
550 (cond
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)
555 :operator "NUMBT")))
556 (t
557 (list (list (intern (concat ":" (symbol-name (car elt))))
558 (cdr elt) :operator "ISTRINC"))))
559 (list (intern (concat ":" (symbol-name (car elt))))
560 (cdr elt)))))))
561
562 (sort
563 (cond
564 ;; If the query is just a list of bug numbers, we return them.
565 (bugs (cdr bugs))
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.
570 (phrase
571 (mapcar
572 (lambda (x) (cdr (assoc "id" x)))
573 (apply 'debbugs-search-est args)))
574 ;; User tags.
575 (tags
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)))
580 ;; Sort function.
581 '<)))
582
583 (defvar debbugs-gnu-current-widget nil)
584 (defvar debbugs-gnu-current-limit nil)
585
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
589 ;; of them.
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)))
593 (debbugs-gnu-mode)
594 (let ((inhibit-read-only t)
595 (debbugs-port "gnu.org"))
596 (erase-buffer)
597 (set (make-local-variable 'debbugs-gnu-current-widget) widget)
598
599 (dolist (status (apply 'debbugs-get-status (widget-get widget :bug-ids)))
600 (let* ((id (cdr (assq 'id status)))
601 (words
602 (mapconcat
603 'identity
604 (cons (cdr (assq 'severity status))
605 (cdr (assq 'keywords status)))
606 ","))
607 (address (mail-header-parse-address
608 (decode-coding-string (cdr (assq 'originator status))
609 'utf-8)))
610 (owner (if (cdr (assq 'owner status))
611 (car (mail-header-parse-address
612 (decode-coding-string (cdr (assq 'owner status))
613 'utf-8)))))
614 (subject (decode-coding-string (cdr (assq 'subject status))
615 'utf-8))
616 merged)
617 (unless (equal (cdr (assq 'pending status)) "pending")
618 (setq words
619 (concat words "," (cdr (assq 'pending status)))))
620 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
621 (when packages
622 (setq words (concat words "," (mapconcat 'identity packages ",")))))
623 (when (setq merged (cdr (assq 'mergedwith status)))
624 (setq words (format "%s,%s"
625 (if (numberp merged)
626 merged
627 (mapconcat 'number-to-string merged ","))
628 words)))
629 (when (or (not merged)
630 (not (let ((found nil))
631 (dolist (id (if (listp merged)
632 merged
633 (list merged)))
634 (dolist (entry tabulated-list-entries)
635 (when (equal id (cdr (assq 'id (car entry))))
636 (setq found t))))
637 found)))
638 (add-to-list
639 'tabulated-list-entries
640 (list
641 status
642 (vector
643 (propertize
644 (format "%5d" id)
645 'face
646 ;; Mark tagged bugs.
647 (if (memq id debbugs-gnu-local-tags)
648 'debbugs-gnu-tagged
649 'default))
650 (propertize
651 ;; Mark status and age.
652 words
653 'face
654 (cond
655 ((equal (cdr (assq 'pending status)) "done")
656 'debbugs-gnu-done)
657 ((member "pending" (cdr (assq 'keywords status)))
658 'debbugs-gnu-pending)
659 ((= (cdr (assq 'date status))
660 (cdr (assq 'log_modified status)))
661 'debbugs-gnu-new)
662 ((< (- (float-time)
663 (cdr (assq 'log_modified status)))
664 (* 60 60 24 7 2))
665 'debbugs-gnu-handled)
666 (t
667 'debbugs-gnu-stale)))
668 (propertize
669 ;; Prefer the name over the address.
670 (or (cdr address)
671 (car address))
672 'face
673 ;; Mark own submitted bugs.
674 (if (and (stringp (car address))
675 (string-equal (car address) user-mail-address))
676 'debbugs-gnu-tagged
677 'default))
678 (propertize
679 subject
680 'face
681 ;; Mark owned bugs.
682 (if (and (stringp owner)
683 (string-equal owner user-mail-address))
684 'debbugs-gnu-tagged
685 'default))))
686 'append))))
687 (tabulated-list-init-header)
688 (tabulated-list-print)
689
690 (set-buffer-modified-p nil)
691 (goto-char (point-min))))
692
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
698 ;; here. (bug#9047)
699 (when (and debbugs-gnu-widgets (= (point) (point-min)))
700 (widget-insert "Page:")
701 (mapc
702 (lambda (obj)
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))
707 debbugs-gnu-widgets)
708 (widget-insert "\n\n")
709 (save-excursion
710 (widget-insert "\nPage:")
711 (mapc (lambda (obj) (widget-apply obj :create)) debbugs-gnu-widgets)
712 (widget-setup)))
713
714 (let ((beg (point))
715 (pos 0)
716 (case-fold-search t)
717 (id (aref cols 0))
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))))
725 (when (and
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)
734 (when
735 (string-match
736 (cdr check)
737 (or (cdr (assq (car check) list-id)) ""))
738 (throw :suppress t)))))))
739 ;; Filter search list.
740 (not (catch :suppress
741 (dolist (check
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 "")))
747 (throw :suppress t))
748 ;; Time value.
749 (when (or (and (numberp (cadr check))
750 (< (cadr check) val))
751 (and (numberp (cddr check))
752 (> (cddr check) val)))
753 (throw :suppress t))))))))
754
755 ;; Insert id.
756 (indent-to (- id-length (length id)))
757 (insert id)
758 ;; Insert state.
759 (indent-to (setq pos (+ pos id-length 1)) 1)
760 (insert (if (> (length state) state-length)
761 (propertize (substring state 0 state-length)
762 'help-echo state)
763 state))
764 ;; Insert submitter.
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)
769 submitter))
770 (indent-to (+ pos (1- submitter-length)))
771 (insert "]")
772 ;; Insert title.
773 (indent-to (setq pos (+ pos submitter-length 1)) 1)
774 (insert (propertize title 'help-echo title))
775 ;; Add properties.
776 (add-text-properties
777 beg (point) `(tabulated-list-id ,list-id mouse-face ,widget-mouse-face))
778 (insert ?\n))))
779
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)
794 map))
795
796 (defun debbugs-gnu-rescan ()
797 "Rescan the current set of bug reports."
798 (interactive)
799
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)))
805 (last-id (car
806 (last (widget-get debbugs-gnu-current-widget :bug-ids))))
807 (ids (debbugs-gnu-get-bugs
808 (widget-get debbugs-gnu-current-widget :query))))
809
810 (while (and (<= first-id last-id) (not (memq first-id ids)))
811 (setq first-id (1+ first-id)))
812
813 (when (<= first-id last-id)
814 (widget-put debbugs-gnu-current-widget :bug-ids (memq first-id ids)))))
815
816 ;; Refresh the buffer. `save-excursion' does not work, so we
817 ;; remember the position.
818 (let ((pos (point)))
819 (debbugs-gnu-show-reports debbugs-gnu-current-widget)
820 (goto-char pos)))
821
822 (defvar debbugs-gnu-sort-state 'number)
823
824 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
825 "Major mode for listing bug reports.
826
827 All normal editing commands are switched off.
828 \\<debbugs-gnu-mode-map>
829
830 The following commands are available:
831
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)
837 ("Submitter" 25 t)
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))
844
845 (defun debbugs-gnu-sort-id (s1 s2)
846 (< (cdr (assq 'id (car s1)))
847 (cdr (assq 'id (car s2)))))
848
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)))
855
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))
859 10))
860
861 (defconst debbugs-gnu-severity-preference
862 '(("serious" . 1)
863 ("important" . 2)
864 ("normal" . 3)
865 ("minor" . 4)
866 ("wishlist" . 5)))
867
868 (defun debbugs-gnu-get-severity-preference (state)
869 (or (cdr (assoc (cdr (assq 'severity state))
870 debbugs-gnu-severity-preference))
871 10))
872
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))))
878 (cond
879 ;; Tagged bugs go to the end.
880 ((and (not (memq id1 debbugs-gnu-local-tags))
881 (memq id2 debbugs-gnu-local-tags))
882 t)
883 ((and (memq id1 debbugs-gnu-local-tags)
884 (not (memq id2 debbugs-gnu-local-tags)))
885 nil)
886 ;; Then, we check the age of the bugs.
887 ((< age1 age2)
888 t)
889 ((> age1 age2)
890 nil)
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)))
894 t)
895 (t nil))))
896
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)))
901 'utf-8))))))
902 (and (stringp owner)
903 (string-equal owner user-mail-address))))
904
905 (defun debbugs-gnu-toggle-sort ()
906 "Toggle sorting by age and by state."
907 (interactive)
908 (if (eq debbugs-gnu-sort-state 'number)
909 (progn
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))
916
917 (defun debbugs-gnu-widen ()
918 "Display all the currently selected bug reports."
919 (interactive)
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)
925 (when id
926 (debbugs-gnu-goto id))))
927
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
931 Subject fields."
932 (interactive "sNarrow to: \nP")
933 (let ((id (debbugs-gnu-current-id t))
934 (inhibit-read-only t)
935 status)
936 (setq debbugs-gnu-current-limit nil)
937 (if (equal string "")
938 (debbugs-gnu-toggle-suppress)
939 (goto-char (point-min))
940 (while (not (eobp))
941 (setq status (debbugs-gnu-current-status))
942 (if (and (not (member string (assq 'keywords status)))
943 (not (member string (assq 'severity status)))
944 (or status-only
945 (not (string-match string (cdr (assq 'originator status)))))
946 (or status-only
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)
950 (forward-line 1)))
951 (when id
952 (debbugs-gnu-goto id)))))
953
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)))
959 (forward-line 1)))
960
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
964 interest to you."
965 (interactive)
966 (save-excursion
967 (beginning-of-line)
968 (let ((inhibit-read-only t)
969 (id (debbugs-gnu-current-id)))
970 (if (memq id debbugs-gnu-local-tags)
971 (progn
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)
975 (put-text-property
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))
980
981 (defun debbugs-gnu--update-tag-face (id)
982 (dolist (entry tabulated-list-entries)
983 (when (equal (cdr (assq 'id (car entry))) id)
984 (aset (cadr entry) 0
985 (propertize
986 (format "%5d" id)
987 'face
988 ;; Mark tagged bugs.
989 (if (memq id debbugs-gnu-local-tags)
990 'debbugs-gnu-tagged
991 'default))))))
992
993 (defun debbugs-gnu-toggle-suppress ()
994 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
995 (interactive)
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))
1000
1001 (defvar debbugs-gnu-bug-number nil)
1002 (defvar debbugs-gnu-subject nil)
1003
1004 (defun debbugs-gnu-current-id (&optional noerror)
1005 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1006 (and (not noerror)
1007 (error "No bug on the current line"))))
1008
1009 (defun debbugs-gnu-current-status ()
1010 (get-text-property (line-beginning-position) 'tabulated-list-id))
1011
1012 (defun debbugs-gnu-current-query ()
1013 (widget-get debbugs-gnu-current-widget :query))
1014
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))
1021 (erase-buffer)
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)
1026 (special-mode))
1027
1028 (defun debbugs-gnu-select-report ()
1029 "Select the report on the current line."
1030 (interactive)
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)
1037 merged
1038 (list 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))))
1046
1047 (defvar debbugs-gnu-summary-mode-map
1048 (let ((map (make-sparse-keymap)))
1049 (define-key map "C" 'debbugs-gnu-send-control-message)
1050 map))
1051
1052 (defvar gnus-posting-styles)
1053
1054 (define-minor-mode debbugs-gnu-summary-mode
1055 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1056
1057 \\{debbugs-gnu-summary-mode-map}"
1058 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1059 (set (make-local-variable 'gnus-posting-styles)
1060 `((".*"
1061 (eval
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)
1070 (lambda (address)
1071 (if (string-match "\\([0-9]+\\)@donarmstrong"
1072 (car address))
1073 (let ((new (format "%s@debbugs.gnu.org"
1074 (match-string 1 (car address)))))
1075 (cons new new))
1076 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))))))))
1080
1081 (defun debbugs-gnu-guess-current-id ()
1082 "Guess the ID based on \"#23\"."
1083 (save-excursion
1084 (beginning-of-line)
1085 (and
1086 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1087 (progn
1088 (goto-char (point-min))
1089 (re-search-forward "#\\([0-9]+\\)" nil t)))
1090 (string-to-number (match-string 1)))))
1091
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.
1097
1098 If given a prefix, and given a tag to set, the tag will be
1099 removed instead."
1100 (interactive
1101 (list (completing-read
1102 "Control message: "
1103 '("serious" "important" "normal" "minor" "wishlist"
1104 "done" "donenotabug" "donewontfix" "doneunreproducible"
1105 "unarchive" "reopen" "close"
1106 "merge" "forcemerge"
1107 "owner" "noowner"
1108 "invalid"
1109 "reassign"
1110 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1111 "pending" "help" "security" "confirmed"
1112 "usertag")
1113 nil t)
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)))
1118 (version
1119 (when (member message '("close" "done"))
1120 (read-string
1121 "Version: "
1122 (cond
1123 ;; Emacs development versions.
1124 ((string-match
1125 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1126 (format "%s.%d"
1127 (match-string 1 emacs-version)
1128 (1+ (string-to-number (match-string 2 emacs-version)))))
1129 ;; Emacs release versions.
1130 ((string-match
1131 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1132 (format "%s.%s"
1133 (match-string 1 emacs-version)
1134 (match-string 2 emacs-version)))
1135 (t emacs-version))))))
1136 (with-temp-buffer
1137 (insert "To: control@debbugs.gnu.org\n"
1138 "From: " (message-make-from) "\n"
1139 (format "Subject: control message for bug #%d\n" id)
1140 "\n"
1141 (cond
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"
1163 id id id))
1164 ((equal message "usertag")
1165 (format "user %s\nusertag %d %s\n"
1166 (completing-read
1167 "Package name or email address: "
1168 (append
1169 debbugs-gnu-all-packages (list user-mail-address))
1170 nil nil (car debbugs-gnu-default-packages))
1171 id (read-string "User tag: ")))
1172 (t
1173 (format "tags %d%s %s\n"
1174 id (if reverse " -" "")
1175 message))))
1176 (funcall send-mail-function))))
1177
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)
1184 map))
1185
1186 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1187 "Major mode for listing user tags.
1188
1189 All normal editing commands are switched off.
1190 \\<debbugs-gnu-usertags-mode-map>
1191
1192 The following commands are available:
1193
1194 \\{debbugs-gnu-usertags-mode-map}"
1195 (buffer-disable-undo)
1196 (setq truncate-lines t)
1197 (setq buffer-read-only t))
1198
1199 ;;;###autoload
1200 (defun debbugs-gnu-usertags (&rest users)
1201 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1202 (interactive
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))
1209
1210 (unwind-protect
1211 (let ((inhibit-read-only t)
1212 (debbugs-port "gnu.org")
1213 (buffer-name "*Emacs User Tags*")
1214 (user-tab-length
1215 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1216
1217 ;; Initialize variables.
1218 (when (and (file-exists-p debbugs-gnu-persistency-file)
1219 (not debbugs-gnu-local-tags))
1220 (with-temp-buffer
1221 (insert-file-contents debbugs-gnu-persistency-file)
1222 (eval (read (current-buffer)))))
1223
1224 ;; Create 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)
1230 ("Tag" 10 t)])
1231 (setq tabulated-list-sort-key (cons "User" nil))
1232 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1233 (erase-buffer)
1234
1235 ;; Retrieve user tags.
1236 (dolist (user users)
1237 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1238 (add-to-list
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)))
1244 'append)))
1245
1246 ;; Add local tags.
1247 (when debbugs-gnu-local-tags
1248 (add-to-list
1249 'tabulated-list-entries
1250 `((("tagged"))
1251 ,(vector "" (propertize "(local tags)"
1252 'mouse-face widget-mouse-face)))))
1253
1254 ;; Show them.
1255 (tabulated-list-init-header)
1256 (tabulated-list-print)
1257
1258 (set-buffer-modified-p nil)
1259 (goto-char (point-min)))))
1260
1261 (defun debbugs-gnu-select-usertag ()
1262 "Select the user tag on the current line."
1263 (interactive)
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))))
1267
1268 ;;;###autoload
1269 (defun debbugs-gnu-bugs (&rest bugs)
1270 "List all BUGS, a list of bug numbers."
1271 (interactive
1272 (mapcar 'string-to-number
1273 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1274 (dolist (elt bugs)
1275 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1276 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1277 (debbugs-gnu nil))
1278
1279 (provide 'debbugs-gnu)
1280
1281 ;;; TODO:
1282
1283 ;; * Reorganize pages after client-side filtering.
1284
1285 ;;; debbugs-gnu.el ends here