1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
10 ;; This file is not part of GNU Emacs.
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This package provides an interface to bug reports which are located
28 ;; on the GNU bug tracker debbugs.gnu.org. Its main purpose is to
29 ;; show and manipulate bug reports from Emacs, but it could be used
30 ;; also for other GNU projects which use the same bug tracker.
32 ;; If you have `debbugs-gnu.el' in your load-path, you could enable
33 ;; the bug tracker commands by the following lines in your ~/.emacs
35 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
36 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
37 ;; (autoload 'debbugs-gnu-usertags "debbugs-gnu" "" 'interactive)
38 ;; (autoload 'debbugs-gnu-bugs "debbugs-gnu" "" 'interactive)
40 ;; The bug tracker is called interactively by
44 ;; It asks for the severities, for which bugs shall be shown. This can
45 ;; be either just one severity, or a list of severities, separated by
46 ;; comma. Valid severities are "serious", "important", "normal",
47 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
48 ;; used, although configured on the GNU bug tracker. If no severity
49 ;; is given, all bugs are selected.
51 ;; There is also the pseudo severity "tagged". When it is used, the
52 ;; function will ask for user tags (a comma separated list), and shows
53 ;; just the bugs which are tagged with them. In general, user tags
54 ;; shall be strings denoting to subprojects of the package, like
55 ;; "cedet" or "tramp" of the package "emacs". If no user tag is
56 ;; given, locally tagged bugs are shown.
58 ;; If a prefix is given to the command, more search parameters are
59 ;; asked for, like packages (also a comma separated list, "emacs" is
60 ;; the default), whether archived bugs shall be shown, and whether
61 ;; closed bugs shall be suppressed from being retrieved.
65 ;; M-x debbugs-gnu-search
67 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
68 ;; search phrase to be used for full text search. Additionally, it
69 ;; asks for key-value pairs to filter bugs. Keys are as described in
70 ;; `debbugs-get-status', the corresponding value must be a regular
71 ;; expression to match for. The other parameters are as described in
72 ;; `debbugs-gnu'. Usually, there is just one value except for the
73 ;; attribute "date", which needs two arguments specifying a period in
74 ;; which the bug has been submitted or modified.
76 ;; The bug reports are downloaded from the bug tracker. In order to
77 ;; not generate too much load of the server, up to 500 bugs will be
78 ;; downloaded at once. If there are more hits, several downloads will
79 ;; be performed, until all bugs are retrieved.
81 ;; These default values could be changed also by customer options
82 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages'
83 ;; and `debbugs-gnu-default-suppress-bugs'.
85 ;; The commands create a page of bug lists. Every bug is shown in one
86 ;; line, including the bug number, the status (combining merged bug
87 ;; numbers, keywords and severities), the name of the submitter, and
88 ;; the title of the bug. On every bug line you could apply the
89 ;; following actions by the following keystrokes:
91 ;; RET: Show corresponding messages in Gnus/Rmail
92 ;; "C": Send a control message
93 ;; "t": Mark the bug locally as tagged
94 ;; "b": Show bugs this bug is blocked by
95 ;; "B": Show bugs this bug is blocking
96 ;; "d": Show bug attributes
98 ;; Furthermore, you could apply the global actions
101 ;; "q": Quit the buffer
102 ;; "s": Toggle bug sorting for age or for state
103 ;; "x": Toggle suppressing of bugs
104 ;; "/": Display only bugs matching a string
105 ;; "R": Display only bugs blocking the current release
106 ;; "w": Display all the currently selected bug reports
108 ;; When you visit the related bug messages in Gnus or Rmail, you could
109 ;; also send control messages by keystroke "C".
111 ;; In the header line of every bug list page, you can toggle sorting
112 ;; per column by selecting a column with the mouse. The sorting
113 ;; happens as expected for the respective column; sorting in the Title
114 ;; column is depending on whether you are the owner of a bug.
116 ;; Another approach for listing bugs is calling the command
118 ;; M-x debbugs-gnu-usertags
120 ;; This command shows you all existing user tags for the packages
121 ;; defined in `debbugs-gnu-default-packages'. A prefix for the
122 ;; command allows you to use other package names, or an arbitrary
123 ;; string for a user who has tagged bugs. The command returns the
124 ;; list of existing user tags for the given user(s) or package
125 ;; name(s), respectively. Applying RET on a user tag, all bugs tagged
126 ;; with this user tag are shown.
128 ;; Unfortunately, it is not possible with the SOAP interface to show
129 ;; all users who have tagged bugs. This list can be retrieved via
130 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi?indexon=users>.
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
135 ;; M-x debbugs-gnu-bugs
137 ;; The bug numbers to be shown shall be entered as comma separated list.
142 (require 'tabulated-list)
145 (eval-when-compile (require 'cl))
147 (autoload 'article-decode-charset "gnus-art")
148 (autoload 'diff-goto-source "diff-mode")
149 (autoload 'diff-hunk-file-names "diff-mode")
150 (autoload 'gnus-article-mime-handles "gnus-art")
151 (autoload 'gnus-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-search ()
341 "Search for Emacs bugs interactively.
342 Search arguments are requested interactively. The \"search
343 phrase\" is used for full text search in the bugs database.
344 Further key-value pairs are requested until an empty key is
345 returned. If a key cannot be queried by a SOAP request, it is
346 marked as \"client-side filter\"."
350 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
351 key val1 val2 phrase severities packages archivedp)
353 ;; Check for the phrase.
354 (setq phrase (read-string debbugs-gnu-phrase-prompt))
355 (if (zerop (length phrase))
357 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
358 ;; We suppress closed bugs if there is no phrase.
359 (setq debbugs-gnu-current-suppress (null phrase))
361 ;; The other queries.
364 (setq key (completing-read
367 '("severity" "package" "tags" "submitter" "date"
369 '("severity" "package" "archive" "src" "tag"
370 "owner" "submitter" "maint" "correspondent"
371 "date" "log_modified" "last_modified"
372 "found_date" "fixed_date" "unarchived"
373 "subject" "done" "forwarded" "msgid" "summary"))
376 ;; Server-side queries.
377 ((equal key "severity")
380 (completing-read-multiple
381 "Enter severities: " debbugs-gnu-all-severities nil t
382 (mapconcat 'identity debbugs-gnu-default-severities ","))))
384 ((equal key "package")
387 (completing-read-multiple
388 "Enter packages: " debbugs-gnu-all-packages nil t
389 (mapconcat 'identity debbugs-gnu-default-packages ","))))
391 ((equal key "archive")
392 ;; We simplify, by assuming just archived bugs are requested.
395 ((member key '("src" "tag" "tags"))
396 (setq val1 (read-string (format "Enter %s: " key)))
397 (when (not (zerop (length val1)))
399 'debbugs-gnu-current-query (cons (intern key) val1))))
401 ((member key '("owner" "submitter" "maint" "correspondent"))
402 (setq val1 (read-string "Enter email address: "))
403 (when (not (zerop (length val1)))
405 'debbugs-gnu-current-query (cons (intern key) val1))))
407 ((equal key "status")
410 (completing-read "Enter status: " '("done" "forwarded" "open")))
411 (when (not (zerop (length val1)))
413 'debbugs-gnu-current-query (cons (intern key) val1))))
415 ;; Client-side filters.
416 ((member key '("date" "log_modified" "last_modified"
417 "found_date" "fixed_date" "unarchived"))
419 (debbugs-gnu-calendar-read
420 (format "Enter %s before YYYY-MM-DD%s: "
421 key (if phrase "" " (client-side filter)"))
423 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
424 (if (string-match date-format val1)
429 (string-to-number (match-string 3 val1))
430 (string-to-number (match-string 2 val1))
431 (string-to-number (match-string 1 val1))))))
434 (debbugs-gnu-calendar-read
435 (format "Enter %s after YYYY-MM-DD%s: "
436 key (if phrase "" " (client-side filter)"))
438 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
439 (if (string-match date-format val2)
444 (string-to-number (match-string 3 val2))
445 (string-to-number (match-string 2 val2))
446 (string-to-number (match-string 1 val2))))))
451 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
452 (cons (intern key) (cons val1 val2)))))
454 ((not (zerop (length key)))
457 (if phrase 'read-string 'read-regexp)
459 key (if phrase ": " " (client-side filter)"))))
460 (when (not (zerop (length val1)))
463 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
464 (cons (intern key) val1))))
467 (t (throw :finished nil)))))
470 (debbugs-gnu severities packages archivedp))))
473 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
474 "List all outstanding bugs."
476 (let (severities archivedp)
479 (completing-read-multiple
480 "Severities: " debbugs-gnu-all-severities nil t
481 (mapconcat 'identity debbugs-gnu-default-severities ",")))
482 ;; The next parameters are asked only when there is a prefix.
483 (if current-prefix-arg
484 (completing-read-multiple
485 "Packages: " debbugs-gnu-all-packages nil t
486 (mapconcat 'identity debbugs-gnu-default-packages ","))
487 debbugs-gnu-default-packages)
488 (when current-prefix-arg
489 (setq archivedp (y-or-n-p "Show archived bugs?")))
490 (when (and current-prefix-arg (not archivedp))
491 (y-or-n-p "Suppress unwanted bugs?"))
492 ;; This one must be asked for severity "tagged".
493 (when (member "tagged" severities)
494 (split-string (read-string "User tag(s): ") "," t)))))
496 ;; Initialize variables.
497 (when (and (file-exists-p debbugs-gnu-persistency-file)
498 (not debbugs-gnu-local-tags))
500 (insert-file-contents debbugs-gnu-persistency-file)
501 (eval (read (current-buffer)))))
502 ;; Per default, we suppress retrieved unwanted bugs.
503 (when (called-interactively-p 'any)
504 (setq debbugs-gnu-current-suppress t))
507 (dolist (severity (if (consp severities) severities (list severities)))
508 (when (not (zerop (length severity)))
509 (when (string-equal severity "tagged")
510 (setq debbugs-gnu-current-suppress nil))
511 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
512 (dolist (package (if (consp packages) packages (list packages)))
513 (when (not (zerop (length package)))
514 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
516 (setq debbugs-gnu-current-suppress nil)
517 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
519 (setq debbugs-gnu-current-suppress t)
520 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
521 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
522 (dolist (tag (if (consp tags) tags (list tags)))
523 (when (not (zerop (length tag)))
524 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
527 (debbugs-gnu-show-reports)
529 ;; Reset query, filter and suppress.
530 (setq debbugs-gnu-current-query nil
531 debbugs-gnu-current-filter nil
532 debbugs-gnu-current-suppress nil))
534 (defun debbugs-gnu-get-bugs (query)
535 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
536 (let* ((debbugs-port "gnu.org")
537 (bugs (assoc 'bugs query))
538 (tags (assoc 'tag query))
539 (local-tags (and (member '(severity . "tagged") query) (not tags)))
540 (phrase (assoc 'phrase query))
542 ;; Compile query arguments.
543 (unless (or query tags)
544 (dolist (elt debbugs-gnu-default-packages)
545 (setq args (append args (list :package elt)))))
547 (unless (equal elt '(severity . "tagged"))
553 ((eq (car elt) 'phrase)
554 (list (list :phrase (cdr elt))))
555 ((eq (car elt) 'date)
556 (list (list :date (cddr elt) (cadr elt)
559 (list (list (intern (concat ":" (symbol-name (car elt))))
560 (cdr elt) :operator "ISTRINC"))))
561 (list (intern (concat ":" (symbol-name (car elt))))
565 ;; If the query is just a list of bug numbers, we return them.
567 ;; If the query contains the pseudo-severity "tagged", we return
568 ;; just the local tagged bugs.
569 (local-tags (copy-sequence debbugs-gnu-local-tags))
570 ;; A full text query.
573 (lambda (x) (cdr (assoc "id" x)))
574 (apply 'debbugs-search-est args)))
577 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
578 (apply 'debbugs-get-usertag args))
579 ;; Otherwise, we retrieve the bugs from the server.
580 (t (apply 'debbugs-get-bugs args)))))
582 (defun debbugs-gnu-show-reports (&optional offline)
584 If OFFLINE is non-nil, the query is not sent to the server. Bugs
585 are taken from the cache instead."
586 (let ((inhibit-read-only t)
587 (buffer-name "*Emacs Bugs*"))
588 ;; The tabulated mode sets several local variables. We must get
590 (when (get-buffer buffer-name)
591 (kill-buffer buffer-name))
592 (switch-to-buffer (get-buffer-create buffer-name))
595 ;; Print bug reports.
597 (let ((debbugs-cache-expiry (if offline nil debbugs-cache-expiry))
599 (apply 'debbugs-get-status
602 (maphash (lambda (key _elem)
606 (debbugs-gnu-get-bugs debbugs-gnu-local-query)))))
607 (let* ((id (cdr (assq 'id status)))
611 (cons (cdr (assq 'severity status))
612 (cdr (assq 'keywords status)))
614 (address (if (cdr (assq 'originator status))
615 (mail-header-parse-address
616 (decode-coding-string (cdr (assq 'originator status))
618 (owner (if (cdr (assq 'owner status))
619 (car (mail-header-parse-address
620 (decode-coding-string (cdr (assq 'owner status))
622 (subject (if (cdr (assq 'subject status))
623 (decode-coding-string (cdr (assq 'subject status))
626 (unless (equal (cdr (assq 'pending status)) "pending")
627 (setq words (concat words "," (cdr (assq 'pending status)))))
628 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
630 (setq words (concat words "," (mapconcat 'identity packages ",")))))
631 (when (setq merged (cdr (assq 'mergedwith status)))
632 (setq words (format "%s,%s"
635 (mapconcat 'number-to-string merged ","))
637 (when (or (not merged)
638 (not (let ((found nil))
639 (dolist (id (if (listp merged)
642 (dolist (entry tabulated-list-entries)
643 (when (equal id (cdr (assq 'id (car entry))))
647 'tabulated-list-entries
655 (if (memq id debbugs-gnu-local-tags)
659 ;; Mark status and age.
663 ((cdr (assq 'archived status))
664 'debbugs-gnu-archived)
665 ((equal (cdr (assq 'pending status)) "done")
667 ((member "pending" (cdr (assq 'keywords status)))
668 'debbugs-gnu-pending)
669 ((= (cdr (assq 'date status))
670 (cdr (assq 'log_modified status)))
673 (cdr (assq 'log_modified status)))
675 'debbugs-gnu-handled)
677 'debbugs-gnu-stale)))
679 ;; Prefer the name over the address.
684 ;; Mark own submitted bugs.
685 (if (and (stringp (car address))
686 (string-equal (car address) user-mail-address))
693 (if (and (stringp owner)
694 (string-equal owner user-mail-address))
699 (tabulated-list-init-header)
700 (tabulated-list-print)
702 (set-buffer-modified-p nil)
703 (goto-char (point-min))))
705 (defun debbugs-gnu-print-entry (list-id cols)
706 "Insert a debbugs entry at point.
707 Used instead of `tabulated-list-print-entry'."
712 (id-length (nth 1 (aref tabulated-list-format 0)))
713 (state (aref cols 1))
714 (state-length (nth 1 (aref tabulated-list-format 1)))
715 (submitter (aref cols 2))
716 (submitter-length (nth 1 (aref tabulated-list-format 2)))
717 (title (aref cols 3))
718 (title-length (nth 1 (aref tabulated-list-format 3))))
720 ;; We may have a narrowing in effect.
721 (or (not debbugs-gnu-limit)
722 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
723 ;; Filter suppressed bugs.
724 (or (not debbugs-gnu-local-suppress)
725 (not (catch :suppress
726 (dolist (check debbugs-gnu-default-suppress-bugs)
730 (or (cdr (assq (car check) list-id)) ""))
731 (throw :suppress t))))))
732 ;; Filter search list.
733 (not (catch :suppress
734 (dolist (check debbugs-gnu-local-filter)
735 (let ((val (cdr (assq (car check) list-id))))
736 (if (stringp (cdr check))
737 ;; Regular expression.
738 (when (not (string-match (cdr check) (or val "")))
741 (when (or (and (numberp (cadr check))
742 (< (cadr check) val))
743 (and (numberp (cddr check))
744 (> (cddr check) val)))
745 (throw :suppress t))))))))
748 (indent-to (- id-length (length id)))
751 (indent-to (setq pos (+ pos id-length 1)) 1)
752 (insert (if (> (length state) state-length)
753 (propertize (substring state 0 state-length)
757 (indent-to (setq pos (+ pos state-length 1)) 1)
758 (insert "[" (if (> (length submitter) (- submitter-length 2))
759 (propertize (substring submitter 0 (- submitter-length 2))
760 'help-echo submitter)
762 (indent-to (+ pos (1- submitter-length)))
765 (indent-to (setq pos (+ pos submitter-length 1)) 1)
766 (insert (propertize title 'help-echo title))
770 `(tabulated-list-id ,list-id mouse-face highlight))
773 (defun debbugs-gnu-menu-map-emacs-enabled ()
774 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
775 (or ;; No package discriminator has been used.
776 (not (assq 'package debbugs-gnu-local-query))
777 ;; Package "emacs" has been selected.
778 (member '(package . "emacs") debbugs-gnu-local-query)))
780 (defconst debbugs-gnu-bug-triage-file
781 (expand-file-name "../admin/notes/bug-triage" data-directory)
782 "The \"bug-triage\" file.")
784 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
785 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
786 (and (debbugs-gnu-menu-map-emacs-enabled)
787 (stringp debbugs-gnu-bug-triage-file)
788 (file-readable-p debbugs-gnu-bug-triage-file)))
790 (defun debbugs-gnu-view-bug-triage ()
791 "Show \"bug-triage\" file."
793 (view-file debbugs-gnu-bug-triage-file))
795 (defvar debbugs-gnu-mode-map
796 (let ((map (make-sparse-keymap))
797 (menu-map (make-sparse-keymap)))
798 (set-keymap-parent map tabulated-list-mode-map)
799 (define-key map "\r" 'debbugs-gnu-select-report)
800 (define-key map [mouse-1] 'debbugs-gnu-select-report)
801 (define-key map [mouse-2] 'debbugs-gnu-select-report)
802 (define-key map "g" 'debbugs-gnu-rescan)
803 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
804 (define-key map "C" 'debbugs-gnu-send-control-message)
806 (define-key map "s" 'debbugs-gnu-toggle-sort)
807 (define-key map "t" 'debbugs-gnu-toggle-tag)
808 (define-key map "x" 'debbugs-gnu-toggle-suppress)
809 (define-key map "/" 'debbugs-gnu-narrow-to-status)
810 (define-key map "w" 'debbugs-gnu-widen)
812 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
813 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
814 (define-key map "d" 'debbugs-gnu-display-status)
816 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
817 (define-key menu-map [debbugs-gnu-select-report]
818 '(menu-item "Show Reports" debbugs-gnu-select-report
819 :help "Show all reports belonging to this bug"))
820 (define-key-after menu-map [debbugs-gnu-rescan]
821 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
822 :help "Refresh bug list")
823 'debbugs-gnu-select-report)
824 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
825 '(menu-item "Show Release Blocking Bugs"
826 debbugs-gnu-show-all-blocking-reports
827 :enable (debbugs-gnu-menu-map-emacs-enabled)
828 :help "Show all bugs blocking next Emacs release")
830 (define-key-after menu-map [debbugs-gnu-send-control-message]
831 '(menu-item "Send Control Message"
832 debbugs-gnu-send-control-message
833 :help "Send control message to debbugs.gnu.org")
834 'debbugs-gnu-show-all-blocking-reports)
836 (define-key-after menu-map [debbugs-gnu-separator1]
837 '(menu-item "--") 'debbugs-gnu-send-control-message)
838 (define-key-after menu-map [debbugs-gnu-search]
839 '(menu-item "Search Bugs" debbugs-gnu-search
840 :help "Search bugs on debbugs.gnu.org")
841 'debbugs-gnu-separator1)
842 (define-key-after menu-map [debbugs-gnu]
843 '(menu-item "Retrieve Bugs" debbugs-gnu
844 :help "Retrieve bugs from debbugs.gnu.org")
846 (define-key-after menu-map [debbugs-gnu-bugs]
847 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
848 :help "Retrieve selected bugs from debbugs.gnu.org")
851 (define-key-after menu-map [debbugs-gnu-separator2]
852 '(menu-item "--") 'debbugs-gnu-bugs)
853 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
854 '(menu-item "Describe Bug Triage Procedure"
855 debbugs-gnu-view-bug-triage
856 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
857 :help "Show procedure of triaging bugs")
858 'debbugs-gnu-separator2)
861 (defun debbugs-gnu-rescan ()
862 "Rescan the current set of bug reports."
864 (let ((id (debbugs-gnu-current-id))
865 (debbugs-gnu-current-query debbugs-gnu-local-query)
866 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
867 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
868 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
869 (debbugs-gnu-show-reports)
871 (debbugs-gnu-goto id))))
873 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
874 "Major mode for listing bug reports.
876 All normal editing commands are switched off.
877 \\<debbugs-gnu-mode-map>
879 The following commands are available:
881 \\{debbugs-gnu-mode-map}"
882 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
883 (set (make-local-variable 'debbugs-gnu-limit) nil)
884 (set (make-local-variable 'debbugs-gnu-local-query)
885 debbugs-gnu-current-query)
886 (set (make-local-variable 'debbugs-gnu-local-filter)
887 debbugs-gnu-current-filter)
888 (set (make-local-variable 'debbugs-gnu-local-suppress)
889 debbugs-gnu-current-suppress)
890 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
891 ("State" 20 debbugs-gnu-sort-state)
893 ("Title" 10 debbugs-gnu-sort-title)])
894 (setq tabulated-list-sort-key (cons "Id" nil))
895 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
896 (buffer-disable-undo)
897 (setq truncate-lines t)
898 (setq buffer-read-only t))
900 (defun debbugs-gnu-sort-id (s1 s2)
901 (> (cdr (assq 'id (car s1)))
902 (cdr (assq 'id (car s2)))))
904 (defconst debbugs-gnu-state-preference
905 '((debbugs-gnu-new . 1)
906 (debbugs-gnu-stale . 2)
907 (debbugs-gnu-handled . 3)
908 (debbugs-gnu-done . 4)
909 (debbugs-gnu-pending . 5)))
911 (defun debbugs-gnu-get-state-preference (face-string)
912 (or (cdr (assq (get-text-property 0 'face face-string)
913 debbugs-gnu-state-preference))
916 (defconst debbugs-gnu-severity-preference
923 (defun debbugs-gnu-get-severity-preference (state)
924 (or (cdr (assoc (cdr (assq 'severity state))
925 debbugs-gnu-severity-preference))
928 (defun debbugs-gnu-sort-state (s1 s2)
929 (let ((id1 (cdr (assq 'id (car s1))))
930 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
931 (id2 (cdr (assq 'id (car s2))))
932 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
934 ;; Tagged bugs go to the end.
935 ((and (not (memq id1 debbugs-gnu-local-tags))
936 (memq id2 debbugs-gnu-local-tags))
938 ((and (memq id1 debbugs-gnu-local-tags)
939 (not (memq id2 debbugs-gnu-local-tags)))
941 ;; Then, we check the age of the bugs.
946 ;; If they have the same age, we check for severity.
947 ((< (debbugs-gnu-get-severity-preference (car s1))
948 (debbugs-gnu-get-severity-preference (car s2)))
952 (defun debbugs-gnu-sort-title (s1 s2)
953 (let ((owner (if (cdr (assq 'owner (car s1)))
954 (car (mail-header-parse-address
955 (decode-coding-string (cdr (assq 'owner (car s1)))
958 (string-equal owner user-mail-address))))
960 (defun debbugs-gnu-toggle-sort ()
961 "Toggle sorting by age and by state."
963 (if (eq debbugs-gnu-sort-state 'number)
965 (setq debbugs-gnu-sort-state 'state)
966 (setq tabulated-list-sort-key (cons "Id" nil)))
967 (setq debbugs-gnu-sort-state 'number)
968 (setq tabulated-list-sort-key (cons "State" nil)))
969 (tabulated-list-init-header)
970 (tabulated-list-print))
972 (defun debbugs-gnu-widen ()
973 "Display all the currently selected bug reports."
975 (let ((id (debbugs-gnu-current-id t))
976 (inhibit-read-only t))
977 (setq debbugs-gnu-limit nil)
978 (tabulated-list-init-header)
979 (tabulated-list-print)
981 (debbugs-gnu-goto id))))
983 (defun debbugs-gnu-show-blocked-by-reports ()
984 "Display all bug reports this report is blocked by."
986 (let ((id (debbugs-gnu-current-id))
987 (status (debbugs-gnu-current-status)))
988 (if (null (cdr (assq 'blockedby status)))
989 (message "Bug %d is not blocked by any other bug" id)
990 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
992 (defun debbugs-gnu-show-blocking-reports ()
993 "Display all bug reports this report is blocking."
995 (let ((id (debbugs-gnu-current-id))
996 (status (debbugs-gnu-current-status)))
997 (if (null (cdr (assq 'blocks status)))
998 (message "Bug %d is not blocking any other bug" id)
999 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
1001 (defun debbugs-gnu-show-all-blocking-reports ()
1002 "Narrow the display to just the reports that are blocking a release."
1004 (let ((blockers (cdr (assq 'blockedby
1005 (car (debbugs-get-status
1006 debbugs-gnu-blocking-report)))))
1007 (id (debbugs-gnu-current-id t))
1008 (inhibit-read-only t)
1010 (setq debbugs-gnu-limit nil)
1011 (goto-char (point-min))
1013 (setq status (debbugs-gnu-current-status))
1014 (if (not (memq (cdr (assq 'id status)) blockers))
1015 (delete-region (point) (progn (forward-line 1) (point)))
1016 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1019 (debbugs-gnu-goto id))))
1021 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1022 "Only display the bugs matching STRING.
1023 If STATUS-ONLY (the prefix), ignore matches in the From and
1025 (interactive "sNarrow to: \nP")
1026 (let ((id (debbugs-gnu-current-id t))
1027 (inhibit-read-only t)
1029 (setq debbugs-gnu-limit nil)
1030 (if (equal string "")
1031 (debbugs-gnu-toggle-suppress)
1032 (goto-char (point-min))
1034 (setq status (debbugs-gnu-current-status))
1035 (if (and (not (member string (assq 'keywords status)))
1036 (not (equal string (cdr (assq 'severity status))))
1039 string (cdr (assq 'originator status)))))
1041 (not (string-match string (cdr (assq 'subject status))))))
1042 (delete-region (point) (progn (forward-line 1) (point)))
1043 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1046 (debbugs-gnu-goto id)))))
1048 (defun debbugs-gnu-goto (id)
1049 "Go to the line displaying bug ID."
1050 (goto-char (point-min))
1051 (while (and (not (eobp))
1052 (not (equal (debbugs-gnu-current-id t) id)))
1055 (defun debbugs-gnu-toggle-tag ()
1056 "Toggle the local tag of the report in the current line.
1057 If a report is tagged locally, it is presumed to be of little
1062 (let ((inhibit-read-only t)
1063 (id (debbugs-gnu-current-id)))
1064 (if (memq id debbugs-gnu-local-tags)
1066 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1067 (put-text-property (point) (+ (point) 5) 'face 'default))
1068 (add-to-list 'debbugs-gnu-local-tags id)
1070 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1071 'face 'debbugs-gnu-tagged))
1072 (debbugs-gnu--update-tag-face id)))
1073 (debbugs-gnu-dump-persistency-file))
1075 (defun debbugs-gnu--update-tag-face (id)
1076 (dolist (entry tabulated-list-entries)
1077 (when (equal (cdr (assq 'id (car entry))) id)
1078 (aset (cadr entry) 0
1082 ;; Mark tagged bugs.
1083 (if (memq id debbugs-gnu-local-tags)
1087 (defun debbugs-gnu-toggle-suppress ()
1088 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1090 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1091 (tabulated-list-init-header)
1092 (tabulated-list-print))
1094 (defvar debbugs-gnu-bug-number nil)
1095 (defvar debbugs-gnu-subject nil)
1097 (defun debbugs-gnu-current-id (&optional noerror)
1098 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1100 (error "No bug on the current line"))))
1102 (defun debbugs-gnu-current-status ()
1103 (get-text-property (line-beginning-position) 'tabulated-list-id))
1105 (defun debbugs-gnu-display-status (query filter status)
1106 "Display the query, filter and status of the report on the current line."
1107 (interactive (list debbugs-gnu-local-query
1108 debbugs-gnu-local-filter
1109 (debbugs-gnu-current-status)))
1110 (switch-to-buffer "*Bug Status*")
1111 (let ((inhibit-read-only t))
1114 (insert ";; Query\n")
1115 (pp query (current-buffer))
1118 (insert ";; Filter\n")
1119 (pp filter (current-buffer))
1122 (insert ";; Status\n")
1123 (pp status (current-buffer)))
1124 (goto-char (point-min)))
1125 (set-buffer-modified-p nil)
1128 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1129 "Read email exchange for debbugs bug ID.
1130 STATUS is the bug's status list.
1131 MERGED is the list of bugs merged with this one."
1132 (let* ((mbox-dir (make-temp-file "debbugs" t))
1133 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1134 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1136 ;; Download messages of all the merged bug reports and append them
1137 ;; to the mailbox of the requested bug.
1139 (dolist (bugno merged)
1140 (let ((fn (make-temp-file "url")))
1141 (debbugs-get-mbox bugno 'mboxmaint fn)
1142 (rmail-get-new-mail fn)
1144 ;; Remove the 'unseen' attribute from all the messages we've
1145 ;; just read, so that all of them appear in the summary with
1147 (while (< rmail-current-message rmail-total-messages)
1148 (rmail-show-message (1+ rmail-current-message))))))
1149 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1150 (set (make-local-variable 'debbugs-gnu-subject)
1151 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1153 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1154 (set-window-text-height nil 10)
1156 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1157 (rmail-show-message 1)))
1159 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1160 "Read email exchange for debbugs bug ID.
1161 STATUS is the bug's status list.
1162 MERGED is the list of bugs merged with this one."
1164 (setq gnus-suppress-duplicates t
1165 gnus-save-duplicate-list t)
1167 (gnus-read-ephemeral-emacs-bug-group
1168 (cons id (if (listp merged) merged (list merged)))
1169 (cons (current-buffer)
1170 (current-window-configuration)))
1171 (with-current-buffer (window-buffer (selected-window))
1172 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1173 (set (make-local-variable 'debbugs-gnu-subject)
1174 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1175 (debbugs-gnu-summary-mode 1)))
1177 (defun debbugs-gnu-select-report ()
1178 "Select the report on the current line."
1180 ;; We open the report messages.
1181 (let* ((status (debbugs-gnu-current-status))
1182 (id (cdr (assq 'id status)))
1183 (merged (cdr (assq 'mergedwith status))))
1184 (setq merged (if (listp merged) merged (list merged)))
1187 (message "No bug report on the current line"))
1188 ((eq debbugs-gnu-mail-backend 'rmail)
1189 (debbugs-read-emacs-bug-with-rmail id status merged))
1190 ((eq debbugs-gnu-mail-backend 'gnus)
1191 (debbugs-read-emacs-bug-with-gnus id status merged))
1192 (t (error "No valid mail backend specified")))))
1194 (defvar debbugs-gnu-summary-mode-map
1195 (let ((map (make-sparse-keymap)))
1196 (define-key map "C" 'debbugs-gnu-send-control-message)
1197 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1200 (define-minor-mode debbugs-gnu-summary-mode
1201 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1203 \\{debbugs-gnu-summary-mode-map}"
1204 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1205 (set (make-local-variable 'gnus-posting-styles)
1208 (when (buffer-live-p gnus-article-copy)
1209 (with-current-buffer gnus-article-copy
1210 (set (make-local-variable 'message-prune-recipient-rules)
1211 '((".*@debbugs.*" "emacs-pretest-bug")
1212 (".*@debbugs.*" "bug-gnu-emacs")
1213 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1214 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1215 (set (make-local-variable 'message-alter-recipients-function)
1217 (if (string-match "\\([0-9]+\\)@donarmstrong"
1219 (let ((new (format "%s@debbugs.gnu.org"
1220 (match-string 1 (car address)))))
1223 ;; `gnus-posting-styles' is eval'ed after
1224 ;; `message-simplify-subject'. So we cannot use m-s-s.
1225 (setq subject ,debbugs-gnu-subject))))))))
1227 (defun debbugs-gnu-guess-current-id ()
1228 "Guess the ID based on \"#23\"."
1232 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1234 (goto-char (point-min))
1235 (re-search-forward "#\\([0-9]+\\)" nil t)))
1236 (string-to-number (match-string 1)))))
1238 (defvar debbugs-gnu-send-mail-function nil
1239 "A function to send control messages from debbugs.")
1241 (defun debbugs-gnu-send-control-message (message &optional reverse)
1242 "Send a control message for the current bug report.
1243 You can set the severity or add a tag, or close the report. If
1244 you use the special \"done\" MESSAGE, the report will be marked as
1245 fixed, and then closed.
1247 If given a prefix, and given a tag to set, the tag will be
1250 (list (completing-read
1252 '("serious" "important" "normal" "minor" "wishlist"
1253 "done" "donenotabug" "donewontfix" "doneunreproducible"
1254 "unarchive" "unmerge" "reopen" "close"
1255 "merge" "forcemerge"
1261 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1262 "pending" "help" "security" "confirmed"
1265 current-prefix-arg))
1266 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1267 (debbugs-gnu-guess-current-id)
1268 (debbugs-gnu-current-id)))
1270 (when (member message '("close" "done"))
1274 ;; Emacs development versions.
1276 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1278 (match-string 1 emacs-version)
1279 (1+ (string-to-number (match-string 2 emacs-version)))))
1280 ;; Emacs release versions.
1282 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1284 (match-string 1 emacs-version)
1285 (match-string 2 emacs-version)))
1286 (t emacs-version)))))
1287 (status (debbugs-gnu-current-status)))
1289 (insert "To: control@debbugs.gnu.org\n"
1290 "From: " (message-make-from) "\n"
1291 (format "Subject: control message for bug #%d\n" id)
1292 mail-header-separator
1295 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1296 (format "%s %d\n" message id))
1297 ((member message '("merge" "forcemerge"))
1298 (format "%s %d %s\n" message id
1299 (read-string "Merge with bug #: ")))
1300 ((member message '("block" "unblock"))
1302 "%s %d by %s\n" message id
1305 (completing-read-multiple
1306 (format "%s with bug(s) #: " (capitalize message))
1307 (if (equal message "unblock")
1308 (mapcar 'number-to-string
1309 (cdr (assq 'blockedby status))))
1310 nil (and (equal message "unblock") status))
1312 ((equal message "owner")
1313 (format "owner %d !\n" id))
1314 ((equal message "retitle")
1315 (format "retitle %d %s\n" id (read-string "New title: ")))
1316 ((equal message "reassign")
1317 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1318 ((equal message "close")
1319 (format "close %d %s\n" id version))
1320 ((equal message "done")
1321 (format "tags %d fixed\nclose %d %s\n" id id version))
1322 ((member message '("donenotabug" "donewontfix"
1323 "doneunreproducible"))
1324 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1325 ((member message '("serious" "important" "normal"
1326 "minor" "wishlist"))
1327 (format "severity %d %s\n" id message))
1328 ((equal message "invalid")
1329 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1331 ((equal message "usertag")
1332 (format "user %s\nusertag %d %s\n"
1334 "Package name or email address: "
1336 debbugs-gnu-all-packages (list user-mail-address))
1337 nil nil (car debbugs-gnu-default-packages))
1338 id (read-string "User tag: ")))
1340 (format "tags %d%s %s\n"
1341 id (if reverse " -" "")
1343 (funcall (or debbugs-gnu-send-mail-function send-mail-function))
1344 (remhash id debbugs-cache-data)
1346 (message "Control message sent:\n%s"
1347 (buffer-substring-no-properties (point) (1- (point-max)))))))
1349 (defvar debbugs-gnu-usertags-mode-map
1350 (let ((map (make-sparse-keymap)))
1351 (set-keymap-parent map tabulated-list-mode-map)
1352 (define-key map "\r" 'debbugs-gnu-select-usertag)
1353 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1354 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1357 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1358 "Major mode for listing user tags.
1360 All normal editing commands are switched off.
1361 \\<debbugs-gnu-usertags-mode-map>
1363 The following commands are available:
1365 \\{debbugs-gnu-usertags-mode-map}"
1366 (buffer-disable-undo)
1367 (setq truncate-lines t)
1368 (setq buffer-read-only t))
1371 (defun debbugs-gnu-usertags (&rest users)
1372 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1374 (if current-prefix-arg
1375 (completing-read-multiple
1376 "Package name(s) or email address: "
1377 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1378 (mapconcat 'identity debbugs-gnu-default-packages ","))
1379 debbugs-gnu-default-packages))
1382 (let ((inhibit-read-only t)
1383 (debbugs-port "gnu.org")
1384 (buffer-name "*Emacs User Tags*")
1386 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1388 ;; Initialize variables.
1389 (when (and (file-exists-p debbugs-gnu-persistency-file)
1390 (not debbugs-gnu-local-tags))
1392 (insert-file-contents debbugs-gnu-persistency-file)
1393 (eval (read (current-buffer)))))
1396 (when (get-buffer buffer-name)
1397 (kill-buffer buffer-name))
1398 (switch-to-buffer (get-buffer-create buffer-name))
1399 (debbugs-gnu-usertags-mode)
1400 (setq tabulated-list-format `[("User" ,user-tab-length t)
1402 (setq tabulated-list-sort-key (cons "User" nil))
1403 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1405 ;; Retrieve user tags.
1406 (dolist (user users)
1407 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1409 'tabulated-list-entries
1410 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1411 `((("tagged") (,user) nil nil (,tag))
1412 ,(vector (propertize user 'mouse-face 'highlight)
1413 (propertize tag 'mouse-face 'highlight)))
1417 (when debbugs-gnu-local-tags
1419 'tabulated-list-entries
1422 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1425 (tabulated-list-init-header)
1426 (tabulated-list-print)
1428 (set-buffer-modified-p nil)
1429 (goto-char (point-min)))))
1431 (defun debbugs-gnu-select-usertag ()
1432 "Select the user tag on the current line."
1434 ;; We open the bug reports.
1435 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1436 (when args (apply 'debbugs-gnu args))))
1439 (defun debbugs-gnu-bugs (&rest bugs)
1440 "List all BUGS, a list of bug numbers."
1442 (mapcar 'string-to-number
1443 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1445 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1446 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1447 ;; We do not suppress bugs requested explicitely.
1448 (setq debbugs-gnu-current-suppress nil)
1451 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1452 "The directory where the main source tree lives.")
1454 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1455 "The directory where the previous source tree lives.")
1457 (defun debbugs-gnu-apply-patch (&optional branch)
1458 "Apply the patch from the current message.
1459 If given a prefix, patch in the branch directory instead."
1461 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1462 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1463 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1464 (let ((rej "/tmp/debbugs-gnu.rej")
1465 (output-buffer (get-buffer-create "*debbugs patch*"))
1467 debbugs-gnu-branch-directory
1468 debbugs-gnu-trunk-directory))
1469 (patch-buffers nil))
1470 (when (file-exists-p rej)
1472 (with-current-buffer output-buffer
1474 (gnus-summary-select-article nil t)
1475 ;; The patches are either in MIME attachements or the main article
1476 ;; buffer. Determine which.
1477 (gnus-with-article-buffer
1478 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1479 (when (string-match "diff\\|patch\\|plain" (mm-handle-media-type handle))
1480 (push (cons (mm-handle-encoding handle)
1481 (mm-handle-buffer handle))
1483 (unless patch-buffers
1484 (gnus-summary-show-article 'raw)
1485 (article-decode-charset)
1486 (push (cons nil gnus-article-buffer) patch-buffers))
1487 (dolist (elem patch-buffers)
1488 (with-current-buffer (generate-new-buffer "*debbugs input patch*")
1489 (insert-buffer-substring (cdr elem))
1490 (cond ((eq (car elem) 'base64)
1491 (base64-decode-region (point-min) (point-max)))
1492 ((eq (car elem) 'quoted-printable)
1493 (quoted-printable-decode-region (point-min) (point-max))))
1494 (debbugs-gnu-fix-patch dir)
1495 (call-process-region (point-min) (point-max)
1496 "patch" nil output-buffer nil
1497 "-r" rej "--no-backup-if-mismatch"
1499 "-d" (expand-file-name dir)
1501 (set-buffer output-buffer)
1502 (when (file-exists-p rej)
1503 (goto-char (point-max))
1504 (insert-file-contents-literally rej))
1505 (goto-char (point-max))
1506 (save-some-buffers t)
1508 (mapc 'kill-process compilation-in-progress)
1509 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1511 (vc-dir-hide-up-to-date)
1512 (goto-char (point-min))
1515 ;; All these commands are asynchronous, so just wait a bit. This
1516 ;; should be done properly a different way.
1518 ;; We've now done everything, so arrange the windows we need to see.
1519 (delete-other-windows)
1520 (switch-to-buffer output-buffer)
1524 (switch-to-buffer "*compilation*")
1525 (goto-char (point-max))
1527 (switch-to-buffer "*vc-diff*")
1528 (goto-char (point-min))))
1530 (defun debbugs-gnu-fix-patch (dir)
1531 (setq dir (directory-file-name (expand-file-name dir)))
1532 (goto-char (point-min))
1533 (while (re-search-forward diff-file-header-re nil t)
1534 (goto-char (match-beginning 0))
1535 (let ((target-name (car (diff-hunk-file-names))))
1536 (when (and target-name
1537 (or (not (string-match "/" target-name))
1538 (and (string-match "^[ab]/" target-name)
1540 (expand-file-name (substring target-name 2)
1542 (file-exists-p (expand-file-name target-name dir))))
1543 ;; We have a simple patch that refers to a file somewhere in the
1545 (when-let ((files (directory-files-recursively
1547 (concat "^" (regexp-quote
1548 (file-name-nondirectory target-name))
1550 (when (re-search-forward (concat "^[+]+ "
1551 (regexp-quote target-name)
1554 (replace-match (concat "+++ a"
1555 (substring (car files) (length dir))
1560 (defun debbugs-gnu-find-contributor (string)
1561 "Search through ChangeLogs to find contributors."
1562 (interactive "sContributor match: ")
1564 (match (concat "^[0-9].*" string)))
1565 (dolist (file (directory-files-recursively
1566 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1568 (when (file-exists-p file)
1569 (insert-file-contents file))
1570 (goto-char (point-min))
1571 (while (and (re-search-forward match nil t)
1572 (not (looking-at ".*tiny change")))
1574 (message "%s is a contributor %d times" string found)
1577 (defun debbugs-gnu-insert-changelog ()
1578 "Add a ChangeLog from a recently applied patch from a third party."
1581 (gnus-with-article-buffer
1583 (goto-char (point-min))
1584 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1585 subject (gnus-fetch-field "subject")))
1586 (let ((add-log-full-name (car from))
1587 (add-log-mailing-address (cadr from)))
1588 (add-change-log-entry-other-window)
1589 (let ((point (point)))
1590 (when (string-match "\\(bug#[0-9]+\\)" subject)
1591 (insert " (" (match-string 1 subject) ")."))
1592 (when (zerop (debbugs-gnu-find-contributor
1593 (let ((bits (split-string (car from))))
1595 ((>= (length bits) 2)
1596 (format "%s.*%s" (car bits) (car (last bits))))
1597 ((= (length bits) 1)
1599 ;; Fall back on the email address.
1602 (goto-char (point-max))
1604 (insert " Copyright-paperwork-exempt: yes"))
1605 (goto-char point)))))
1607 (defvar debbugs-gnu-lisp-mode-map
1608 (let ((map (make-sparse-keymap)))
1609 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1612 (define-minor-mode debbugs-gnu-lisp-mode
1613 "Minor mode for providing a debbugs interface in Lisp buffers.
1614 \\{debbugs-gnu-lisp-mode-map}"
1615 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1617 (defvar debbugs-gnu-diff-mode-map
1618 (let ((map (make-sparse-keymap)))
1619 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1622 (define-minor-mode debbugs-gnu-diff-mode
1623 "Minor mode for providing a debbugs interface in diff buffers.
1624 \\{debbugs-gnu-diff-mode-map}"
1625 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1627 (defun debbugs-gnu-diff-select ()
1628 "Select the diff under point."
1630 (delete-other-windows)
1633 (defvar debbugs-gnu-change-mode-map
1634 (let ((map (make-sparse-keymap)))
1635 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1638 (define-minor-mode debbugs-gnu-change-mode
1639 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1640 \\{debbugs-gnu-change-mode-map}"
1641 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1643 (defun debbugs-gnu-change-checkin ()
1644 "Prepare checking in the current changes."
1646 (save-some-buffers t)
1647 (when (get-buffer "*vc-dir*")
1648 (kill-buffer (get-buffer "*vc-dir*")))
1649 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1650 (if (equal (cl-subseq default-directory 0 (length trunk))
1652 (vc-dir debbugs-gnu-trunk-directory)
1653 (vc-dir debbugs-gnu-branch-directory)))
1654 (goto-char (point-min))
1655 (while (not (search-forward "edited" nil t))
1658 (while (search-forward "edited" nil t)
1660 (beginning-of-line))
1662 (vc-next-action nil)
1663 (log-edit-insert-changelog t)
1664 (delete-other-windows)
1667 (switch-to-buffer "*vc-diff*")
1670 (defun debbugs-gnu-save-cache ()
1671 "Save the bugs cache to a file."
1673 (unless debbugs-cache-data
1674 (error "No data to cache"))
1675 (unless (file-exists-p "~/.emacs.d/debbugs-cache")
1676 (make-directory "~/.emacs.d/debbugs-cache" t))
1677 (let ((coding-system-for-write 'utf-8))
1678 (with-temp-file "~/.emacs.d/debbugs-cache/list"
1679 (prin1 debbugs-cache-data (current-buffer)))))
1681 (provide 'debbugs-gnu)
1685 ;; * Another random thought - is it possible to implement some local
1686 ;; cache, so only changed bugs are fetched? Glenn Morris.
1688 ;;; debbugs-gnu.el ends here