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