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