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 suppressed from being retrieved.
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, several downloads will
79 ;; be performed, until all bugs are retrieved.
81 ;; These default values could be changed also by customer options
82 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages'
83 ;; and `debbugs-gnu-default-suppress-bugs'.
85 ;; The commands create a page of bug lists. Every bug is shown in one
86 ;; line, including the bug number, the status (combining merged bug
87 ;; numbers, keywords and severities), the name of the submitter, and
88 ;; the title of the bug. On every bug line you could apply the
89 ;; 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 or Rmail, you could
109 ;; also 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 package names, or an arbitrary
123 ;; string for a user who has tagged bugs. The command returns the
124 ;; list of existing user tags for the given user(s) or package
125 ;; name(s), respectively. Applying RET on a user tag, all bugs tagged
126 ;; with 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 ;; Buffer-local variables.
178 (defvar debbugs-gnu-local-query)
179 (defvar debbugs-gnu-local-filter)
180 (defvar debbugs-gnu-local-suppress)
181 (defvar debbugs-gnu-sort-state)
182 (defvar debbugs-gnu-limit)
184 (defgroup debbugs-gnu ()
185 "UI for the debbugs.gnu.org bug tracker."
189 (defvar debbugs-gnu-blocking-report 19759
190 "The ID of the current release report used to track blocking bug reports.")
192 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
193 "*The list severities bugs are searched for.
194 \"tagged\" is not a severity but marks locally tagged bugs."
195 ;; <http://debbugs.gnu.org/Developer.html#severities>
196 ;; /ssh:debbugs:/etc/debbugs/config @gSeverityList
197 ;; We don't use "critical" and "grave".
199 :type '(set (const "serious")
207 (defconst debbugs-gnu-all-severities
208 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
209 "*List of all possible severities.")
211 (defcustom debbugs-gnu-default-packages '("emacs")
212 "*The list of packages to be searched for."
213 ;; <http://debbugs.gnu.org/Packages.html>
214 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
216 :type '(set (const "adns")
222 (const "debbugs.gnu.org")
225 (const "emacs-xwidgets")
242 (defconst debbugs-gnu-all-packages
243 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
244 "*List of all possible package names.")
246 (defcustom debbugs-gnu-default-suppress-bugs
247 '((pending . "done"))
248 "*A list of specs for bugs to be suppressed.
249 An element of this list is a cons cell \(KEY . REGEXP\), with key
250 being returned by `debbugs-get-status', and REGEXP a regular
251 expression matching the corresponding value, a string. Showing
252 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
254 :type '(alist :key-type symbol :value-type regexp)
257 (defcustom debbugs-gnu-mail-backend 'gnus
258 "*The email backend to use for reading bug report email exchange.
259 If this is 'gnus, the default, use Gnus.
260 If this is 'rmail, use Rmail instead."
262 :type '(choice (const :tag "Use Gnus" 'gnus)
263 (const :tag "Use Rmail" 'rmail))
266 (defface debbugs-gnu-archived '((t (:inverse-video t)))
267 "Face for archived bug reports.")
269 (defface debbugs-gnu-new '((t (:foreground "red")))
270 "Face for new reports that nobody has answered.")
272 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
273 "Face for reports that have been modified recently.")
275 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
276 "Face for reports that are pending.")
278 (defface debbugs-gnu-stale '((t (:foreground "orange")))
279 "Face for reports that have not been touched for a week.")
281 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
282 "Face for closed bug reports.")
284 (defface debbugs-gnu-tagged '((t (:foreground "red")))
285 "Face for reports that have been tagged locally.")
287 (defvar debbugs-gnu-local-tags nil
288 "List of bug numbers tagged locally, and kept persistent.")
290 (defvar debbugs-gnu-persistency-file
291 (expand-file-name (locate-user-emacs-file "debbugs"))
292 "File name of a persistency store for debbugs variables")
294 (defun debbugs-gnu-dump-persistency-file ()
295 "Function to store debbugs variables persistently."
296 (with-temp-file debbugs-gnu-persistency-file
298 ";; -*- emacs-lisp -*-\n"
299 ";; Debbugs tags connection history. Don't change this file.\n\n"
300 (format "(setq debbugs-gnu-local-tags '%S)"
301 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
303 (defvar debbugs-gnu-current-query nil
304 "The query object of the current search.
305 It will be applied server-side, when calling `debbugs-get-bugs'.
306 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
308 (defvar debbugs-gnu-current-filter nil
309 "The filter object for the current search.
310 It will be applied client-side, when parsing the results of
311 `debbugs-get-status'. It has a similar format as
312 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
313 a date, value is the cons cell \(BEFORE . AFTER\).")
315 (defvar debbugs-gnu-current-suppress nil
316 "Whether bugs shall be suppressed.
317 The specification which bugs shall be suppressed is taken from
318 `debbugs-gnu-default-suppress-bugs'.")
320 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
321 "Return a string read from the minibuffer.
322 Derived from `calendar-read'."
323 (let ((value (read-string prompt initial-contents)))
324 (while (not (funcall acceptable value))
325 (setq value (read-string prompt initial-contents)))
328 (defconst debbugs-gnu-phrase-prompt
330 "Enter search phrase: "
332 The search phrase contains words to be searched for, combined by
333 operators like AND, ANDNOT and OR. If there is no operator
334 between the words, AND is used by default. The phrase can also
335 be empty, in this case only the following attributes are used for
339 (defun debbugs-gnu-search ()
340 "Search for Emacs bugs interactively.
341 Search arguments are requested interactively. The \"search
342 phrase\" is used for full text search in the bugs database.
343 Further key-value pairs are requested until an empty key is
344 returned. If a key cannot be queried by a SOAP request, it is
345 marked as \"client-side filter\"."
349 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
350 key val1 val2 phrase severities packages archivedp)
352 ;; Check for the phrase.
353 (setq phrase (read-string debbugs-gnu-phrase-prompt))
354 (if (zerop (length phrase))
356 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
357 ;; We suppress closed bugs if there is no phrase.
358 (setq debbugs-gnu-current-suppress (null phrase))
360 ;; The other queries.
363 (setq key (completing-read
366 '("severity" "package" "tags" "submitter" "date"
368 '("severity" "package" "archive" "src" "tag"
369 "owner" "submitter" "maint" "correspondent"
370 "date" "log_modified" "last_modified"
371 "found_date" "fixed_date" "unarchived"
372 "subject" "done" "forwarded" "msgid" "summary"))
375 ;; Server-side queries.
376 ((equal key "severity")
379 (completing-read-multiple
380 "Enter severities: " debbugs-gnu-all-severities nil t
381 (mapconcat 'identity debbugs-gnu-default-severities ","))))
383 ((equal key "package")
386 (completing-read-multiple
387 "Enter packages: " debbugs-gnu-all-packages nil t
388 (mapconcat 'identity debbugs-gnu-default-packages ","))))
390 ((equal key "archive")
391 ;; We simplify, by assuming just archived bugs are requested.
394 ((member key '("src" "tag" "tags"))
395 (setq val1 (read-string (format "Enter %s: " key)))
396 (when (not (zerop (length val1)))
398 'debbugs-gnu-current-query (cons (intern key) val1))))
400 ((member key '("owner" "submitter" "maint" "correspondent"))
401 (setq val1 (read-string "Enter email address: "))
402 (when (not (zerop (length val1)))
404 'debbugs-gnu-current-query (cons (intern key) val1))))
406 ((equal key "status")
409 (completing-read "Enter status: " '("done" "forwarded" "open")))
410 (when (not (zerop (length val1)))
412 'debbugs-gnu-current-query (cons (intern key) val1))))
414 ;; Client-side filters.
415 ((member key '("date" "log_modified" "last_modified"
416 "found_date" "fixed_date" "unarchived"))
418 (debbugs-gnu-calendar-read
419 (format "Enter %s before YYYY-MM-DD%s: "
420 key (if phrase "" " (client-side filter)"))
422 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
423 (if (string-match date-format val1)
428 (string-to-number (match-string 3 val1))
429 (string-to-number (match-string 2 val1))
430 (string-to-number (match-string 1 val1))))))
433 (debbugs-gnu-calendar-read
434 (format "Enter %s after YYYY-MM-DD%s: "
435 key (if phrase "" " (client-side filter)"))
437 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
438 (if (string-match date-format val2)
443 (string-to-number (match-string 3 val2))
444 (string-to-number (match-string 2 val2))
445 (string-to-number (match-string 1 val2))))))
450 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
451 (cons (intern key) (cons val1 val2)))))
453 ((not (zerop (length key)))
456 (if phrase 'read-string 'read-regexp)
458 key (if phrase ": " " (client-side filter)"))))
459 (when (not (zerop (length val1)))
462 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
463 (cons (intern key) val1))))
466 (t (throw :finished nil)))))
469 (debbugs-gnu severities packages archivedp))))
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 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 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 debbugs-gnu-current-suppress nil)
516 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
518 (setq 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, filter and suppress.
529 (setq debbugs-gnu-current-query nil
530 debbugs-gnu-current-filter nil
531 debbugs-gnu-current-suppress nil))
533 (defun debbugs-gnu-get-bugs (query)
534 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
535 (let* ((debbugs-port "gnu.org")
536 (bugs (assoc 'bugs query))
537 (tags (assoc 'tag query))
538 (local-tags (and (member '(severity . "tagged") query) (not tags)))
539 (phrase (assoc 'phrase query))
541 ;; Compile query arguments.
542 (unless (or query tags)
543 (dolist (elt debbugs-gnu-default-packages)
544 (setq args (append args (list :package elt)))))
546 (unless (equal elt '(severity . "tagged"))
552 ((eq (car elt) 'phrase)
553 (list (list :phrase (cdr elt))))
554 ((eq (car elt) 'date)
555 (list (list :date (cddr elt) (cadr elt)
558 (list (list (intern (concat ":" (symbol-name (car elt))))
559 (cdr elt) :operator "ISTRINC"))))
560 (list (intern (concat ":" (symbol-name (car elt))))
564 ;; If the query is just a list of bug numbers, we return them.
566 ;; If the query contains the pseudo-severity "tagged", we return
567 ;; just the local tagged bugs.
568 (local-tags (copy-sequence debbugs-gnu-local-tags))
569 ;; A full text query.
572 (lambda (x) (cdr (assoc "id" x)))
573 (apply 'debbugs-search-est args)))
576 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
577 (apply 'debbugs-get-usertag args))
578 ;; Otherwise, we retrieve the bugs from the server.
579 (t (apply 'debbugs-get-bugs args)))))
581 (defun debbugs-gnu-show-reports ()
583 (let ((inhibit-read-only t)
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-local-query)))
596 (let* ((id (cdr (assq 'id status)))
600 (cons (cdr (assq 'severity status))
601 (cdr (assq 'keywords status)))
603 (address (if (cdr (assq 'originator status))
604 (mail-header-parse-address
605 (decode-coding-string (cdr (assq 'originator status))
607 (owner (if (cdr (assq 'owner status))
608 (car (mail-header-parse-address
609 (decode-coding-string (cdr (assq 'owner status))
611 (subject (if (cdr (assq 'subject status))
612 (decode-coding-string (cdr (assq 'subject status))
615 (unless (equal (cdr (assq 'pending status)) "pending")
616 (setq words (concat words "," (cdr (assq 'pending status)))))
617 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
619 (setq words (concat words "," (mapconcat 'identity packages ",")))))
620 (when (setq merged (cdr (assq 'mergedwith status)))
621 (setq words (format "%s,%s"
624 (mapconcat 'number-to-string merged ","))
626 (when (or (not merged)
627 (not (let ((found nil))
628 (dolist (id (if (listp merged)
631 (dolist (entry tabulated-list-entries)
632 (when (equal id (cdr (assq 'id (car entry))))
636 'tabulated-list-entries
644 (if (memq id debbugs-gnu-local-tags)
648 ;; Mark status and age.
652 ((cdr (assq 'archived status))
653 'debbugs-gnu-archived)
654 ((equal (cdr (assq 'pending status)) "done")
656 ((member "pending" (cdr (assq 'keywords status)))
657 'debbugs-gnu-pending)
658 ((= (cdr (assq 'date status))
659 (cdr (assq 'log_modified status)))
662 (cdr (assq 'log_modified status)))
664 'debbugs-gnu-handled)
666 'debbugs-gnu-stale)))
668 ;; Prefer the name over the address.
673 ;; Mark own submitted bugs.
674 (if (and (stringp (car address))
675 (string-equal (car address) user-mail-address))
682 (if (and (stringp owner)
683 (string-equal owner user-mail-address))
688 (tabulated-list-init-header)
689 (tabulated-list-print)
691 (set-buffer-modified-p nil)
692 (goto-char (point-min))))
694 (defun debbugs-gnu-print-entry (list-id cols)
695 "Insert a debbugs entry at point.
696 Used instead of `tabulated-list-print-entry'."
701 (id-length (nth 1 (aref tabulated-list-format 0)))
702 (state (aref cols 1))
703 (state-length (nth 1 (aref tabulated-list-format 1)))
704 (submitter (aref cols 2))
705 (submitter-length (nth 1 (aref tabulated-list-format 2)))
706 (title (aref cols 3))
707 (title-length (nth 1 (aref tabulated-list-format 3))))
709 ;; We may have a narrowing in effect.
710 (or (not debbugs-gnu-limit)
711 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
712 ;; Filter suppressed bugs.
713 (or (not debbugs-gnu-local-suppress)
714 (not (catch :suppress
715 (dolist (check debbugs-gnu-default-suppress-bugs)
719 (or (cdr (assq (car check) list-id)) ""))
720 (throw :suppress t))))))
721 ;; Filter search list.
722 (not (catch :suppress
723 (dolist (check debbugs-gnu-local-filter)
724 (let ((val (cdr (assq (car check) list-id))))
725 (if (stringp (cdr check))
726 ;; Regular expression.
727 (when (not (string-match (cdr check) (or val "")))
730 (when (or (and (numberp (cadr check))
731 (< (cadr check) val))
732 (and (numberp (cddr check))
733 (> (cddr check) val)))
734 (throw :suppress t))))))))
737 (indent-to (- id-length (length id)))
740 (indent-to (setq pos (+ pos id-length 1)) 1)
741 (insert (if (> (length state) state-length)
742 (propertize (substring state 0 state-length)
746 (indent-to (setq pos (+ pos state-length 1)) 1)
747 (insert "[" (if (> (length submitter) (- submitter-length 2))
748 (propertize (substring submitter 0 (- submitter-length 2))
749 'help-echo submitter)
751 (indent-to (+ pos (1- submitter-length)))
754 (indent-to (setq pos (+ pos submitter-length 1)) 1)
755 (insert (propertize title 'help-echo title))
759 `(tabulated-list-id ,list-id mouse-face highlight))
762 (defun debbugs-gnu-menu-map-emacs-enabled ()
763 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
764 (or ;; No package discriminator has been used.
765 (not (assq 'package debbugs-gnu-local-query))
766 ;; Package "emacs" has been selected.
767 (member '(package . "emacs") debbugs-gnu-local-query)))
769 (defconst debbugs-gnu-bug-triage-file
770 (expand-file-name "../admin/notes/bug-triage" data-directory)
771 "The \"bug-triage\" file.")
773 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
774 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
775 (and (debbugs-gnu-menu-map-emacs-enabled)
776 (stringp debbugs-gnu-bug-triage-file)
777 (file-readable-p debbugs-gnu-bug-triage-file)))
779 (defun debbugs-gnu-view-bug-triage ()
780 "Show \"bug-triage\" file."
782 (view-file debbugs-gnu-bug-triage-file))
784 (defvar debbugs-gnu-mode-map
785 (let ((map (make-sparse-keymap))
786 (menu-map (make-sparse-keymap)))
787 (set-keymap-parent map tabulated-list-mode-map)
788 (define-key map "\r" 'debbugs-gnu-select-report)
789 (define-key map [mouse-1] 'debbugs-gnu-select-report)
790 (define-key map [mouse-2] 'debbugs-gnu-select-report)
791 (define-key map "g" 'debbugs-gnu-rescan)
792 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
793 (define-key map "C" 'debbugs-gnu-send-control-message)
795 (define-key map "s" 'debbugs-gnu-toggle-sort)
796 (define-key map "t" 'debbugs-gnu-toggle-tag)
797 (define-key map "x" 'debbugs-gnu-toggle-suppress)
798 (define-key map "/" 'debbugs-gnu-narrow-to-status)
799 (define-key map "w" 'debbugs-gnu-widen)
801 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
802 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
803 (define-key map "d" 'debbugs-gnu-display-status)
805 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
806 (define-key menu-map [debbugs-gnu-select-report]
807 '(menu-item "Show Reports" debbugs-gnu-select-report
808 :help "Show all reports belonging to this bug"))
809 (define-key-after menu-map [debbugs-gnu-rescan]
810 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
811 :help "Refresh bug list")
812 'debbugs-gnu-select-report)
813 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
814 '(menu-item "Show Release Blocking Bugs"
815 debbugs-gnu-show-all-blocking-reports
816 :enable (debbugs-gnu-menu-map-emacs-enabled)
817 :help "Show all bugs blocking next Emacs release")
819 (define-key-after menu-map [debbugs-gnu-send-control-message]
820 '(menu-item "Send Control Message"
821 debbugs-gnu-send-control-message
822 :help "Send control message to debbugs.gnu.org")
823 'debbugs-gnu-show-all-blocking-reports)
825 (define-key-after menu-map [debbugs-gnu-separator1]
826 '(menu-item "--") 'debbugs-gnu-send-control-message)
827 (define-key-after menu-map [debbugs-gnu-search]
828 '(menu-item "Search Bugs" debbugs-gnu-search
829 :help "Search bugs on debbugs.gnu.org")
830 'debbugs-gnu-separator1)
831 (define-key-after menu-map [debbugs-gnu]
832 '(menu-item "Retrieve Bugs" debbugs-gnu
833 :help "Retrieve bugs from debbugs.gnu.org")
835 (define-key-after menu-map [debbugs-gnu-bugs]
836 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
837 :help "Retrieve selected bugs from debbugs.gnu.org")
840 (define-key-after menu-map [debbugs-gnu-separator2]
841 '(menu-item "--") 'debbugs-gnu-bugs)
842 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
843 '(menu-item "Describe Bug Triage Procedure"
844 debbugs-gnu-view-bug-triage
845 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
846 :help "Show procedure of triaging bugs")
847 'debbugs-gnu-separator2)
850 (defun debbugs-gnu-rescan ()
851 "Rescan the current set of bug reports."
853 (let ((id (debbugs-gnu-current-id))
854 (debbugs-gnu-current-query debbugs-gnu-local-query)
855 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
856 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
857 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
858 (debbugs-gnu-show-reports)
860 (debbugs-gnu-goto id))))
862 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
863 "Major mode for listing bug reports.
865 All normal editing commands are switched off.
866 \\<debbugs-gnu-mode-map>
868 The following commands are available:
870 \\{debbugs-gnu-mode-map}"
871 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
872 (set (make-local-variable 'debbugs-gnu-limit) nil)
873 (set (make-local-variable 'debbugs-gnu-local-query)
874 debbugs-gnu-current-query)
875 (set (make-local-variable 'debbugs-gnu-local-filter)
876 debbugs-gnu-current-filter)
877 (set (make-local-variable 'debbugs-gnu-local-suppress)
878 debbugs-gnu-current-suppress)
879 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
880 ("State" 20 debbugs-gnu-sort-state)
882 ("Title" 10 debbugs-gnu-sort-title)])
883 (setq tabulated-list-sort-key (cons "Id" nil))
884 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
885 (buffer-disable-undo)
886 (setq truncate-lines t)
887 (setq buffer-read-only t))
889 (defun debbugs-gnu-sort-id (s1 s2)
890 (> (cdr (assq 'id (car s1)))
891 (cdr (assq 'id (car s2)))))
893 (defconst debbugs-gnu-state-preference
894 '((debbugs-gnu-new . 1)
895 (debbugs-gnu-stale . 2)
896 (debbugs-gnu-handled . 3)
897 (debbugs-gnu-done . 4)
898 (debbugs-gnu-pending . 5)))
900 (defun debbugs-gnu-get-state-preference (face-string)
901 (or (cdr (assq (get-text-property 0 'face face-string)
902 debbugs-gnu-state-preference))
905 (defconst debbugs-gnu-severity-preference
912 (defun debbugs-gnu-get-severity-preference (state)
913 (or (cdr (assoc (cdr (assq 'severity state))
914 debbugs-gnu-severity-preference))
917 (defun debbugs-gnu-sort-state (s1 s2)
918 (let ((id1 (cdr (assq 'id (car s1))))
919 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
920 (id2 (cdr (assq 'id (car s2))))
921 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
923 ;; Tagged bugs go to the end.
924 ((and (not (memq id1 debbugs-gnu-local-tags))
925 (memq id2 debbugs-gnu-local-tags))
927 ((and (memq id1 debbugs-gnu-local-tags)
928 (not (memq id2 debbugs-gnu-local-tags)))
930 ;; Then, we check the age of the bugs.
935 ;; If they have the same age, we check for severity.
936 ((< (debbugs-gnu-get-severity-preference (car s1))
937 (debbugs-gnu-get-severity-preference (car s2)))
941 (defun debbugs-gnu-sort-title (s1 s2)
942 (let ((owner (if (cdr (assq 'owner (car s1)))
943 (car (mail-header-parse-address
944 (decode-coding-string (cdr (assq 'owner (car s1)))
947 (string-equal owner user-mail-address))))
949 (defun debbugs-gnu-toggle-sort ()
950 "Toggle sorting by age and by state."
952 (if (eq debbugs-gnu-sort-state 'number)
954 (setq debbugs-gnu-sort-state 'state)
955 (setq tabulated-list-sort-key (cons "Id" nil)))
956 (setq debbugs-gnu-sort-state 'number)
957 (setq tabulated-list-sort-key (cons "State" nil)))
958 (tabulated-list-init-header)
959 (tabulated-list-print))
961 (defun debbugs-gnu-widen ()
962 "Display all the currently selected bug reports."
964 (let ((id (debbugs-gnu-current-id t))
965 (inhibit-read-only t))
966 (setq debbugs-gnu-limit nil)
967 (tabulated-list-init-header)
968 (tabulated-list-print)
970 (debbugs-gnu-goto id))))
972 (defun debbugs-gnu-show-blocked-by-reports ()
973 "Display all bug reports this report is blocked by."
975 (let ((id (debbugs-gnu-current-id))
976 (status (debbugs-gnu-current-status)))
977 (if (null (cdr (assq 'blockedby status)))
978 (message "Bug %d is not blocked by any other bug" id)
979 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
981 (defun debbugs-gnu-show-blocking-reports ()
982 "Display all bug reports this report is blocking."
984 (let ((id (debbugs-gnu-current-id))
985 (status (debbugs-gnu-current-status)))
986 (if (null (cdr (assq 'blocks status)))
987 (message "Bug %d is not blocking any other bug" id)
988 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
990 (defun debbugs-gnu-show-all-blocking-reports ()
991 "Narrow the display to just the reports that are blocking a release."
993 (let ((blockers (cdr (assq 'blockedby
994 (car (debbugs-get-status
995 debbugs-gnu-blocking-report)))))
996 (id (debbugs-gnu-current-id t))
997 (inhibit-read-only t)
999 (setq debbugs-gnu-limit nil)
1000 (goto-char (point-min))
1002 (setq status (debbugs-gnu-current-status))
1003 (if (not (memq (cdr (assq 'id status)) blockers))
1004 (delete-region (point) (progn (forward-line 1) (point)))
1005 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1008 (debbugs-gnu-goto id))))
1010 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1011 "Only display the bugs matching STRING.
1012 If STATUS-ONLY (the prefix), ignore matches in the From and
1014 (interactive "sNarrow to: \nP")
1015 (let ((id (debbugs-gnu-current-id t))
1016 (inhibit-read-only t)
1018 (setq debbugs-gnu-limit nil)
1019 (if (equal string "")
1020 (debbugs-gnu-toggle-suppress)
1021 (goto-char (point-min))
1023 (setq status (debbugs-gnu-current-status))
1024 (if (and (not (member string (assq 'keywords status)))
1025 (not (equal string (cdr (assq 'severity status))))
1028 string (cdr (assq 'originator status)))))
1030 (not (string-match string (cdr (assq 'subject status))))))
1031 (delete-region (point) (progn (forward-line 1) (point)))
1032 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1035 (debbugs-gnu-goto id)))))
1037 (defun debbugs-gnu-goto (id)
1038 "Go to the line displaying bug ID."
1039 (goto-char (point-min))
1040 (while (and (not (eobp))
1041 (not (equal (debbugs-gnu-current-id t) id)))
1044 (defun debbugs-gnu-toggle-tag ()
1045 "Toggle the local tag of the report in the current line.
1046 If a report is tagged locally, it is presumed to be of little
1051 (let ((inhibit-read-only t)
1052 (id (debbugs-gnu-current-id)))
1053 (if (memq id debbugs-gnu-local-tags)
1055 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1056 (put-text-property (point) (+ (point) 5) 'face 'default))
1057 (add-to-list 'debbugs-gnu-local-tags id)
1059 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1060 'face 'debbugs-gnu-tagged))
1061 (debbugs-gnu--update-tag-face id)))
1062 (debbugs-gnu-dump-persistency-file))
1064 (defun debbugs-gnu--update-tag-face (id)
1065 (dolist (entry tabulated-list-entries)
1066 (when (equal (cdr (assq 'id (car entry))) id)
1067 (aset (cadr entry) 0
1071 ;; Mark tagged bugs.
1072 (if (memq id debbugs-gnu-local-tags)
1076 (defun debbugs-gnu-toggle-suppress ()
1077 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1079 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1080 (tabulated-list-init-header)
1081 (tabulated-list-print))
1083 (defvar debbugs-gnu-bug-number nil)
1084 (defvar debbugs-gnu-subject nil)
1086 (defun debbugs-gnu-current-id (&optional noerror)
1087 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1089 (error "No bug on the current line"))))
1091 (defun debbugs-gnu-current-status ()
1092 (get-text-property (line-beginning-position) 'tabulated-list-id))
1094 (defun debbugs-gnu-display-status (query filter status)
1095 "Display the query, filter and status of the report on the current line."
1096 (interactive (list debbugs-gnu-local-query
1097 debbugs-gnu-local-filter
1098 (debbugs-gnu-current-status)))
1099 (switch-to-buffer "*Bug Status*")
1100 (let ((inhibit-read-only t))
1103 (insert ";; Query\n")
1104 (pp query (current-buffer))
1107 (insert ";; Filter\n")
1108 (pp filter (current-buffer))
1111 (insert ";; Status\n")
1112 (pp status (current-buffer)))
1113 (goto-char (point-min)))
1114 (set-buffer-modified-p nil)
1117 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1118 "Read email exchange for debbugs bug ID.
1119 STATUS is the bug's status list.
1120 MERGED is the list of bugs merged with this one."
1121 (let* ((mbox-dir (make-temp-file "debbugs" t))
1122 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1123 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1125 ;; Download messages of all the merged bug reports and append them
1126 ;; to the mailbox of the requested bug.
1128 (dolist (bugno merged)
1129 (let ((fn (make-temp-file "url")))
1130 (debbugs-get-mbox bugno 'mboxmaint fn)
1131 (rmail-get-new-mail fn)
1133 ;; Remove the 'unseen' attribute from all the messages we've
1134 ;; just read, so that all of them appear in the summary with
1136 (while (< rmail-current-message rmail-total-messages)
1137 (rmail-show-message (1+ rmail-current-message))))))
1138 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1139 (set (make-local-variable 'debbugs-gnu-subject)
1140 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1142 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1143 (set-window-text-height nil 10)
1145 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1146 (rmail-show-message 1)))
1148 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1149 "Read email exchange for debbugs bug ID.
1150 STATUS is the bug's status list.
1151 MERGED is the list of bugs merged with this one."
1153 (setq gnus-suppress-duplicates t
1154 gnus-save-duplicate-list t)
1156 (gnus-read-ephemeral-emacs-bug-group
1157 (cons id (if (listp merged) merged (list merged)))
1158 (cons (current-buffer)
1159 (current-window-configuration)))
1160 (with-current-buffer (window-buffer (selected-window))
1161 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1162 (set (make-local-variable 'debbugs-gnu-subject)
1163 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1164 (debbugs-gnu-summary-mode 1)))
1166 (defun debbugs-gnu-select-report ()
1167 "Select the report on the current line."
1169 ;; We open the report messages.
1170 (let* ((status (debbugs-gnu-current-status))
1171 (id (cdr (assq 'id status)))
1172 (merged (cdr (assq 'mergedwith status))))
1173 (setq merged (if (listp merged) merged (list merged)))
1176 (message "No bug report on the current line"))
1177 ((eq debbugs-gnu-mail-backend 'rmail)
1178 (debbugs-read-emacs-bug-with-rmail id status merged))
1179 ((eq debbugs-gnu-mail-backend 'gnus)
1180 (debbugs-read-emacs-bug-with-gnus id status merged))
1181 (t (error "No valid mail backend specified")))))
1183 (defvar debbugs-gnu-summary-mode-map
1184 (let ((map (make-sparse-keymap)))
1185 (define-key map "C" 'debbugs-gnu-send-control-message)
1186 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1189 (define-minor-mode debbugs-gnu-summary-mode
1190 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1192 \\{debbugs-gnu-summary-mode-map}"
1193 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1194 (set (make-local-variable 'gnus-posting-styles)
1197 (when (buffer-live-p gnus-article-copy)
1198 (with-current-buffer gnus-article-copy
1199 (set (make-local-variable 'message-prune-recipient-rules)
1200 '((".*@debbugs.*" "emacs-pretest-bug")
1201 (".*@debbugs.*" "bug-gnu-emacs")
1202 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1203 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1204 (set (make-local-variable 'message-alter-recipients-function)
1206 (if (string-match "\\([0-9]+\\)@donarmstrong"
1208 (let ((new (format "%s@debbugs.gnu.org"
1209 (match-string 1 (car address)))))
1212 ;; `gnus-posting-styles' is eval'ed after
1213 ;; `message-simplify-subject'. So we cannot use m-s-s.
1214 (setq subject ,debbugs-gnu-subject))))))))
1216 (defun debbugs-gnu-guess-current-id ()
1217 "Guess the ID based on \"#23\"."
1221 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1223 (goto-char (point-min))
1224 (re-search-forward "#\\([0-9]+\\)" nil t)))
1225 (string-to-number (match-string 1)))))
1227 (defun debbugs-gnu-send-control-message (message &optional reverse)
1228 "Send a control message for the current bug report.
1229 You can set the severity or add a tag, or close the report. If
1230 you use the special \"done\" MESSAGE, the report will be marked as
1231 fixed, and then closed.
1233 If given a prefix, and given a tag to set, the tag will be
1236 (list (completing-read
1238 '("serious" "important" "normal" "minor" "wishlist"
1239 "done" "donenotabug" "donewontfix" "doneunreproducible"
1240 "unarchive" "unmerge" "reopen" "close"
1241 "merge" "forcemerge"
1246 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1247 "pending" "help" "security" "confirmed"
1250 current-prefix-arg))
1251 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1252 (debbugs-gnu-guess-current-id)
1253 (debbugs-gnu-current-id)))
1255 (when (member message '("close" "done"))
1259 ;; Emacs development versions.
1261 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1263 (match-string 1 emacs-version)
1264 (1+ (string-to-number (match-string 2 emacs-version)))))
1265 ;; Emacs release versions.
1267 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1269 (match-string 1 emacs-version)
1270 (match-string 2 emacs-version)))
1271 (t emacs-version)))))
1272 (status (debbugs-gnu-current-status)))
1274 (insert "To: control@debbugs.gnu.org\n"
1275 "From: " (message-make-from) "\n"
1276 (format "Subject: control message for bug #%d\n" id)
1277 mail-header-separator
1280 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1281 (format "%s %d\n" message id))
1282 ((member message '("merge" "forcemerge"))
1283 (format "%s %d %s\n" message id
1284 (read-string "Merge with bug #: ")))
1285 ((member message '("block" "unblock"))
1287 "%s %d by %s\n" message id
1290 (completing-read-multiple
1291 (format "%s with bug(s) #: " (capitalize message))
1292 (if (equal message "unblock")
1293 (mapcar 'number-to-string
1294 (cdr (assq 'blockedby status))))
1295 nil (and (equal message "unblock") status))
1297 ((equal message "owner")
1298 (format "owner %d !\n" id))
1299 ((equal message "reassign")
1300 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1301 ((equal message "close")
1302 (format "close %d %s\n" id version))
1303 ((equal message "done")
1304 (format "tags %d fixed\nclose %d %s\n" id id version))
1305 ((member message '("donenotabug" "donewontfix"
1306 "doneunreproducible"))
1307 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1308 ((member message '("serious" "important" "normal"
1309 "minor" "wishlist"))
1310 (format "severity %d %s\n" id message))
1311 ((equal message "invalid")
1312 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1314 ((equal message "usertag")
1315 (format "user %s\nusertag %d %s\n"
1317 "Package name or email address: "
1319 debbugs-gnu-all-packages (list user-mail-address))
1320 nil nil (car debbugs-gnu-default-packages))
1321 id (read-string "User tag: ")))
1323 (format "tags %d%s %s\n"
1324 id (if reverse " -" "")
1326 (funcall send-mail-function)
1327 (remhash id debbugs-cache-data)
1329 (message "Control message sent:\n%s"
1330 (buffer-substring-no-properties (point) (1- (point-max)))))))
1332 (defvar debbugs-gnu-usertags-mode-map
1333 (let ((map (make-sparse-keymap)))
1334 (set-keymap-parent map tabulated-list-mode-map)
1335 (define-key map "\r" 'debbugs-gnu-select-usertag)
1336 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1337 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1340 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1341 "Major mode for listing user tags.
1343 All normal editing commands are switched off.
1344 \\<debbugs-gnu-usertags-mode-map>
1346 The following commands are available:
1348 \\{debbugs-gnu-usertags-mode-map}"
1349 (buffer-disable-undo)
1350 (setq truncate-lines t)
1351 (setq buffer-read-only t))
1354 (defun debbugs-gnu-usertags (&rest users)
1355 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1357 (if current-prefix-arg
1358 (completing-read-multiple
1359 "Package name(s) or email address: "
1360 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1361 (mapconcat 'identity debbugs-gnu-default-packages ","))
1362 debbugs-gnu-default-packages))
1365 (let ((inhibit-read-only t)
1366 (debbugs-port "gnu.org")
1367 (buffer-name "*Emacs User Tags*")
1369 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1371 ;; Initialize variables.
1372 (when (and (file-exists-p debbugs-gnu-persistency-file)
1373 (not debbugs-gnu-local-tags))
1375 (insert-file-contents debbugs-gnu-persistency-file)
1376 (eval (read (current-buffer)))))
1379 (when (get-buffer buffer-name)
1380 (kill-buffer buffer-name))
1381 (switch-to-buffer (get-buffer-create buffer-name))
1382 (debbugs-gnu-usertags-mode)
1383 (setq tabulated-list-format `[("User" ,user-tab-length t)
1385 (setq tabulated-list-sort-key (cons "User" nil))
1386 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1388 ;; Retrieve user tags.
1389 (dolist (user users)
1390 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1392 'tabulated-list-entries
1393 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1394 `((("tagged") (,user) nil nil (,tag))
1395 ,(vector (propertize user 'mouse-face 'highlight)
1396 (propertize tag 'mouse-face 'highlight)))
1400 (when debbugs-gnu-local-tags
1402 'tabulated-list-entries
1405 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1408 (tabulated-list-init-header)
1409 (tabulated-list-print)
1411 (set-buffer-modified-p nil)
1412 (goto-char (point-min)))))
1414 (defun debbugs-gnu-select-usertag ()
1415 "Select the user tag on the current line."
1417 ;; We open the bug reports.
1418 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1419 (when args (apply 'debbugs-gnu args))))
1422 (defun debbugs-gnu-bugs (&rest bugs)
1423 "List all BUGS, a list of bug numbers."
1425 (mapcar 'string-to-number
1426 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1428 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1429 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1430 ;; We do not suppress bugs requested explicitely.
1431 (setq debbugs-gnu-current-suppress nil)
1434 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1435 "The directory where the main source tree lives.")
1437 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1438 "The directory where the previous source tree lives.")
1440 (defun debbugs-gnu-apply-patch (&optional branch)
1441 "Apply the patch from the current message.
1442 If given a prefix, patch in the branch directory instead."
1444 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1445 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1446 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1447 (let ((rej "/tmp/debbugs-gnu.rej")
1448 (output-buffer (get-buffer-create "*debbugs patch*"))
1450 debbugs-gnu-branch-directory
1451 debbugs-gnu-trunk-directory))
1452 (patch-buffers nil))
1453 (when (file-exists-p rej)
1455 (with-current-buffer output-buffer
1457 (gnus-summary-select-article nil t)
1458 ;; The patches are either in MIME attachements or the main article
1459 ;; buffer. Determine which.
1460 (gnus-with-article-buffer
1461 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1462 (when (string-match "diff\\|patch" (mm-handle-media-type handle))
1463 (push (cons (mm-handle-encoding handle)
1464 (mm-handle-buffer handle))
1466 (unless patch-buffers
1467 (gnus-summary-show-article 'raw)
1468 (article-decode-charset)
1469 (push (cons nil gnus-article-buffer) patch-buffers))
1470 (dolist (elem patch-buffers)
1472 (insert-buffer-substring (cdr elem))
1473 (cond ((eq (car elem) 'base64)
1474 (base64-decode-region (point-min) (point-max)))
1475 ((eq (car elem) 'quoted-printable)
1476 (quoted-printable-decode-region (point-min) (point-max))))
1477 (debbugs-gnu-fix-patch dir)
1478 (call-process-region (point-min) (point-max)
1479 "patch" nil output-buffer nil
1480 "-r" rej "--no-backup-if-mismatch"
1482 "-d" (expand-file-name dir)
1484 (set-buffer output-buffer)
1485 (when (file-exists-p rej)
1486 (goto-char (point-max))
1487 (insert-file-contents-literally rej))
1488 (goto-char (point-max))
1489 (save-some-buffers t)
1491 (mapc 'kill-process compilation-in-progress)
1492 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1494 (vc-dir-hide-up-to-date)
1495 (goto-char (point-min))
1498 ;; All these commands are asynchronous, so just wait a bit. This
1499 ;; should be done properly a different way.
1501 ;; We've now done everything, so arrange the windows we need to see.
1502 (delete-other-windows)
1503 (switch-to-buffer output-buffer)
1507 (switch-to-buffer "*compilation*")
1508 (goto-char (point-max))
1510 (switch-to-buffer "*vc-diff*")
1511 (goto-char (point-min))))
1513 (defun debbugs-gnu-fix-patch (dir)
1514 (setq dir (directory-file-name (expand-file-name dir)))
1515 (goto-char (point-min))
1516 (while (re-search-forward diff-file-header-re nil t)
1517 (goto-char (match-beginning 0))
1518 (let ((target-name (car (diff-hunk-file-names))))
1519 (when (and target-name
1520 (or (not (string-match "/" target-name))
1521 (and (string-match "^[ab]/" target-name)
1523 (expand-file-name (substring target-name 2)
1525 (file-exists-p (expand-file-name target-name dir))))
1526 ;; We have a simple patch that refers to a file somewhere in the
1528 (when-let ((files (directory-files-recursively
1530 (concat "^" (regexp-quote
1531 (file-name-nondirectory target-name))
1533 (when (re-search-forward (concat "^[+]+ "
1534 (regexp-quote target-name)
1537 (replace-match (concat "+++ a"
1538 (substring (car files) (length dir))
1543 (defun debbugs-gnu-find-contributor (string)
1544 "Search through ChangeLogs to find contributors."
1545 (interactive "sContributor match: ")
1547 (match (concat "^[0-9].*" string)))
1548 (dolist (file (directory-files-recursively
1549 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1551 (when (file-exists-p file)
1552 (insert-file-contents file))
1553 (goto-char (point-min))
1554 (while (and (re-search-forward match nil t)
1555 (not (looking-at ".*tiny change")))
1557 (message "%s is a contributor %d times" string found)
1560 (defun debbugs-gnu-insert-changelog ()
1561 "Add a ChangeLog from a recently applied patch from a third party."
1564 (gnus-with-article-buffer
1566 (goto-char (point-min))
1567 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1568 subject (gnus-fetch-field "subject")))
1569 (let ((add-log-full-name (car from))
1570 (add-log-mailing-address (cadr from)))
1571 (add-change-log-entry-other-window)
1572 (let ((point (point)))
1573 (when (string-match "\\(bug#[0-9]+\\)" subject)
1574 (insert " (" (match-string 1 subject) ")."))
1575 (when (zerop (debbugs-gnu-find-contributor
1576 (let ((bits (split-string (car from))))
1578 ((>= (length bits) 2)
1579 (format "%s.*%s" (car bits) (car (last bits))))
1580 ((= (length bits) 1)
1582 ;; Fall back on the email address.
1585 (goto-char (point-max))
1587 (insert " (tiny change"))
1588 (goto-char point)))))
1590 (defvar debbugs-gnu-lisp-mode-map
1591 (let ((map (make-sparse-keymap)))
1592 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1595 (define-minor-mode debbugs-gnu-lisp-mode
1596 "Minor mode for providing a debbugs interface in Lisp buffers.
1597 \\{debbugs-gnu-lisp-mode-map}"
1598 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1600 (defvar debbugs-gnu-diff-mode-map
1601 (let ((map (make-sparse-keymap)))
1602 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1605 (define-minor-mode debbugs-gnu-diff-mode
1606 "Minor mode for providing a debbugs interface in diff buffers.
1607 \\{debbugs-gnu-diff-mode-map}"
1608 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1610 (defun debbugs-gnu-diff-select ()
1611 "Select the diff under point."
1613 (delete-other-windows)
1616 (defvar debbugs-gnu-change-mode-map
1617 (let ((map (make-sparse-keymap)))
1618 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1621 (define-minor-mode debbugs-gnu-change-mode
1622 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1623 \\{debbugs-gnu-change-mode-map}"
1624 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1626 (defun debbugs-gnu-change-checkin ()
1627 "Prepare checking in the current changes."
1629 (save-some-buffers t)
1630 (when (get-buffer "*vc-dir*")
1631 (kill-buffer (get-buffer "*vc-dir*")))
1632 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1633 (if (equal (cl-subseq default-directory 0 (length trunk))
1635 (vc-dir debbugs-gnu-trunk-directory)
1636 (vc-dir debbugs-gnu-branch-directory)))
1637 (goto-char (point-min))
1638 (while (not (search-forward "edited" nil t))
1641 (while (search-forward "edited" nil t)
1643 (beginning-of-line))
1645 (vc-next-action nil)
1646 (log-edit-insert-changelog t)
1647 (delete-other-windows)
1650 (switch-to-buffer "*vc-diff*")
1653 (provide 'debbugs-gnu)
1657 ;; * Another random thought - is it possible to implement some local
1658 ;; cache, so only changed bugs are fetched? Glenn Morris.
1660 ;;; debbugs-gnu.el ends here