]> code.delx.au - gnu-emacs-elpa/blob - packages/debbugs/debbugs-gnu.el
6d7180284d1d12e19cda38adb786a587c36a43bd
[gnu-emacs-elpa] / packages / debbugs / debbugs-gnu.el
1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
2
3 ;; Copyright (C) 2011-2015 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.7
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 ;; "b": Show bugs this bug is blocked by
96 ;; "B": Show bugs this bug is blocking
97 ;; "d": Show bug attributes
98
99 ;; Furthermore, you could apply the global actions
100
101 ;; "g": Rescan bugs
102 ;; "q": Quit the buffer
103 ;; "s": Toggle bug sorting for age or for state
104 ;; "x": Toggle suppressing of bugs
105 ;; "/": Display only bugs matching a string
106 ;; "w": Display all the currently selected bug reports
107
108 ;; When you visit the related bug messages in Gnus, you could also
109 ;; send control messages by keystroke "C".
110
111 ;; In the header line of every bug list page, you can toggle sorting
112 ;; per column by selecting a column with the mouse. The sorting
113 ;; happens as expected for the respective column; sorting in the Title
114 ;; column is depending on whether you are the owner of a bug.
115
116 ;; Another approach for listing bugs is calling the command
117 ;;
118 ;; M-x debbugs-gnu-usertags
119
120 ;; This command shows you all existing user tags for the packages
121 ;; defined in `debbugs-gnu-default-packages'. A prefix for the
122 ;; command allows you to use other packe names, or an arbitrary string
123 ;; for a user who has tagged bugs. The command returns the list of
124 ;; existing user tags for the given user(s) or package name(s),
125 ;; respectively. Applying RET on a user tag, all bugs tagged with
126 ;; this user tag are shown.
127
128 ;; Unfortunately, it is not possible with the SOAP interface to show
129 ;; all users who have tagged bugs. This list can be retrieved via
130 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi?indexon=users>.
131
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
134 ;;
135 ;; M-x debbugs-gnu-bugs
136
137 ;; The bug numbers to be shown shall be entered as comma separated list.
138
139 ;;; Code:
140
141 (require 'debbugs)
142 (require 'widget)
143 (require 'wid-edit)
144 (require 'tabulated-list)
145 (require 'add-log)
146 (eval-when-compile (require 'cl))
147
148 (autoload 'article-decode-charset "gnus-art")
149 (autoload 'diff-goto-source "diff-mode")
150 (autoload 'gnus-article-mime-handles "gnus-art")
151 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
152 (autoload 'gnus-summary-article-header "gnus-sum")
153 (autoload 'gnus-summary-select-article "gnus-sum")
154 (autoload 'gnus-summary-show-article "gnus-sum")
155 (autoload 'gnus-with-article-buffer "gnus-art")
156 (autoload 'log-edit-insert-changelog "log-edit")
157 (autoload 'mail-header-subject "nnheader")
158 (autoload 'message-make-from "message")
159 (autoload 'vc-dir-hide-up-to-date "vc-dir")
160 (autoload 'vc-dir-mark "vc-dir")
161 (defvar compilation-in-progress)
162
163 (defgroup debbugs-gnu ()
164 "UI for the debbugs.gnu.org bug tracker."
165 :group 'debbugs
166 :version "24.1")
167
168 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
169 "*The list severities bugs are searched for.
170 \"tagged\" is not a severity but marks locally tagged bugs."
171 ;; <http://debbugs.gnu.org/Developer.html#severities>
172 :group 'debbugs-gnu
173 :type '(set (const "serious")
174 (const "important")
175 (const "normal")
176 (const "minor")
177 (const "wishlist")
178 (const "tagged"))
179 :version "24.1")
180
181 (defconst debbugs-gnu-all-severities
182 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
183 "*List of all possible severities.")
184
185 (defcustom debbugs-gnu-default-packages '("emacs")
186 "*The list of packages to be searched for."
187 ;; <http://debbugs.gnu.org/Packages.html>
188 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
189 :group 'debbugs-gnu
190 :type '(set (const "adns")
191 (const "auctex")
192 (const "automake")
193 (const "cc-mode")
194 (const "coreutils")
195 (const "cppi")
196 (const "debbugs.gnu.org")
197 (const "diffutils")
198 (const "emacs")
199 (const "emacs-xwidgets")
200 (const "fm")
201 (const "gnus")
202 (const "grep")
203 (const "guile")
204 (const "guix")
205 (const "gzip")
206 (const "idutils")
207 (const "libtool")
208 (const "mh-e")
209 (const "org-mode")
210 (const "parted")
211 (const "sed")
212 (const "vc-dwim")
213 (const "woodchuck"))
214 :version "24.4")
215
216 (defconst debbugs-gnu-all-packages
217 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
218 "*List of all possible package names.")
219
220 (defcustom debbugs-gnu-default-hits-per-page 500
221 "*The number of bugs shown per page."
222 :group 'debbugs-gnu
223 :type 'integer
224 :version "24.1")
225
226 (defcustom debbugs-gnu-default-suppress-bugs
227 '((pending . "done"))
228 "*A list of specs for bugs to be suppressed.
229 An element of this list is a cons cell \(KEY . REGEXP\), with key
230 being returned by `debbugs-get-status', and VAL a regular
231 expression matching the corresponding value, a string. Showing
232 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
233 :group 'debbugs-gnu
234 :type '(alist :key-type symbol :value-type regexp)
235 :version "24.1")
236
237 (defface debbugs-gnu-new '((t (:foreground "red")))
238 "Face for new reports that nobody has answered.")
239
240 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
241 "Face for reports that have been modified recently.")
242
243 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
244 "Face for reports that are pending.")
245
246 (defface debbugs-gnu-stale '((t (:foreground "orange")))
247 "Face for reports that have not been touched for a week.")
248
249 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
250 "Face for closed bug reports.")
251
252 (defface debbugs-gnu-tagged '((t (:foreground "red")))
253 "Face for reports that have been tagged locally.")
254
255 (defvar debbugs-gnu-widgets nil)
256
257 (defvar debbugs-gnu-widget-map
258 (let ((map (make-sparse-keymap)))
259 (define-key map "\r" 'widget-button-press)
260 (define-key map [mouse-2] 'widget-button-press)
261 map))
262
263 (defvar debbugs-gnu-local-tags nil
264 "List of bug numbers tagged locally, and kept persistent.")
265
266 (defvar debbugs-gnu-persistency-file
267 (expand-file-name (locate-user-emacs-file "debbugs"))
268 "File name of a persistency store for debbugs variables")
269
270 (defun debbugs-gnu-dump-persistency-file ()
271 "Function to store debbugs variables persistently."
272 (with-temp-file debbugs-gnu-persistency-file
273 (insert
274 ";; -*- emacs-lisp -*-\n"
275 ";; Debbugs tags connection history. Don't change this file.\n\n"
276 (format "(setq debbugs-gnu-local-tags '%S)"
277 (sort (copy-sequence debbugs-gnu-local-tags) '<)))))
278
279 (defvar debbugs-gnu-current-query nil
280 "The query object of the current search.
281 It will be applied server-side, when calling `debbugs-get-bugs'.
282 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
283
284 (defvar debbugs-gnu-current-filter nil
285 "The filter object for the current search.
286 It will be applied client-side, when parsing the results of
287 `debbugs-get-status'. It has a similar format as
288 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
289 a date, value is the cons cell \(BEFORE . AFTER\).")
290
291 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
292 "Return a string read from the minibuffer.
293 Derived from `calendar-read'."
294 (let ((value (read-string prompt initial-contents)))
295 (while (not (funcall acceptable value))
296 (setq value (read-string prompt initial-contents)))
297 value))
298
299 (defconst debbugs-gnu-phrase-prompt
300 (propertize
301 "Enter search phrase: "
302 'help-echo "\
303 The search phrase contains words to be searched for, combined by
304 operators like AND, ANDNOT and OR. If there is no operator
305 between the words, AND is used by default. The phrase can also
306 be empty, in this case only the following attributes are used for
307 search."))
308
309 ;;;###autoload
310 (defun debbugs-gnu-search ()
311 "Search for Emacs bugs interactively.
312 Search arguments are requested interactively. The \"search
313 phrase\" is used for full text search in the bugs database.
314 Further key-value pairs are requested until an empty key is
315 returned. If a key cannot be queried by a SOAP request, it is
316 marked as \"client-side filter\"."
317 (interactive)
318
319 (unwind-protect
320 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
321 key val1 val2 phrase severities packages archivedp)
322
323 ;; Check for the phrase.
324 (setq phrase (read-string debbugs-gnu-phrase-prompt))
325 (if (zerop (length phrase))
326 (setq phrase nil)
327 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
328
329 ;; The other queries.
330 (catch :finished
331 (while t
332 (setq key (completing-read
333 "Enter attribute: "
334 (if phrase
335 '("severity" "package" "tags" "submitter" "date"
336 "subject" "status")
337 '("severity" "package" "archive" "src" "tag"
338 "owner" "submitter" "maint" "correspondent"
339 "date" "log_modified" "last_modified"
340 "found_date" "fixed_date" "unarchived"
341 "subject" "done" "forwarded" "msgid" "summary"))
342 nil t))
343 (cond
344 ;; Server-side queries.
345 ((equal key "severity")
346 (setq
347 severities
348 (completing-read-multiple
349 "Enter severities: " debbugs-gnu-all-severities nil t
350 (mapconcat 'identity debbugs-gnu-default-severities ","))))
351
352 ((equal key "package")
353 (setq
354 packages
355 (completing-read-multiple
356 "Enter packages: " debbugs-gnu-all-packages nil t
357 (mapconcat 'identity debbugs-gnu-default-packages ","))))
358
359 ((equal key "archive")
360 ;; We simplify, by assuming just archived bugs are requested.
361 (setq archivedp t))
362
363 ((member key '("src" "tag" "tags"))
364 (setq val1 (read-string (format "Enter %s: " key)))
365 (when (not (zerop (length val1)))
366 (add-to-list
367 'debbugs-gnu-current-query (cons (intern key) val1))))
368
369 ((member key '("owner" "submitter" "maint" "correspondent"))
370 (setq val1 (read-string "Enter email address: "))
371 (when (not (zerop (length val1)))
372 (add-to-list
373 'debbugs-gnu-current-query (cons (intern key) val1))))
374
375 ((equal key "status")
376 (setq
377 val1
378 (completing-read "Enter status: " '("done" "forwarded" "open")))
379 (when (not (zerop (length val1)))
380 (add-to-list
381 'debbugs-gnu-current-query (cons (intern key) val1))))
382
383 ;; Client-side filters.
384 ((member key '("date" "log_modified" "last_modified"
385 "found_date" "fixed_date" "unarchived"))
386 (setq val1
387 (debbugs-gnu-calendar-read
388 (format "Enter %s before 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 val1)
393 (setq val1 (floor
394 (float-time
395 (encode-time
396 0 0 0
397 (string-to-number (match-string 3 val1))
398 (string-to-number (match-string 2 val1))
399 (string-to-number (match-string 1 val1))))))
400 (setq val1 nil))
401 (setq val2
402 (debbugs-gnu-calendar-read
403 (format "Enter %s after YYYY-MM-DD%s: "
404 key (if phrase "" " (client-side filter)"))
405 (lambda (x)
406 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
407 (if (string-match date-format val2)
408 (setq val2 (floor
409 (float-time
410 (encode-time
411 0 0 0
412 (string-to-number (match-string 3 val2))
413 (string-to-number (match-string 2 val2))
414 (string-to-number (match-string 1 val2))))))
415 (setq val2 nil))
416 (when (or val1 val2)
417 (add-to-list
418 (if phrase
419 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
420 (cons (intern key) (cons val1 val2)))))
421
422 ((not (zerop (length key)))
423 (setq val1
424 (funcall
425 (if phrase 'read-string 'read-regexp)
426 (format "Enter %s%s"
427 key (if phrase ": " " (client-side filter)"))))
428 (when (not (zerop (length val1)))
429 (add-to-list
430 (if phrase
431 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
432 (cons (intern key) val1))))
433
434 ;; The End.
435 (t (throw :finished nil)))))
436
437 ;; Do the search.
438 (debbugs-gnu severities packages archivedp))
439
440 ;; Reset query and filter.
441 (setq debbugs-gnu-current-query nil
442 debbugs-gnu-current-filter nil)))
443
444 ;;;###autoload
445 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
446 "List all outstanding bugs."
447 (interactive
448 (let (severities archivedp)
449 (list
450 (setq severities
451 (completing-read-multiple
452 "Severities: " debbugs-gnu-all-severities nil t
453 (mapconcat 'identity debbugs-gnu-default-severities ",")))
454 ;; The next parameters are asked only when there is a prefix.
455 (if current-prefix-arg
456 (completing-read-multiple
457 "Packages: " debbugs-gnu-all-packages nil t
458 (mapconcat 'identity debbugs-gnu-default-packages ","))
459 debbugs-gnu-default-packages)
460 (when current-prefix-arg
461 (setq archivedp (y-or-n-p "Show archived bugs?")))
462 (when (and current-prefix-arg (not archivedp))
463 (y-or-n-p "Suppress unwanted bugs?"))
464 ;; This one must be asked for severity "tagged".
465 (when (member "tagged" severities)
466 (split-string (read-string "User tag(s): ") "," t)))))
467
468 ;; Initialize variables.
469 (when (and (file-exists-p debbugs-gnu-persistency-file)
470 (not debbugs-gnu-local-tags))
471 (with-temp-buffer
472 (insert-file-contents debbugs-gnu-persistency-file)
473 (eval (read (current-buffer)))))
474 (setq debbugs-gnu-widgets nil)
475
476 ;; Add queries.
477 (dolist (severity (if (consp severities) severities (list severities)))
478 (when (not (zerop (length severity)))
479 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
480 (dolist (package (if (consp packages) packages (list packages)))
481 (when (not (zerop (length package)))
482 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
483 (when archivedp
484 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
485 (when suppress
486 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
487 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
488 (dolist (tag (if (consp tags) tags (list tags)))
489 (when (not (zerop (length tag)))
490 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
491
492 (unwind-protect
493 (let ((hits debbugs-gnu-default-hits-per-page)
494 (ids (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
495
496 (if (> (length ids) hits)
497 (let ((cursor-in-echo-area nil))
498 (setq hits
499 (string-to-number
500 (read-string
501 (format
502 "How many reports (available %d, default %d): "
503 (length ids) hits)
504 nil
505 nil
506 (number-to-string hits))))))
507
508 (if (> (length ids) hits)
509 (let ((i 0)
510 curr-ids)
511 (while ids
512 (setq i (1+ i)
513 curr-ids (butlast ids (- (length ids) hits)))
514 (add-to-list
515 'debbugs-gnu-widgets
516 (widget-convert
517 'push-button
518 :follow-link 'mouse-face
519 :notify (lambda (widget &rest ignore)
520 (debbugs-gnu-show-reports widget))
521 :keymap debbugs-gnu-widget-map
522 :suppress suppress
523 :buffer-name (format "*Emacs Bugs*<%d>" i)
524 :bug-ids curr-ids
525 :query debbugs-gnu-current-query
526 :filter debbugs-gnu-current-filter
527 :help-echo (format "%d-%d" (car ids) (car (last curr-ids)))
528 :format " %[%v%]"
529 (number-to-string i))
530 'append)
531 (setq ids (last ids (- (length ids) hits))))
532 (debbugs-gnu-show-reports (car debbugs-gnu-widgets)))
533
534 (debbugs-gnu-show-reports
535 (widget-convert
536 'const
537 :suppress suppress
538 :buffer-name "*Emacs Bugs*"
539 :bug-ids ids
540 :query debbugs-gnu-current-query
541 :filter debbugs-gnu-current-filter))))
542
543 ;; Reset query and filter.
544 (setq debbugs-gnu-current-query nil
545 debbugs-gnu-current-filter nil)))
546
547 (defun debbugs-gnu-get-bugs (query)
548 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
549 (let* ((debbugs-port "gnu.org")
550 (bugs (assoc 'bugs query))
551 (tags (assoc 'tag query))
552 (local-tags (and (member '(severity . "tagged") query) (not tags)))
553 (phrase (assoc 'phrase query))
554 args)
555 ;; Compile query arguments.
556 (unless (or query tags)
557 (dolist (elt debbugs-gnu-default-packages)
558 (setq args (append args (list :package elt)))))
559 (dolist (elt query)
560 (unless (equal elt '(severity . "tagged"))
561 (setq args
562 (append
563 args
564 (if phrase
565 (cond
566 ((eq (car elt) 'phrase)
567 (list (list :phrase (cdr elt) :max 500)))
568 ((eq (car elt) 'date)
569 (list (list :date (cddr elt) (cadr elt)
570 :operator "NUMBT")))
571 (t
572 (list (list (intern (concat ":" (symbol-name (car elt))))
573 (cdr elt) :operator "ISTRINC"))))
574 (list (intern (concat ":" (symbol-name (car elt))))
575 (cdr elt)))))))
576
577 (sort
578 (cond
579 ;; If the query is just a list of bug numbers, we return them.
580 (bugs (cdr bugs))
581 ;; If the query contains the pseudo-severity "tagged", we return
582 ;; just the local tagged bugs.
583 (local-tags (copy-sequence debbugs-gnu-local-tags))
584 ;; A full text query.
585 (phrase
586 (mapcar
587 (lambda (x) (cdr (assoc "id" x)))
588 (apply 'debbugs-search-est args)))
589 ;; User tags.
590 (tags
591 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
592 (apply 'debbugs-get-usertag args))
593 ;; Otherwise, we retrieve the bugs from the server.
594 (t (apply 'debbugs-get-bugs args)))
595 ;; Sort function.
596 '<)))
597
598 (defvar debbugs-gnu-current-widget nil)
599 (defvar debbugs-gnu-current-limit nil)
600
601 (defun debbugs-gnu-show-reports (widget)
602 "Show bug reports as given in WIDGET property :bug-ids."
603 ;; The tabulated mode sets several local variables. We must get rid
604 ;; of them.
605 (when (get-buffer (widget-get widget :buffer-name))
606 (kill-buffer (widget-get widget :buffer-name)))
607 (pop-to-buffer (get-buffer-create (widget-get widget :buffer-name)))
608 (debbugs-gnu-mode)
609 (let ((inhibit-read-only t)
610 (debbugs-port "gnu.org"))
611 (erase-buffer)
612 (set (make-local-variable 'debbugs-gnu-current-widget) widget)
613
614 (dolist (status (apply 'debbugs-get-status (widget-get widget :bug-ids)))
615 (let* ((id (cdr (assq 'id status)))
616 (words
617 (mapconcat
618 'identity
619 (cons (cdr (assq 'severity status))
620 (cdr (assq 'keywords status)))
621 ","))
622 (address (mail-header-parse-address
623 (decode-coding-string (cdr (assq 'originator status))
624 'utf-8)))
625 (owner (if (cdr (assq 'owner status))
626 (car (mail-header-parse-address
627 (decode-coding-string (cdr (assq 'owner status))
628 'utf-8)))))
629 (subject (decode-coding-string (cdr (assq 'subject status))
630 'utf-8))
631 merged)
632 (unless (equal (cdr (assq 'pending status)) "pending")
633 (setq words
634 (concat words "," (cdr (assq 'pending status)))))
635 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
636 (when packages
637 (setq words (concat words "," (mapconcat 'identity packages ",")))))
638 (when (setq merged (cdr (assq 'mergedwith status)))
639 (setq words (format "%s,%s"
640 (if (numberp merged)
641 merged
642 (mapconcat 'number-to-string merged ","))
643 words)))
644 (when (or (not merged)
645 (not (let ((found nil))
646 (dolist (id (if (listp merged)
647 merged
648 (list merged)))
649 (dolist (entry tabulated-list-entries)
650 (when (equal id (cdr (assq 'id (car entry))))
651 (setq found t))))
652 found)))
653 (add-to-list
654 'tabulated-list-entries
655 (list
656 status
657 (vector
658 (propertize
659 (format "%5d" id)
660 'face
661 ;; Mark tagged bugs.
662 (if (memq id debbugs-gnu-local-tags)
663 'debbugs-gnu-tagged
664 'default))
665 (propertize
666 ;; Mark status and age.
667 words
668 'face
669 (cond
670 ((equal (cdr (assq 'pending status)) "done")
671 'debbugs-gnu-done)
672 ((member "pending" (cdr (assq 'keywords status)))
673 'debbugs-gnu-pending)
674 ((= (cdr (assq 'date status))
675 (cdr (assq 'log_modified status)))
676 'debbugs-gnu-new)
677 ((< (- (float-time)
678 (cdr (assq 'log_modified status)))
679 (* 60 60 24 7 2))
680 'debbugs-gnu-handled)
681 (t
682 'debbugs-gnu-stale)))
683 (propertize
684 ;; Prefer the name over the address.
685 (or (cdr address)
686 (car address))
687 'face
688 ;; Mark own submitted bugs.
689 (if (and (stringp (car address))
690 (string-equal (car address) user-mail-address))
691 'debbugs-gnu-tagged
692 'default))
693 (propertize
694 subject
695 'face
696 ;; Mark owned bugs.
697 (if (and (stringp owner)
698 (string-equal owner user-mail-address))
699 'debbugs-gnu-tagged
700 'default))))
701 'append))))
702 (tabulated-list-init-header)
703 (tabulated-list-print)
704
705 (set-buffer-modified-p nil)
706 (goto-char (point-min))))
707
708 (defun debbugs-gnu-print-entry (list-id cols)
709 "Insert a debbugs entry at point.
710 Used instead of `tabulated-list-print-entry'."
711 ;; This shall be in `debbugs-gnu-show-reports'. But
712 ;; `tabulated-list-print' erases the buffer, therefore we do it
713 ;; here. (bug#9047)
714 (when (and debbugs-gnu-widgets (= (point) (point-min)))
715 (widget-insert "Page:")
716 (mapc
717 (lambda (obj)
718 (if (eq obj debbugs-gnu-current-widget)
719 (widget-put obj :button-face 'widget-button-pressed)
720 (widget-put obj :button-face 'widget-button-face))
721 (widget-apply obj :create))
722 debbugs-gnu-widgets)
723 (widget-insert "\n\n")
724 (save-excursion
725 (widget-insert "\nPage:")
726 (mapc (lambda (obj) (widget-apply obj :create)) debbugs-gnu-widgets)
727 (widget-setup)))
728
729 (let ((beg (point))
730 (pos 0)
731 (case-fold-search t)
732 (id (aref cols 0))
733 (id-length (nth 1 (aref tabulated-list-format 0)))
734 (state (aref cols 1))
735 (state-length (nth 1 (aref tabulated-list-format 1)))
736 (submitter (aref cols 2))
737 (submitter-length (nth 1 (aref tabulated-list-format 2)))
738 (title (aref cols 3))
739 (title-length (nth 1 (aref tabulated-list-format 3))))
740 (when (and
741 ;; We may have a narrowing in effect.
742 (or (not debbugs-gnu-current-limit)
743 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
744 ;; Filter suppressed bugs.
745 (or (not (widget-get debbugs-gnu-current-widget :suppress))
746 (and (not (memq (cdr (assq 'id list-id)) debbugs-gnu-local-tags))
747 (not (catch :suppress
748 (dolist (check debbugs-gnu-default-suppress-bugs)
749 (when
750 (string-match
751 (cdr check)
752 (or (cdr (assq (car check) list-id)) ""))
753 (throw :suppress t)))))))
754 ;; Filter search list.
755 (not (catch :suppress
756 (dolist (check
757 (widget-get debbugs-gnu-current-widget :filter))
758 (let ((val (cdr (assq (car check) list-id))))
759 (if (stringp (cdr check))
760 ;; Regular expression.
761 (when (not (string-match (cdr check) (or val "")))
762 (throw :suppress t))
763 ;; Time value.
764 (when (or (and (numberp (cadr check))
765 (< (cadr check) val))
766 (and (numberp (cddr check))
767 (> (cddr check) val)))
768 (throw :suppress t))))))))
769
770 ;; Insert id.
771 (indent-to (- id-length (length id)))
772 (insert id)
773 ;; Insert state.
774 (indent-to (setq pos (+ pos id-length 1)) 1)
775 (insert (if (> (length state) state-length)
776 (propertize (substring state 0 state-length)
777 'help-echo state)
778 state))
779 ;; Insert submitter.
780 (indent-to (setq pos (+ pos state-length 1)) 1)
781 (insert "[" (if (> (length submitter) (- submitter-length 2))
782 (propertize (substring submitter 0 (- submitter-length 2))
783 'help-echo submitter)
784 submitter))
785 (indent-to (+ pos (1- submitter-length)))
786 (insert "]")
787 ;; Insert title.
788 (indent-to (setq pos (+ pos submitter-length 1)) 1)
789 (insert (propertize title 'help-echo title))
790 ;; Add properties.
791 (add-text-properties
792 beg (point) `(tabulated-list-id ,list-id mouse-face ,widget-mouse-face))
793 (insert ?\n))))
794
795 (defvar debbugs-gnu-mode-map
796 (let ((map (make-sparse-keymap)))
797 (set-keymap-parent map tabulated-list-mode-map)
798 (define-key map "\r" 'debbugs-gnu-select-report)
799 (define-key map [mouse-1] 'debbugs-gnu-select-report)
800 (define-key map [mouse-2] 'debbugs-gnu-select-report)
801 (define-key map "s" 'debbugs-gnu-toggle-sort)
802 (define-key map "t" 'debbugs-gnu-toggle-tag)
803 (define-key map "d" 'debbugs-gnu-display-status)
804 (define-key map "g" 'debbugs-gnu-rescan)
805 (define-key map "x" 'debbugs-gnu-toggle-suppress)
806 (define-key map "/" 'debbugs-gnu-narrow-to-status)
807 (define-key map "w" 'debbugs-gnu-widen)
808 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
809 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
810 (define-key map "C" 'debbugs-gnu-send-control-message)
811 map))
812
813 (defun debbugs-gnu-rescan ()
814 "Rescan the current set of bug reports."
815 (interactive)
816
817 ;; The last page will be provided with new bug ids.
818 ;; TODO: Do it also for the other pages.
819 (when (and debbugs-gnu-widgets
820 (eq debbugs-gnu-current-widget (car (last debbugs-gnu-widgets))))
821 (let ((first-id (car (widget-get debbugs-gnu-current-widget :bug-ids)))
822 (last-id (car
823 (last (widget-get debbugs-gnu-current-widget :bug-ids))))
824 (ids (debbugs-gnu-get-bugs
825 (widget-get debbugs-gnu-current-widget :query))))
826
827 (while (and (<= first-id last-id) (not (memq first-id ids)))
828 (setq first-id (1+ first-id)))
829
830 (when (<= first-id last-id)
831 (widget-put debbugs-gnu-current-widget :bug-ids (memq first-id ids)))))
832
833 ;; Refresh the buffer. `save-excursion' does not work, so we
834 ;; remember the position.
835 (let ((pos (point)))
836 (debbugs-gnu-show-reports debbugs-gnu-current-widget)
837 (goto-char pos)))
838
839 (defvar debbugs-gnu-sort-state 'number)
840
841 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
842 "Major mode for listing bug reports.
843
844 All normal editing commands are switched off.
845 \\<debbugs-gnu-mode-map>
846
847 The following commands are available:
848
849 \\{debbugs-gnu-mode-map}"
850 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
851 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
852 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
853 ("State" 20 debbugs-gnu-sort-state)
854 ("Submitter" 25 t)
855 ("Title" 10 debbugs-gnu-sort-title)])
856 (setq tabulated-list-sort-key (cons "Id" nil))
857 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
858 (buffer-disable-undo)
859 (setq truncate-lines t)
860 (setq buffer-read-only t))
861
862 (defun debbugs-gnu-sort-id (s1 s2)
863 (< (cdr (assq 'id (car s1)))
864 (cdr (assq 'id (car s2)))))
865
866 (defconst debbugs-gnu-state-preference
867 '((debbugs-gnu-new . 1)
868 (debbugs-gnu-stale . 2)
869 (debbugs-gnu-handled . 3)
870 (debbugs-gnu-done . 4)
871 (debbugs-gnu-pending . 5)))
872
873 (defun debbugs-gnu-get-state-preference (face-string)
874 (or (cdr (assq (get-text-property 0 'face face-string)
875 debbugs-gnu-state-preference))
876 10))
877
878 (defconst debbugs-gnu-severity-preference
879 '(("serious" . 1)
880 ("important" . 2)
881 ("normal" . 3)
882 ("minor" . 4)
883 ("wishlist" . 5)))
884
885 (defun debbugs-gnu-get-severity-preference (state)
886 (or (cdr (assoc (cdr (assq 'severity state))
887 debbugs-gnu-severity-preference))
888 10))
889
890 (defun debbugs-gnu-sort-state (s1 s2)
891 (let ((id1 (cdr (assq 'id (car s1))))
892 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
893 (id2 (cdr (assq 'id (car s2))))
894 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
895 (cond
896 ;; Tagged bugs go to the end.
897 ((and (not (memq id1 debbugs-gnu-local-tags))
898 (memq id2 debbugs-gnu-local-tags))
899 t)
900 ((and (memq id1 debbugs-gnu-local-tags)
901 (not (memq id2 debbugs-gnu-local-tags)))
902 nil)
903 ;; Then, we check the age of the bugs.
904 ((< age1 age2)
905 t)
906 ((> age1 age2)
907 nil)
908 ;; If they have the same age, we check for severity.
909 ((< (debbugs-gnu-get-severity-preference (car s1))
910 (debbugs-gnu-get-severity-preference (car s2)))
911 t)
912 (t nil))))
913
914 (defun debbugs-gnu-sort-title (s1 s2)
915 (let ((owner (if (cdr (assq 'owner (car s1)))
916 (car (mail-header-parse-address
917 (decode-coding-string (cdr (assq 'owner (car s1)))
918 'utf-8))))))
919 (and (stringp owner)
920 (string-equal owner user-mail-address))))
921
922 (defun debbugs-gnu-toggle-sort ()
923 "Toggle sorting by age and by state."
924 (interactive)
925 (if (eq debbugs-gnu-sort-state 'number)
926 (progn
927 (setq debbugs-gnu-sort-state 'state)
928 (setq tabulated-list-sort-key (cons "Id" nil)))
929 (setq debbugs-gnu-sort-state 'number)
930 (setq tabulated-list-sort-key (cons "State" nil)))
931 (tabulated-list-init-header)
932 (tabulated-list-print))
933
934 (defun debbugs-gnu-widen ()
935 "Display all the currently selected bug reports."
936 (interactive)
937 (let ((id (debbugs-gnu-current-id t))
938 (inhibit-read-only t))
939 (setq debbugs-gnu-current-limit nil)
940 (tabulated-list-init-header)
941 (tabulated-list-print)
942 (when id
943 (debbugs-gnu-goto id))))
944
945 (defun debbugs-gnu-show-blocked-by-reports ()
946 "Display all bug reports this report is blocked by."
947 (interactive)
948 (let ((id (debbugs-gnu-current-id))
949 (status (debbugs-gnu-current-status)))
950 (if (null (cdr (assq 'blockedby status)))
951 (message "Bug %d is not blocked by any other bug" id)
952 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
953
954 (defun debbugs-gnu-show-blocking-reports ()
955 "Display all bug reports this report is blocking."
956 (interactive)
957 (let ((id (debbugs-gnu-current-id))
958 (status (debbugs-gnu-current-status)))
959 (if (null (cdr (assq 'blocks status)))
960 (message "Bug %d is not blocking any other bug" id)
961 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
962
963 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
964 "Only display the bugs matching STRING.
965 If STATUS-ONLY (the prefix), ignore matches in the From and
966 Subject fields."
967 (interactive "sNarrow to: \nP")
968 (let ((id (debbugs-gnu-current-id t))
969 (inhibit-read-only t)
970 status)
971 (setq debbugs-gnu-current-limit nil)
972 (if (equal string "")
973 (debbugs-gnu-toggle-suppress)
974 (goto-char (point-min))
975 (while (not (eobp))
976 (setq status (debbugs-gnu-current-status))
977 (if (and (not (member string (assq 'keywords status)))
978 (not (member string (assq 'severity status)))
979 (or status-only
980 (not (string-match string (cdr (assq 'originator status)))))
981 (or status-only
982 (not (string-match string (cdr (assq 'subject status))))))
983 (delete-region (point) (progn (forward-line 1) (point)))
984 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
985 (forward-line 1)))
986 (when id
987 (debbugs-gnu-goto id)))))
988
989 (defun debbugs-gnu-goto (id)
990 "Go to the line displaying bug ID."
991 (goto-char (point-min))
992 (while (and (not (eobp))
993 (not (equal (debbugs-gnu-current-id t) id)))
994 (forward-line 1)))
995
996 (defun debbugs-gnu-toggle-tag ()
997 "Toggle the local tag of the report in the current line.
998 If a report is tagged locally, it is presumed to be of little
999 interest to you."
1000 (interactive)
1001 (save-excursion
1002 (beginning-of-line)
1003 (let ((inhibit-read-only t)
1004 (id (debbugs-gnu-current-id)))
1005 (if (memq id debbugs-gnu-local-tags)
1006 (progn
1007 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1008 (put-text-property (point) (+ (point) 5) 'face 'default))
1009 (add-to-list 'debbugs-gnu-local-tags id)
1010 (put-text-property
1011 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1012 'face 'debbugs-gnu-tagged))
1013 (debbugs-gnu--update-tag-face id)))
1014 (debbugs-gnu-dump-persistency-file))
1015
1016 (defun debbugs-gnu--update-tag-face (id)
1017 (dolist (entry tabulated-list-entries)
1018 (when (equal (cdr (assq 'id (car entry))) id)
1019 (aset (cadr entry) 0
1020 (propertize
1021 (format "%5d" id)
1022 'face
1023 ;; Mark tagged bugs.
1024 (if (memq id debbugs-gnu-local-tags)
1025 'debbugs-gnu-tagged
1026 'default))))))
1027
1028 (defun debbugs-gnu-toggle-suppress ()
1029 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1030 (interactive)
1031 (widget-put debbugs-gnu-current-widget :suppress
1032 (not (widget-get debbugs-gnu-current-widget :suppress)))
1033 (tabulated-list-init-header)
1034 (tabulated-list-print))
1035
1036 (defvar debbugs-gnu-bug-number nil)
1037 (defvar debbugs-gnu-subject nil)
1038
1039 (defun debbugs-gnu-current-id (&optional noerror)
1040 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1041 (and (not noerror)
1042 (error "No bug on the current line"))))
1043
1044 (defun debbugs-gnu-current-status ()
1045 (get-text-property (line-beginning-position) 'tabulated-list-id))
1046
1047 (defun debbugs-gnu-current-query ()
1048 (widget-get debbugs-gnu-current-widget :query))
1049
1050 (defun debbugs-gnu-display-status (query status)
1051 "Display the query and status of the report on the current line."
1052 (interactive (list (debbugs-gnu-current-query)
1053 (debbugs-gnu-current-status)))
1054 (pop-to-buffer "*Bug Status*")
1055 (let ((inhibit-read-only t))
1056 (erase-buffer)
1057 (when query (pp query (current-buffer)))
1058 (when status (pp status (current-buffer)))
1059 (goto-char (point-min)))
1060 (set-buffer-modified-p nil)
1061 (special-mode))
1062
1063 (defun debbugs-gnu-select-report ()
1064 "Select the report on the current line."
1065 (interactive)
1066 ;; We open the report messages.
1067 (let* ((status (debbugs-gnu-current-status))
1068 (id (cdr (assq 'id status)))
1069 (merged (cdr (assq 'mergedwith status))))
1070 (gnus-read-ephemeral-emacs-bug-group
1071 (cons id (if (listp merged)
1072 merged
1073 (list merged)))
1074 (cons (current-buffer)
1075 (current-window-configuration)))
1076 (with-current-buffer (window-buffer (selected-window))
1077 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1078 (set (make-local-variable 'debbugs-gnu-subject)
1079 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1080 (debbugs-gnu-summary-mode 1))))
1081
1082 (defvar debbugs-gnu-summary-mode-map
1083 (let ((map (make-sparse-keymap)))
1084 (define-key map "C" 'debbugs-gnu-send-control-message)
1085 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1086 map))
1087
1088 (defvar gnus-posting-styles)
1089
1090 (define-minor-mode debbugs-gnu-summary-mode
1091 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1092
1093 \\{debbugs-gnu-summary-mode-map}"
1094 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1095 (set (make-local-variable 'gnus-posting-styles)
1096 `((".*"
1097 (eval
1098 (when (buffer-live-p gnus-article-copy)
1099 (with-current-buffer gnus-article-copy
1100 (set (make-local-variable 'message-prune-recipient-rules)
1101 '((".*@debbugs.*" "emacs-pretest-bug")
1102 (".*@debbugs.*" "bug-gnu-emacs")
1103 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1104 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1105 (set (make-local-variable 'message-alter-recipients-function)
1106 (lambda (address)
1107 (if (string-match "\\([0-9]+\\)@donarmstrong"
1108 (car address))
1109 (let ((new (format "%s@debbugs.gnu.org"
1110 (match-string 1 (car address)))))
1111 (cons new new))
1112 address)))
1113 ;; `gnus-posting-styles' is eval'ed after
1114 ;; `message-simplify-subject'. So we cannot use m-s-s.
1115 (setq subject ,debbugs-gnu-subject))))))))
1116
1117 (defun debbugs-gnu-guess-current-id ()
1118 "Guess the ID based on \"#23\"."
1119 (save-excursion
1120 (beginning-of-line)
1121 (and
1122 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1123 (progn
1124 (goto-char (point-min))
1125 (re-search-forward "#\\([0-9]+\\)" nil t)))
1126 (string-to-number (match-string 1)))))
1127
1128 (defun debbugs-gnu-send-control-message (message &optional reverse)
1129 "Send a control message for the current bug report.
1130 You can set the severity or add a tag, or close the report. If
1131 you use the special \"done\" MESSAGE, the report will be marked as
1132 fixed, and then closed.
1133
1134 If given a prefix, and given a tag to set, the tag will be
1135 removed instead."
1136 (interactive
1137 (list (completing-read
1138 "Control message: "
1139 '("serious" "important" "normal" "minor" "wishlist"
1140 "done" "donenotabug" "donewontfix" "doneunreproducible"
1141 "unarchive" "unmerge" "reopen" "close"
1142 "merge" "forcemerge"
1143 "block" "unblock"
1144 "owner" "noowner"
1145 "invalid"
1146 "reassign"
1147 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1148 "pending" "help" "security" "confirmed"
1149 "usertag")
1150 nil t)
1151 current-prefix-arg))
1152 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1153 (debbugs-gnu-guess-current-id)
1154 (debbugs-gnu-current-id)))
1155 (version
1156 (when (member message '("close" "done"))
1157 (read-string
1158 "Version: "
1159 (cond
1160 ;; Emacs development versions.
1161 ((string-match
1162 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1163 (format "%s.%d"
1164 (match-string 1 emacs-version)
1165 (1+ (string-to-number (match-string 2 emacs-version)))))
1166 ;; Emacs release versions.
1167 ((string-match
1168 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1169 (format "%s.%s"
1170 (match-string 1 emacs-version)
1171 (match-string 2 emacs-version)))
1172 (t emacs-version)))))
1173 (status (debbugs-gnu-current-status)))
1174 (with-temp-buffer
1175 (insert "To: control@debbugs.gnu.org\n"
1176 "From: " (message-make-from) "\n"
1177 (format "Subject: control message for bug #%d\n" id)
1178 "\n"
1179 (cond
1180 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1181 (format "%s %d\n" message id))
1182 ((member message '("merge" "forcemerge"))
1183 (format "%s %d %s\n" message id
1184 (read-string "Merge with bug #: ")))
1185 ((member message '("block" "unblock"))
1186 (format
1187 "%s %d by %s\n" message id
1188 (mapconcat
1189 'identity
1190 (completing-read-multiple
1191 (format "%s with bug(s) #: " (capitalize message))
1192 (if (equal message "unblock")
1193 (mapcar 'number-to-string
1194 (cdr (assq 'blockedby status))))
1195 nil (and (equal message "unblock") status))
1196 " ")))
1197 ((equal message "owner")
1198 (format "owner %d !\n" id))
1199 ((equal message "reassign")
1200 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1201 ((equal message "close")
1202 (format "close %d %s\n" id version))
1203 ((equal message "done")
1204 (format "tags %d fixed\nclose %d %s\n" id id version))
1205 ((member message '("donenotabug" "donewontfix"
1206 "doneunreproducible"))
1207 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1208 ((member message '("serious" "important" "normal"
1209 "minor" "wishlist"))
1210 (format "severity %d %s\n" id message))
1211 ((equal message "invalid")
1212 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1213 id id id))
1214 ((equal message "usertag")
1215 (format "user %s\nusertag %d %s\n"
1216 (completing-read
1217 "Package name or email address: "
1218 (append
1219 debbugs-gnu-all-packages (list user-mail-address))
1220 nil nil (car debbugs-gnu-default-packages))
1221 id (read-string "User tag: ")))
1222 (t
1223 (format "tags %d%s %s\n"
1224 id (if reverse " -" "")
1225 message))))
1226 (funcall send-mail-function))))
1227
1228 (defvar debbugs-gnu-usertags-mode-map
1229 (let ((map (make-sparse-keymap)))
1230 (set-keymap-parent map tabulated-list-mode-map)
1231 (define-key map "\r" 'debbugs-gnu-select-usertag)
1232 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1233 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1234 map))
1235
1236 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1237 "Major mode for listing user tags.
1238
1239 All normal editing commands are switched off.
1240 \\<debbugs-gnu-usertags-mode-map>
1241
1242 The following commands are available:
1243
1244 \\{debbugs-gnu-usertags-mode-map}"
1245 (buffer-disable-undo)
1246 (setq truncate-lines t)
1247 (setq buffer-read-only t))
1248
1249 ;;;###autoload
1250 (defun debbugs-gnu-usertags (&rest users)
1251 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1252 (interactive
1253 (if current-prefix-arg
1254 (completing-read-multiple
1255 "Package name(s) or email address: "
1256 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1257 (mapconcat 'identity debbugs-gnu-default-packages ","))
1258 debbugs-gnu-default-packages))
1259
1260 (unwind-protect
1261 (let ((inhibit-read-only t)
1262 (debbugs-port "gnu.org")
1263 (buffer-name "*Emacs User Tags*")
1264 (user-tab-length
1265 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1266
1267 ;; Initialize variables.
1268 (when (and (file-exists-p debbugs-gnu-persistency-file)
1269 (not debbugs-gnu-local-tags))
1270 (with-temp-buffer
1271 (insert-file-contents debbugs-gnu-persistency-file)
1272 (eval (read (current-buffer)))))
1273
1274 ;; Create buffer.
1275 (when (get-buffer buffer-name)
1276 (kill-buffer buffer-name))
1277 (pop-to-buffer (get-buffer-create buffer-name))
1278 (debbugs-gnu-usertags-mode)
1279 (setq tabulated-list-format `[("User" ,user-tab-length t)
1280 ("Tag" 10 t)])
1281 (setq tabulated-list-sort-key (cons "User" nil))
1282 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1283 (erase-buffer)
1284
1285 ;; Retrieve user tags.
1286 (dolist (user users)
1287 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1288 (add-to-list
1289 'tabulated-list-entries
1290 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1291 `((("tagged") (,user) nil nil (,tag))
1292 ,(vector (propertize user 'mouse-face widget-mouse-face)
1293 (propertize tag 'mouse-face widget-mouse-face)))
1294 'append)))
1295
1296 ;; Add local tags.
1297 (when debbugs-gnu-local-tags
1298 (add-to-list
1299 'tabulated-list-entries
1300 `((("tagged"))
1301 ,(vector "" (propertize "(local tags)"
1302 'mouse-face widget-mouse-face)))))
1303
1304 ;; Show them.
1305 (tabulated-list-init-header)
1306 (tabulated-list-print)
1307
1308 (set-buffer-modified-p nil)
1309 (goto-char (point-min)))))
1310
1311 (defun debbugs-gnu-select-usertag ()
1312 "Select the user tag on the current line."
1313 (interactive)
1314 ;; We open the bug reports.
1315 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1316 (when args (apply 'debbugs-gnu args))))
1317
1318 ;;;###autoload
1319 (defun debbugs-gnu-bugs (&rest bugs)
1320 "List all BUGS, a list of bug numbers."
1321 (interactive
1322 (mapcar 'string-to-number
1323 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1324 (dolist (elt bugs)
1325 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1326 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1327 (debbugs-gnu nil))
1328
1329 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1330 "The directory where the main source tree lives.")
1331
1332 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-24/"
1333 "The directory where the previous source tree lives.")
1334
1335 (defun debbugs-gnu-apply-patch (&optional branch)
1336 "Apply the patch from the current message.
1337 If given a prefix, patch in the branch directory instead."
1338 (interactive "P")
1339 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1340 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1341 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1342 (let ((rej "/tmp/debbugs-gnu.rej")
1343 (output-buffer (get-buffer-create "*debbugs patch*"))
1344 (dir (if branch
1345 debbugs-gnu-branch-directory
1346 debbugs-gnu-trunk-directory))
1347 (patch-buffers nil))
1348 (when (file-exists-p rej)
1349 (delete-file rej))
1350 (with-current-buffer output-buffer
1351 (erase-buffer))
1352 (gnus-summary-select-article nil t)
1353 ;; The patches are either in MIME attachements or the main article
1354 ;; buffer. Determine which.
1355 (gnus-with-article-buffer
1356 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1357 (when (string-match "diff\\|patch" (mm-handle-media-type handle))
1358 (push (mm-handle-buffer handle) patch-buffers))))
1359 (unless patch-buffers
1360 (gnus-summary-show-article 'raw)
1361 (article-decode-charset)
1362 (push (current-buffer) patch-buffers))
1363 (dolist (buffer patch-buffers)
1364 (with-current-buffer buffer
1365 (call-process-region (point-min) (point-max)
1366 "patch" nil output-buffer nil
1367 "-r" rej "--no-backup-if-mismatch"
1368 "-l" "-f"
1369 "-d" (expand-file-name dir)
1370 "-p1")))
1371 (set-buffer output-buffer)
1372 (when (file-exists-p rej)
1373 (goto-char (point-max))
1374 (insert-file-contents-literally rej))
1375 (goto-char (point-max))
1376 (save-some-buffers t)
1377 (require 'compile)
1378 (mapc 'kill-process compilation-in-progress)
1379 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1380 (vc-dir dir)
1381 (vc-dir-hide-up-to-date)
1382 (goto-char (point-min))
1383 (sit-for 1)
1384 (vc-diff)
1385 ;; All these commands are asynchronous, so just wait a bit. This
1386 ;; should be done properly a different way.
1387 (sit-for 2)
1388 ;; We've now done everything, so arrange the windows we need to see.
1389 (delete-other-windows)
1390 (switch-to-buffer output-buffer)
1391 (split-window)
1392 (split-window)
1393 (other-window 1)
1394 (switch-to-buffer "*compilation*")
1395 (goto-char (point-max))
1396 (other-window 1)
1397 (switch-to-buffer "*vc-diff*")
1398 (goto-char (point-min))))
1399
1400 (defun debbugs-gnu-find-contributor (string)
1401 "Search through ChangeLogs to find contributors."
1402 (interactive "sContributor match: ")
1403 (let ((found 0)
1404 (match (concat "^[0-9].*" string)))
1405 (dolist (file (directory-files-recursively
1406 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1407 (with-temp-buffer
1408 (when (file-exists-p file)
1409 (insert-file-contents file))
1410 (goto-char (point-min))
1411 (while (and (re-search-forward match nil t)
1412 (not (looking-at ".*tiny change")))
1413 (cl-incf found))))
1414 (message "%s is a contributor %d times" string found)
1415 found))
1416
1417 (defun debbugs-gnu-insert-changelog ()
1418 "Add a ChangeLog from a recently applied patch from a third party."
1419 (interactive)
1420 (let (from subject)
1421 (gnus-with-article-buffer
1422 (widen)
1423 (goto-char (point-min))
1424 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1425 subject (gnus-fetch-field "subject")))
1426 (let ((add-log-full-name (car from))
1427 (add-log-mailing-address (cadr from)))
1428 (add-change-log-entry-other-window)
1429 (let ((point (point)))
1430 (when (string-match "\\(bug#[0-9]+\\)" subject)
1431 (insert " (" (match-string 1 subject) ")."))
1432 (when (zerop (debbugs-gnu-find-contributor
1433 (let ((bits (split-string (car from))))
1434 (cond
1435 ((>= (length bits) 2)
1436 (format "%s.*%s" (car bits) (car (last bits))))
1437 ((= (length bits) 1)
1438 (car bits))
1439 ;; Fall back on the email address.
1440 (t
1441 (cadr from))))))
1442 (goto-char (point-min))
1443 (end-of-line)
1444 (insert " (tiny change"))
1445 (goto-char point)))))
1446
1447 (defvar debbugs-gnu-lisp-mode-map
1448 (let ((map (make-sparse-keymap)))
1449 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1450 map))
1451
1452 (define-minor-mode debbugs-gnu-lisp-mode
1453 "Minor mode for providing a debbugs interface in Lisp buffers.
1454 \\{debbugs-gnu-lisp-mode-map}"
1455 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1456
1457 (defvar debbugs-gnu-diff-mode-map
1458 (let ((map (make-sparse-keymap)))
1459 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1460 map))
1461
1462 (define-minor-mode debbugs-gnu-diff-mode
1463 "Minor mode for providing a debbugs interface in diff buffers.
1464 \\{debbugs-gnu-diff-mode-map}"
1465 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1466
1467 (defun debbugs-gnu-diff-select ()
1468 "Select the diff under point."
1469 (interactive)
1470 (delete-other-windows)
1471 (diff-goto-source))
1472
1473 (defvar debbugs-gnu-change-mode-map
1474 (let ((map (make-sparse-keymap)))
1475 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1476 map))
1477
1478 (define-minor-mode debbugs-gnu-change-mode
1479 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1480 \\{debbugs-gnu-change-mode-map}"
1481 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1482
1483 (defun debbugs-gnu-change-checkin ()
1484 "Prepare checking in the current changes."
1485 (interactive)
1486 (save-some-buffers t)
1487 (when (get-buffer "*vc-dir*")
1488 (kill-buffer (get-buffer "*vc-dir*")))
1489 (vc-dir debbugs-gnu-trunk-directory)
1490 (goto-char (point-min))
1491 (while (not (search-forward "edited" nil t))
1492 (sit-for 0.01))
1493 (beginning-of-line)
1494 (while (search-forward "edited" nil t)
1495 (vc-dir-mark)
1496 (beginning-of-line))
1497 (vc-diff nil)
1498 (vc-next-action nil)
1499 (log-edit-insert-changelog t)
1500 (delete-other-windows)
1501 (split-window)
1502 (other-window 1)
1503 (switch-to-buffer "*vc-diff*")
1504 (other-window 1))
1505
1506 (provide 'debbugs-gnu)
1507
1508 ;;; TODO:
1509
1510 ;; * Reorganize pages after client-side filtering.
1511
1512 ;;; debbugs-gnu.el ends here