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 (defcustom debbugs-gnu-suppress-closed t
209 "If non-nil, don't show closed bugs."
214 (defconst debbugs-gnu-all-severities
215 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
216 "*List of all possible severities.")
218 (defcustom debbugs-gnu-default-packages '("emacs")
219 "*The list of packages to be searched for."
220 ;; <http://debbugs.gnu.org/Packages.html>
221 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
223 :type '(set (const "adns")
229 (const "debbugs.gnu.org")
232 (const "emacs-xwidgets")
249 (defconst debbugs-gnu-all-packages
250 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
251 "*List of all possible package names.")
253 (defcustom debbugs-gnu-default-suppress-bugs
254 '((pending . "done"))
255 "*A list of specs for bugs to be suppressed.
256 An element of this list is a cons cell \(KEY . REGEXP\), with key
257 being returned by `debbugs-get-status', and REGEXP a regular
258 expression matching the corresponding value, a string. Showing
259 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
261 :type '(alist :key-type symbol :value-type regexp)
264 (defcustom debbugs-gnu-mail-backend 'gnus
265 "*The email backend to use for reading bug report email exchange.
266 If this is 'gnus, the default, use Gnus.
267 If this is 'rmail, use Rmail instead."
269 :type '(choice (const :tag "Use Gnus" 'gnus)
270 (const :tag "Use Rmail" 'rmail))
273 (defface debbugs-gnu-archived '((t (:inverse-video t)))
274 "Face for archived bug reports.")
276 (defface debbugs-gnu-new '((t (:foreground "red")))
277 "Face for new reports that nobody has answered.")
279 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
280 "Face for reports that have been modified recently.")
282 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
283 "Face for reports that are pending.")
285 (defface debbugs-gnu-stale '((t (:foreground "orange")))
286 "Face for reports that have not been touched for two weeks.")
288 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
289 "Face for closed bug reports.")
291 (defface debbugs-gnu-tagged '((t (:foreground "red")))
292 "Face for reports that have been tagged locally.")
294 (defvar debbugs-gnu-local-tags nil
295 "List of bug numbers tagged locally, and kept persistent.")
297 (defvar debbugs-gnu-persistency-file
298 (expand-file-name (locate-user-emacs-file "debbugs"))
299 "File name of a persistency store for debbugs variables")
301 (defun debbugs-gnu-dump-persistency-file ()
302 "Function to store debbugs variables persistently."
303 (with-temp-file debbugs-gnu-persistency-file
305 ";; -*- emacs-lisp -*-\n"
306 ";; Debbugs tags connection history. Don't change this file.\n\n"
307 (format "(setq debbugs-gnu-local-tags '%S)"
308 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
310 (defvar debbugs-gnu-current-query nil
311 "The query object of the current search.
312 It will be applied server-side, when calling `debbugs-get-bugs'.
313 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
315 (defvar debbugs-gnu-current-filter nil
316 "The filter object for the current search.
317 It will be applied client-side, when parsing the results of
318 `debbugs-get-status'. It has a similar format as
319 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
320 a date, value is the cons cell \(BEFORE . AFTER\).")
322 (defvar debbugs-gnu-current-suppress nil
323 "Whether bugs shall be suppressed.
324 The specification which bugs shall be suppressed is taken from
325 `debbugs-gnu-default-suppress-bugs'.")
327 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
328 "Return a string read from the minibuffer.
329 Derived from `calendar-read'."
330 (let ((value (read-string prompt initial-contents)))
331 (while (not (funcall acceptable value))
332 (setq value (read-string prompt initial-contents)))
335 (defconst debbugs-gnu-phrase-prompt
337 "Enter search phrase: "
339 The search phrase contains words to be searched for, combined by
340 operators like AND, ANDNOT and OR. If there is no operator
341 between the words, AND is used by default. The phrase can also
342 be empty, in this case only the following attributes are used for
346 (defun debbugs-gnu-patches ()
347 "List the bug reports that have been marked as containing a patch."
349 (debbugs-gnu nil '("emacs") nil nil "patch"))
352 (defun debbugs-gnu-search ()
353 "Search for Emacs bugs interactively.
354 Search arguments are requested interactively. The \"search
355 phrase\" is used for full text search in the bugs database.
356 Further key-value pairs are requested until an empty key is
357 returned. If a key cannot be queried by a SOAP request, it is
358 marked as \"client-side filter\"."
362 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
363 key val1 val2 phrase severities packages archivedp)
365 ;; Check for the phrase.
366 (setq phrase (read-string debbugs-gnu-phrase-prompt))
367 (if (zerop (length phrase))
369 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
370 ;; We suppress closed bugs if there is no phrase.
371 (setq debbugs-gnu-current-suppress
372 (if (not debbugs-gnu-suppress-closed)
376 ;; The other queries.
379 (setq key (completing-read
382 '("severity" "package" "tags" "submitter" "date"
384 '("severity" "package" "archive" "src" "tag"
385 "owner" "submitter" "maint" "correspondent"
386 "date" "log_modified" "last_modified"
387 "found_date" "fixed_date" "unarchived"
388 "subject" "done" "forwarded" "msgid" "summary"))
391 ;; Server-side queries.
392 ((equal key "severity")
395 (completing-read-multiple
396 "Enter severities: " debbugs-gnu-all-severities nil t
397 (mapconcat 'identity debbugs-gnu-default-severities ","))))
399 ((equal key "package")
402 (completing-read-multiple
403 "Enter packages: " debbugs-gnu-all-packages nil t
404 (mapconcat 'identity debbugs-gnu-default-packages ","))))
406 ((equal key "archive")
407 ;; We simplify, by assuming just archived bugs are requested.
410 ((member key '("src" "tag" "tags"))
411 (setq val1 (read-string (format "Enter %s: " key)))
412 (when (not (zerop (length val1)))
414 'debbugs-gnu-current-query (cons (intern key) val1))))
416 ((member key '("owner" "submitter" "maint" "correspondent"))
417 (setq val1 (read-string "Enter email address: "))
418 (when (not (zerop (length val1)))
420 'debbugs-gnu-current-query (cons (intern key) val1))))
422 ((equal key "status")
425 (completing-read "Enter status: " '("done" "forwarded" "open")))
426 (when (not (zerop (length val1)))
428 'debbugs-gnu-current-query (cons (intern key) val1))))
430 ;; Client-side filters.
431 ((member key '("date" "log_modified" "last_modified"
432 "found_date" "fixed_date" "unarchived"))
434 (debbugs-gnu-calendar-read
435 (format "Enter %s before YYYY-MM-DD%s: "
436 key (if phrase "" " (client-side filter)"))
438 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
439 (if (string-match date-format val1)
444 (string-to-number (match-string 3 val1))
445 (string-to-number (match-string 2 val1))
446 (string-to-number (match-string 1 val1))))))
449 (debbugs-gnu-calendar-read
450 (format "Enter %s after YYYY-MM-DD%s: "
451 key (if phrase "" " (client-side filter)"))
453 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
454 (if (string-match date-format val2)
459 (string-to-number (match-string 3 val2))
460 (string-to-number (match-string 2 val2))
461 (string-to-number (match-string 1 val2))))))
466 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
467 (cons (intern key) (cons val1 val2)))))
469 ((not (zerop (length key)))
472 (if phrase 'read-string 'read-regexp)
474 key (if phrase ": " " (client-side filter)"))))
475 (when (not (zerop (length val1)))
478 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
479 (cons (intern key) val1))))
482 (t (throw :finished nil)))))
485 (debbugs-gnu severities packages archivedp))))
488 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
489 "List all outstanding bugs."
491 (let (severities archivedp)
494 (completing-read-multiple
495 "Severities: " debbugs-gnu-all-severities nil t
496 (mapconcat 'identity debbugs-gnu-default-severities ",")))
497 ;; The next parameters are asked only when there is a prefix.
498 (if current-prefix-arg
499 (completing-read-multiple
500 "Packages: " debbugs-gnu-all-packages nil t
501 (mapconcat 'identity debbugs-gnu-default-packages ","))
502 debbugs-gnu-default-packages)
503 (when current-prefix-arg
504 (setq archivedp (y-or-n-p "Show archived bugs?")))
505 (when (and current-prefix-arg (not archivedp))
506 (y-or-n-p "Suppress unwanted bugs?"))
507 ;; This one must be asked for severity "tagged".
508 (when (member "tagged" severities)
509 (split-string (read-string "User tag(s): ") "," t)))))
511 ;; Initialize variables.
512 (when (and (file-exists-p debbugs-gnu-persistency-file)
513 (not debbugs-gnu-local-tags))
515 (insert-file-contents debbugs-gnu-persistency-file)
516 (eval (read (current-buffer)))))
517 ;; Per default, we suppress retrieved unwanted bugs.
518 (when (and (called-interactively-p 'any)
519 debbugs-gnu-suppress-closed)
520 (setq debbugs-gnu-current-suppress t))
523 (dolist (severity (if (consp severities) severities (list severities)))
524 (when (not (zerop (length severity)))
525 (when (string-equal severity "tagged")
526 (setq debbugs-gnu-current-suppress nil))
527 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
528 (dolist (package (if (consp packages) packages (list packages)))
529 (when (not (zerop (length package)))
530 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
532 (setq debbugs-gnu-current-suppress nil)
533 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
535 (setq debbugs-gnu-current-suppress t)
536 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
537 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
538 (dolist (tag (if (consp tags) tags (list tags)))
539 (when (not (zerop (length tag)))
540 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
543 (debbugs-gnu-show-reports)
545 ;; Reset query, filter and suppress.
546 (setq debbugs-gnu-current-query nil
547 debbugs-gnu-current-filter nil
548 debbugs-gnu-current-suppress nil))
550 (defun debbugs-gnu-get-bugs (query)
551 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
552 (let* ((debbugs-port "gnu.org")
553 (bugs (assoc 'bugs query))
554 (tags (assoc 'tag query))
555 (local-tags (and (member '(severity . "tagged") query) (not tags)))
556 (phrase (assoc 'phrase query))
558 ;; Compile query arguments.
559 (unless (or query tags)
560 (dolist (elt debbugs-gnu-default-packages)
561 (setq args (append args (list :package elt)))))
563 (unless (equal elt '(severity . "tagged"))
569 ((eq (car elt) 'phrase)
570 (list (list :phrase (cdr elt))))
571 ((eq (car elt) 'date)
572 (list (list :date (cddr elt) (cadr elt)
575 (list (list (intern (concat ":" (symbol-name (car elt))))
576 (cdr elt) :operator "ISTRINC"))))
577 (list (intern (concat ":" (symbol-name (car elt))))
581 ;; If the query is just a list of bug numbers, we return them.
583 ;; If the query contains the pseudo-severity "tagged", we return
584 ;; just the local tagged bugs.
585 (local-tags (copy-sequence debbugs-gnu-local-tags))
586 ;; A full text query.
589 (lambda (x) (cdr (assoc "id" x)))
590 (apply 'debbugs-search-est args)))
591 ;; Otherwise, we retrieve the bugs from the server.
592 (t (apply 'debbugs-get-bugs args)))))
594 (defun debbugs-gnu-show-reports (&optional offline)
596 If OFFLINE is non-nil, the query is not sent to the server. Bugs
597 are taken from the cache instead."
598 (let ((inhibit-read-only t)
599 (buffer-name "*Emacs Bugs*"))
600 ;; The tabulated mode sets several local variables. We must get
602 (when (get-buffer buffer-name)
603 (kill-buffer buffer-name))
604 (switch-to-buffer (get-buffer-create buffer-name))
607 ;; Print bug reports.
609 (let ((debbugs-cache-expiry (if offline nil debbugs-cache-expiry))
611 (apply 'debbugs-get-status
614 (maphash (lambda (key _elem)
618 (debbugs-gnu-get-bugs debbugs-gnu-local-query)))))
619 (let* ((id (cdr (assq 'id status)))
623 (cons (cdr (assq 'severity status))
624 (cdr (assq 'keywords status)))
626 (address (if (cdr (assq 'originator status))
627 (mail-header-parse-address
628 (decode-coding-string (cdr (assq 'originator status))
630 (owner (if (cdr (assq 'owner status))
631 (car (mail-header-parse-address
632 (decode-coding-string (cdr (assq 'owner status))
634 (subject (if (cdr (assq 'subject status))
635 (decode-coding-string (cdr (assq 'subject status))
638 (unless (equal (cdr (assq 'pending status)) "pending")
639 (setq words (concat words "," (cdr (assq 'pending status)))))
640 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
642 (setq words (concat words "," (mapconcat 'identity packages ",")))))
643 (when (setq merged (cdr (assq 'mergedwith status)))
644 (setq words (format "%s,%s"
647 (mapconcat 'number-to-string merged ","))
649 (when (or (not merged)
650 (not (let ((found nil))
651 (dolist (id (if (listp merged)
654 (dolist (entry tabulated-list-entries)
655 (when (equal id (cdr (assq 'id (car entry))))
659 'tabulated-list-entries
667 (if (memq id debbugs-gnu-local-tags)
671 ;; Mark status and age.
675 ((cdr (assq 'archived status))
676 'debbugs-gnu-archived)
677 ((equal (cdr (assq 'pending status)) "done")
679 ((member "pending" (cdr (assq 'keywords status)))
680 'debbugs-gnu-pending)
681 ((= (cdr (assq 'date status))
682 (cdr (assq 'log_modified status)))
685 (cdr (assq 'log_modified status)))
687 'debbugs-gnu-handled)
689 'debbugs-gnu-stale)))
691 ;; Prefer the name over the address.
696 ;; Mark own submitted bugs.
697 (if (and (stringp (car address))
698 (string-equal (car address) user-mail-address))
705 (if (and (stringp owner)
706 (string-equal owner user-mail-address))
711 (tabulated-list-init-header)
712 (tabulated-list-print)
714 (set-buffer-modified-p nil)
715 (goto-char (point-min))))
717 (defun debbugs-gnu-print-entry (list-id cols)
718 "Insert a debbugs entry at point.
719 Used instead of `tabulated-list-print-entry'."
724 (id-length (nth 1 (aref tabulated-list-format 0)))
725 (state (aref cols 1))
726 (state-length (nth 1 (aref tabulated-list-format 1)))
727 (submitter (aref cols 2))
728 (submitter-length (nth 1 (aref tabulated-list-format 2)))
729 (title (aref cols 3))
730 ;; (title-length (nth 1 (aref tabulated-list-format 3)))
733 ;; We may have a narrowing in effect.
734 (or (not debbugs-gnu-limit)
735 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
736 ;; Filter suppressed bugs.
737 (or (not debbugs-gnu-local-suppress)
738 (not (catch :suppress
739 (dolist (check debbugs-gnu-default-suppress-bugs)
743 (or (cdr (assq (car check) list-id)) ""))
744 (throw :suppress t))))))
745 ;; Filter search list.
746 (not (catch :suppress
747 (dolist (check debbugs-gnu-local-filter)
748 (let ((val (cdr (assq (car check) list-id))))
749 (if (stringp (cdr check))
750 ;; Regular expression.
751 (when (not (string-match (cdr check) (or val "")))
754 (when (or (and (numberp (cadr check))
755 (< (cadr check) val))
756 (and (numberp (cddr check))
757 (> (cddr check) val)))
758 (throw :suppress t))))))))
761 (indent-to (- id-length (length id)))
764 (indent-to (setq pos (+ pos id-length 1)) 1)
765 (insert (if (> (length state) state-length)
766 (propertize (substring state 0 state-length)
770 (indent-to (setq pos (+ pos state-length 1)) 1)
771 (insert "[" (if (> (length submitter) (- submitter-length 2))
772 (propertize (substring submitter 0 (- submitter-length 2))
773 'help-echo submitter)
775 (indent-to (+ pos (1- submitter-length)))
778 (indent-to (setq pos (+ pos submitter-length 1)) 1)
779 (insert (propertize title 'help-echo title))
783 `(tabulated-list-id ,list-id mouse-face highlight))
786 (defun debbugs-gnu-menu-map-emacs-enabled ()
787 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
788 (or ;; No package discriminator has been used.
789 (not (assq 'package debbugs-gnu-local-query))
790 ;; Package "emacs" has been selected.
791 (member '(package . "emacs") debbugs-gnu-local-query)))
793 (defconst debbugs-gnu-bug-triage-file
794 (expand-file-name "../admin/notes/bug-triage" data-directory)
795 "The \"bug-triage\" file.")
797 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
798 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
799 (and (debbugs-gnu-menu-map-emacs-enabled)
800 (stringp debbugs-gnu-bug-triage-file)
801 (file-readable-p debbugs-gnu-bug-triage-file)))
803 (defun debbugs-gnu-view-bug-triage ()
804 "Show \"bug-triage\" file."
806 (view-file debbugs-gnu-bug-triage-file))
808 (defvar debbugs-gnu-mode-map
809 (let ((map (make-sparse-keymap))
810 (menu-map (make-sparse-keymap)))
811 (set-keymap-parent map tabulated-list-mode-map)
812 (define-key map "\r" 'debbugs-gnu-select-report)
813 (define-key map [mouse-1] 'debbugs-gnu-select-report)
814 (define-key map [mouse-2] 'debbugs-gnu-select-report)
815 (define-key map "g" 'debbugs-gnu-rescan)
816 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
817 (define-key map "C" 'debbugs-gnu-send-control-message)
819 (define-key map "s" 'debbugs-gnu-toggle-sort)
820 (define-key map "t" 'debbugs-gnu-toggle-tag)
821 (define-key map "x" 'debbugs-gnu-toggle-suppress)
822 (define-key map "/" 'debbugs-gnu-narrow-to-status)
823 (define-key map "w" 'debbugs-gnu-widen)
825 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
826 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
827 (define-key map "d" 'debbugs-gnu-display-status)
829 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
830 (define-key menu-map [debbugs-gnu-select-report]
831 '(menu-item "Show Reports" debbugs-gnu-select-report
832 :help "Show all reports belonging to this bug"))
833 (define-key-after menu-map [debbugs-gnu-rescan]
834 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
835 :help "Refresh bug list")
836 'debbugs-gnu-select-report)
837 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
838 '(menu-item "Show Release Blocking Bugs"
839 debbugs-gnu-show-all-blocking-reports
840 :enable (debbugs-gnu-menu-map-emacs-enabled)
841 :help "Show all bugs blocking next Emacs release")
843 (define-key-after menu-map [debbugs-gnu-send-control-message]
844 '(menu-item "Send Control Message"
845 debbugs-gnu-send-control-message
846 :help "Send control message to debbugs.gnu.org")
847 'debbugs-gnu-show-all-blocking-reports)
849 (define-key-after menu-map [debbugs-gnu-separator1]
850 '(menu-item "--") 'debbugs-gnu-send-control-message)
851 (define-key-after menu-map [debbugs-gnu-search]
852 '(menu-item "Search Bugs" debbugs-gnu-search
853 :help "Search bugs on debbugs.gnu.org")
854 'debbugs-gnu-separator1)
855 (define-key-after menu-map [debbugs-gnu]
856 '(menu-item "Retrieve Bugs" debbugs-gnu
857 :help "Retrieve bugs from debbugs.gnu.org")
859 (define-key-after menu-map [debbugs-gnu-bugs]
860 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
861 :help "Retrieve selected bugs from debbugs.gnu.org")
864 (define-key-after menu-map [debbugs-gnu-separator2]
865 '(menu-item "--") 'debbugs-gnu-bugs)
866 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
867 '(menu-item "Describe Bug Triage Procedure"
868 debbugs-gnu-view-bug-triage
869 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
870 :help "Show procedure of triaging bugs")
871 'debbugs-gnu-separator2)
874 (defun debbugs-gnu-rescan ()
875 "Rescan the current set of bug reports."
877 (let ((id (debbugs-gnu-current-id))
878 (debbugs-gnu-current-query debbugs-gnu-local-query)
879 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
880 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
881 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
882 (debbugs-gnu-show-reports)
884 (debbugs-gnu-goto id))))
886 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
887 "Major mode for listing bug reports.
889 All normal editing commands are switched off.
890 \\<debbugs-gnu-mode-map>
892 The following commands are available:
894 \\{debbugs-gnu-mode-map}"
895 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
896 (set (make-local-variable 'debbugs-gnu-limit) nil)
897 (set (make-local-variable 'debbugs-gnu-local-query)
898 debbugs-gnu-current-query)
899 (set (make-local-variable 'debbugs-gnu-local-filter)
900 debbugs-gnu-current-filter)
901 (set (make-local-variable 'debbugs-gnu-local-suppress)
902 debbugs-gnu-current-suppress)
903 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
904 ("State" 20 debbugs-gnu-sort-state)
906 ("Title" 10 debbugs-gnu-sort-title)])
907 (setq tabulated-list-sort-key (cons "Id" nil))
908 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
909 (buffer-disable-undo)
910 (setq truncate-lines t)
911 (setq buffer-read-only t))
913 (defun debbugs-gnu-sort-id (s1 s2)
914 (> (cdr (assq 'id (car s1)))
915 (cdr (assq 'id (car s2)))))
917 (defconst debbugs-gnu-state-preference
918 '((debbugs-gnu-new . 1)
919 (debbugs-gnu-stale . 2)
920 (debbugs-gnu-handled . 3)
921 (debbugs-gnu-done . 4)
922 (debbugs-gnu-pending . 5)))
924 (defun debbugs-gnu-get-state-preference (face-string)
925 (or (cdr (assq (get-text-property 0 'face face-string)
926 debbugs-gnu-state-preference))
929 (defconst debbugs-gnu-severity-preference
936 (defun debbugs-gnu-get-severity-preference (state)
937 (or (cdr (assoc (cdr (assq 'severity state))
938 debbugs-gnu-severity-preference))
941 (defun debbugs-gnu-sort-state (s1 s2)
942 (let ((id1 (cdr (assq 'id (car s1))))
943 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
944 (id2 (cdr (assq 'id (car s2))))
945 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
947 ;; Tagged bugs go to the end.
948 ((and (not (memq id1 debbugs-gnu-local-tags))
949 (memq id2 debbugs-gnu-local-tags))
951 ((and (memq id1 debbugs-gnu-local-tags)
952 (not (memq id2 debbugs-gnu-local-tags)))
954 ;; Then, we check the age of the bugs.
959 ;; If they have the same age, we check for severity.
960 ((< (debbugs-gnu-get-severity-preference (car s1))
961 (debbugs-gnu-get-severity-preference (car s2)))
965 (defun debbugs-gnu-sort-title (s1 _s2)
966 (let ((owner (if (cdr (assq 'owner (car s1)))
967 (car (mail-header-parse-address
968 (decode-coding-string (cdr (assq 'owner (car s1)))
971 (string-equal owner user-mail-address))))
973 (defun debbugs-gnu-toggle-sort ()
974 "Toggle sorting by age and by state."
976 (if (eq debbugs-gnu-sort-state 'number)
978 (setq debbugs-gnu-sort-state 'state)
979 (setq tabulated-list-sort-key (cons "Id" nil)))
980 (setq debbugs-gnu-sort-state 'number)
981 (setq tabulated-list-sort-key (cons "State" nil)))
982 (tabulated-list-init-header)
983 (tabulated-list-print))
985 (defun debbugs-gnu-widen ()
986 "Display all the currently selected bug reports."
988 (let ((id (debbugs-gnu-current-id t))
989 (inhibit-read-only t))
990 (setq debbugs-gnu-limit nil)
991 (tabulated-list-init-header)
992 (tabulated-list-print)
994 (debbugs-gnu-goto id))))
996 (defun debbugs-gnu-show-blocked-by-reports ()
997 "Display all bug reports this report is blocked by."
999 (let ((id (debbugs-gnu-current-id))
1000 (status (debbugs-gnu-current-status)))
1001 (if (null (cdr (assq 'blockedby status)))
1002 (message "Bug %d is not blocked by any other bug" id)
1003 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
1005 (defun debbugs-gnu-show-blocking-reports ()
1006 "Display all bug reports this report is blocking."
1008 (let ((id (debbugs-gnu-current-id))
1009 (status (debbugs-gnu-current-status)))
1010 (if (null (cdr (assq 'blocks status)))
1011 (message "Bug %d is not blocking any other bug" id)
1012 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
1014 (defun debbugs-gnu-show-all-blocking-reports ()
1015 "Narrow the display to just the reports that are blocking a release."
1017 (let ((blockers (cdr (assq 'blockedby
1018 (car (debbugs-get-status
1019 debbugs-gnu-blocking-report)))))
1020 (id (debbugs-gnu-current-id t))
1021 (inhibit-read-only t)
1023 (setq debbugs-gnu-limit nil)
1024 (goto-char (point-min))
1026 (setq status (debbugs-gnu-current-status))
1027 (if (not (memq (cdr (assq 'id status)) blockers))
1028 (delete-region (point) (progn (forward-line 1) (point)))
1029 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1032 (debbugs-gnu-goto id))))
1034 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1035 "Only display the bugs matching STRING.
1036 If STATUS-ONLY (the prefix), ignore matches in the From and
1038 (interactive "sNarrow to: \nP")
1039 (let ((id (debbugs-gnu-current-id t))
1040 (inhibit-read-only t)
1042 (setq debbugs-gnu-limit nil)
1043 (if (equal string "")
1044 (debbugs-gnu-toggle-suppress)
1045 (goto-char (point-min))
1047 (setq status (debbugs-gnu-current-status))
1048 (if (and (not (member string (assq 'keywords status)))
1049 (not (equal string (cdr (assq 'severity status))))
1052 string (cdr (assq 'originator status)))))
1054 (not (string-match string (cdr (assq 'subject status))))))
1055 (delete-region (point) (progn (forward-line 1) (point)))
1056 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1059 (debbugs-gnu-goto id)))))
1061 (defun debbugs-gnu-goto (id)
1062 "Go to the line displaying bug ID."
1063 (goto-char (point-min))
1064 (while (and (not (eobp))
1065 (not (equal (debbugs-gnu-current-id t) id)))
1068 (defun debbugs-gnu-toggle-tag ()
1069 "Toggle the local tag of the report in the current line.
1070 If a report is tagged locally, it is presumed to be of little
1075 (let ((inhibit-read-only t)
1076 (id (debbugs-gnu-current-id)))
1077 (if (memq id debbugs-gnu-local-tags)
1079 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1080 (put-text-property (point) (+ (point) 5) 'face 'default))
1081 (add-to-list 'debbugs-gnu-local-tags id)
1083 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1084 'face 'debbugs-gnu-tagged))
1085 (debbugs-gnu--update-tag-face id)))
1086 (debbugs-gnu-dump-persistency-file))
1088 (defun debbugs-gnu--update-tag-face (id)
1089 (dolist (entry tabulated-list-entries)
1090 (when (equal (cdr (assq 'id (car entry))) id)
1091 (aset (cadr entry) 0
1095 ;; Mark tagged bugs.
1096 (if (memq id debbugs-gnu-local-tags)
1100 (defun debbugs-gnu-toggle-suppress ()
1101 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1103 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1104 (tabulated-list-init-header)
1105 (tabulated-list-print))
1107 (defvar debbugs-gnu-bug-number nil)
1108 (defvar debbugs-gnu-subject nil)
1110 (defun debbugs-gnu-current-id (&optional noerror)
1111 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1113 (error "No bug on the current line"))))
1115 (defun debbugs-gnu-current-status ()
1116 (get-text-property (line-beginning-position) 'tabulated-list-id))
1118 (defun debbugs-gnu-display-status (query filter status)
1119 "Display the query, filter and status of the report on the current line."
1120 (interactive (list debbugs-gnu-local-query
1121 debbugs-gnu-local-filter
1122 (debbugs-gnu-current-status)))
1123 (switch-to-buffer "*Bug Status*")
1124 (let ((inhibit-read-only t))
1127 (insert ";; Query\n")
1128 (pp query (current-buffer))
1131 (insert ";; Filter\n")
1132 (pp filter (current-buffer))
1135 (insert ";; Status\n")
1136 (pp status (current-buffer)))
1137 (goto-char (point-min)))
1138 (set-buffer-modified-p nil)
1141 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1142 "Read email exchange for debbugs bug ID.
1143 STATUS is the bug's status list.
1144 MERGED is the list of bugs merged with this one."
1145 (let* ((mbox-dir (make-temp-file "debbugs" t))
1146 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1147 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1149 ;; Download messages of all the merged bug reports and append them
1150 ;; to the mailbox of the requested bug.
1152 (dolist (bugno merged)
1153 (let ((fn (make-temp-file "url")))
1154 (debbugs-get-mbox bugno 'mboxmaint fn)
1155 (rmail-get-new-mail fn)
1157 ;; Remove the 'unseen' attribute from all the messages we've
1158 ;; just read, so that all of them appear in the summary with
1160 (while (< rmail-current-message rmail-total-messages)
1161 (rmail-show-message (1+ rmail-current-message))))))
1162 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1163 (set (make-local-variable 'debbugs-gnu-subject)
1164 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1166 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1167 (set-window-text-height nil 10)
1169 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1170 (rmail-show-message 1)))
1172 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1173 "Read email exchange for debbugs bug ID.
1174 STATUS is the bug's status list.
1175 MERGED is the list of bugs merged with this one."
1177 (setq gnus-suppress-duplicates t
1178 gnus-save-duplicate-list t)
1180 (gnus-read-ephemeral-emacs-bug-group
1181 (cons id (if (listp merged) merged (list merged)))
1182 (cons (current-buffer)
1183 (current-window-configuration)))
1184 (with-current-buffer (window-buffer (selected-window))
1185 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1186 (set (make-local-variable 'debbugs-gnu-subject)
1187 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1188 (debbugs-gnu-summary-mode 1)))
1190 (defun debbugs-gnu-select-report ()
1191 "Select the report on the current line."
1193 ;; We open the report messages.
1194 (let* ((status (debbugs-gnu-current-status))
1195 (id (cdr (assq 'id status)))
1196 (merged (cdr (assq 'mergedwith status))))
1197 (setq merged (if (listp merged) merged (list merged)))
1200 (message "No bug report on the current line"))
1201 ((eq debbugs-gnu-mail-backend 'rmail)
1202 (debbugs-read-emacs-bug-with-rmail id status merged))
1203 ((eq debbugs-gnu-mail-backend 'gnus)
1204 (debbugs-read-emacs-bug-with-gnus id status merged))
1205 (t (error "No valid mail backend specified")))))
1207 (defvar debbugs-gnu-summary-mode-map
1208 (let ((map (make-sparse-keymap)))
1209 (define-key map "C" 'debbugs-gnu-send-control-message)
1210 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1213 (define-minor-mode debbugs-gnu-summary-mode
1214 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1216 \\{debbugs-gnu-summary-mode-map}"
1217 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1218 (set (make-local-variable 'gnus-posting-styles)
1221 (when (buffer-live-p gnus-article-copy)
1222 (with-current-buffer gnus-article-copy
1223 (set (make-local-variable 'message-prune-recipient-rules)
1224 '((".*@debbugs.*" "emacs-pretest-bug")
1225 (".*@debbugs.*" "bug-gnu-emacs")
1226 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1227 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1228 (set (make-local-variable 'message-alter-recipients-function)
1230 (if (string-match "\\([0-9]+\\)@donarmstrong"
1232 (let ((new (format "%s@debbugs.gnu.org"
1233 (match-string 1 (car address)))))
1236 ;; `gnus-posting-styles' is eval'ed after
1237 ;; `message-simplify-subject'. So we cannot use m-s-s.
1238 (setq subject ,debbugs-gnu-subject))))))))
1240 (defun debbugs-gnu-guess-current-id ()
1241 "Guess the ID based on \"#23\"."
1245 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1247 (goto-char (point-min))
1248 (re-search-forward "#\\([0-9]+\\)" nil t)))
1249 (string-to-number (match-string 1)))))
1251 (defvar debbugs-gnu-send-mail-function nil
1252 "A function to send control messages from debbugs.")
1254 (defun debbugs-gnu-send-control-message (message &optional reverse)
1255 "Send a control message for the current bug report.
1256 You can set the severity or add a tag, or close the report. If
1257 you use the special \"done\" MESSAGE, the report will be marked as
1258 fixed, and then closed.
1260 If given a prefix, and given a tag to set, the tag will be
1263 (list (completing-read
1265 '("serious" "important" "normal" "minor" "wishlist"
1266 "done" "donenotabug" "donewontfix" "doneunreproducible"
1267 "unarchive" "unmerge" "reopen" "close"
1268 "merge" "forcemerge"
1274 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1275 "pending" "help" "security" "confirmed"
1278 current-prefix-arg))
1279 (let* ((id (or (debbugs-gnu-current-id t)
1280 debbugs-gnu-bug-number ; Set on group entry.
1281 (debbugs-gnu-guess-current-id)))
1283 (when (member message '("close" "done"))
1287 ;; Emacs development versions.
1289 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1291 (match-string 1 emacs-version)
1292 (1+ (string-to-number (match-string 2 emacs-version)))))
1293 ;; Emacs release versions.
1295 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1297 (match-string 1 emacs-version)
1298 (match-string 2 emacs-version)))
1299 (t emacs-version)))))
1300 (status (debbugs-gnu-current-status)))
1302 (insert "To: control@debbugs.gnu.org\n"
1303 "From: " (message-make-from) "\n"
1304 (format "Subject: control message for bug #%d\n" id)
1305 mail-header-separator
1308 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1309 (format "%s %d\n" message id))
1310 ((member message '("merge" "forcemerge"))
1311 (format "%s %d %s\n" message id
1312 (read-string "Merge with bug #: ")))
1313 ((member message '("block" "unblock"))
1315 "%s %d by %s\n" message id
1318 (completing-read-multiple
1319 (format "%s with bug(s) #: " (capitalize message))
1320 (if (equal message "unblock")
1321 (mapcar 'number-to-string
1322 (cdr (assq 'blockedby status))))
1323 nil (and (equal message "unblock") status))
1325 ((equal message "owner")
1326 (format "owner %d !\n" id))
1327 ((equal message "retitle")
1328 (format "retitle %d %s\n" id (read-string "New title: ")))
1329 ((equal message "reassign")
1330 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1331 ((equal message "close")
1332 (format "close %d %s\n" id version))
1333 ((equal message "done")
1334 (format "tags %d fixed\nclose %d %s\n" id id version))
1335 ((member message '("donenotabug" "donewontfix"
1336 "doneunreproducible"))
1337 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1338 ((member message '("serious" "important" "normal"
1339 "minor" "wishlist"))
1340 (format "severity %d %s\n" id message))
1341 ((equal message "invalid")
1342 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1344 ((equal message "usertag")
1345 (format "user %s\nusertag %d %s\n"
1347 "Package name or email address: "
1349 debbugs-gnu-all-packages (list user-mail-address))
1350 nil nil (car debbugs-gnu-default-packages))
1351 id (read-string "User tag: ")))
1353 (format "tags %d%s %s\n"
1354 id (if reverse " -" "")
1356 (funcall (or debbugs-gnu-send-mail-function send-mail-function))
1357 (remhash id debbugs-cache-data)
1359 (message "Control message sent:\n%s"
1360 (buffer-substring-no-properties (point) (1- (point-max)))))))
1362 (defvar debbugs-gnu-usertags-mode-map
1363 (let ((map (make-sparse-keymap)))
1364 (set-keymap-parent map tabulated-list-mode-map)
1365 (define-key map "\r" 'debbugs-gnu-select-usertag)
1366 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1367 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1370 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1371 "Major mode for listing user tags.
1373 All normal editing commands are switched off.
1374 \\<debbugs-gnu-usertags-mode-map>
1376 The following commands are available:
1378 \\{debbugs-gnu-usertags-mode-map}"
1379 (buffer-disable-undo)
1380 (setq truncate-lines t)
1381 (setq buffer-read-only t))
1384 (defun debbugs-gnu-usertags (&rest users)
1385 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1387 (if current-prefix-arg
1388 (completing-read-multiple
1389 "Package name(s) or email address: "
1390 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1391 (mapconcat 'identity debbugs-gnu-default-packages ","))
1392 debbugs-gnu-default-packages))
1395 (let ((inhibit-read-only t)
1396 (debbugs-port "gnu.org")
1397 (buffer-name "*Emacs User Tags*")
1399 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1401 ;; Initialize variables.
1402 (when (and (file-exists-p debbugs-gnu-persistency-file)
1403 (not debbugs-gnu-local-tags))
1405 (insert-file-contents debbugs-gnu-persistency-file)
1406 (eval (read (current-buffer)))))
1409 (when (get-buffer buffer-name)
1410 (kill-buffer buffer-name))
1411 (switch-to-buffer (get-buffer-create buffer-name))
1412 (debbugs-gnu-usertags-mode)
1413 (setq tabulated-list-format `[("User" ,user-tab-length t)
1415 (setq tabulated-list-sort-key (cons "User" nil))
1416 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1418 ;; Retrieve user tags.
1419 (dolist (user users)
1420 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1422 'tabulated-list-entries
1423 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1424 `((("tagged") (,user) nil nil (,tag))
1425 ,(vector (propertize user 'mouse-face 'highlight)
1426 (propertize tag 'mouse-face 'highlight)))
1430 (when debbugs-gnu-local-tags
1432 'tabulated-list-entries
1435 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1438 (tabulated-list-init-header)
1439 (tabulated-list-print)
1441 (set-buffer-modified-p nil)
1442 (goto-char (point-min)))))
1444 (defun debbugs-gnu-select-usertag ()
1445 "Select the user tag on the current line."
1447 ;; We open the bug reports.
1448 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1449 (when args (apply 'debbugs-gnu args))))
1452 (defun debbugs-gnu-bugs (&rest bugs)
1453 "List all BUGS, a list of bug numbers."
1455 (mapcar 'string-to-number
1456 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1458 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1459 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1460 ;; We do not suppress bugs requested explicitely.
1461 (setq debbugs-gnu-current-suppress nil)
1464 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1465 "The directory where the main source tree lives.")
1467 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1468 "The directory where the previous source tree lives.")
1470 (defun debbugs-gnu-apply-patch (&optional branch)
1471 "Apply the patch from the current message.
1472 If given a prefix, patch in the branch directory instead."
1474 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1475 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1476 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1477 (let ((rej "/tmp/debbugs-gnu.rej")
1478 (output-buffer (get-buffer-create "*debbugs patch*"))
1480 debbugs-gnu-branch-directory
1481 debbugs-gnu-trunk-directory))
1482 (patch-buffers nil))
1483 (when (file-exists-p rej)
1485 (with-current-buffer output-buffer
1487 (gnus-summary-select-article nil t)
1488 ;; The patches are either in MIME attachements or the main article
1489 ;; buffer. Determine which.
1490 (gnus-with-article-buffer
1491 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1492 (when (string-match "diff\\|patch\\|plain" (mm-handle-media-type handle))
1493 (push (cons (mm-handle-encoding handle)
1494 (mm-handle-buffer handle))
1496 (unless patch-buffers
1497 (gnus-summary-show-article 'raw)
1498 (article-decode-charset)
1499 (push (cons nil gnus-article-buffer) patch-buffers))
1500 (dolist (elem patch-buffers)
1501 (with-current-buffer (generate-new-buffer "*debbugs input patch*")
1502 (insert-buffer-substring (cdr elem))
1503 (cond ((eq (car elem) 'base64)
1504 (base64-decode-region (point-min) (point-max)))
1505 ((eq (car elem) 'quoted-printable)
1506 (quoted-printable-decode-region (point-min) (point-max))))
1507 (debbugs-gnu-fix-patch dir)
1508 (call-process-region (point-min) (point-max)
1509 "patch" nil output-buffer nil
1510 "-r" rej "--no-backup-if-mismatch"
1512 "-d" (expand-file-name dir)
1514 (set-buffer output-buffer)
1515 (when (file-exists-p rej)
1516 (goto-char (point-max))
1517 (insert-file-contents-literally rej))
1518 (goto-char (point-max))
1519 (save-some-buffers t)
1521 (mapc 'kill-process compilation-in-progress)
1522 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1524 (vc-dir-hide-up-to-date)
1525 (goto-char (point-min))
1528 ;; All these commands are asynchronous, so just wait a bit. This
1529 ;; should be done properly a different way.
1531 ;; We've now done everything, so arrange the windows we need to see.
1532 (delete-other-windows)
1533 (switch-to-buffer output-buffer)
1537 (switch-to-buffer "*compilation*")
1538 (goto-char (point-max))
1540 (switch-to-buffer "*vc-diff*")
1541 (goto-char (point-min))))
1543 (defun debbugs-gnu-fix-patch (dir)
1544 (setq dir (directory-file-name (expand-file-name dir)))
1545 (goto-char (point-min))
1546 (while (re-search-forward diff-file-header-re nil t)
1547 (goto-char (match-beginning 0))
1548 (let ((target-name (car (diff-hunk-file-names))))
1549 (when (and target-name
1550 (or (not (string-match "/" target-name))
1551 (and (string-match "^[ab]/" target-name)
1553 (expand-file-name (substring target-name 2)
1555 (file-exists-p (expand-file-name target-name dir))))
1556 ;; We have a simple patch that refers to a file somewhere in the
1558 (when-let ((files (directory-files-recursively
1560 (concat "^" (regexp-quote
1561 (file-name-nondirectory target-name))
1563 (when (re-search-forward (concat "^[+]+ "
1564 (regexp-quote target-name)
1567 (replace-match (concat "+++ a"
1568 (substring (car files) (length dir))
1573 (defun debbugs-gnu-find-contributor (string)
1574 "Search through ChangeLogs to find contributors."
1575 (interactive "sContributor match: ")
1577 (match (concat "^[0-9].*" string)))
1578 (dolist (file (directory-files-recursively
1579 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1581 (when (file-exists-p file)
1582 (insert-file-contents file))
1583 (goto-char (point-min))
1584 (while (and (re-search-forward match nil t)
1585 (not (looking-at ".*tiny change")))
1587 (message "%s is a contributor %d times" string found)
1590 (defvar debbugs-gnu-patch-subject nil)
1592 (defun debbugs-gnu-insert-changelog ()
1593 "Add a ChangeLog from a recently applied patch from a third party."
1595 (let (from subject patch-subject changelog)
1596 (gnus-with-article-buffer
1598 (goto-char (point-min))
1599 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1600 subject (gnus-fetch-field "subject"))
1601 ;; If it's a patch formatted the right way, extract that data.
1602 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1603 (when (string-match "diff\\|patch\\|plain"
1604 (mm-handle-media-type handle))
1606 (insert-buffer-substring (mm-handle-buffer handle))
1607 (cond ((eq (mm-handle-encoding handle) 'base64)
1608 (base64-decode-region (point-min) (point-max)))
1609 ((eq (mm-handle-encoding handle) 'quoted-printable)
1610 (quoted-printable-decode-region (point-min) (point-max))))
1612 (or (gnus-fetch-field "subject") patch-subject))
1613 (goto-char (point-min))
1614 (when (re-search-forward "^[*] " nil t)
1615 (let ((start (match-beginning 0)))
1616 (while (and (not (eobp))
1617 (not (looking-at "---")))
1619 (setq changelog (buffer-substring
1620 start (line-end-position 0)))))))))
1621 (let ((add-log-full-name (car from))
1622 (add-log-mailing-address (cadr from)))
1623 (add-change-log-entry-other-window)
1625 (setq-local debbugs-gnu-patch-subject patch-subject))
1627 (delete-region (line-beginning-position) (point-max))
1629 (narrow-to-region (point) (point))
1631 (indent-region (point-min) (point-max))))
1632 (let ((point (point)))
1633 (when (string-match "\\(bug#[0-9]+\\)" subject)
1634 (insert " (" (match-string 1 subject) ")."))
1635 (when (zerop (debbugs-gnu-find-contributor
1636 (let ((bits (split-string (car from))))
1638 ((>= (length bits) 2)
1639 (format "%s.*%s" (car bits) (car (last bits))))
1640 ((= (length bits) 1)
1642 ;; Fall back on the email address.
1645 (goto-char (point-max))
1649 (insert " Copyright-paperwork-exempt: yes"))
1650 (goto-char point)))))
1652 (defvar debbugs-gnu-lisp-mode-map
1653 (let ((map (make-sparse-keymap)))
1654 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1657 (define-minor-mode debbugs-gnu-lisp-mode
1658 "Minor mode for providing a debbugs interface in Lisp buffers.
1659 \\{debbugs-gnu-lisp-mode-map}"
1660 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1662 (defvar debbugs-gnu-diff-mode-map
1663 (let ((map (make-sparse-keymap)))
1664 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1667 (define-minor-mode debbugs-gnu-diff-mode
1668 "Minor mode for providing a debbugs interface in diff buffers.
1669 \\{debbugs-gnu-diff-mode-map}"
1670 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1672 (defun debbugs-gnu-diff-select ()
1673 "Select the diff under point."
1675 (delete-other-windows)
1678 (defvar debbugs-gnu-change-mode-map
1679 (let ((map (make-sparse-keymap)))
1680 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1683 (define-minor-mode debbugs-gnu-change-mode
1684 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1685 \\{debbugs-gnu-change-mode-map}"
1686 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1688 (defun debbugs-gnu-change-checkin ()
1689 "Prepare checking in the current changes."
1691 (save-some-buffers t)
1692 (when (get-buffer "*vc-dir*")
1693 (kill-buffer (get-buffer "*vc-dir*")))
1694 (let ((patch-subject debbugs-gnu-patch-subject))
1695 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1696 (if (equal (cl-subseq default-directory 0 (length trunk))
1698 (vc-dir debbugs-gnu-trunk-directory)
1699 (vc-dir debbugs-gnu-branch-directory)))
1700 (goto-char (point-min))
1701 (while (not (search-forward "edited" nil t))
1704 (while (search-forward "edited" nil t)
1706 (beginning-of-line))
1708 (vc-next-action nil)
1709 (delete-region (point-min) (point-max))
1710 (log-edit-insert-changelog t)
1711 (delete-other-windows)
1714 (switch-to-buffer "*vc-diff*")
1718 (replace-regexp-in-string "^ *\\[PATCH\\] *" "" patch-subject)
1721 (defun debbugs-gnu-save-cache ()
1722 "Save the bugs cache to a file."
1724 (unless debbugs-cache-data
1725 (error "No data to cache"))
1726 (unless (file-exists-p "~/.emacs.d/debbugs-cache")
1727 (make-directory "~/.emacs.d/debbugs-cache" t))
1728 (let ((coding-system-for-write 'utf-8))
1729 (with-temp-file "~/.emacs.d/debbugs-cache/list"
1730 (prin1 debbugs-cache-data (current-buffer)))))
1732 (provide 'debbugs-gnu)
1736 ;; * Another random thought - is it possible to implement some local
1737 ;; cache, so only changed bugs are fetched? Glenn Morris.
1739 ;;; debbugs-gnu.el ends here