1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
10 ;; This file is not part of GNU Emacs.
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This package provides an interface to bug reports which are located
28 ;; on the GNU bug tracker debbugs.gnu.org. Its main purpose is to
29 ;; show and manipulate bug reports from Emacs, but it could be used
30 ;; also for other GNU projects which use the same bug tracker.
32 ;; If you have `debbugs-gnu.el' in your load-path, you could enable
33 ;; the bug tracker commands by the following lines in your ~/.emacs
35 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
36 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
37 ;; (autoload 'debbugs-gnu-usertags "debbugs-gnu" "" 'interactive)
38 ;; (autoload 'debbugs-gnu-bugs "debbugs-gnu" "" 'interactive)
40 ;; The bug tracker is called interactively by
44 ;; It asks for the severities, for which bugs shall be shown. This can
45 ;; be either just one severity, or a list of severities, separated by
46 ;; comma. Valid severities are "serious", "important", "normal",
47 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
48 ;; used, although configured on the GNU bug tracker. If no severity
49 ;; is given, all bugs are selected.
51 ;; There is also the pseudo severity "tagged". When it is used, the
52 ;; function will ask for user tags (a comma separated list), and shows
53 ;; just the bugs which are tagged with them. In general, user tags
54 ;; shall be strings denoting to subprojects of the package, like
55 ;; "cedet" or "tramp" of the package "emacs". If no user tag is
56 ;; given, locally tagged bugs are shown.
58 ;; If a prefix is given to the command, more search parameters are
59 ;; asked for, like packages (also a comma separated list, "emacs" is
60 ;; the default), whether archived bugs shall be shown, and whether
61 ;; closed bugs shall be shown.
65 ;; M-x debbugs-gnu-search
67 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
68 ;; search phrase to be used for full text search. Additionally, it
69 ;; asks for key-value pairs to filter bugs. Keys are as described in
70 ;; `debbugs-get-status', the corresponding value must be a regular
71 ;; expression to match for. The other parameters are as described in
72 ;; `debbugs-gnu'. Usually, there is just one value except for the
73 ;; attribute "date", which needs two arguments specifying a period in
74 ;; which the bug has been submitted or modified.
76 ;; The bug reports are downloaded from the bug tracker. In order to
77 ;; not generate too much load of the server, up to 500 bugs will be
78 ;; downloaded at once. If there are more hits, you will be asked to
79 ;; change this limit, but please don't increase this number too much.
81 ;; These default values could be changed also by customer options
82 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages',
83 ;; `debbugs-gnu-default-hits-per-page' and `debbugs-gnu-default-suppress-bugs'.
85 ;; The commands create one or more pages of bug lists. Every bug is
86 ;; shown in one line, including the bug number, the status (combining
87 ;; merged bug numbers, keywords and severities), the name of the
88 ;; submitter, and the title of the bug. On every bug line you could
89 ;; apply the following actions by the following keystrokes:
91 ;; RET: Show corresponding messages in Gnus/Rmail
92 ;; "C": Send a control message
93 ;; "t": Mark the bug locally as tagged
94 ;; "b": Show bugs this bug is blocked by
95 ;; "B": Show bugs this bug is blocking
96 ;; "d": Show bug attributes
98 ;; Furthermore, you could apply the global actions
101 ;; "q": Quit the buffer
102 ;; "s": Toggle bug sorting for age or for state
103 ;; "x": Toggle suppressing of bugs
104 ;; "/": Display only bugs matching a string
105 ;; "R": Display only bugs blocking the current release
106 ;; "w": Display all the currently selected bug reports
108 ;; When you visit the related bug messages in Gnus, you could also
109 ;; send control messages by keystroke "C".
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.
116 ;; Another approach for listing bugs is calling the command
118 ;; M-x debbugs-gnu-usertags
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.
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>.
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
135 ;; M-x debbugs-gnu-bugs
137 ;; The bug numbers to be shown shall be entered as comma separated list.
142 (require 'tabulated-list)
145 (eval-when-compile (require 'cl))
147 (autoload 'article-decode-charset "gnus-art")
148 (autoload 'diff-goto-source "diff-mode")
149 (autoload 'diff-hunk-file-names "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-goto-body "message")
159 (autoload 'message-make-from "message")
160 (autoload 'rmail-get-new-mail "rmail")
161 (autoload 'rmail-show-message "rmail")
162 (autoload 'rmail-summary "rmailsum")
163 (autoload 'vc-dir-hide-up-to-date "vc-dir")
164 (autoload 'vc-dir-mark "vc-dir")
166 (defvar compilation-in-progress)
167 (defvar diff-file-header-re)
168 (defvar gnus-article-buffer)
169 (defvar gnus-posting-styles)
170 (defvar gnus-save-duplicate-list)
171 (defvar gnus-suppress-duplicates)
172 (defvar rmail-current-message)
173 (defvar rmail-mode-map)
174 (defvar rmail-summary-mode-map)
175 (defvar rmail-total-messages)
177 (defgroup debbugs-gnu ()
178 "UI for the debbugs.gnu.org bug tracker."
182 (defvar debbugs-gnu-blocking-report 19759
183 "The ID of the current release report used to track blocking bug reports.")
185 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
186 "*The list severities bugs are searched for.
187 \"tagged\" is not a severity but marks locally tagged bugs."
188 ;; <http://debbugs.gnu.org/Developer.html#severities>
189 ;; /ssh:debbugs:/etc/debbugs/config @gSeverityList
190 ;; We don't use "critical" and "grave".
192 :type '(set (const "serious")
200 (defconst debbugs-gnu-all-severities
201 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
202 "*List of all possible severities.")
204 (defcustom debbugs-gnu-default-packages '("emacs")
205 "*The list of packages to be searched for."
206 ;; <http://debbugs.gnu.org/Packages.html>
207 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
209 :type '(set (const "adns")
215 (const "debbugs.gnu.org")
218 (const "emacs-xwidgets")
235 (defconst debbugs-gnu-all-packages
236 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
237 "*List of all possible package names.")
239 (defcustom debbugs-gnu-default-suppress-bugs
240 '((pending . "done"))
241 "*A list of specs for bugs to be suppressed.
242 An element of this list is a cons cell \(KEY . REGEXP\), with key
243 being returned by `debbugs-get-status', and REGEXP a regular
244 expression matching the corresponding value, a string. Showing
245 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
247 :type '(alist :key-type symbol :value-type regexp)
250 (defcustom debbugs-gnu-mail-backend 'gnus
251 "*The email backend to use for reading bug report email exchange.
252 If this is 'gnus, the default, use Gnus.
253 If this is 'rmail, use Rmail instead."
255 :type '(choice (const :tag "Use Gnus" 'gnus)
256 (const :tag "Use Rmail" 'rmail))
259 (defface debbugs-gnu-archived '((t (:inverse-video t)))
260 "Face for archived bug reports.")
262 (defface debbugs-gnu-new '((t (:foreground "red")))
263 "Face for new reports that nobody has answered.")
265 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
266 "Face for reports that have been modified recently.")
268 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
269 "Face for reports that are pending.")
271 (defface debbugs-gnu-stale '((t (:foreground "orange")))
272 "Face for reports that have not been touched for a week.")
274 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
275 "Face for closed bug reports.")
277 (defface debbugs-gnu-tagged '((t (:foreground "red")))
278 "Face for reports that have been tagged locally.")
280 (defvar debbugs-gnu-local-tags nil
281 "List of bug numbers tagged locally, and kept persistent.")
283 (defvar debbugs-gnu-persistency-file
284 (expand-file-name (locate-user-emacs-file "debbugs"))
285 "File name of a persistency store for debbugs variables")
287 (defun debbugs-gnu-dump-persistency-file ()
288 "Function to store debbugs variables persistently."
289 (with-temp-file debbugs-gnu-persistency-file
291 ";; -*- emacs-lisp -*-\n"
292 ";; Debbugs tags connection history. Don't change this file.\n\n"
293 (format "(setq debbugs-gnu-local-tags '%S)"
294 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
296 (defvar debbugs-gnu-current-query nil
297 "The query object of the current search.
298 It will be applied server-side, when calling `debbugs-get-bugs'.
299 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
301 (defvar debbugs-gnu-current-filter nil
302 "The filter object for the current search.
303 It will be applied client-side, when parsing the results of
304 `debbugs-get-status'. It has a similar format as
305 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
306 a date, value is the cons cell \(BEFORE . AFTER\).")
308 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
309 "Return a string read from the minibuffer.
310 Derived from `calendar-read'."
311 (let ((value (read-string prompt initial-contents)))
312 (while (not (funcall acceptable value))
313 (setq value (read-string prompt initial-contents)))
316 (defconst debbugs-gnu-phrase-prompt
318 "Enter search phrase: "
320 The search phrase contains words to be searched for, combined by
321 operators like AND, ANDNOT and OR. If there is no operator
322 between the words, AND is used by default. The phrase can also
323 be empty, in this case only the following attributes are used for
327 (defun debbugs-gnu-search ()
328 "Search for Emacs bugs interactively.
329 Search arguments are requested interactively. The \"search
330 phrase\" is used for full text search in the bugs database.
331 Further key-value pairs are requested until an empty key is
332 returned. If a key cannot be queried by a SOAP request, it is
333 marked as \"client-side filter\"."
337 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
338 key val1 val2 phrase severities packages archivedp)
340 ;; Check for the phrase.
341 (setq phrase (read-string debbugs-gnu-phrase-prompt))
342 (if (zerop (length phrase))
344 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
345 ;; We suppress the bugs if there is no phrase.
346 (setq-default debbugs-gnu-current-suppress (null phrase))
348 ;; The other queries.
351 (setq key (completing-read
354 '("severity" "package" "tags" "submitter" "date"
356 '("severity" "package" "archive" "src" "tag"
357 "owner" "submitter" "maint" "correspondent"
358 "date" "log_modified" "last_modified"
359 "found_date" "fixed_date" "unarchived"
360 "subject" "done" "forwarded" "msgid" "summary"))
363 ;; Server-side queries.
364 ((equal key "severity")
367 (completing-read-multiple
368 "Enter severities: " debbugs-gnu-all-severities nil t
369 (mapconcat 'identity debbugs-gnu-default-severities ","))))
371 ((equal key "package")
374 (completing-read-multiple
375 "Enter packages: " debbugs-gnu-all-packages nil t
376 (mapconcat 'identity debbugs-gnu-default-packages ","))))
378 ((equal key "archive")
379 ;; We simplify, by assuming just archived bugs are requested.
382 ((member key '("src" "tag" "tags"))
383 (setq val1 (read-string (format "Enter %s: " key)))
384 (when (not (zerop (length val1)))
386 'debbugs-gnu-current-query (cons (intern key) val1))))
388 ((member key '("owner" "submitter" "maint" "correspondent"))
389 (setq val1 (read-string "Enter email address: "))
390 (when (not (zerop (length val1)))
392 'debbugs-gnu-current-query (cons (intern key) val1))))
394 ((equal key "status")
397 (completing-read "Enter status: " '("done" "forwarded" "open")))
398 (when (not (zerop (length val1)))
400 'debbugs-gnu-current-query (cons (intern key) val1))))
402 ;; Client-side filters.
403 ((member key '("date" "log_modified" "last_modified"
404 "found_date" "fixed_date" "unarchived"))
406 (debbugs-gnu-calendar-read
407 (format "Enter %s before YYYY-MM-DD%s: "
408 key (if phrase "" " (client-side filter)"))
410 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
411 (if (string-match date-format val1)
416 (string-to-number (match-string 3 val1))
417 (string-to-number (match-string 2 val1))
418 (string-to-number (match-string 1 val1))))))
421 (debbugs-gnu-calendar-read
422 (format "Enter %s after YYYY-MM-DD%s: "
423 key (if phrase "" " (client-side filter)"))
425 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
426 (if (string-match date-format val2)
431 (string-to-number (match-string 3 val2))
432 (string-to-number (match-string 2 val2))
433 (string-to-number (match-string 1 val2))))))
438 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
439 (cons (intern key) (cons val1 val2)))))
441 ((not (zerop (length key)))
444 (if phrase 'read-string 'read-regexp)
446 key (if phrase ": " " (client-side filter)"))))
447 (when (not (zerop (length val1)))
450 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
451 (cons (intern key) val1))))
454 (t (throw :finished nil)))))
457 (debbugs-gnu severities packages archivedp))
459 ;; Reset query and filter.
460 (setq debbugs-gnu-current-query nil
461 debbugs-gnu-current-filter nil)))
463 (defvar debbugs-gnu-current-limit nil
464 "List of bug ids to be shown, if non-nil")
466 (defvar debbugs-gnu-current-suppress nil
467 "Whether bugs shall be suppressed.
468 The specification which bugs shall be suppressed is taken from
469 `debbugs-gnu-default-suppress-bugs'.")
472 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
473 "List all outstanding bugs."
475 (let (severities archivedp)
478 (completing-read-multiple
479 "Severities: " debbugs-gnu-all-severities nil t
480 (mapconcat 'identity debbugs-gnu-default-severities ",")))
481 ;; The next parameters are asked only when there is a prefix.
482 (if current-prefix-arg
483 (completing-read-multiple
484 "Packages: " debbugs-gnu-all-packages nil t
485 (mapconcat 'identity debbugs-gnu-default-packages ","))
486 debbugs-gnu-default-packages)
487 (when current-prefix-arg
488 (setq archivedp (y-or-n-p "Show archived bugs?")))
489 (when (and current-prefix-arg (not archivedp))
490 (y-or-n-p "Suppress unwanted bugs?"))
491 ;; This one must be asked for severity "tagged".
492 (when (member "tagged" severities)
493 (split-string (read-string "User tag(s): ") "," t)))))
495 ;; Initialize variables.
496 (when (and (file-exists-p debbugs-gnu-persistency-file)
497 (not debbugs-gnu-local-tags))
499 (insert-file-contents debbugs-gnu-persistency-file)
500 (eval (read (current-buffer)))))
501 ;; Per default, we suppress retrieved unwanted bugs.
502 (when (called-interactively-p 'any)
503 (setq-default debbugs-gnu-current-suppress t))
506 (dolist (severity (if (consp severities) severities (list severities)))
507 (when (not (zerop (length severity)))
508 (when (string-equal severity "tagged")
509 (setq-default debbugs-gnu-current-suppress nil))
510 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
511 (dolist (package (if (consp packages) packages (list packages)))
512 (when (not (zerop (length package)))
513 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
515 (setq-default debbugs-gnu-current-suppress nil)
516 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
518 (setq-default debbugs-gnu-current-suppress t)
519 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
520 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
521 (dolist (tag (if (consp tags) tags (list tags)))
522 (when (not (zerop (length tag)))
523 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
526 (debbugs-gnu-show-reports)
528 ;; Reset query and filter.
529 (setq debbugs-gnu-current-query nil
530 debbugs-gnu-current-filter nil))
532 (defun debbugs-gnu-get-bugs (query)
533 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
534 (let* ((debbugs-port "gnu.org")
535 (bugs (assoc 'bugs query))
536 (tags (assoc 'tag query))
537 (local-tags (and (member '(severity . "tagged") query) (not tags)))
538 (phrase (assoc 'phrase query))
540 ;; Compile query arguments.
541 (unless (or query tags)
542 (dolist (elt debbugs-gnu-default-packages)
543 (setq args (append args (list :package elt)))))
545 (unless (equal elt '(severity . "tagged"))
551 ((eq (car elt) 'phrase)
552 (list (list :phrase (cdr elt) :max 500)))
553 ((eq (car elt) 'date)
554 (list (list :date (cddr elt) (cadr elt)
557 (list (list (intern (concat ":" (symbol-name (car elt))))
558 (cdr elt) :operator "ISTRINC"))))
559 (list (intern (concat ":" (symbol-name (car elt))))
563 ;; If the query is just a list of bug numbers, we return them.
565 ;; If the query contains the pseudo-severity "tagged", we return
566 ;; just the local tagged bugs.
567 (local-tags (copy-sequence debbugs-gnu-local-tags))
568 ;; A full text query.
571 (lambda (x) (cdr (assoc "id" x)))
572 (apply 'debbugs-search-est args)))
575 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
576 (apply 'debbugs-get-usertag args))
577 ;; Otherwise, we retrieve the bugs from the server.
578 (t (apply 'debbugs-get-bugs args)))))
580 (defun debbugs-gnu-show-reports ()
582 (let ((inhibit-read-only t)
583 (debbugs-port "gnu.org")
584 (buffer-name "*Emacs Bugs*"))
585 ;; The tabulated mode sets several local variables. We must get
587 (when (get-buffer buffer-name)
588 (kill-buffer buffer-name))
589 (switch-to-buffer (get-buffer-create buffer-name))
592 ;; Print bug reports.
594 (apply 'debbugs-get-status
595 (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
596 (let* ((id (cdr (assq 'id status)))
600 (cons (cdr (assq 'severity status))
601 (cdr (assq 'keywords status)))
603 (address (mail-header-parse-address
604 (decode-coding-string (cdr (assq 'originator status))
606 (owner (if (cdr (assq 'owner status))
607 (car (mail-header-parse-address
608 (decode-coding-string (cdr (assq 'owner status))
610 (subject (decode-coding-string (cdr (assq 'subject status))
613 (unless (equal (cdr (assq 'pending status)) "pending")
614 (setq words (concat words "," (cdr (assq 'pending status)))))
615 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
617 (setq words (concat words "," (mapconcat 'identity packages ",")))))
618 (when (setq merged (cdr (assq 'mergedwith status)))
619 (setq words (format "%s,%s"
622 (mapconcat 'number-to-string merged ","))
624 (when (or (not merged)
625 (not (let ((found nil))
626 (dolist (id (if (listp merged)
629 (dolist (entry tabulated-list-entries)
630 (when (equal id (cdr (assq 'id (car entry))))
634 'tabulated-list-entries
642 (if (memq id debbugs-gnu-local-tags)
646 ;; Mark status and age.
650 ((cdr (assq 'archived status))
651 'debbugs-gnu-archived)
652 ((equal (cdr (assq 'pending status)) "done")
654 ((member "pending" (cdr (assq 'keywords status)))
655 'debbugs-gnu-pending)
656 ((= (cdr (assq 'date status))
657 (cdr (assq 'log_modified status)))
660 (cdr (assq 'log_modified status)))
662 'debbugs-gnu-handled)
664 'debbugs-gnu-stale)))
666 ;; Prefer the name over the address.
670 ;; Mark own submitted bugs.
671 (if (and (stringp (car address))
672 (string-equal (car address) user-mail-address))
679 (if (and (stringp owner)
680 (string-equal owner user-mail-address))
685 (tabulated-list-init-header)
686 (tabulated-list-print)
688 (set-buffer-modified-p nil)
689 (goto-char (point-min))))
691 (defun debbugs-gnu-print-entry (list-id cols)
692 "Insert a debbugs entry at point.
693 Used instead of `tabulated-list-print-entry'."
698 (id-length (nth 1 (aref tabulated-list-format 0)))
699 (state (aref cols 1))
700 (state-length (nth 1 (aref tabulated-list-format 1)))
701 (submitter (aref cols 2))
702 (submitter-length (nth 1 (aref tabulated-list-format 2)))
703 (title (aref cols 3))
704 (title-length (nth 1 (aref tabulated-list-format 3))))
706 ;; We may have a narrowing in effect.
707 (or (not debbugs-gnu-current-limit)
708 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
709 ;; Filter suppressed bugs.
710 (or (not debbugs-gnu-current-suppress)
711 (not (catch :suppress
712 (dolist (check debbugs-gnu-default-suppress-bugs)
716 (or (cdr (assq (car check) list-id)) ""))
717 (throw :suppress t))))))
718 ;; Filter search list.
719 (not (catch :suppress
720 (dolist (check debbugs-gnu-current-filter)
721 (let ((val (cdr (assq (car check) list-id))))
722 (if (stringp (cdr check))
723 ;; Regular expression.
724 (when (not (string-match (cdr check) (or val "")))
727 (when (or (and (numberp (cadr check))
728 (< (cadr check) val))
729 (and (numberp (cddr check))
730 (> (cddr check) val)))
731 (throw :suppress t))))))))
734 (indent-to (- id-length (length id)))
737 (indent-to (setq pos (+ pos id-length 1)) 1)
738 (insert (if (> (length state) state-length)
739 (propertize (substring state 0 state-length)
743 (indent-to (setq pos (+ pos state-length 1)) 1)
744 (insert "[" (if (> (length submitter) (- submitter-length 2))
745 (propertize (substring submitter 0 (- submitter-length 2))
746 'help-echo submitter)
748 (indent-to (+ pos (1- submitter-length)))
751 (indent-to (setq pos (+ pos submitter-length 1)) 1)
752 (insert (propertize title 'help-echo title))
756 `(tabulated-list-id ,list-id mouse-face highlight))
759 (defvar debbugs-gnu-mode-map
760 (let ((map (make-sparse-keymap))
761 (menu-map (make-sparse-keymap)))
762 (set-keymap-parent map tabulated-list-mode-map)
763 (define-key map "\r" 'debbugs-gnu-select-report)
764 (define-key map [mouse-1] 'debbugs-gnu-select-report)
765 (define-key map [mouse-2] 'debbugs-gnu-select-report)
766 (define-key map "s" 'debbugs-gnu-toggle-sort)
767 (define-key map "t" 'debbugs-gnu-toggle-tag)
768 (define-key map "d" 'debbugs-gnu-display-status)
769 (define-key map "g" 'debbugs-gnu-rescan)
770 (define-key map "x" 'debbugs-gnu-toggle-suppress)
771 (define-key map "/" 'debbugs-gnu-narrow-to-status)
772 (define-key map "w" 'debbugs-gnu-widen)
773 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
774 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
775 (define-key map "C" 'debbugs-gnu-send-control-message)
776 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
778 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
779 (define-key menu-map [debbugs-gnu-select-report]
780 '(menu-item "Show Reports" debbugs-gnu-select-report
781 :help "Show all reports belonging to this bug"))
782 (define-key-after menu-map [debbugs-gnu-rescan]
783 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
784 :help "Refresh bug list")
785 'debbugs-gnu-select-report)
786 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
787 '(menu-item "Show Release Blocking Bugs"
788 debbugs-gnu-show-all-blocking-reports
789 :help "Show all bugs blocking next Emacs release")
790 ;:enable '(assq 'phrase debbugs-gnu-current-query))
792 (define-key-after menu-map [debbugs-gnu-separator]
793 '(menu-item "--") 'debbugs-gnu-show-all-blocking-reports)
794 (define-key-after menu-map [debbugs-gnu-search]
795 '(menu-item "Search Bugs" debbugs-gnu-search
796 :help "Search bugs on debbugs.gnu.org")
797 'debbugs-gnu-separator)
798 (define-key-after menu-map [debbugs-gnu]
799 '(menu-item "Retrieve Bugs" debbugs-gnu
800 :help "Retrieve bugs from debbugs.gnu.org")
802 (define-key-after menu-map [debbugs-gnu-bugs]
803 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
804 :help "Retrieve selected bugs from debbugs.gnu.org")
808 (defun debbugs-gnu-rescan ()
809 "Rescan the current set of bug reports."
811 ;; Refresh the buffer. `save-excursion' does not work, so we
812 ;; remember the position.
813 (setq-default debbugs-gnu-current-suppress debbugs-gnu-current-suppress)
815 (debbugs-gnu-show-reports)
818 (defvar debbugs-gnu-sort-state 'number)
820 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
821 "Major mode for listing bug reports.
823 All normal editing commands are switched off.
824 \\<debbugs-gnu-mode-map>
826 The following commands are available:
828 \\{debbugs-gnu-mode-map}"
829 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
830 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
831 (set (make-local-variable 'debbugs-gnu-current-suppress)
832 debbugs-gnu-current-suppress)
833 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
834 ("State" 20 debbugs-gnu-sort-state)
836 ("Title" 10 debbugs-gnu-sort-title)])
837 (setq tabulated-list-sort-key (cons "Id" nil))
838 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
839 (buffer-disable-undo)
840 (setq truncate-lines t)
841 (setq buffer-read-only t))
843 (defun debbugs-gnu-sort-id (s1 s2)
844 (> (cdr (assq 'id (car s1)))
845 (cdr (assq 'id (car s2)))))
847 (defconst debbugs-gnu-state-preference
848 '((debbugs-gnu-new . 1)
849 (debbugs-gnu-stale . 2)
850 (debbugs-gnu-handled . 3)
851 (debbugs-gnu-done . 4)
852 (debbugs-gnu-pending . 5)))
854 (defun debbugs-gnu-get-state-preference (face-string)
855 (or (cdr (assq (get-text-property 0 'face face-string)
856 debbugs-gnu-state-preference))
859 (defconst debbugs-gnu-severity-preference
866 (defun debbugs-gnu-get-severity-preference (state)
867 (or (cdr (assoc (cdr (assq 'severity state))
868 debbugs-gnu-severity-preference))
871 (defun debbugs-gnu-sort-state (s1 s2)
872 (let ((id1 (cdr (assq 'id (car s1))))
873 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
874 (id2 (cdr (assq 'id (car s2))))
875 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
877 ;; Tagged bugs go to the end.
878 ((and (not (memq id1 debbugs-gnu-local-tags))
879 (memq id2 debbugs-gnu-local-tags))
881 ((and (memq id1 debbugs-gnu-local-tags)
882 (not (memq id2 debbugs-gnu-local-tags)))
884 ;; Then, we check the age of the bugs.
889 ;; If they have the same age, we check for severity.
890 ((< (debbugs-gnu-get-severity-preference (car s1))
891 (debbugs-gnu-get-severity-preference (car s2)))
895 (defun debbugs-gnu-sort-title (s1 s2)
896 (let ((owner (if (cdr (assq 'owner (car s1)))
897 (car (mail-header-parse-address
898 (decode-coding-string (cdr (assq 'owner (car s1)))
901 (string-equal owner user-mail-address))))
903 (defun debbugs-gnu-toggle-sort ()
904 "Toggle sorting by age and by state."
906 (if (eq debbugs-gnu-sort-state 'number)
908 (setq debbugs-gnu-sort-state 'state)
909 (setq tabulated-list-sort-key (cons "Id" nil)))
910 (setq debbugs-gnu-sort-state 'number)
911 (setq tabulated-list-sort-key (cons "State" nil)))
912 (tabulated-list-init-header)
913 (tabulated-list-print))
915 (defun debbugs-gnu-widen ()
916 "Display all the currently selected bug reports."
918 (let ((id (debbugs-gnu-current-id t))
919 (inhibit-read-only t))
920 (setq debbugs-gnu-current-limit nil)
921 (tabulated-list-init-header)
922 (tabulated-list-print)
924 (debbugs-gnu-goto id))))
926 (defun debbugs-gnu-show-blocked-by-reports ()
927 "Display all bug reports this report is blocked by."
929 (let ((id (debbugs-gnu-current-id))
930 (status (debbugs-gnu-current-status)))
931 (if (null (cdr (assq 'blockedby status)))
932 (message "Bug %d is not blocked by any other bug" id)
933 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
935 (defun debbugs-gnu-show-blocking-reports ()
936 "Display all bug reports this report is blocking."
938 (let ((id (debbugs-gnu-current-id))
939 (status (debbugs-gnu-current-status)))
940 (if (null (cdr (assq 'blocks status)))
941 (message "Bug %d is not blocking any other bug" id)
942 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
944 (defun debbugs-gnu-show-all-blocking-reports ()
945 "Narrow the display to just the reports that are blocking a release."
947 (let ((blockers (cdr (assq 'blockedby
948 (car (debbugs-get-status
949 debbugs-gnu-blocking-report)))))
950 (id (debbugs-gnu-current-id t))
951 (inhibit-read-only t)
953 (setq debbugs-gnu-current-limit nil)
954 (goto-char (point-min))
956 (setq status (debbugs-gnu-current-status))
957 (if (not (memq (cdr (assq 'id status)) blockers))
958 (delete-region (point) (progn (forward-line 1) (point)))
959 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
962 (debbugs-gnu-goto id))))
964 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
965 "Only display the bugs matching STRING.
966 If STATUS-ONLY (the prefix), ignore matches in the From and
968 (interactive "sNarrow to: \nP")
969 (let ((id (debbugs-gnu-current-id t))
970 (inhibit-read-only t)
972 (setq debbugs-gnu-current-limit nil)
973 (if (equal string "")
974 (debbugs-gnu-toggle-suppress)
975 (goto-char (point-min))
977 (setq status (debbugs-gnu-current-status))
978 (if (and (not (member string (assq 'keywords status)))
979 (not (equal string (cdr (assq 'severity status))))
982 string (cdr (assq 'originator status)))))
984 (not (string-match string (cdr (assq 'subject status))))))
985 (delete-region (point) (progn (forward-line 1) (point)))
986 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
989 (debbugs-gnu-goto id)))))
991 (defun debbugs-gnu-goto (id)
992 "Go to the line displaying bug ID."
993 (goto-char (point-min))
994 (while (and (not (eobp))
995 (not (equal (debbugs-gnu-current-id t) id)))
998 (defun debbugs-gnu-toggle-tag ()
999 "Toggle the local tag of the report in the current line.
1000 If a report is tagged locally, it is presumed to be of little
1005 (let ((inhibit-read-only t)
1006 (id (debbugs-gnu-current-id)))
1007 (if (memq id debbugs-gnu-local-tags)
1009 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1010 (put-text-property (point) (+ (point) 5) 'face 'default))
1011 (add-to-list 'debbugs-gnu-local-tags id)
1013 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1014 'face 'debbugs-gnu-tagged))
1015 (debbugs-gnu--update-tag-face id)))
1016 (debbugs-gnu-dump-persistency-file))
1018 (defun debbugs-gnu--update-tag-face (id)
1019 (dolist (entry tabulated-list-entries)
1020 (when (equal (cdr (assq 'id (car entry))) id)
1021 (aset (cadr entry) 0
1025 ;; Mark tagged bugs.
1026 (if (memq id debbugs-gnu-local-tags)
1030 (defun debbugs-gnu-toggle-suppress ()
1031 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1033 (setq debbugs-gnu-current-suppress (not debbugs-gnu-current-suppress))
1034 (tabulated-list-init-header)
1035 (tabulated-list-print))
1037 (defvar debbugs-gnu-bug-number nil)
1038 (defvar debbugs-gnu-subject nil)
1040 (defun debbugs-gnu-current-id (&optional noerror)
1041 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1043 (error "No bug on the current line"))))
1045 (defun debbugs-gnu-current-status ()
1046 (get-text-property (line-beginning-position) 'tabulated-list-id))
1048 (defun debbugs-gnu-current-query ()
1049 debbugs-gnu-current-query)
1051 (defun debbugs-gnu-display-status (query status)
1052 "Display the query and status of the report on the current line."
1053 (interactive (list (debbugs-gnu-current-query)
1054 (debbugs-gnu-current-status)))
1055 (switch-to-buffer "*Bug Status*")
1056 (let ((inhibit-read-only t))
1058 (when query (pp query (current-buffer)))
1059 (when status (pp status (current-buffer)))
1060 (goto-char (point-min)))
1061 (set-buffer-modified-p nil)
1064 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1065 "Read email exchange for debbugs bug ID.
1066 STATUS is the bug's status list.
1067 MERGED is the list of bugs merged with this one."
1068 (let* ((mbox-dir (make-temp-file "debbugs" t))
1069 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1070 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1072 ;; Download messages of all the merged bug reports and append them
1073 ;; to the mailbox of the requested bug.
1075 (dolist (bugno merged)
1076 (let ((fn (make-temp-file "url")))
1077 (debbugs-get-mbox bugno 'mboxmaint fn)
1078 (rmail-get-new-mail fn)
1080 ;; Remove the 'unseen' attribute from all the messages we've
1081 ;; just read, so that all of them appear in the summary with
1083 (while (< rmail-current-message rmail-total-messages)
1084 (rmail-show-message (1+ rmail-current-message))))))
1085 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1086 (set (make-local-variable 'debbugs-gnu-subject)
1087 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1089 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1090 (set-window-text-height nil 10)
1092 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1093 (rmail-show-message 1)))
1095 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1096 "Read email exchange for debbugs bug ID.
1097 STATUS is the bug's status list.
1098 MERGED is the list of bugs merged with this one."
1100 (setq gnus-suppress-duplicates t
1101 gnus-save-duplicate-list t)
1103 (gnus-read-ephemeral-emacs-bug-group
1104 (cons id (if (listp merged) merged (list merged)))
1105 (cons (current-buffer)
1106 (current-window-configuration)))
1107 (with-current-buffer (window-buffer (selected-window))
1108 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1109 (set (make-local-variable 'debbugs-gnu-subject)
1110 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1111 (debbugs-gnu-summary-mode 1)))
1113 (defun debbugs-gnu-select-report ()
1114 "Select the report on the current line."
1116 ;; We open the report messages.
1117 (let* ((status (debbugs-gnu-current-status))
1118 (id (cdr (assq 'id status)))
1119 (merged (cdr (assq 'mergedwith status))))
1120 (setq merged (if (listp merged) merged (list merged)))
1123 (message "No bug report on the current line"))
1124 ((eq debbugs-gnu-mail-backend 'rmail)
1125 (debbugs-read-emacs-bug-with-rmail id status merged))
1126 ((eq debbugs-gnu-mail-backend 'gnus)
1127 (debbugs-read-emacs-bug-with-gnus id status merged))
1128 (t (error "No valid mail backend specified")))))
1130 (defvar debbugs-gnu-summary-mode-map
1131 (let ((map (make-sparse-keymap)))
1132 (define-key map "C" 'debbugs-gnu-send-control-message)
1133 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1136 (define-minor-mode debbugs-gnu-summary-mode
1137 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1139 \\{debbugs-gnu-summary-mode-map}"
1140 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1141 (set (make-local-variable 'gnus-posting-styles)
1144 (when (buffer-live-p gnus-article-copy)
1145 (with-current-buffer gnus-article-copy
1146 (set (make-local-variable 'message-prune-recipient-rules)
1147 '((".*@debbugs.*" "emacs-pretest-bug")
1148 (".*@debbugs.*" "bug-gnu-emacs")
1149 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1150 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1151 (set (make-local-variable 'message-alter-recipients-function)
1153 (if (string-match "\\([0-9]+\\)@donarmstrong"
1155 (let ((new (format "%s@debbugs.gnu.org"
1156 (match-string 1 (car address)))))
1159 ;; `gnus-posting-styles' is eval'ed after
1160 ;; `message-simplify-subject'. So we cannot use m-s-s.
1161 (setq subject ,debbugs-gnu-subject))))))))
1163 (defun debbugs-gnu-guess-current-id ()
1164 "Guess the ID based on \"#23\"."
1168 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1170 (goto-char (point-min))
1171 (re-search-forward "#\\([0-9]+\\)" nil t)))
1172 (string-to-number (match-string 1)))))
1174 (defun debbugs-gnu-send-control-message (message &optional reverse)
1175 "Send a control message for the current bug report.
1176 You can set the severity or add a tag, or close the report. If
1177 you use the special \"done\" MESSAGE, the report will be marked as
1178 fixed, and then closed.
1180 If given a prefix, and given a tag to set, the tag will be
1183 (list (completing-read
1185 '("serious" "important" "normal" "minor" "wishlist"
1186 "done" "donenotabug" "donewontfix" "doneunreproducible"
1187 "unarchive" "unmerge" "reopen" "close"
1188 "merge" "forcemerge"
1193 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1194 "pending" "help" "security" "confirmed"
1197 current-prefix-arg))
1198 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1199 (debbugs-gnu-guess-current-id)
1200 (debbugs-gnu-current-id)))
1202 (when (member message '("close" "done"))
1206 ;; Emacs development versions.
1208 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1210 (match-string 1 emacs-version)
1211 (1+ (string-to-number (match-string 2 emacs-version)))))
1212 ;; Emacs release versions.
1214 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1216 (match-string 1 emacs-version)
1217 (match-string 2 emacs-version)))
1218 (t emacs-version)))))
1219 (status (debbugs-gnu-current-status)))
1221 (insert "To: control@debbugs.gnu.org\n"
1222 "From: " (message-make-from) "\n"
1223 (format "Subject: control message for bug #%d\n" id)
1226 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1227 (format "%s %d\n" message id))
1228 ((member message '("merge" "forcemerge"))
1229 (format "%s %d %s\n" message id
1230 (read-string "Merge with bug #: ")))
1231 ((member message '("block" "unblock"))
1233 "%s %d by %s\n" message id
1236 (completing-read-multiple
1237 (format "%s with bug(s) #: " (capitalize message))
1238 (if (equal message "unblock")
1239 (mapcar 'number-to-string
1240 (cdr (assq 'blockedby status))))
1241 nil (and (equal message "unblock") status))
1243 ((equal message "owner")
1244 (format "owner %d !\n" id))
1245 ((equal message "reassign")
1246 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1247 ((equal message "close")
1248 (format "close %d %s\n" id version))
1249 ((equal message "done")
1250 (format "tags %d fixed\nclose %d %s\n" id id version))
1251 ((member message '("donenotabug" "donewontfix"
1252 "doneunreproducible"))
1253 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1254 ((member message '("serious" "important" "normal"
1255 "minor" "wishlist"))
1256 (format "severity %d %s\n" id message))
1257 ((equal message "invalid")
1258 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1260 ((equal message "usertag")
1261 (format "user %s\nusertag %d %s\n"
1263 "Package name or email address: "
1265 debbugs-gnu-all-packages (list user-mail-address))
1266 nil nil (car debbugs-gnu-default-packages))
1267 id (read-string "User tag: ")))
1269 (format "tags %d%s %s\n"
1270 id (if reverse " -" "")
1272 (funcall send-mail-function)
1274 (message "Control message sent:\n%s"
1275 (buffer-substring-no-properties (point) (1- (point-max)))))))
1277 (defvar debbugs-gnu-usertags-mode-map
1278 (let ((map (make-sparse-keymap)))
1279 (set-keymap-parent map tabulated-list-mode-map)
1280 (define-key map "\r" 'debbugs-gnu-select-usertag)
1281 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1282 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1285 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1286 "Major mode for listing user tags.
1288 All normal editing commands are switched off.
1289 \\<debbugs-gnu-usertags-mode-map>
1291 The following commands are available:
1293 \\{debbugs-gnu-usertags-mode-map}"
1294 (buffer-disable-undo)
1295 (setq truncate-lines t)
1296 (setq buffer-read-only t))
1299 (defun debbugs-gnu-usertags (&rest users)
1300 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1302 (if current-prefix-arg
1303 (completing-read-multiple
1304 "Package name(s) or email address: "
1305 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1306 (mapconcat 'identity debbugs-gnu-default-packages ","))
1307 debbugs-gnu-default-packages))
1310 (let ((inhibit-read-only t)
1311 (debbugs-port "gnu.org")
1312 (buffer-name "*Emacs User Tags*")
1314 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1316 ;; Initialize variables.
1317 (when (and (file-exists-p debbugs-gnu-persistency-file)
1318 (not debbugs-gnu-local-tags))
1320 (insert-file-contents debbugs-gnu-persistency-file)
1321 (eval (read (current-buffer)))))
1324 (when (get-buffer buffer-name)
1325 (kill-buffer buffer-name))
1326 (switch-to-buffer (get-buffer-create buffer-name))
1327 (debbugs-gnu-usertags-mode)
1328 (setq tabulated-list-format `[("User" ,user-tab-length t)
1330 (setq tabulated-list-sort-key (cons "User" nil))
1331 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1333 ;; Retrieve user tags.
1334 (dolist (user users)
1335 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1337 'tabulated-list-entries
1338 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1339 `((("tagged") (,user) nil nil (,tag))
1340 ,(vector (propertize user 'mouse-face 'highlight)
1341 (propertize tag 'mouse-face 'highlight)))
1345 (when debbugs-gnu-local-tags
1347 'tabulated-list-entries
1350 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1353 (tabulated-list-init-header)
1354 (tabulated-list-print)
1356 (set-buffer-modified-p nil)
1357 (goto-char (point-min)))))
1359 (defun debbugs-gnu-select-usertag ()
1360 "Select the user tag on the current line."
1362 ;; We open the bug reports.
1363 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1364 (when args (apply 'debbugs-gnu args))))
1367 (defun debbugs-gnu-bugs (&rest bugs)
1368 "List all BUGS, a list of bug numbers."
1370 (mapcar 'string-to-number
1371 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1373 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1374 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1375 ;; We do not suppress bugs requested explicitely.
1376 (setq-default debbugs-gnu-current-suppress nil)
1379 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1380 "The directory where the main source tree lives.")
1382 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1383 "The directory where the previous source tree lives.")
1385 (defun debbugs-gnu-apply-patch (&optional branch)
1386 "Apply the patch from the current message.
1387 If given a prefix, patch in the branch directory instead."
1389 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1390 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1391 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1392 (let ((rej "/tmp/debbugs-gnu.rej")
1393 (output-buffer (get-buffer-create "*debbugs patch*"))
1395 debbugs-gnu-branch-directory
1396 debbugs-gnu-trunk-directory))
1397 (patch-buffers nil))
1398 (when (file-exists-p rej)
1400 (with-current-buffer output-buffer
1402 (gnus-summary-select-article nil t)
1403 ;; The patches are either in MIME attachements or the main article
1404 ;; buffer. Determine which.
1405 (gnus-with-article-buffer
1406 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1407 (when (string-match "diff\\|patch" (mm-handle-media-type handle))
1408 (push (cons (mm-handle-encoding handle)
1409 (mm-handle-buffer handle))
1411 (unless patch-buffers
1412 (gnus-summary-show-article 'raw)
1413 (article-decode-charset)
1414 (push (cons nil gnus-article-buffer) patch-buffers))
1415 (dolist (elem patch-buffers)
1417 (insert-buffer-substring (cdr elem))
1418 (cond ((eq (car elem) 'base64)
1419 (base64-decode-region (point-min) (point-max)))
1420 ((eq (car elem) 'qp)
1421 (quoted-printable-decode-region (point-min) (point-max))))
1422 (debbugs-gnu-fix-patch dir)
1423 (call-process-region (point-min) (point-max)
1424 "patch" nil output-buffer nil
1425 "-r" rej "--no-backup-if-mismatch"
1427 "-d" (expand-file-name dir)
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)
1436 (mapc 'kill-process compilation-in-progress)
1437 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1439 (vc-dir-hide-up-to-date)
1440 (goto-char (point-min))
1443 ;; All these commands are asynchronous, so just wait a bit. This
1444 ;; should be done properly a different way.
1446 ;; We've now done everything, so arrange the windows we need to see.
1447 (delete-other-windows)
1448 (switch-to-buffer output-buffer)
1452 (switch-to-buffer "*compilation*")
1453 (goto-char (point-max))
1455 (switch-to-buffer "*vc-diff*")
1456 (goto-char (point-min))))
1458 (defun debbugs-gnu-fix-patch (dir)
1459 (setq dir (directory-file-name (expand-file-name dir)))
1460 (goto-char (point-min))
1461 (while (re-search-forward diff-file-header-re nil t)
1462 (goto-char (match-beginning 0))
1463 (let ((target-name (car (diff-hunk-file-names))))
1464 (when (and target-name
1465 (or (not (string-match "/" target-name))
1466 (and (string-match "^[ab]/" target-name)
1468 (expand-file-name (substring target-name 2)
1470 (file-exists-p (expand-file-name target-name dir))))
1471 ;; We have a simple patch that refers to a file somewhere in the
1473 (when-let ((files (directory-files-recursively
1475 (concat "^" (regexp-quote
1476 (file-name-nondirectory target-name))
1478 (when (re-search-forward (concat "^[+]+ "
1479 (regexp-quote target-name)
1482 (replace-match (concat "+++ a"
1483 (substring (car files) (length dir))
1488 (defun debbugs-gnu-find-contributor (string)
1489 "Search through ChangeLogs to find contributors."
1490 (interactive "sContributor match: ")
1492 (match (concat "^[0-9].*" string)))
1493 (dolist (file (directory-files-recursively
1494 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1496 (when (file-exists-p file)
1497 (insert-file-contents file))
1498 (goto-char (point-min))
1499 (while (and (re-search-forward match nil t)
1500 (not (looking-at ".*tiny change")))
1502 (message "%s is a contributor %d times" string found)
1505 (defun debbugs-gnu-insert-changelog ()
1506 "Add a ChangeLog from a recently applied patch from a third party."
1509 (gnus-with-article-buffer
1511 (goto-char (point-min))
1512 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1513 subject (gnus-fetch-field "subject")))
1514 (let ((add-log-full-name (car from))
1515 (add-log-mailing-address (cadr from)))
1516 (add-change-log-entry-other-window)
1517 (let ((point (point)))
1518 (when (string-match "\\(bug#[0-9]+\\)" subject)
1519 (insert " (" (match-string 1 subject) ")."))
1520 (when (zerop (debbugs-gnu-find-contributor
1521 (let ((bits (split-string (car from))))
1523 ((>= (length bits) 2)
1524 (format "%s.*%s" (car bits) (car (last bits))))
1525 ((= (length bits) 1)
1527 ;; Fall back on the email address.
1530 (goto-char (point-max))
1532 (insert " (tiny change"))
1533 (goto-char point)))))
1535 (defvar debbugs-gnu-lisp-mode-map
1536 (let ((map (make-sparse-keymap)))
1537 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1540 (define-minor-mode debbugs-gnu-lisp-mode
1541 "Minor mode for providing a debbugs interface in Lisp buffers.
1542 \\{debbugs-gnu-lisp-mode-map}"
1543 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1545 (defvar debbugs-gnu-diff-mode-map
1546 (let ((map (make-sparse-keymap)))
1547 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1550 (define-minor-mode debbugs-gnu-diff-mode
1551 "Minor mode for providing a debbugs interface in diff buffers.
1552 \\{debbugs-gnu-diff-mode-map}"
1553 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1555 (defun debbugs-gnu-diff-select ()
1556 "Select the diff under point."
1558 (delete-other-windows)
1561 (defvar debbugs-gnu-change-mode-map
1562 (let ((map (make-sparse-keymap)))
1563 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1566 (define-minor-mode debbugs-gnu-change-mode
1567 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1568 \\{debbugs-gnu-change-mode-map}"
1569 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1571 (defun debbugs-gnu-change-checkin ()
1572 "Prepare checking in the current changes."
1574 (save-some-buffers t)
1575 (when (get-buffer "*vc-dir*")
1576 (kill-buffer (get-buffer "*vc-dir*")))
1577 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1578 (if (equal (cl-subseq default-directory 0 (length trunk))
1580 (vc-dir debbugs-gnu-trunk-directory)
1581 (vc-dir debbugs-gnu-branch-directory)))
1582 (goto-char (point-min))
1583 (while (not (search-forward "edited" nil t))
1586 (while (search-forward "edited" nil t)
1588 (beginning-of-line))
1590 (vc-next-action nil)
1591 (log-edit-insert-changelog t)
1592 (delete-other-windows)
1595 (switch-to-buffer "*vc-diff*")
1598 (provide 'debbugs-gnu)
1602 ;; * Another random thought - is it possible to implement some local
1603 ;; cache, so only changed bugs are fetched? Glenn Morris.
1605 ;;; debbugs-gnu.el ends here