1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
11 ;; This file is not part of GNU Emacs.
13 ;; This program is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This package provides an interface to bug reports which are located
29 ;; on the GNU bug tracker debbugs.gnu.org. Its main purpose is to
30 ;; show and manipulate bug reports from Emacs, but it could be used
31 ;; also for other GNU projects which use the same bug tracker.
33 ;; If you have `debbugs-gnu.el' in your load-path, you could enable
34 ;; the bug tracker commands by the following lines in your ~/.emacs
36 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
37 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
38 ;; (autoload 'debbugs-gnu-usertags "debbugs-gnu" "" 'interactive)
39 ;; (autoload 'debbugs-gnu-bugs "debbugs-gnu" "" 'interactive)
41 ;; The bug tracker is called interactively by
45 ;; It asks for the severities, for which bugs shall be shown. This can
46 ;; be either just one severity, or a list of severities, separated by
47 ;; comma. Valid severities are "serious", "important", "normal",
48 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
49 ;; used, although configured on the GNU bug tracker. If no severity
50 ;; is given, all bugs are selected.
52 ;; There is also the pseudo severity "tagged". When it is used, the
53 ;; function will ask for user tags (a comma separated list), and shows
54 ;; just the bugs which are tagged with them. In general, user tags
55 ;; shall be strings denoting to subprojects of the package, like
56 ;; "cedet" or "tramp" of the package "emacs". If no user tag is
57 ;; given, locally tagged bugs are shown.
59 ;; If a prefix is given to the command, more search parameters are
60 ;; asked for, like packages (also a comma separated list, "emacs" is
61 ;; the default), whether archived bugs shall be shown, and whether
62 ;; closed bugs shall be shown.
66 ;; M-x debbugs-gnu-search
68 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
69 ;; search phrase to be used for full text search. Additionally, it
70 ;; asks for key-value pairs to filter bugs. Keys are as described in
71 ;; `debbugs-get-status', the corresponding value must be a regular
72 ;; expression to match for. The other parameters are as described in
73 ;; `debbugs-gnu'. Usually, there is just one value except for the
74 ;; attribute "date", which needs two arguments specifying a period in
75 ;; which the bug has been submitted or modified.
77 ;; The bug reports are downloaded from the bug tracker. In order to
78 ;; not generate too much load of the server, up to 500 bugs will be
79 ;; downloaded at once. If there are more hits, you will be asked to
80 ;; change this limit, but please don't increase this number too much.
82 ;; These default values could be changed also by customer options
83 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages',
84 ;; `debbugs-gnu-default-hits-per-page' and `debbugs-gnu-default-suppress-bugs'.
86 ;; The commands create one or more pages of bug lists. Every bug is
87 ;; shown in one line, including the bug number, the status (combining
88 ;; merged bug numbers, keywords and severities), the name of the
89 ;; submitter, and the title of the bug. On every bug line you could
90 ;; apply the following actions by the following keystrokes:
92 ;; RET: Show corresponding messages in Gnus/Rmail
93 ;; "C": Send a control message
94 ;; "t": Mark the bug locally as tagged
95 ;; "b": Show bugs this bug is blocked by
96 ;; "B": Show bugs this bug is blocking
97 ;; "d": Show bug attributes
99 ;; Furthermore, you could apply the global actions
102 ;; "q": Quit the buffer
103 ;; "s": Toggle bug sorting for age or for state
104 ;; "x": Toggle suppressing of bugs
105 ;; "/": Display only bugs matching a string
106 ;; "R": Display only bugs blocking the current release
107 ;; "w": Display all the currently selected bug reports
109 ;; When you visit the related bug messages in Gnus, you could also
110 ;; send control messages by keystroke "C".
112 ;; In the header line of every bug list page, you can toggle sorting
113 ;; per column by selecting a column with the mouse. The sorting
114 ;; happens as expected for the respective column; sorting in the Title
115 ;; column is depending on whether you are the owner of a bug.
117 ;; Another approach for listing bugs is calling the command
119 ;; M-x debbugs-gnu-usertags
121 ;; This command shows you all existing user tags for the packages
122 ;; defined in `debbugs-gnu-default-packages'. A prefix for the
123 ;; command allows you to use other packe names, or an arbitrary string
124 ;; for a user who has tagged bugs. The command returns the list of
125 ;; existing user tags for the given user(s) or package name(s),
126 ;; respectively. Applying RET on a user tag, all bugs tagged with
127 ;; this user tag are shown.
129 ;; Unfortunately, it is not possible with the SOAP interface to show
130 ;; all users who have tagged bugs. This list can be retrieved via
131 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi?indexon=users>.
133 ;; Finally, if you simply want to list some bugs with known bug
134 ;; numbers, call the command
136 ;; M-x debbugs-gnu-bugs
138 ;; The bug numbers to be shown shall be entered as comma separated list.
143 (require 'tabulated-list)
146 (eval-when-compile (require 'cl))
148 (autoload 'article-decode-charset "gnus-art")
149 (autoload 'diff-goto-source "diff-mode")
150 (autoload 'diff-hunk-file-names "diff-mode")
151 (autoload 'gnus-article-mime-handles "gnus-art")
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-make-from "message")
160 (autoload 'rmail-get-new-mail "rmail")
161 (autoload 'rmail-show-message "rmail")
162 (autoload 'rmail-summary "rmailsum")
163 (autoload 'vc-dir-hide-up-to-date "vc-dir")
164 (autoload 'vc-dir-mark "vc-dir")
166 (defvar compilation-in-progress)
167 (defvar diff-file-header-re)
168 (defvar gnus-article-buffer)
169 (defvar gnus-posting-styles)
170 (defvar gnus-save-duplicate-list)
171 (defvar gnus-suppress-duplicates)
172 (defvar rmail-current-message)
173 (defvar rmail-mode-map)
174 (defvar rmail-summary-mode-map)
175 (defvar rmail-total-messages)
177 (defgroup debbugs-gnu ()
178 "UI for the debbugs.gnu.org bug tracker."
182 (defvar debbugs-gnu-blocking-report 19759
183 "The ID of the current release report used to track blocking bug reports.")
185 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
186 "*The list severities bugs are searched for.
187 \"tagged\" is not a severity but marks locally tagged bugs."
188 ;; <http://debbugs.gnu.org/Developer.html#severities>
189 ;; /ssh:debbugs:/etc/debbugs/config @gSeverityList
190 ;; We don't use "critical" and "grave".
192 :type '(set (const "serious")
200 (defconst debbugs-gnu-all-severities
201 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
202 "*List of all possible severities.")
204 (defcustom debbugs-gnu-default-packages '("emacs")
205 "*The list of packages to be searched for."
206 ;; <http://debbugs.gnu.org/Packages.html>
207 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
209 :type '(set (const "adns")
215 (const "debbugs.gnu.org")
218 (const "emacs-xwidgets")
235 (defconst debbugs-gnu-all-packages
236 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
237 "*List of all possible package names.")
239 (defcustom debbugs-gnu-default-suppress-bugs
240 '((pending . "done"))
241 "*A list of specs for bugs to be suppressed.
242 An element of this list is a cons cell \(KEY . REGEXP\), with key
243 being returned by `debbugs-get-status', and VAL a regular
244 expression matching the corresponding value, a string. Showing
245 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
247 :type '(alist :key-type symbol :value-type regexp)
250 (defcustom debbugs-gnu-mail-backend 'gnus
251 "*The email backend to use for reading bug report email exchange.
252 If this is 'gnus, the default, use Gnus.
253 If this is 'rmail, use Rmail instead."
255 :type '(choice (const :tag "Use Gnus" 'gnus)
256 (const :tag "Use Rmail" 'rmail))
259 (defface debbugs-gnu-archived '((t (:inverse-video t)))
260 "Face for archived bug reports.")
262 (defface debbugs-gnu-new '((t (:foreground "red")))
263 "Face for new reports that nobody has answered.")
265 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
266 "Face for reports that have been modified recently.")
268 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
269 "Face for reports that are pending.")
271 (defface debbugs-gnu-stale '((t (:foreground "orange")))
272 "Face for reports that have not been touched for a week.")
274 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
275 "Face for closed bug reports.")
277 (defface debbugs-gnu-tagged '((t (:foreground "red")))
278 "Face for reports that have been tagged locally.")
280 (defvar debbugs-gnu-local-tags nil
281 "List of bug numbers tagged locally, and kept persistent.")
283 (defvar debbugs-gnu-persistency-file
284 (expand-file-name (locate-user-emacs-file "debbugs"))
285 "File name of a persistency store for debbugs variables")
287 (defun debbugs-gnu-dump-persistency-file ()
288 "Function to store debbugs variables persistently."
289 (with-temp-file debbugs-gnu-persistency-file
291 ";; -*- emacs-lisp -*-\n"
292 ";; Debbugs tags connection history. Don't change this file.\n\n"
293 (format "(setq debbugs-gnu-local-tags '%S)"
294 (sort (copy-sequence debbugs-gnu-local-tags) '<)))))
296 (defvar debbugs-gnu-current-query nil
297 "The query object of the current search.
298 It will be applied server-side, when calling `debbugs-get-bugs'.
299 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
301 (defvar debbugs-gnu-current-filter nil
302 "The filter object for the current search.
303 It will be applied client-side, when parsing the results of
304 `debbugs-get-status'. It has a similar format as
305 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
306 a date, value is the cons cell \(BEFORE . AFTER\).")
308 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
309 "Return a string read from the minibuffer.
310 Derived from `calendar-read'."
311 (let ((value (read-string prompt initial-contents)))
312 (while (not (funcall acceptable value))
313 (setq value (read-string prompt initial-contents)))
316 (defconst debbugs-gnu-phrase-prompt
318 "Enter search phrase: "
320 The search phrase contains words to be searched for, combined by
321 operators like AND, ANDNOT and OR. If there is no operator
322 between the words, AND is used by default. The phrase can also
323 be empty, in this case only the following attributes are used for
327 (defun debbugs-gnu-search ()
328 "Search for Emacs bugs interactively.
329 Search arguments are requested interactively. The \"search
330 phrase\" is used for full text search in the bugs database.
331 Further key-value pairs are requested until an empty key is
332 returned. If a key cannot be queried by a SOAP request, it is
333 marked as \"client-side filter\"."
337 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
338 key val1 val2 phrase severities packages archivedp)
340 ;; Check for the phrase.
341 (setq phrase (read-string debbugs-gnu-phrase-prompt))
342 (if (zerop (length phrase))
344 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
346 ;; The other queries.
349 (setq key (completing-read
352 '("severity" "package" "tags" "submitter" "date"
354 '("severity" "package" "archive" "src" "tag"
355 "owner" "submitter" "maint" "correspondent"
356 "date" "log_modified" "last_modified"
357 "found_date" "fixed_date" "unarchived"
358 "subject" "done" "forwarded" "msgid" "summary"))
361 ;; Server-side queries.
362 ((equal key "severity")
365 (completing-read-multiple
366 "Enter severities: " debbugs-gnu-all-severities nil t
367 (mapconcat 'identity debbugs-gnu-default-severities ","))))
369 ((equal key "package")
372 (completing-read-multiple
373 "Enter packages: " debbugs-gnu-all-packages nil t
374 (mapconcat 'identity debbugs-gnu-default-packages ","))))
376 ((equal key "archive")
377 ;; We simplify, by assuming just archived bugs are requested.
380 ((member key '("src" "tag" "tags"))
381 (setq val1 (read-string (format "Enter %s: " key)))
382 (when (not (zerop (length val1)))
384 'debbugs-gnu-current-query (cons (intern key) val1))))
386 ((member key '("owner" "submitter" "maint" "correspondent"))
387 (setq val1 (read-string "Enter email address: "))
388 (when (not (zerop (length val1)))
390 'debbugs-gnu-current-query (cons (intern key) val1))))
392 ((equal key "status")
395 (completing-read "Enter status: " '("done" "forwarded" "open")))
396 (when (not (zerop (length val1)))
398 'debbugs-gnu-current-query (cons (intern key) val1))))
400 ;; Client-side filters.
401 ((member key '("date" "log_modified" "last_modified"
402 "found_date" "fixed_date" "unarchived"))
404 (debbugs-gnu-calendar-read
405 (format "Enter %s before YYYY-MM-DD%s: "
406 key (if phrase "" " (client-side filter)"))
408 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
409 (if (string-match date-format val1)
414 (string-to-number (match-string 3 val1))
415 (string-to-number (match-string 2 val1))
416 (string-to-number (match-string 1 val1))))))
419 (debbugs-gnu-calendar-read
420 (format "Enter %s after YYYY-MM-DD%s: "
421 key (if phrase "" " (client-side filter)"))
423 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
424 (if (string-match date-format val2)
429 (string-to-number (match-string 3 val2))
430 (string-to-number (match-string 2 val2))
431 (string-to-number (match-string 1 val2))))))
436 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
437 (cons (intern key) (cons val1 val2)))))
439 ((not (zerop (length key)))
442 (if phrase 'read-string 'read-regexp)
444 key (if phrase ": " " (client-side filter)"))))
445 (when (not (zerop (length val1)))
448 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
449 (cons (intern key) val1))))
452 (t (throw :finished nil)))))
455 (debbugs-gnu severities packages archivedp))
457 ;; Reset query and filter.
458 (setq debbugs-gnu-current-query nil
459 debbugs-gnu-current-filter nil)))
461 (defvar debbugs-gnu-current-limit nil)
462 (defvar debbugs-gnu-current-suppress nil)
465 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
466 "List all outstanding bugs."
468 (let (severities archivedp)
471 (completing-read-multiple
472 "Severities: " debbugs-gnu-all-severities nil t
473 (mapconcat 'identity debbugs-gnu-default-severities ",")))
474 ;; The next parameters are asked only when there is a prefix.
475 (if current-prefix-arg
476 (completing-read-multiple
477 "Packages: " debbugs-gnu-all-packages nil t
478 (mapconcat 'identity debbugs-gnu-default-packages ","))
479 debbugs-gnu-default-packages)
480 (when current-prefix-arg
481 (setq archivedp (y-or-n-p "Show archived bugs?")))
482 (when (and current-prefix-arg (not archivedp))
483 (y-or-n-p "Suppress unwanted bugs?"))
484 ;; This one must be asked for severity "tagged".
485 (when (member "tagged" severities)
486 (split-string (read-string "User tag(s): ") "," t)))))
488 ;; Initialize variables.
489 (when (and (file-exists-p debbugs-gnu-persistency-file)
490 (not debbugs-gnu-local-tags))
492 (insert-file-contents debbugs-gnu-persistency-file)
493 (eval (read (current-buffer)))))
496 (dolist (severity (if (consp severities) severities (list severities)))
497 (when (not (zerop (length severity)))
498 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
499 (dolist (package (if (consp packages) packages (list packages)))
500 (when (not (zerop (length package)))
501 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
503 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
505 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
506 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded"))
507 (setq debbugs-gnu-current-suppress suppress))
508 (dolist (tag (if (consp tags) tags (list tags)))
509 (when (not (zerop (length tag)))
510 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
513 (debbugs-gnu-show-reports)
515 ;; Reset query and filter.
516 (setq debbugs-gnu-current-query nil
517 debbugs-gnu-current-filter nil))
519 (defun debbugs-gnu-get-bugs (query)
520 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
521 (let* ((debbugs-port "gnu.org")
522 (bugs (assoc 'bugs query))
523 (tags (assoc 'tag query))
524 (local-tags (and (member '(severity . "tagged") query) (not tags)))
525 (phrase (assoc 'phrase query))
527 ;; Compile query arguments.
528 (unless (or query tags)
529 (dolist (elt debbugs-gnu-default-packages)
530 (setq args (append args (list :package elt)))))
532 (unless (equal elt '(severity . "tagged"))
538 ((eq (car elt) 'phrase)
539 (list (list :phrase (cdr elt) :max 500)))
540 ((eq (car elt) 'date)
541 (list (list :date (cddr elt) (cadr elt)
544 (list (list (intern (concat ":" (symbol-name (car elt))))
545 (cdr elt) :operator "ISTRINC"))))
546 (list (intern (concat ":" (symbol-name (car elt))))
551 ;; If the query is just a list of bug numbers, we return them.
553 ;; If the query contains the pseudo-severity "tagged", we return
554 ;; just the local tagged bugs.
555 (local-tags (copy-sequence debbugs-gnu-local-tags))
556 ;; A full text query.
559 (lambda (x) (cdr (assoc "id" x)))
560 (apply 'debbugs-search-est args)))
563 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
564 (apply 'debbugs-get-usertag args))
565 ;; Otherwise, we retrieve the bugs from the server.
566 (t (apply 'debbugs-get-bugs args)))
570 (defun debbugs-gnu-show-reports ()
572 (let ((inhibit-read-only t)
573 (debbugs-port "gnu.org")
574 (buffer-name "*Emacs Bugs*"))
575 ;; The tabulated mode sets several local variables. We must get
577 (when (get-buffer buffer-name)
578 (kill-buffer buffer-name))
579 (switch-to-buffer (get-buffer-create buffer-name))
582 ;; Print bug reports.
584 (apply 'debbugs-get-status
585 (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
586 (let* ((id (cdr (assq 'id status)))
590 (cons (cdr (assq 'severity status))
591 (cdr (assq 'keywords status)))
593 (address (mail-header-parse-address
594 (decode-coding-string (cdr (assq 'originator status))
596 (owner (if (cdr (assq 'owner status))
597 (car (mail-header-parse-address
598 (decode-coding-string (cdr (assq 'owner status))
600 (subject (decode-coding-string (cdr (assq 'subject status))
603 (unless (equal (cdr (assq 'pending status)) "pending")
604 (setq words (concat words "," (cdr (assq 'pending status)))))
605 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
607 (setq words (concat words "," (mapconcat 'identity packages ",")))))
608 (when (setq merged (cdr (assq 'mergedwith status)))
609 (setq words (format "%s,%s"
612 (mapconcat 'number-to-string merged ","))
614 (when (or (not merged)
615 (not (let ((found nil))
616 (dolist (id (if (listp merged)
619 (dolist (entry tabulated-list-entries)
620 (when (equal id (cdr (assq 'id (car entry))))
624 'tabulated-list-entries
632 (if (memq id debbugs-gnu-local-tags)
636 ;; Mark status and age.
640 ((cdr (assq 'archived status))
641 'debbugs-gnu-archived)
642 ((equal (cdr (assq 'pending status)) "done")
644 ((member "pending" (cdr (assq 'keywords status)))
645 'debbugs-gnu-pending)
646 ((= (cdr (assq 'date status))
647 (cdr (assq 'log_modified status)))
650 (cdr (assq 'log_modified status)))
652 'debbugs-gnu-handled)
654 'debbugs-gnu-stale)))
656 ;; Prefer the name over the address.
660 ;; Mark own submitted bugs.
661 (if (and (stringp (car address))
662 (string-equal (car address) user-mail-address))
669 (if (and (stringp owner)
670 (string-equal owner user-mail-address))
675 (tabulated-list-init-header)
676 (tabulated-list-print)
678 (set-buffer-modified-p nil)
679 (goto-char (point-min))))
681 (defun debbugs-gnu-print-entry (list-id cols)
682 "Insert a debbugs entry at point.
683 Used instead of `tabulated-list-print-entry'."
688 (id-length (nth 1 (aref tabulated-list-format 0)))
689 (state (aref cols 1))
690 (state-length (nth 1 (aref tabulated-list-format 1)))
691 (submitter (aref cols 2))
692 (submitter-length (nth 1 (aref tabulated-list-format 2)))
693 (title (aref cols 3))
694 (title-length (nth 1 (aref tabulated-list-format 3))))
696 ;; We may have a narrowing in effect.
697 (or (not debbugs-gnu-current-limit)
698 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
699 ;; Filter suppressed bugs.
700 (or (not debbugs-gnu-current-suppress)
701 (and (not (memq (cdr (assq 'id list-id)) debbugs-gnu-local-tags))
702 (not (catch :suppress
703 (dolist (check debbugs-gnu-default-suppress-bugs)
707 (or (cdr (assq (car check) list-id)) ""))
708 (throw :suppress t)))))))
709 ;; Filter search list.
710 (not (catch :suppress
711 (dolist (check debbugs-gnu-current-filter)
712 (let ((val (cdr (assq (car check) list-id))))
713 (if (stringp (cdr check))
714 ;; Regular expression.
715 (when (not (string-match (cdr check) (or val "")))
718 (when (or (and (numberp (cadr check))
719 (< (cadr check) val))
720 (and (numberp (cddr check))
721 (> (cddr check) val)))
722 (throw :suppress t))))))))
725 (indent-to (- id-length (length id)))
728 (indent-to (setq pos (+ pos id-length 1)) 1)
729 (insert (if (> (length state) state-length)
730 (propertize (substring state 0 state-length)
734 (indent-to (setq pos (+ pos state-length 1)) 1)
735 (insert "[" (if (> (length submitter) (- submitter-length 2))
736 (propertize (substring submitter 0 (- submitter-length 2))
737 'help-echo submitter)
739 (indent-to (+ pos (1- submitter-length)))
742 (indent-to (setq pos (+ pos submitter-length 1)) 1)
743 (insert (propertize title 'help-echo title))
747 `(tabulated-list-id ,list-id mouse-face highlight))
750 (defvar debbugs-gnu-mode-map
751 (let ((map (make-sparse-keymap)))
752 (set-keymap-parent map tabulated-list-mode-map)
753 (define-key map "\r" 'debbugs-gnu-select-report)
754 (define-key map [mouse-1] 'debbugs-gnu-select-report)
755 (define-key map [mouse-2] 'debbugs-gnu-select-report)
756 (define-key map "s" 'debbugs-gnu-toggle-sort)
757 (define-key map "t" 'debbugs-gnu-toggle-tag)
758 (define-key map "d" 'debbugs-gnu-display-status)
759 (define-key map "g" 'debbugs-gnu-rescan)
760 (define-key map "x" 'debbugs-gnu-toggle-suppress)
761 (define-key map "/" 'debbugs-gnu-narrow-to-status)
762 (define-key map "w" 'debbugs-gnu-widen)
763 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
764 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
765 (define-key map "C" 'debbugs-gnu-send-control-message)
766 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
769 (defun debbugs-gnu-rescan ()
770 "Rescan the current set of bug reports."
772 ;; Refresh the buffer. `save-excursion' does not work, so we
773 ;; remember the position.
775 (debbugs-gnu-show-reports)
778 (defvar debbugs-gnu-sort-state 'number)
780 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
781 "Major mode for listing bug reports.
783 All normal editing commands are switched off.
784 \\<debbugs-gnu-mode-map>
786 The following commands are available:
788 \\{debbugs-gnu-mode-map}"
789 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
790 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
791 (set (make-local-variable 'debbugs-gnu-current-suppress) nil)
792 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
793 ("State" 20 debbugs-gnu-sort-state)
795 ("Title" 10 debbugs-gnu-sort-title)])
796 (setq tabulated-list-sort-key (cons "Id" nil))
797 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
798 (buffer-disable-undo)
799 (setq truncate-lines t)
800 (setq buffer-read-only t))
802 (defun debbugs-gnu-sort-id (s1 s2)
803 (< (cdr (assq 'id (car s1)))
804 (cdr (assq 'id (car s2)))))
806 (defconst debbugs-gnu-state-preference
807 '((debbugs-gnu-new . 1)
808 (debbugs-gnu-stale . 2)
809 (debbugs-gnu-handled . 3)
810 (debbugs-gnu-done . 4)
811 (debbugs-gnu-pending . 5)))
813 (defun debbugs-gnu-get-state-preference (face-string)
814 (or (cdr (assq (get-text-property 0 'face face-string)
815 debbugs-gnu-state-preference))
818 (defconst debbugs-gnu-severity-preference
825 (defun debbugs-gnu-get-severity-preference (state)
826 (or (cdr (assoc (cdr (assq 'severity state))
827 debbugs-gnu-severity-preference))
830 (defun debbugs-gnu-sort-state (s1 s2)
831 (let ((id1 (cdr (assq 'id (car s1))))
832 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
833 (id2 (cdr (assq 'id (car s2))))
834 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
836 ;; Tagged bugs go to the end.
837 ((and (not (memq id1 debbugs-gnu-local-tags))
838 (memq id2 debbugs-gnu-local-tags))
840 ((and (memq id1 debbugs-gnu-local-tags)
841 (not (memq id2 debbugs-gnu-local-tags)))
843 ;; Then, we check the age of the bugs.
848 ;; If they have the same age, we check for severity.
849 ((< (debbugs-gnu-get-severity-preference (car s1))
850 (debbugs-gnu-get-severity-preference (car s2)))
854 (defun debbugs-gnu-sort-title (s1 s2)
855 (let ((owner (if (cdr (assq 'owner (car s1)))
856 (car (mail-header-parse-address
857 (decode-coding-string (cdr (assq 'owner (car s1)))
860 (string-equal owner user-mail-address))))
862 (defun debbugs-gnu-toggle-sort ()
863 "Toggle sorting by age and by state."
865 (if (eq debbugs-gnu-sort-state 'number)
867 (setq debbugs-gnu-sort-state 'state)
868 (setq tabulated-list-sort-key (cons "Id" nil)))
869 (setq debbugs-gnu-sort-state 'number)
870 (setq tabulated-list-sort-key (cons "State" nil)))
871 (tabulated-list-init-header)
872 (tabulated-list-print))
874 (defun debbugs-gnu-widen ()
875 "Display all the currently selected bug reports."
877 (let ((id (debbugs-gnu-current-id t))
878 (inhibit-read-only t))
879 (setq debbugs-gnu-current-limit nil)
880 (tabulated-list-init-header)
881 (tabulated-list-print)
883 (debbugs-gnu-goto id))))
885 (defun debbugs-gnu-show-blocked-by-reports ()
886 "Display all bug reports this report is blocked by."
888 (let ((id (debbugs-gnu-current-id))
889 (status (debbugs-gnu-current-status)))
890 (if (null (cdr (assq 'blockedby status)))
891 (message "Bug %d is not blocked by any other bug" id)
892 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
894 (defun debbugs-gnu-show-blocking-reports ()
895 "Display all bug reports this report is blocking."
897 (let ((id (debbugs-gnu-current-id))
898 (status (debbugs-gnu-current-status)))
899 (if (null (cdr (assq 'blocks status)))
900 (message "Bug %d is not blocking any other bug" id)
901 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
903 (defun debbugs-gnu-show-all-blocking-reports ()
904 "Narrow the display to just the reports that are blocking a release."
906 (let ((blockers (cdr (assq 'blockedby
907 (car (debbugs-get-status
908 debbugs-gnu-blocking-report)))))
909 (id (debbugs-gnu-current-id t))
910 (inhibit-read-only t)
912 (setq debbugs-gnu-current-limit nil)
913 (goto-char (point-min))
915 (setq status (debbugs-gnu-current-status))
916 (if (not (memq (cdr (assq 'id status)) blockers))
917 (delete-region (point) (progn (forward-line 1) (point)))
918 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
921 (debbugs-gnu-goto id))))
923 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
924 "Only display the bugs matching STRING.
925 If STATUS-ONLY (the prefix), ignore matches in the From and
927 (interactive "sNarrow to: \nP")
928 (let ((id (debbugs-gnu-current-id t))
929 (inhibit-read-only t)
931 (setq debbugs-gnu-current-limit nil)
932 (if (equal string "")
933 (debbugs-gnu-toggle-suppress)
934 (goto-char (point-min))
936 (setq status (debbugs-gnu-current-status))
937 (if (and (not (member string (assq 'keywords status)))
938 (not (equal string (cdr (assq 'severity status))))
941 string (cdr (assq 'originator status)))))
943 (not (string-match string (cdr (assq 'subject status))))))
944 (delete-region (point) (progn (forward-line 1) (point)))
945 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
948 (debbugs-gnu-goto id)))))
950 (defun debbugs-gnu-goto (id)
951 "Go to the line displaying bug ID."
952 (goto-char (point-min))
953 (while (and (not (eobp))
954 (not (equal (debbugs-gnu-current-id t) id)))
957 (defun debbugs-gnu-toggle-tag ()
958 "Toggle the local tag of the report in the current line.
959 If a report is tagged locally, it is presumed to be of little
964 (let ((inhibit-read-only t)
965 (id (debbugs-gnu-current-id)))
966 (if (memq id debbugs-gnu-local-tags)
968 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
969 (put-text-property (point) (+ (point) 5) 'face 'default))
970 (add-to-list 'debbugs-gnu-local-tags id)
972 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
973 'face 'debbugs-gnu-tagged))
974 (debbugs-gnu--update-tag-face id)))
975 (debbugs-gnu-dump-persistency-file))
977 (defun debbugs-gnu--update-tag-face (id)
978 (dolist (entry tabulated-list-entries)
979 (when (equal (cdr (assq 'id (car entry))) id)
985 (if (memq id debbugs-gnu-local-tags)
989 (defun debbugs-gnu-toggle-suppress ()
990 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
992 (setq debbugs-gnu-current-suppress (not debbugs-gnu-current-suppress))
993 (tabulated-list-init-header)
994 (tabulated-list-print))
996 (defvar debbugs-gnu-bug-number nil)
997 (defvar debbugs-gnu-subject nil)
999 (defun debbugs-gnu-current-id (&optional noerror)
1000 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1002 (error "No bug on the current line"))))
1004 (defun debbugs-gnu-current-status ()
1005 (get-text-property (line-beginning-position) 'tabulated-list-id))
1007 (defun debbugs-gnu-current-query ()
1008 debbugs-gnu-current-query)
1010 (defun debbugs-gnu-display-status (query status)
1011 "Display the query and status of the report on the current line."
1012 (interactive (list (debbugs-gnu-current-query)
1013 (debbugs-gnu-current-status)))
1014 (switch-to-buffer "*Bug Status*")
1015 (let ((inhibit-read-only t))
1017 (when query (pp query (current-buffer)))
1018 (when status (pp status (current-buffer)))
1019 (goto-char (point-min)))
1020 (set-buffer-modified-p nil)
1023 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1024 "Read email exchange for debbugs bug ID.
1025 STATUS is the bug's status list.
1026 MERGED is the list of bugs merged with this one."
1027 (let* ((mbox-dir (make-temp-file "debbugs" t))
1028 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1029 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1031 ;; Download messages of all the merged bug reports and append them
1032 ;; to the mailbox of the requested bug.
1034 (dolist (bugno merged)
1035 (let ((fn (make-temp-file "url")))
1036 (debbugs-get-mbox bugno 'mboxmaint fn)
1037 (rmail-get-new-mail fn)
1039 ;; Remove the 'unseen' attribute from all the messages we've
1040 ;; just read, so that all of them appear in the summary with
1042 (while (< rmail-current-message rmail-total-messages)
1043 (rmail-show-message (1+ rmail-current-message))))))
1044 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1045 (set (make-local-variable 'debbugs-gnu-subject)
1046 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1048 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1049 (set-window-text-height nil 10)
1051 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1052 (rmail-show-message 1)))
1054 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1055 "Read email exchange for debbugs bug ID.
1056 STATUS is the bug's status list.
1057 MERGED is the list of bugs merged with this one."
1059 (setq gnus-suppress-duplicates t
1060 gnus-save-duplicate-list t)
1062 (gnus-read-ephemeral-emacs-bug-group
1063 (cons id (if (listp merged) merged (list merged)))
1064 (cons (current-buffer)
1065 (current-window-configuration)))
1066 (with-current-buffer (window-buffer (selected-window))
1067 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1068 (set (make-local-variable 'debbugs-gnu-subject)
1069 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1070 (debbugs-gnu-summary-mode 1)))
1072 (defun debbugs-gnu-select-report ()
1073 "Select the report on the current line."
1075 ;; We open the report messages.
1076 (let* ((status (debbugs-gnu-current-status))
1077 (id (cdr (assq 'id status)))
1078 (merged (cdr (assq 'mergedwith status))))
1079 (setq merged (if (listp merged) merged (list merged)))
1082 (message "No bug report on the current line"))
1083 ((eq debbugs-gnu-mail-backend 'rmail)
1084 (debbugs-read-emacs-bug-with-rmail id status merged))
1085 ((eq debbugs-gnu-mail-backend 'gnus)
1086 (debbugs-read-emacs-bug-with-gnus id status merged))
1087 (t (error "No valid mail backend specified")))))
1089 (defvar debbugs-gnu-summary-mode-map
1090 (let ((map (make-sparse-keymap)))
1091 (define-key map "C" 'debbugs-gnu-send-control-message)
1092 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1095 (define-minor-mode debbugs-gnu-summary-mode
1096 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1098 \\{debbugs-gnu-summary-mode-map}"
1099 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1100 (set (make-local-variable 'gnus-posting-styles)
1103 (when (buffer-live-p gnus-article-copy)
1104 (with-current-buffer gnus-article-copy
1105 (set (make-local-variable 'message-prune-recipient-rules)
1106 '((".*@debbugs.*" "emacs-pretest-bug")
1107 (".*@debbugs.*" "bug-gnu-emacs")
1108 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1109 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1110 (set (make-local-variable 'message-alter-recipients-function)
1112 (if (string-match "\\([0-9]+\\)@donarmstrong"
1114 (let ((new (format "%s@debbugs.gnu.org"
1115 (match-string 1 (car address)))))
1118 ;; `gnus-posting-styles' is eval'ed after
1119 ;; `message-simplify-subject'. So we cannot use m-s-s.
1120 (setq subject ,debbugs-gnu-subject))))))))
1122 (defun debbugs-gnu-guess-current-id ()
1123 "Guess the ID based on \"#23\"."
1127 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1129 (goto-char (point-min))
1130 (re-search-forward "#\\([0-9]+\\)" nil t)))
1131 (string-to-number (match-string 1)))))
1133 (defun debbugs-gnu-send-control-message (message &optional reverse)
1134 "Send a control message for the current bug report.
1135 You can set the severity or add a tag, or close the report. If
1136 you use the special \"done\" MESSAGE, the report will be marked as
1137 fixed, and then closed.
1139 If given a prefix, and given a tag to set, the tag will be
1142 (list (completing-read
1144 '("serious" "important" "normal" "minor" "wishlist"
1145 "done" "donenotabug" "donewontfix" "doneunreproducible"
1146 "unarchive" "unmerge" "reopen" "close"
1147 "merge" "forcemerge"
1152 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1153 "pending" "help" "security" "confirmed"
1156 current-prefix-arg))
1157 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1158 (debbugs-gnu-guess-current-id)
1159 (debbugs-gnu-current-id)))
1161 (when (member message '("close" "done"))
1165 ;; Emacs development versions.
1167 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1169 (match-string 1 emacs-version)
1170 (1+ (string-to-number (match-string 2 emacs-version)))))
1171 ;; Emacs release versions.
1173 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1175 (match-string 1 emacs-version)
1176 (match-string 2 emacs-version)))
1177 (t emacs-version)))))
1178 (status (debbugs-gnu-current-status)))
1180 (insert "To: control@debbugs.gnu.org\n"
1181 "From: " (message-make-from) "\n"
1182 (format "Subject: control message for bug #%d\n" id)
1185 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1186 (format "%s %d\n" message id))
1187 ((member message '("merge" "forcemerge"))
1188 (format "%s %d %s\n" message id
1189 (read-string "Merge with bug #: ")))
1190 ((member message '("block" "unblock"))
1192 "%s %d by %s\n" message id
1195 (completing-read-multiple
1196 (format "%s with bug(s) #: " (capitalize message))
1197 (if (equal message "unblock")
1198 (mapcar 'number-to-string
1199 (cdr (assq 'blockedby status))))
1200 nil (and (equal message "unblock") status))
1202 ((equal message "owner")
1203 (format "owner %d !\n" id))
1204 ((equal message "reassign")
1205 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1206 ((equal message "close")
1207 (format "close %d %s\n" id version))
1208 ((equal message "done")
1209 (format "tags %d fixed\nclose %d %s\n" id id version))
1210 ((member message '("donenotabug" "donewontfix"
1211 "doneunreproducible"))
1212 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1213 ((member message '("serious" "important" "normal"
1214 "minor" "wishlist"))
1215 (format "severity %d %s\n" id message))
1216 ((equal message "invalid")
1217 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1219 ((equal message "usertag")
1220 (format "user %s\nusertag %d %s\n"
1222 "Package name or email address: "
1224 debbugs-gnu-all-packages (list user-mail-address))
1225 nil nil (car debbugs-gnu-default-packages))
1226 id (read-string "User tag: ")))
1228 (format "tags %d%s %s\n"
1229 id (if reverse " -" "")
1231 (funcall send-mail-function))))
1233 (defvar debbugs-gnu-usertags-mode-map
1234 (let ((map (make-sparse-keymap)))
1235 (set-keymap-parent map tabulated-list-mode-map)
1236 (define-key map "\r" 'debbugs-gnu-select-usertag)
1237 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1238 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1241 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1242 "Major mode for listing user tags.
1244 All normal editing commands are switched off.
1245 \\<debbugs-gnu-usertags-mode-map>
1247 The following commands are available:
1249 \\{debbugs-gnu-usertags-mode-map}"
1250 (buffer-disable-undo)
1251 (setq truncate-lines t)
1252 (setq buffer-read-only t))
1255 (defun debbugs-gnu-usertags (&rest users)
1256 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1258 (if current-prefix-arg
1259 (completing-read-multiple
1260 "Package name(s) or email address: "
1261 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1262 (mapconcat 'identity debbugs-gnu-default-packages ","))
1263 debbugs-gnu-default-packages))
1266 (let ((inhibit-read-only t)
1267 (debbugs-port "gnu.org")
1268 (buffer-name "*Emacs User Tags*")
1270 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1272 ;; Initialize variables.
1273 (when (and (file-exists-p debbugs-gnu-persistency-file)
1274 (not debbugs-gnu-local-tags))
1276 (insert-file-contents debbugs-gnu-persistency-file)
1277 (eval (read (current-buffer)))))
1280 (when (get-buffer buffer-name)
1281 (kill-buffer buffer-name))
1282 (switch-to-buffer (get-buffer-create buffer-name))
1283 (debbugs-gnu-usertags-mode)
1284 (setq tabulated-list-format `[("User" ,user-tab-length t)
1286 (setq tabulated-list-sort-key (cons "User" nil))
1287 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1289 ;; Retrieve user tags.
1290 (dolist (user users)
1291 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1293 'tabulated-list-entries
1294 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1295 `((("tagged") (,user) nil nil (,tag))
1296 ,(vector (propertize user 'mouse-face 'highlight)
1297 (propertize tag 'mouse-face 'highlight)))
1301 (when debbugs-gnu-local-tags
1303 'tabulated-list-entries
1306 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1309 (tabulated-list-init-header)
1310 (tabulated-list-print)
1312 (set-buffer-modified-p nil)
1313 (goto-char (point-min)))))
1315 (defun debbugs-gnu-select-usertag ()
1316 "Select the user tag on the current line."
1318 ;; We open the bug reports.
1319 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1320 (when args (apply 'debbugs-gnu args))))
1323 (defun debbugs-gnu-bugs (&rest bugs)
1324 "List all BUGS, a list of bug numbers."
1326 (mapcar 'string-to-number
1327 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1329 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1330 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1333 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1334 "The directory where the main source tree lives.")
1336 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1337 "The directory where the previous source tree lives.")
1339 (defun debbugs-gnu-apply-patch (&optional branch)
1340 "Apply the patch from the current message.
1341 If given a prefix, patch in the branch directory instead."
1343 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1344 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1345 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1346 (let ((rej "/tmp/debbugs-gnu.rej")
1347 (output-buffer (get-buffer-create "*debbugs patch*"))
1349 debbugs-gnu-branch-directory
1350 debbugs-gnu-trunk-directory))
1351 (patch-buffers nil))
1352 (when (file-exists-p rej)
1354 (with-current-buffer output-buffer
1356 (gnus-summary-select-article nil t)
1357 ;; The patches are either in MIME attachements or the main article
1358 ;; buffer. Determine which.
1359 (gnus-with-article-buffer
1360 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1361 (when (string-match "diff\\|patch" (mm-handle-media-type handle))
1362 (push (cons (mm-handle-encoding handle)
1363 (mm-handle-buffer handle))
1365 (unless patch-buffers
1366 (gnus-summary-show-article 'raw)
1367 (article-decode-charset)
1368 (push (cons nil gnus-article-buffer) patch-buffers))
1369 (dolist (elem patch-buffers)
1371 (insert-buffer-substring (cdr elem))
1372 (cond ((eq (car elem) 'base64)
1373 (base64-decode-region (point-min) (point-max)))
1374 ((eq (car elem) 'qp)
1375 (quoted-printable-decode-region (point-min) (point-max))))
1376 (debbugs-gnu-fix-patch dir)
1377 (call-process-region (point-min) (point-max)
1378 "patch" nil output-buffer nil
1379 "-r" rej "--no-backup-if-mismatch"
1381 "-d" (expand-file-name dir)
1383 (set-buffer output-buffer)
1384 (when (file-exists-p rej)
1385 (goto-char (point-max))
1386 (insert-file-contents-literally rej))
1387 (goto-char (point-max))
1388 (save-some-buffers t)
1390 (mapc 'kill-process compilation-in-progress)
1391 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1393 (vc-dir-hide-up-to-date)
1394 (goto-char (point-min))
1397 ;; All these commands are asynchronous, so just wait a bit. This
1398 ;; should be done properly a different way.
1400 ;; We've now done everything, so arrange the windows we need to see.
1401 (delete-other-windows)
1402 (switch-to-buffer output-buffer)
1406 (switch-to-buffer "*compilation*")
1407 (goto-char (point-max))
1409 (switch-to-buffer "*vc-diff*")
1410 (goto-char (point-min))))
1412 (defun debbugs-gnu-fix-patch (dir)
1413 (setq dir (directory-file-name (expand-file-name dir)))
1414 (goto-char (point-min))
1415 (while (re-search-forward diff-file-header-re nil t)
1416 (goto-char (match-beginning 0))
1417 (let ((target-name (car (diff-hunk-file-names))))
1418 (when (and target-name
1419 (or (not (string-match "/" target-name))
1420 (and (string-match "^[ab]/" target-name)
1422 (expand-file-name (substring target-name 2)
1424 (file-exists-p (expand-file-name target-name dir))))
1425 ;; We have a simple patch that refers to a file somewhere in the
1427 (when-let ((files (directory-files-recursively
1429 (concat "^" (regexp-quote
1430 (file-name-nondirectory target-name))
1432 (when (re-search-forward (concat "^[+]+ "
1433 (regexp-quote target-name)
1436 (replace-match (concat "+++ a"
1437 (substring (car files) (length dir))
1442 (defun debbugs-gnu-find-contributor (string)
1443 "Search through ChangeLogs to find contributors."
1444 (interactive "sContributor match: ")
1446 (match (concat "^[0-9].*" string)))
1447 (dolist (file (directory-files-recursively
1448 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1450 (when (file-exists-p file)
1451 (insert-file-contents file))
1452 (goto-char (point-min))
1453 (while (and (re-search-forward match nil t)
1454 (not (looking-at ".*tiny change")))
1456 (message "%s is a contributor %d times" string found)
1459 (defun debbugs-gnu-insert-changelog ()
1460 "Add a ChangeLog from a recently applied patch from a third party."
1463 (gnus-with-article-buffer
1465 (goto-char (point-min))
1466 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1467 subject (gnus-fetch-field "subject")))
1468 (let ((add-log-full-name (car from))
1469 (add-log-mailing-address (cadr from)))
1470 (add-change-log-entry-other-window)
1471 (let ((point (point)))
1472 (when (string-match "\\(bug#[0-9]+\\)" subject)
1473 (insert " (" (match-string 1 subject) ")."))
1474 (when (zerop (debbugs-gnu-find-contributor
1475 (let ((bits (split-string (car from))))
1477 ((>= (length bits) 2)
1478 (format "%s.*%s" (car bits) (car (last bits))))
1479 ((= (length bits) 1)
1481 ;; Fall back on the email address.
1484 (goto-char (point-max))
1486 (insert " (tiny change"))
1487 (goto-char point)))))
1489 (defvar debbugs-gnu-lisp-mode-map
1490 (let ((map (make-sparse-keymap)))
1491 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1494 (define-minor-mode debbugs-gnu-lisp-mode
1495 "Minor mode for providing a debbugs interface in Lisp buffers.
1496 \\{debbugs-gnu-lisp-mode-map}"
1497 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1499 (defvar debbugs-gnu-diff-mode-map
1500 (let ((map (make-sparse-keymap)))
1501 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1504 (define-minor-mode debbugs-gnu-diff-mode
1505 "Minor mode for providing a debbugs interface in diff buffers.
1506 \\{debbugs-gnu-diff-mode-map}"
1507 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1509 (defun debbugs-gnu-diff-select ()
1510 "Select the diff under point."
1512 (delete-other-windows)
1515 (defvar debbugs-gnu-change-mode-map
1516 (let ((map (make-sparse-keymap)))
1517 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1520 (define-minor-mode debbugs-gnu-change-mode
1521 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1522 \\{debbugs-gnu-change-mode-map}"
1523 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1525 (defun debbugs-gnu-change-checkin ()
1526 "Prepare checking in the current changes."
1528 (save-some-buffers t)
1529 (when (get-buffer "*vc-dir*")
1530 (kill-buffer (get-buffer "*vc-dir*")))
1531 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1532 (if (equal (cl-subseq default-directory 0 (length trunk))
1534 (vc-dir debbugs-gnu-trunk-directory)
1535 (vc-dir debbugs-gnu-branch-directory)))
1536 (goto-char (point-min))
1537 (while (not (search-forward "edited" nil t))
1540 (while (search-forward "edited" nil t)
1542 (beginning-of-line))
1544 (vc-next-action nil)
1545 (log-edit-insert-changelog t)
1546 (delete-other-windows)
1549 (switch-to-buffer "*vc-diff*")
1552 (provide 'debbugs-gnu)
1556 ;; * Another random thought - is it possible to implement some local
1557 ;; cache, so only changed bugs are fetched? Glenn Morris.
1559 ;;; debbugs-gnu.el ends here