1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker -*- lexical-binding:t -*-
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)
144 (eval-when-compile (require 'subr-x))
145 (eval-when-compile (require 'cl-lib))
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-fetch-field "gnus-util")
152 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
153 (autoload 'gnus-summary-article-header "gnus-sum")
154 (autoload 'gnus-summary-select-article "gnus-sum")
155 (autoload 'gnus-summary-show-article "gnus-sum")
156 (autoload 'gnus-with-article-buffer "gnus-art")
157 (autoload 'log-edit-insert-changelog "log-edit")
158 (autoload 'mail-header-subject "nnheader")
159 (autoload 'message-goto-body "message")
160 (autoload 'message-make-from "message")
161 (autoload 'rmail-get-new-mail "rmail")
162 (autoload 'rmail-show-message "rmail")
163 (autoload 'rmail-summary "rmailsum")
164 (autoload 'vc-dir-hide-up-to-date "vc-dir")
165 (autoload 'vc-dir-mark "vc-dir")
167 (defvar compilation-in-progress)
168 (defvar diff-file-header-re)
169 (defvar gnus-article-buffer)
170 (defvar gnus-posting-styles)
171 (defvar gnus-save-duplicate-list)
172 (defvar gnus-suppress-duplicates)
173 (defvar rmail-current-message)
174 (defvar rmail-mode-map)
175 (defvar rmail-summary-mode-map)
176 (defvar rmail-total-messages)
178 ;; Buffer-local variables.
179 (defvar debbugs-gnu-local-query)
180 (defvar debbugs-gnu-local-filter)
181 (defvar debbugs-gnu-local-suppress)
182 (defvar debbugs-gnu-sort-state)
183 (defvar debbugs-gnu-limit)
185 (defgroup debbugs-gnu ()
186 "UI for the debbugs.gnu.org bug tracker."
190 (defvar debbugs-gnu-blocking-report 19759
191 "The ID of the current release report used to track blocking bug reports.")
193 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
194 "*The list severities bugs are searched for.
195 \"tagged\" is not a severity but marks locally tagged bugs."
196 ;; <http://debbugs.gnu.org/Developer.html#severities>
197 ;; /ssh:debbugs:/etc/debbugs/config @gSeverityList
198 ;; We don't use "critical" and "grave".
200 :type '(set (const "serious")
208 (defconst debbugs-gnu-all-severities
209 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
210 "*List of all possible severities.")
212 (defcustom debbugs-gnu-default-packages '("emacs")
213 "*The list of packages to be searched for."
214 ;; <http://debbugs.gnu.org/Packages.html>
215 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
217 :type '(set (const "adns")
223 (const "debbugs.gnu.org")
226 (const "emacs-xwidgets")
243 (defconst debbugs-gnu-all-packages
244 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
245 "*List of all possible package names.")
247 (defcustom debbugs-gnu-default-suppress-bugs
248 '((pending . "done"))
249 "*A list of specs for bugs to be suppressed.
250 An element of this list is a cons cell \(KEY . REGEXP\), with key
251 being returned by `debbugs-get-status', and REGEXP a regular
252 expression matching the corresponding value, a string. Showing
253 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
255 :type '(alist :key-type symbol :value-type regexp)
258 (defcustom debbugs-gnu-mail-backend 'gnus
259 "*The email backend to use for reading bug report email exchange.
260 If this is 'gnus, the default, use Gnus.
261 If this is 'rmail, use Rmail instead."
263 :type '(choice (const :tag "Use Gnus" 'gnus)
264 (const :tag "Use Rmail" 'rmail))
267 (defface debbugs-gnu-archived '((t (:inverse-video t)))
268 "Face for archived bug reports.")
270 (defface debbugs-gnu-new '((t (:foreground "red")))
271 "Face for new reports that nobody has answered.")
273 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
274 "Face for reports that have been modified recently.")
276 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
277 "Face for reports that are pending.")
279 (defface debbugs-gnu-stale '((t (:foreground "orange")))
280 "Face for reports that have not been touched for two weeks.")
282 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
283 "Face for closed bug reports.")
285 (defface debbugs-gnu-tagged '((t (:foreground "red")))
286 "Face for reports that have been tagged locally.")
288 (defvar debbugs-gnu-local-tags nil
289 "List of bug numbers tagged locally, and kept persistent.")
291 (defvar debbugs-gnu-persistency-file
292 (expand-file-name (locate-user-emacs-file "debbugs"))
293 "File name of a persistency store for debbugs variables")
295 (defun debbugs-gnu-dump-persistency-file ()
296 "Function to store debbugs variables persistently."
297 (with-temp-file debbugs-gnu-persistency-file
299 ";; -*- emacs-lisp -*-\n"
300 ";; Debbugs tags connection history. Don't change this file.\n\n"
301 (format "(setq debbugs-gnu-local-tags '%S)"
302 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
304 (defvar debbugs-gnu-current-query nil
305 "The query object of the current search.
306 It will be applied server-side, when calling `debbugs-get-bugs'.
307 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
309 (defvar debbugs-gnu-current-filter nil
310 "The filter object for the current search.
311 It will be applied client-side, when parsing the results of
312 `debbugs-get-status'. It has a similar format as
313 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
314 a date, value is the cons cell \(BEFORE . AFTER\).")
316 (defvar debbugs-gnu-current-suppress nil
317 "Whether bugs shall be suppressed.
318 The specification which bugs shall be suppressed is taken from
319 `debbugs-gnu-default-suppress-bugs'.")
321 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
322 "Return a string read from the minibuffer.
323 Derived from `calendar-read'."
324 (let ((value (read-string prompt initial-contents)))
325 (while (not (funcall acceptable value))
326 (setq value (read-string prompt initial-contents)))
329 (defconst debbugs-gnu-phrase-prompt
331 "Enter search phrase: "
333 The search phrase contains words to be searched for, combined by
334 operators like AND, ANDNOT and OR. If there is no operator
335 between the words, AND is used by default. The phrase can also
336 be empty, in this case only the following attributes are used for
340 (defun debbugs-gnu-patches ()
341 "List the bug reports that have been marked as containing a patch."
343 (debbugs-gnu nil '("emacs") nil nil "patch"))
346 (defun debbugs-gnu-search ()
347 "Search for Emacs bugs interactively.
348 Search arguments are requested interactively. The \"search
349 phrase\" is used for full text search in the bugs database.
350 Further key-value pairs are requested until an empty key is
351 returned. If a key cannot be queried by a SOAP request, it is
352 marked as \"client-side filter\"."
356 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
357 key val1 val2 phrase severities packages archivedp)
359 ;; Check for the phrase.
360 (setq phrase (read-string debbugs-gnu-phrase-prompt))
361 (if (zerop (length phrase))
363 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
364 ;; We suppress closed bugs if there is no phrase.
365 (setq debbugs-gnu-current-suppress (null phrase))
367 ;; The other queries.
370 (setq key (completing-read
373 '("severity" "package" "tags" "submitter" "date"
375 '("severity" "package" "archive" "src" "tag"
376 "owner" "submitter" "maint" "correspondent"
377 "date" "log_modified" "last_modified"
378 "found_date" "fixed_date" "unarchived"
379 "subject" "done" "forwarded" "msgid" "summary"))
382 ;; Server-side queries.
383 ((equal key "severity")
386 (completing-read-multiple
387 "Enter severities: " debbugs-gnu-all-severities nil t
388 (mapconcat 'identity debbugs-gnu-default-severities ","))))
390 ((equal key "package")
393 (completing-read-multiple
394 "Enter packages: " debbugs-gnu-all-packages nil t
395 (mapconcat 'identity debbugs-gnu-default-packages ","))))
397 ((equal key "archive")
398 ;; We simplify, by assuming just archived bugs are requested.
401 ((member key '("src" "tag" "tags"))
402 (setq val1 (read-string (format "Enter %s: " key)))
403 (when (not (zerop (length val1)))
405 'debbugs-gnu-current-query (cons (intern key) val1))))
407 ((member key '("owner" "submitter" "maint" "correspondent"))
408 (setq val1 (read-string "Enter email address: "))
409 (when (not (zerop (length val1)))
411 'debbugs-gnu-current-query (cons (intern key) val1))))
413 ((equal key "status")
416 (completing-read "Enter status: " '("done" "forwarded" "open")))
417 (when (not (zerop (length val1)))
419 'debbugs-gnu-current-query (cons (intern key) val1))))
421 ;; Client-side filters.
422 ((member key '("date" "log_modified" "last_modified"
423 "found_date" "fixed_date" "unarchived"))
425 (debbugs-gnu-calendar-read
426 (format "Enter %s before YYYY-MM-DD%s: "
427 key (if phrase "" " (client-side filter)"))
429 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
430 (if (string-match date-format val1)
435 (string-to-number (match-string 3 val1))
436 (string-to-number (match-string 2 val1))
437 (string-to-number (match-string 1 val1))))))
440 (debbugs-gnu-calendar-read
441 (format "Enter %s after YYYY-MM-DD%s: "
442 key (if phrase "" " (client-side filter)"))
444 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
445 (if (string-match date-format val2)
450 (string-to-number (match-string 3 val2))
451 (string-to-number (match-string 2 val2))
452 (string-to-number (match-string 1 val2))))))
457 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
458 (cons (intern key) (cons val1 val2)))))
460 ((not (zerop (length key)))
463 (if phrase 'read-string 'read-regexp)
465 key (if phrase ": " " (client-side filter)"))))
466 (when (not (zerop (length val1)))
469 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
470 (cons (intern key) val1))))
473 (t (throw :finished nil)))))
476 (debbugs-gnu severities packages archivedp))))
479 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
480 "List all outstanding bugs."
482 (let (severities archivedp)
485 (completing-read-multiple
486 "Severities: " debbugs-gnu-all-severities nil t
487 (mapconcat 'identity debbugs-gnu-default-severities ",")))
488 ;; The next parameters are asked only when there is a prefix.
489 (if current-prefix-arg
490 (completing-read-multiple
491 "Packages: " debbugs-gnu-all-packages nil t
492 (mapconcat 'identity debbugs-gnu-default-packages ","))
493 debbugs-gnu-default-packages)
494 (when current-prefix-arg
495 (setq archivedp (y-or-n-p "Show archived bugs?")))
496 (when (and current-prefix-arg (not archivedp))
497 (y-or-n-p "Suppress unwanted bugs?"))
498 ;; This one must be asked for severity "tagged".
499 (when (member "tagged" severities)
500 (split-string (read-string "User tag(s): ") "," t)))))
502 ;; Initialize variables.
503 (when (and (file-exists-p debbugs-gnu-persistency-file)
504 (not debbugs-gnu-local-tags))
506 (insert-file-contents debbugs-gnu-persistency-file)
507 (eval (read (current-buffer)))))
508 ;; Per default, we suppress retrieved unwanted bugs.
509 (when (called-interactively-p 'any)
510 (setq debbugs-gnu-current-suppress t))
513 (dolist (severity (if (consp severities) severities (list severities)))
514 (when (not (zerop (length severity)))
515 (when (string-equal severity "tagged")
516 (setq debbugs-gnu-current-suppress nil))
517 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
518 (dolist (package (if (consp packages) packages (list packages)))
519 (when (not (zerop (length package)))
520 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
522 (setq debbugs-gnu-current-suppress nil)
523 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
525 (setq debbugs-gnu-current-suppress t)
526 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
527 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
528 (dolist (tag (if (consp tags) tags (list tags)))
529 (when (not (zerop (length tag)))
530 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
533 (debbugs-gnu-show-reports)
535 ;; Reset query, filter and suppress.
536 (setq debbugs-gnu-current-query nil
537 debbugs-gnu-current-filter nil
538 debbugs-gnu-current-suppress nil))
540 (defun debbugs-gnu-get-bugs (query)
541 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
542 (let* ((debbugs-port "gnu.org")
543 (bugs (assoc 'bugs query))
544 (tags (assoc 'tag query))
545 (local-tags (and (member '(severity . "tagged") query) (not tags)))
546 (phrase (assoc 'phrase query))
548 ;; Compile query arguments.
549 (unless (or query tags)
550 (dolist (elt debbugs-gnu-default-packages)
551 (setq args (append args (list :package elt)))))
553 (unless (equal elt '(severity . "tagged"))
559 ((eq (car elt) 'phrase)
560 (list (list :phrase (cdr elt))))
561 ((eq (car elt) 'date)
562 (list (list :date (cddr elt) (cadr elt)
565 (list (list (intern (concat ":" (symbol-name (car elt))))
566 (cdr elt) :operator "ISTRINC"))))
567 (list (intern (concat ":" (symbol-name (car elt))))
571 ;; If the query is just a list of bug numbers, we return them.
573 ;; If the query contains the pseudo-severity "tagged", we return
574 ;; just the local tagged bugs.
575 (local-tags (copy-sequence debbugs-gnu-local-tags))
576 ;; A full text query.
579 (lambda (x) (cdr (assoc "id" x)))
580 (apply 'debbugs-search-est args)))
581 ;; Otherwise, we retrieve the bugs from the server.
582 (t (apply 'debbugs-get-bugs args)))))
584 (defun debbugs-gnu-show-reports (&optional offline)
586 If OFFLINE is non-nil, the query is not sent to the server. Bugs
587 are taken from the cache instead."
588 (let ((inhibit-read-only t)
589 (buffer-name "*Emacs Bugs*"))
590 ;; The tabulated mode sets several local variables. We must get
592 (when (get-buffer buffer-name)
593 (kill-buffer buffer-name))
594 (switch-to-buffer (get-buffer-create buffer-name))
597 ;; Print bug reports.
599 (let ((debbugs-cache-expiry (if offline nil debbugs-cache-expiry))
601 (apply 'debbugs-get-status
604 (maphash (lambda (key _elem)
608 (debbugs-gnu-get-bugs debbugs-gnu-local-query)))))
609 (let* ((id (cdr (assq 'id status)))
613 (cons (cdr (assq 'severity status))
614 (cdr (assq 'keywords status)))
616 (address (if (cdr (assq 'originator status))
617 (mail-header-parse-address
618 (decode-coding-string (cdr (assq 'originator status))
620 (owner (if (cdr (assq 'owner status))
621 (car (mail-header-parse-address
622 (decode-coding-string (cdr (assq 'owner status))
624 (subject (if (cdr (assq 'subject status))
625 (decode-coding-string (cdr (assq 'subject status))
628 (unless (equal (cdr (assq 'pending status)) "pending")
629 (setq words (concat words "," (cdr (assq 'pending status)))))
630 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
632 (setq words (concat words "," (mapconcat 'identity packages ",")))))
633 (when (setq merged (cdr (assq 'mergedwith status)))
634 (setq words (format "%s,%s"
637 (mapconcat 'number-to-string merged ","))
639 (when (or (not merged)
640 (not (let ((found nil))
641 (dolist (id (if (listp merged)
644 (dolist (entry tabulated-list-entries)
645 (when (equal id (cdr (assq 'id (car entry))))
649 'tabulated-list-entries
657 (if (memq id debbugs-gnu-local-tags)
661 ;; Mark status and age.
665 ((cdr (assq 'archived status))
666 'debbugs-gnu-archived)
667 ((equal (cdr (assq 'pending status)) "done")
669 ((member "pending" (cdr (assq 'keywords status)))
670 'debbugs-gnu-pending)
671 ((= (cdr (assq 'date status))
672 (cdr (assq 'log_modified status)))
675 (cdr (assq 'log_modified status)))
677 'debbugs-gnu-handled)
679 'debbugs-gnu-stale)))
681 ;; Prefer the name over the address.
686 ;; Mark own submitted bugs.
687 (if (and (stringp (car address))
688 (string-equal (car address) user-mail-address))
695 (if (and (stringp owner)
696 (string-equal owner user-mail-address))
701 (tabulated-list-init-header)
702 (tabulated-list-print)
704 (set-buffer-modified-p nil)
705 (goto-char (point-min))))
707 (defun debbugs-gnu-print-entry (list-id cols)
708 "Insert a debbugs entry at point.
709 Used instead of `tabulated-list-print-entry'."
714 (id-length (nth 1 (aref tabulated-list-format 0)))
715 (state (aref cols 1))
716 (state-length (nth 1 (aref tabulated-list-format 1)))
717 (submitter (aref cols 2))
718 (submitter-length (nth 1 (aref tabulated-list-format 2)))
719 (title (aref cols 3))
720 ;; (title-length (nth 1 (aref tabulated-list-format 3)))
723 ;; We may have a narrowing in effect.
724 (or (not debbugs-gnu-limit)
725 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
726 ;; Filter suppressed bugs.
727 (or (not debbugs-gnu-local-suppress)
728 (not (catch :suppress
729 (dolist (check debbugs-gnu-default-suppress-bugs)
733 (or (cdr (assq (car check) list-id)) ""))
734 (throw :suppress t))))))
735 ;; Filter search list.
736 (not (catch :suppress
737 (dolist (check debbugs-gnu-local-filter)
738 (let ((val (cdr (assq (car check) list-id))))
739 (if (stringp (cdr check))
740 ;; Regular expression.
741 (when (not (string-match (cdr check) (or val "")))
744 (when (or (and (numberp (cadr check))
745 (< (cadr check) val))
746 (and (numberp (cddr check))
747 (> (cddr check) val)))
748 (throw :suppress t))))))))
751 (indent-to (- id-length (length id)))
754 (indent-to (setq pos (+ pos id-length 1)) 1)
755 (insert (if (> (length state) state-length)
756 (propertize (substring state 0 state-length)
760 (indent-to (setq pos (+ pos state-length 1)) 1)
761 (insert "[" (if (> (length submitter) (- submitter-length 2))
762 (propertize (substring submitter 0 (- submitter-length 2))
763 'help-echo submitter)
765 (indent-to (+ pos (1- submitter-length)))
768 (indent-to (setq pos (+ pos submitter-length 1)) 1)
769 (insert (propertize title 'help-echo title))
773 `(tabulated-list-id ,list-id mouse-face highlight))
776 (defun debbugs-gnu-menu-map-emacs-enabled ()
777 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
778 (or ;; No package discriminator has been used.
779 (not (assq 'package debbugs-gnu-local-query))
780 ;; Package "emacs" has been selected.
781 (member '(package . "emacs") debbugs-gnu-local-query)))
783 (defconst debbugs-gnu-bug-triage-file
784 (expand-file-name "../admin/notes/bug-triage" data-directory)
785 "The \"bug-triage\" file.")
787 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
788 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
789 (and (debbugs-gnu-menu-map-emacs-enabled)
790 (stringp debbugs-gnu-bug-triage-file)
791 (file-readable-p debbugs-gnu-bug-triage-file)))
793 (defun debbugs-gnu-view-bug-triage ()
794 "Show \"bug-triage\" file."
796 (view-file debbugs-gnu-bug-triage-file))
798 (defvar debbugs-gnu-mode-map
799 (let ((map (make-sparse-keymap))
800 (menu-map (make-sparse-keymap)))
801 (set-keymap-parent map tabulated-list-mode-map)
802 (define-key map "\r" 'debbugs-gnu-select-report)
803 (define-key map [mouse-1] 'debbugs-gnu-select-report)
804 (define-key map [mouse-2] 'debbugs-gnu-select-report)
805 (define-key map "g" 'debbugs-gnu-rescan)
806 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
807 (define-key map "C" 'debbugs-gnu-send-control-message)
809 (define-key map "s" 'debbugs-gnu-toggle-sort)
810 (define-key map "t" 'debbugs-gnu-toggle-tag)
811 (define-key map "x" 'debbugs-gnu-toggle-suppress)
812 (define-key map "/" 'debbugs-gnu-narrow-to-status)
813 (define-key map "w" 'debbugs-gnu-widen)
815 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
816 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
817 (define-key map "d" 'debbugs-gnu-display-status)
819 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
820 (define-key menu-map [debbugs-gnu-select-report]
821 '(menu-item "Show Reports" debbugs-gnu-select-report
822 :help "Show all reports belonging to this bug"))
823 (define-key-after menu-map [debbugs-gnu-rescan]
824 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
825 :help "Refresh bug list")
826 'debbugs-gnu-select-report)
827 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
828 '(menu-item "Show Release Blocking Bugs"
829 debbugs-gnu-show-all-blocking-reports
830 :enable (debbugs-gnu-menu-map-emacs-enabled)
831 :help "Show all bugs blocking next Emacs release")
833 (define-key-after menu-map [debbugs-gnu-send-control-message]
834 '(menu-item "Send Control Message"
835 debbugs-gnu-send-control-message
836 :help "Send control message to debbugs.gnu.org")
837 'debbugs-gnu-show-all-blocking-reports)
839 (define-key-after menu-map [debbugs-gnu-separator1]
840 '(menu-item "--") 'debbugs-gnu-send-control-message)
841 (define-key-after menu-map [debbugs-gnu-search]
842 '(menu-item "Search Bugs" debbugs-gnu-search
843 :help "Search bugs on debbugs.gnu.org")
844 'debbugs-gnu-separator1)
845 (define-key-after menu-map [debbugs-gnu]
846 '(menu-item "Retrieve Bugs" debbugs-gnu
847 :help "Retrieve bugs from debbugs.gnu.org")
849 (define-key-after menu-map [debbugs-gnu-bugs]
850 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
851 :help "Retrieve selected bugs from debbugs.gnu.org")
854 (define-key-after menu-map [debbugs-gnu-separator2]
855 '(menu-item "--") 'debbugs-gnu-bugs)
856 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
857 '(menu-item "Describe Bug Triage Procedure"
858 debbugs-gnu-view-bug-triage
859 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
860 :help "Show procedure of triaging bugs")
861 'debbugs-gnu-separator2)
864 (defun debbugs-gnu-rescan ()
865 "Rescan the current set of bug reports."
867 (let ((id (debbugs-gnu-current-id))
868 (debbugs-gnu-current-query debbugs-gnu-local-query)
869 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
870 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
871 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
872 (debbugs-gnu-show-reports)
874 (debbugs-gnu-goto id))))
876 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
877 "Major mode for listing bug reports.
879 All normal editing commands are switched off.
880 \\<debbugs-gnu-mode-map>
882 The following commands are available:
884 \\{debbugs-gnu-mode-map}"
885 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
886 (set (make-local-variable 'debbugs-gnu-limit) nil)
887 (set (make-local-variable 'debbugs-gnu-local-query)
888 debbugs-gnu-current-query)
889 (set (make-local-variable 'debbugs-gnu-local-filter)
890 debbugs-gnu-current-filter)
891 (set (make-local-variable 'debbugs-gnu-local-suppress)
892 debbugs-gnu-current-suppress)
893 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
894 ("State" 20 debbugs-gnu-sort-state)
896 ("Title" 10 debbugs-gnu-sort-title)])
897 (setq tabulated-list-sort-key (cons "Id" nil))
898 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
899 (buffer-disable-undo)
900 (setq truncate-lines t)
901 (setq buffer-read-only t))
903 (defun debbugs-gnu-sort-id (s1 s2)
904 (> (cdr (assq 'id (car s1)))
905 (cdr (assq 'id (car s2)))))
907 (defconst debbugs-gnu-state-preference
908 '((debbugs-gnu-new . 1)
909 (debbugs-gnu-stale . 2)
910 (debbugs-gnu-handled . 3)
911 (debbugs-gnu-done . 4)
912 (debbugs-gnu-pending . 5)))
914 (defun debbugs-gnu-get-state-preference (face-string)
915 (or (cdr (assq (get-text-property 0 'face face-string)
916 debbugs-gnu-state-preference))
919 (defconst debbugs-gnu-severity-preference
926 (defun debbugs-gnu-get-severity-preference (state)
927 (or (cdr (assoc (cdr (assq 'severity state))
928 debbugs-gnu-severity-preference))
931 (defun debbugs-gnu-sort-state (s1 s2)
932 (let ((id1 (cdr (assq 'id (car s1))))
933 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
934 (id2 (cdr (assq 'id (car s2))))
935 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
937 ;; Tagged bugs go to the end.
938 ((and (not (memq id1 debbugs-gnu-local-tags))
939 (memq id2 debbugs-gnu-local-tags))
941 ((and (memq id1 debbugs-gnu-local-tags)
942 (not (memq id2 debbugs-gnu-local-tags)))
944 ;; Then, we check the age of the bugs.
949 ;; If they have the same age, we check for severity.
950 ((< (debbugs-gnu-get-severity-preference (car s1))
951 (debbugs-gnu-get-severity-preference (car s2)))
955 (defun debbugs-gnu-sort-title (s1 _s2)
956 (let ((owner (if (cdr (assq 'owner (car s1)))
957 (car (mail-header-parse-address
958 (decode-coding-string (cdr (assq 'owner (car s1)))
961 (string-equal owner user-mail-address))))
963 (defun debbugs-gnu-toggle-sort ()
964 "Toggle sorting by age and by state."
966 (if (eq debbugs-gnu-sort-state 'number)
968 (setq debbugs-gnu-sort-state 'state)
969 (setq tabulated-list-sort-key (cons "Id" nil)))
970 (setq debbugs-gnu-sort-state 'number)
971 (setq tabulated-list-sort-key (cons "State" nil)))
972 (tabulated-list-init-header)
973 (tabulated-list-print))
975 (defun debbugs-gnu-widen ()
976 "Display all the currently selected bug reports."
978 (let ((id (debbugs-gnu-current-id t))
979 (inhibit-read-only t))
980 (setq debbugs-gnu-limit nil)
981 (tabulated-list-init-header)
982 (tabulated-list-print)
984 (debbugs-gnu-goto id))))
986 (defun debbugs-gnu-show-blocked-by-reports ()
987 "Display all bug reports this report is blocked by."
989 (let ((id (debbugs-gnu-current-id))
990 (status (debbugs-gnu-current-status)))
991 (if (null (cdr (assq 'blockedby status)))
992 (message "Bug %d is not blocked by any other bug" id)
993 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
995 (defun debbugs-gnu-show-blocking-reports ()
996 "Display all bug reports this report is blocking."
998 (let ((id (debbugs-gnu-current-id))
999 (status (debbugs-gnu-current-status)))
1000 (if (null (cdr (assq 'blocks status)))
1001 (message "Bug %d is not blocking any other bug" id)
1002 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
1004 (defun debbugs-gnu-show-all-blocking-reports ()
1005 "Narrow the display to just the reports that are blocking a release."
1007 (let ((blockers (cdr (assq 'blockedby
1008 (car (debbugs-get-status
1009 debbugs-gnu-blocking-report)))))
1010 (id (debbugs-gnu-current-id t))
1011 (inhibit-read-only t)
1013 (setq debbugs-gnu-limit nil)
1014 (goto-char (point-min))
1016 (setq status (debbugs-gnu-current-status))
1017 (if (not (memq (cdr (assq 'id status)) blockers))
1018 (delete-region (point) (progn (forward-line 1) (point)))
1019 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1022 (debbugs-gnu-goto id))))
1024 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1025 "Only display the bugs matching STRING.
1026 If STATUS-ONLY (the prefix), ignore matches in the From and
1028 (interactive "sNarrow to: \nP")
1029 (let ((id (debbugs-gnu-current-id t))
1030 (inhibit-read-only t)
1032 (setq debbugs-gnu-limit nil)
1033 (if (equal string "")
1034 (debbugs-gnu-toggle-suppress)
1035 (goto-char (point-min))
1037 (setq status (debbugs-gnu-current-status))
1038 (if (and (not (member string (assq 'keywords status)))
1039 (not (equal string (cdr (assq 'severity status))))
1042 string (cdr (assq 'originator status)))))
1044 (not (string-match string (cdr (assq 'subject status))))))
1045 (delete-region (point) (progn (forward-line 1) (point)))
1046 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1049 (debbugs-gnu-goto id)))))
1051 (defun debbugs-gnu-goto (id)
1052 "Go to the line displaying bug ID."
1053 (goto-char (point-min))
1054 (while (and (not (eobp))
1055 (not (equal (debbugs-gnu-current-id t) id)))
1058 (defun debbugs-gnu-toggle-tag ()
1059 "Toggle the local tag of the report in the current line.
1060 If a report is tagged locally, it is presumed to be of little
1065 (let ((inhibit-read-only t)
1066 (id (debbugs-gnu-current-id)))
1067 (if (memq id debbugs-gnu-local-tags)
1069 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1070 (put-text-property (point) (+ (point) 5) 'face 'default))
1071 (add-to-list 'debbugs-gnu-local-tags id)
1073 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1074 'face 'debbugs-gnu-tagged))
1075 (debbugs-gnu--update-tag-face id)))
1076 (debbugs-gnu-dump-persistency-file))
1078 (defun debbugs-gnu--update-tag-face (id)
1079 (dolist (entry tabulated-list-entries)
1080 (when (equal (cdr (assq 'id (car entry))) id)
1081 (aset (cadr entry) 0
1085 ;; Mark tagged bugs.
1086 (if (memq id debbugs-gnu-local-tags)
1090 (defun debbugs-gnu-toggle-suppress ()
1091 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1093 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1094 (tabulated-list-init-header)
1095 (tabulated-list-print))
1097 (defvar debbugs-gnu-bug-number nil)
1098 (defvar debbugs-gnu-subject nil)
1100 (defun debbugs-gnu-current-id (&optional noerror)
1101 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1103 (error "No bug on the current line"))))
1105 (defun debbugs-gnu-current-status ()
1106 (get-text-property (line-beginning-position) 'tabulated-list-id))
1108 (defun debbugs-gnu-display-status (query filter status)
1109 "Display the query, filter and status of the report on the current line."
1110 (interactive (list debbugs-gnu-local-query
1111 debbugs-gnu-local-filter
1112 (debbugs-gnu-current-status)))
1113 (switch-to-buffer "*Bug Status*")
1114 (let ((inhibit-read-only t))
1117 (insert ";; Query\n")
1118 (pp query (current-buffer))
1121 (insert ";; Filter\n")
1122 (pp filter (current-buffer))
1125 (insert ";; Status\n")
1126 (pp status (current-buffer)))
1127 (goto-char (point-min)))
1128 (set-buffer-modified-p nil)
1131 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1132 "Read email exchange for debbugs bug ID.
1133 STATUS is the bug's status list.
1134 MERGED is the list of bugs merged with this one."
1135 (let* ((mbox-dir (make-temp-file "debbugs" t))
1136 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1137 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1139 ;; Download messages of all the merged bug reports and append them
1140 ;; to the mailbox of the requested bug.
1142 (dolist (bugno merged)
1143 (let ((fn (make-temp-file "url")))
1144 (debbugs-get-mbox bugno 'mboxmaint fn)
1145 (rmail-get-new-mail fn)
1147 ;; Remove the 'unseen' attribute from all the messages we've
1148 ;; just read, so that all of them appear in the summary with
1150 (while (< rmail-current-message rmail-total-messages)
1151 (rmail-show-message (1+ rmail-current-message))))))
1152 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1153 (set (make-local-variable 'debbugs-gnu-subject)
1154 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1156 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1157 (set-window-text-height nil 10)
1159 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1160 (rmail-show-message 1)))
1162 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1163 "Read email exchange for debbugs bug ID.
1164 STATUS is the bug's status list.
1165 MERGED is the list of bugs merged with this one."
1167 (setq gnus-suppress-duplicates t
1168 gnus-save-duplicate-list t)
1170 (gnus-read-ephemeral-emacs-bug-group
1171 (cons id (if (listp merged) merged (list merged)))
1172 (cons (current-buffer)
1173 (current-window-configuration)))
1174 (with-current-buffer (window-buffer (selected-window))
1175 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1176 (set (make-local-variable 'debbugs-gnu-subject)
1177 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1178 (debbugs-gnu-summary-mode 1)))
1180 (defun debbugs-gnu-select-report ()
1181 "Select the report on the current line."
1183 ;; We open the report messages.
1184 (let* ((status (debbugs-gnu-current-status))
1185 (id (cdr (assq 'id status)))
1186 (merged (cdr (assq 'mergedwith status))))
1187 (setq merged (if (listp merged) merged (list merged)))
1190 (message "No bug report on the current line"))
1191 ((eq debbugs-gnu-mail-backend 'rmail)
1192 (debbugs-read-emacs-bug-with-rmail id status merged))
1193 ((eq debbugs-gnu-mail-backend 'gnus)
1194 (debbugs-read-emacs-bug-with-gnus id status merged))
1195 (t (error "No valid mail backend specified")))))
1197 (defvar debbugs-gnu-summary-mode-map
1198 (let ((map (make-sparse-keymap)))
1199 (define-key map "C" 'debbugs-gnu-send-control-message)
1200 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1203 (define-minor-mode debbugs-gnu-summary-mode
1204 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1206 \\{debbugs-gnu-summary-mode-map}"
1207 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1208 (set (make-local-variable 'gnus-posting-styles)
1211 (when (buffer-live-p gnus-article-copy)
1212 (with-current-buffer gnus-article-copy
1213 (set (make-local-variable 'message-prune-recipient-rules)
1214 '((".*@debbugs.*" "emacs-pretest-bug")
1215 (".*@debbugs.*" "bug-gnu-emacs")
1216 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1217 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1218 (set (make-local-variable 'message-alter-recipients-function)
1220 (if (string-match "\\([0-9]+\\)@donarmstrong"
1222 (let ((new (format "%s@debbugs.gnu.org"
1223 (match-string 1 (car address)))))
1226 ;; `gnus-posting-styles' is eval'ed after
1227 ;; `message-simplify-subject'. So we cannot use m-s-s.
1228 (setq subject ,debbugs-gnu-subject))))))))
1230 (defun debbugs-gnu-guess-current-id ()
1231 "Guess the ID based on \"#23\"."
1235 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1237 (goto-char (point-min))
1238 (re-search-forward "#\\([0-9]+\\)" nil t)))
1239 (string-to-number (match-string 1)))))
1241 (defvar debbugs-gnu-send-mail-function nil
1242 "A function to send control messages from debbugs.")
1244 (defun debbugs-gnu-send-control-message (message &optional reverse)
1245 "Send a control message for the current bug report.
1246 You can set the severity or add a tag, or close the report. If
1247 you use the special \"done\" MESSAGE, the report will be marked as
1248 fixed, and then closed.
1250 If given a prefix, and given a tag to set, the tag will be
1253 (list (completing-read
1255 '("serious" "important" "normal" "minor" "wishlist"
1256 "done" "donenotabug" "donewontfix" "doneunreproducible"
1257 "unarchive" "unmerge" "reopen" "close"
1258 "merge" "forcemerge"
1264 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1265 "pending" "help" "security" "confirmed"
1268 current-prefix-arg))
1269 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1270 (debbugs-gnu-guess-current-id)
1271 (debbugs-gnu-current-id)))
1273 (when (member message '("close" "done"))
1277 ;; Emacs development versions.
1279 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1281 (match-string 1 emacs-version)
1282 (1+ (string-to-number (match-string 2 emacs-version)))))
1283 ;; Emacs release versions.
1285 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1287 (match-string 1 emacs-version)
1288 (match-string 2 emacs-version)))
1289 (t emacs-version)))))
1290 (status (debbugs-gnu-current-status)))
1292 (insert "To: control@debbugs.gnu.org\n"
1293 "From: " (message-make-from) "\n"
1294 (format "Subject: control message for bug #%d\n" id)
1295 mail-header-separator
1298 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1299 (format "%s %d\n" message id))
1300 ((member message '("merge" "forcemerge"))
1301 (format "%s %d %s\n" message id
1302 (read-string "Merge with bug #: ")))
1303 ((member message '("block" "unblock"))
1305 "%s %d by %s\n" message id
1308 (completing-read-multiple
1309 (format "%s with bug(s) #: " (capitalize message))
1310 (if (equal message "unblock")
1311 (mapcar 'number-to-string
1312 (cdr (assq 'blockedby status))))
1313 nil (and (equal message "unblock") status))
1315 ((equal message "owner")
1316 (format "owner %d !\n" id))
1317 ((equal message "retitle")
1318 (format "retitle %d %s\n" id (read-string "New title: ")))
1319 ((equal message "reassign")
1320 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1321 ((equal message "close")
1322 (format "close %d %s\n" id version))
1323 ((equal message "done")
1324 (format "tags %d fixed\nclose %d %s\n" id id version))
1325 ((member message '("donenotabug" "donewontfix"
1326 "doneunreproducible"))
1327 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1328 ((member message '("serious" "important" "normal"
1329 "minor" "wishlist"))
1330 (format "severity %d %s\n" id message))
1331 ((equal message "invalid")
1332 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1334 ((equal message "usertag")
1335 (format "user %s\nusertag %d %s\n"
1337 "Package name or email address: "
1339 debbugs-gnu-all-packages (list user-mail-address))
1340 nil nil (car debbugs-gnu-default-packages))
1341 id (read-string "User tag: ")))
1343 (format "tags %d%s %s\n"
1344 id (if reverse " -" "")
1346 (funcall (or debbugs-gnu-send-mail-function send-mail-function))
1347 (remhash id debbugs-cache-data)
1349 (message "Control message sent:\n%s"
1350 (buffer-substring-no-properties (point) (1- (point-max)))))))
1352 (defvar debbugs-gnu-usertags-mode-map
1353 (let ((map (make-sparse-keymap)))
1354 (set-keymap-parent map tabulated-list-mode-map)
1355 (define-key map "\r" 'debbugs-gnu-select-usertag)
1356 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1357 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1360 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1361 "Major mode for listing user tags.
1363 All normal editing commands are switched off.
1364 \\<debbugs-gnu-usertags-mode-map>
1366 The following commands are available:
1368 \\{debbugs-gnu-usertags-mode-map}"
1369 (buffer-disable-undo)
1370 (setq truncate-lines t)
1371 (setq buffer-read-only t))
1374 (defun debbugs-gnu-usertags (&rest users)
1375 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1377 (if current-prefix-arg
1378 (completing-read-multiple
1379 "Package name(s) or email address: "
1380 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1381 (mapconcat 'identity debbugs-gnu-default-packages ","))
1382 debbugs-gnu-default-packages))
1385 (let ((inhibit-read-only t)
1386 (debbugs-port "gnu.org")
1387 (buffer-name "*Emacs User Tags*")
1389 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1391 ;; Initialize variables.
1392 (when (and (file-exists-p debbugs-gnu-persistency-file)
1393 (not debbugs-gnu-local-tags))
1395 (insert-file-contents debbugs-gnu-persistency-file)
1396 (eval (read (current-buffer)))))
1399 (when (get-buffer buffer-name)
1400 (kill-buffer buffer-name))
1401 (switch-to-buffer (get-buffer-create buffer-name))
1402 (debbugs-gnu-usertags-mode)
1403 (setq tabulated-list-format `[("User" ,user-tab-length t)
1405 (setq tabulated-list-sort-key (cons "User" nil))
1406 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1408 ;; Retrieve user tags.
1409 (dolist (user users)
1410 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1412 'tabulated-list-entries
1413 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1414 `((("tagged") (,user) nil nil (,tag))
1415 ,(vector (propertize user 'mouse-face 'highlight)
1416 (propertize tag 'mouse-face 'highlight)))
1420 (when debbugs-gnu-local-tags
1422 'tabulated-list-entries
1425 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1428 (tabulated-list-init-header)
1429 (tabulated-list-print)
1431 (set-buffer-modified-p nil)
1432 (goto-char (point-min)))))
1434 (defun debbugs-gnu-select-usertag ()
1435 "Select the user tag on the current line."
1437 ;; We open the bug reports.
1438 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1439 (when args (apply 'debbugs-gnu args))))
1442 (defun debbugs-gnu-bugs (&rest bugs)
1443 "List all BUGS, a list of bug numbers."
1445 (mapcar 'string-to-number
1446 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1448 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1449 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1450 ;; We do not suppress bugs requested explicitely.
1451 (setq debbugs-gnu-current-suppress nil)
1454 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1455 "The directory where the main source tree lives.")
1457 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1458 "The directory where the previous source tree lives.")
1460 (defun debbugs-gnu-apply-patch (&optional branch)
1461 "Apply the patch from the current message.
1462 If given a prefix, patch in the branch directory instead."
1464 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1465 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1466 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1467 (let ((rej "/tmp/debbugs-gnu.rej")
1468 (output-buffer (get-buffer-create "*debbugs patch*"))
1470 debbugs-gnu-branch-directory
1471 debbugs-gnu-trunk-directory))
1472 (patch-buffers nil))
1473 (when (file-exists-p rej)
1475 (with-current-buffer output-buffer
1477 (gnus-summary-select-article nil t)
1478 ;; The patches are either in MIME attachements or the main article
1479 ;; buffer. Determine which.
1480 (gnus-with-article-buffer
1481 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1482 (when (string-match "diff\\|patch\\|plain" (mm-handle-media-type handle))
1483 (push (cons (mm-handle-encoding handle)
1484 (mm-handle-buffer handle))
1486 (unless patch-buffers
1487 (gnus-summary-show-article 'raw)
1488 (article-decode-charset)
1489 (push (cons nil gnus-article-buffer) patch-buffers))
1490 (dolist (elem patch-buffers)
1491 (with-current-buffer (generate-new-buffer "*debbugs input patch*")
1492 (insert-buffer-substring (cdr elem))
1493 (cond ((eq (car elem) 'base64)
1494 (base64-decode-region (point-min) (point-max)))
1495 ((eq (car elem) 'quoted-printable)
1496 (quoted-printable-decode-region (point-min) (point-max))))
1497 (debbugs-gnu-fix-patch dir)
1498 (call-process-region (point-min) (point-max)
1499 "patch" nil output-buffer nil
1500 "-r" rej "--no-backup-if-mismatch"
1502 "-d" (expand-file-name dir)
1504 (set-buffer output-buffer)
1505 (when (file-exists-p rej)
1506 (goto-char (point-max))
1507 (insert-file-contents-literally rej))
1508 (goto-char (point-max))
1509 (save-some-buffers t)
1511 (mapc 'kill-process compilation-in-progress)
1512 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1514 (vc-dir-hide-up-to-date)
1515 (goto-char (point-min))
1518 ;; All these commands are asynchronous, so just wait a bit. This
1519 ;; should be done properly a different way.
1521 ;; We've now done everything, so arrange the windows we need to see.
1522 (delete-other-windows)
1523 (switch-to-buffer output-buffer)
1527 (switch-to-buffer "*compilation*")
1528 (goto-char (point-max))
1530 (switch-to-buffer "*vc-diff*")
1531 (goto-char (point-min))))
1533 (defun debbugs-gnu-fix-patch (dir)
1534 (setq dir (directory-file-name (expand-file-name dir)))
1535 (goto-char (point-min))
1536 (while (re-search-forward diff-file-header-re nil t)
1537 (goto-char (match-beginning 0))
1538 (let ((target-name (car (diff-hunk-file-names))))
1539 (when (and target-name
1540 (or (not (string-match "/" target-name))
1541 (and (string-match "^[ab]/" target-name)
1543 (expand-file-name (substring target-name 2)
1545 (file-exists-p (expand-file-name target-name dir))))
1546 ;; We have a simple patch that refers to a file somewhere in the
1548 (when-let ((files (directory-files-recursively
1550 (concat "^" (regexp-quote
1551 (file-name-nondirectory target-name))
1553 (when (re-search-forward (concat "^[+]+ "
1554 (regexp-quote target-name)
1557 (replace-match (concat "+++ a"
1558 (substring (car files) (length dir))
1563 (defun debbugs-gnu-find-contributor (string)
1564 "Search through ChangeLogs to find contributors."
1565 (interactive "sContributor match: ")
1567 (match (concat "^[0-9].*" string)))
1568 (dolist (file (directory-files-recursively
1569 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1571 (when (file-exists-p file)
1572 (insert-file-contents file))
1573 (goto-char (point-min))
1574 (while (and (re-search-forward match nil t)
1575 (not (looking-at ".*tiny change")))
1577 (message "%s is a contributor %d times" string found)
1580 (defvar debbugs-gnu-patch-subject nil)
1582 (defun debbugs-gnu-insert-changelog ()
1583 "Add a ChangeLog from a recently applied patch from a third party."
1585 (let (from subject patch-subject changelog)
1586 (gnus-with-article-buffer
1588 (goto-char (point-min))
1589 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1590 subject (gnus-fetch-field "subject"))
1591 ;; If it's a patch formatted the right way, extract that data.
1592 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1593 (when (string-match "diff\\|patch\\|plain"
1594 (mm-handle-media-type handle))
1596 (insert-buffer-substring (mm-handle-buffer handle))
1597 (cond ((eq (mm-handle-encoding handle) 'base64)
1598 (base64-decode-region (point-min) (point-max)))
1599 ((eq (mm-handle-encoding handle) 'quoted-printable)
1600 (quoted-printable-decode-region (point-min) (point-max))))
1602 (or (gnus-fetch-field "subject") patch-subject))
1603 (goto-char (point-min))
1604 (when (re-search-forward "^[*] " nil t)
1605 (let ((start (match-beginning 0)))
1606 (while (and (not (eobp))
1607 (not (looking-at "---")))
1609 (setq changelog (buffer-substring
1610 start (line-end-position 0)))))))))
1611 (let ((add-log-full-name (car from))
1612 (add-log-mailing-address (cadr from)))
1613 (add-change-log-entry-other-window)
1615 (setq-local debbugs-gnu-patch-subject patch-subject))
1617 (delete-region (line-beginning-position) (point-max))
1619 (narrow-to-region (point) (point))
1621 (indent-region (point-min) (point-max))))
1622 (let ((point (point)))
1623 (when (string-match "\\(bug#[0-9]+\\)" subject)
1624 (insert " (" (match-string 1 subject) ")."))
1625 (when (zerop (debbugs-gnu-find-contributor
1626 (let ((bits (split-string (car from))))
1628 ((>= (length bits) 2)
1629 (format "%s.*%s" (car bits) (car (last bits))))
1630 ((= (length bits) 1)
1632 ;; Fall back on the email address.
1635 (goto-char (point-max))
1639 (insert " Copyright-paperwork-exempt: yes"))
1640 (goto-char point)))))
1642 (defvar debbugs-gnu-lisp-mode-map
1643 (let ((map (make-sparse-keymap)))
1644 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1647 (define-minor-mode debbugs-gnu-lisp-mode
1648 "Minor mode for providing a debbugs interface in Lisp buffers.
1649 \\{debbugs-gnu-lisp-mode-map}"
1650 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1652 (defvar debbugs-gnu-diff-mode-map
1653 (let ((map (make-sparse-keymap)))
1654 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1657 (define-minor-mode debbugs-gnu-diff-mode
1658 "Minor mode for providing a debbugs interface in diff buffers.
1659 \\{debbugs-gnu-diff-mode-map}"
1660 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1662 (defun debbugs-gnu-diff-select ()
1663 "Select the diff under point."
1665 (delete-other-windows)
1668 (defvar debbugs-gnu-change-mode-map
1669 (let ((map (make-sparse-keymap)))
1670 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1673 (define-minor-mode debbugs-gnu-change-mode
1674 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1675 \\{debbugs-gnu-change-mode-map}"
1676 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1678 (defun debbugs-gnu-change-checkin ()
1679 "Prepare checking in the current changes."
1681 (save-some-buffers t)
1682 (when (get-buffer "*vc-dir*")
1683 (kill-buffer (get-buffer "*vc-dir*")))
1684 (let ((patch-subject debbugs-gnu-patch-subject))
1685 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1686 (if (equal (cl-subseq default-directory 0 (length trunk))
1688 (vc-dir debbugs-gnu-trunk-directory)
1689 (vc-dir debbugs-gnu-branch-directory)))
1690 (goto-char (point-min))
1691 (while (not (search-forward "edited" nil t))
1694 (while (search-forward "edited" nil t)
1696 (beginning-of-line))
1698 (vc-next-action nil)
1699 (delete-region (point-min) (point-max))
1700 (log-edit-insert-changelog t)
1701 (delete-other-windows)
1704 (switch-to-buffer "*vc-diff*")
1708 (replace-regexp-in-string "^ *\\[PATCH\\] *" "" patch-subject)
1711 (defun debbugs-gnu-save-cache ()
1712 "Save the bugs cache to a file."
1714 (unless debbugs-cache-data
1715 (error "No data to cache"))
1716 (unless (file-exists-p "~/.emacs.d/debbugs-cache")
1717 (make-directory "~/.emacs.d/debbugs-cache" t))
1718 (let ((coding-system-for-write 'utf-8))
1719 (with-temp-file "~/.emacs.d/debbugs-cache/list"
1720 (prin1 debbugs-cache-data (current-buffer)))))
1722 (provide 'debbugs-gnu)
1726 ;; * Another random thought - is it possible to implement some local
1727 ;; cache, so only changed bugs are fetched? Glenn Morris.
1729 ;;; debbugs-gnu.el ends here