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