]> code.delx.au - gnu-emacs-elpa/blob - packages/debbugs/debbugs-gnu.el
Improvement on debbugs
[gnu-emacs-elpa] / packages / debbugs / debbugs-gnu.el
1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
2
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
8 ;; Package: debbugs
9
10 ;; This file is not part of GNU Emacs.
11
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.
16
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.
21
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/>.
24
25 ;;; Commentary:
26
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.
31
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
34 ;;
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)
39
40 ;; The bug tracker is called interactively by
41 ;;
42 ;; M-x debbugs-gnu
43
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.
50
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.
57
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 shown.
62
63 ;; Another command is
64 ;;
65 ;; M-x debbugs-gnu-search
66
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.
75
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, you will be asked to
79 ;; change this limit, but please don't increase this number too much.
80
81 ;; These default values could be changed also by customer options
82 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages',
83 ;; `debbugs-gnu-default-hits-per-page' and `debbugs-gnu-default-suppress-bugs'.
84
85 ;; The commands create one or more pages of bug lists. Every bug is
86 ;; shown in one line, including the bug number, the status (combining
87 ;; merged bug numbers, keywords and severities), the name of the
88 ;; submitter, and the title of the bug. On every bug line you could
89 ;; apply the following actions by the following keystrokes:
90
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
97
98 ;; Furthermore, you could apply the global actions
99
100 ;; "g": Rescan bugs
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
107
108 ;; When you visit the related bug messages in Gnus, you could also
109 ;; send control messages by keystroke "C".
110
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.
115
116 ;; Another approach for listing bugs is calling the command
117 ;;
118 ;; M-x debbugs-gnu-usertags
119
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 packe names, or an arbitrary string
123 ;; for a user who has tagged bugs. The command returns the list of
124 ;; existing user tags for the given user(s) or package name(s),
125 ;; respectively. Applying RET on a user tag, all bugs tagged with
126 ;; this user tag are shown.
127
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>.
131
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
134 ;;
135 ;; M-x debbugs-gnu-bugs
136
137 ;; The bug numbers to be shown shall be entered as comma separated list.
138
139 ;;; Code:
140
141 (require 'debbugs)
142 (require 'tabulated-list)
143 (require 'add-log)
144 (require 'subr-x)
145 (eval-when-compile (require 'cl))
146
147 (autoload 'article-decode-charset "gnus-art")
148 (autoload 'diff-goto-source "diff-mode")
149 (autoload 'diff-hunk-file-names "diff-mode")
150 (autoload 'gnus-article-mime-handles "gnus-art")
151 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
152 (autoload 'gnus-summary-article-header "gnus-sum")
153 (autoload 'gnus-summary-select-article "gnus-sum")
154 (autoload 'gnus-summary-show-article "gnus-sum")
155 (autoload 'gnus-with-article-buffer "gnus-art")
156 (autoload 'log-edit-insert-changelog "log-edit")
157 (autoload 'mail-header-subject "nnheader")
158 (autoload 'message-goto-body "message")
159 (autoload 'message-make-from "message")
160 (autoload 'rmail-get-new-mail "rmail")
161 (autoload 'rmail-show-message "rmail")
162 (autoload 'rmail-summary "rmailsum")
163 (autoload 'vc-dir-hide-up-to-date "vc-dir")
164 (autoload 'vc-dir-mark "vc-dir")
165
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)
176
177 (defgroup debbugs-gnu ()
178 "UI for the debbugs.gnu.org bug tracker."
179 :group 'debbugs
180 :version "24.1")
181
182 (defvar debbugs-gnu-blocking-report 19759
183 "The ID of the current release report used to track blocking bug reports.")
184
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".
191 :group 'debbugs-gnu
192 :type '(set (const "serious")
193 (const "important")
194 (const "normal")
195 (const "minor")
196 (const "wishlist")
197 (const "tagged"))
198 :version "24.1")
199
200 (defconst debbugs-gnu-all-severities
201 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
202 "*List of all possible severities.")
203
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>
208 :group 'debbugs-gnu
209 :type '(set (const "adns")
210 (const "auctex")
211 (const "automake")
212 (const "cc-mode")
213 (const "coreutils")
214 (const "cppi")
215 (const "debbugs.gnu.org")
216 (const "diffutils")
217 (const "emacs")
218 (const "emacs-xwidgets")
219 (const "fm")
220 (const "gnus")
221 (const "grep")
222 (const "guile")
223 (const "guix")
224 (const "gzip")
225 (const "idutils")
226 (const "libtool")
227 (const "mh-e")
228 (const "org-mode")
229 (const "parted")
230 (const "sed")
231 (const "vc-dwim")
232 (const "woodchuck"))
233 :version "25.1")
234
235 (defconst debbugs-gnu-all-packages
236 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
237 "*List of all possible package names.")
238
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 REGEXP a regular
244 expression matching the corresponding value, a string. Showing
245 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
246 :group 'debbugs-gnu
247 :type '(alist :key-type symbol :value-type regexp)
248 :version "24.1")
249
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."
254 :group 'debbugs-gnu
255 :type '(choice (const :tag "Use Gnus" 'gnus)
256 (const :tag "Use Rmail" 'rmail))
257 :version "25.1")
258
259 (defface debbugs-gnu-archived '((t (:inverse-video t)))
260 "Face for archived bug reports.")
261
262 (defface debbugs-gnu-new '((t (:foreground "red")))
263 "Face for new reports that nobody has answered.")
264
265 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
266 "Face for reports that have been modified recently.")
267
268 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
269 "Face for reports that are pending.")
270
271 (defface debbugs-gnu-stale '((t (:foreground "orange")))
272 "Face for reports that have not been touched for a week.")
273
274 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
275 "Face for closed bug reports.")
276
277 (defface debbugs-gnu-tagged '((t (:foreground "red")))
278 "Face for reports that have been tagged locally.")
279
280 (defvar debbugs-gnu-local-tags nil
281 "List of bug numbers tagged locally, and kept persistent.")
282
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")
286
287 (defun debbugs-gnu-dump-persistency-file ()
288 "Function to store debbugs variables persistently."
289 (with-temp-file debbugs-gnu-persistency-file
290 (insert
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) '>)))))
295
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'.")
300
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\).")
307
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)))
314 value))
315
316 (defconst debbugs-gnu-phrase-prompt
317 (propertize
318 "Enter search phrase: "
319 'help-echo "\
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
324 search."))
325
326 ;;;###autoload
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\"."
334 (interactive)
335
336 (unwind-protect
337 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
338 key val1 val2 phrase severities packages archivedp)
339
340 ;; Check for the phrase.
341 (setq phrase (read-string debbugs-gnu-phrase-prompt))
342 (if (zerop (length phrase))
343 (setq phrase nil)
344 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
345 ;; We suppress the bugs if there is no phrase.
346 (setq-default debbugs-gnu-current-suppress (null phrase))
347
348 ;; The other queries.
349 (catch :finished
350 (while t
351 (setq key (completing-read
352 "Enter attribute: "
353 (if phrase
354 '("severity" "package" "tags" "submitter" "date"
355 "subject" "status")
356 '("severity" "package" "archive" "src" "tag"
357 "owner" "submitter" "maint" "correspondent"
358 "date" "log_modified" "last_modified"
359 "found_date" "fixed_date" "unarchived"
360 "subject" "done" "forwarded" "msgid" "summary"))
361 nil t))
362 (cond
363 ;; Server-side queries.
364 ((equal key "severity")
365 (setq
366 severities
367 (completing-read-multiple
368 "Enter severities: " debbugs-gnu-all-severities nil t
369 (mapconcat 'identity debbugs-gnu-default-severities ","))))
370
371 ((equal key "package")
372 (setq
373 packages
374 (completing-read-multiple
375 "Enter packages: " debbugs-gnu-all-packages nil t
376 (mapconcat 'identity debbugs-gnu-default-packages ","))))
377
378 ((equal key "archive")
379 ;; We simplify, by assuming just archived bugs are requested.
380 (setq archivedp t))
381
382 ((member key '("src" "tag" "tags"))
383 (setq val1 (read-string (format "Enter %s: " key)))
384 (when (not (zerop (length val1)))
385 (add-to-list
386 'debbugs-gnu-current-query (cons (intern key) val1))))
387
388 ((member key '("owner" "submitter" "maint" "correspondent"))
389 (setq val1 (read-string "Enter email address: "))
390 (when (not (zerop (length val1)))
391 (add-to-list
392 'debbugs-gnu-current-query (cons (intern key) val1))))
393
394 ((equal key "status")
395 (setq
396 val1
397 (completing-read "Enter status: " '("done" "forwarded" "open")))
398 (when (not (zerop (length val1)))
399 (add-to-list
400 'debbugs-gnu-current-query (cons (intern key) val1))))
401
402 ;; Client-side filters.
403 ((member key '("date" "log_modified" "last_modified"
404 "found_date" "fixed_date" "unarchived"))
405 (setq val1
406 (debbugs-gnu-calendar-read
407 (format "Enter %s before YYYY-MM-DD%s: "
408 key (if phrase "" " (client-side filter)"))
409 (lambda (x)
410 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
411 (if (string-match date-format val1)
412 (setq val1 (floor
413 (float-time
414 (encode-time
415 0 0 0
416 (string-to-number (match-string 3 val1))
417 (string-to-number (match-string 2 val1))
418 (string-to-number (match-string 1 val1))))))
419 (setq val1 nil))
420 (setq val2
421 (debbugs-gnu-calendar-read
422 (format "Enter %s after YYYY-MM-DD%s: "
423 key (if phrase "" " (client-side filter)"))
424 (lambda (x)
425 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
426 (if (string-match date-format val2)
427 (setq val2 (floor
428 (float-time
429 (encode-time
430 0 0 0
431 (string-to-number (match-string 3 val2))
432 (string-to-number (match-string 2 val2))
433 (string-to-number (match-string 1 val2))))))
434 (setq val2 nil))
435 (when (or val1 val2)
436 (add-to-list
437 (if phrase
438 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
439 (cons (intern key) (cons val1 val2)))))
440
441 ((not (zerop (length key)))
442 (setq val1
443 (funcall
444 (if phrase 'read-string 'read-regexp)
445 (format "Enter %s%s"
446 key (if phrase ": " " (client-side filter)"))))
447 (when (not (zerop (length val1)))
448 (add-to-list
449 (if phrase
450 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
451 (cons (intern key) val1))))
452
453 ;; The End.
454 (t (throw :finished nil)))))
455
456 ;; Do the search.
457 (debbugs-gnu severities packages archivedp))
458
459 ;; Reset query and filter.
460 (setq debbugs-gnu-current-query nil
461 debbugs-gnu-current-filter nil)))
462
463 (defvar debbugs-gnu-current-limit nil
464 "List of bug ids to be shown, if non-nil")
465
466 (defvar debbugs-gnu-current-suppress nil
467 "Whether bugs shall be suppressed.
468 The specification which bugs shall be suppressed is taken from
469 `debbugs-gnu-default-suppress-bugs'.")
470
471 ;;;###autoload
472 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
473 "List all outstanding bugs."
474 (interactive
475 (let (severities archivedp)
476 (list
477 (setq severities
478 (completing-read-multiple
479 "Severities: " debbugs-gnu-all-severities nil t
480 (mapconcat 'identity debbugs-gnu-default-severities ",")))
481 ;; The next parameters are asked only when there is a prefix.
482 (if current-prefix-arg
483 (completing-read-multiple
484 "Packages: " debbugs-gnu-all-packages nil t
485 (mapconcat 'identity debbugs-gnu-default-packages ","))
486 debbugs-gnu-default-packages)
487 (when current-prefix-arg
488 (setq archivedp (y-or-n-p "Show archived bugs?")))
489 (when (and current-prefix-arg (not archivedp))
490 (y-or-n-p "Suppress unwanted bugs?"))
491 ;; This one must be asked for severity "tagged".
492 (when (member "tagged" severities)
493 (split-string (read-string "User tag(s): ") "," t)))))
494
495 ;; Initialize variables.
496 (when (and (file-exists-p debbugs-gnu-persistency-file)
497 (not debbugs-gnu-local-tags))
498 (with-temp-buffer
499 (insert-file-contents debbugs-gnu-persistency-file)
500 (eval (read (current-buffer)))))
501 ;; Per default, we suppress retrieved unwanted bugs.
502 (when (called-interactively-p 'any)
503 (setq-default debbugs-gnu-current-suppress t))
504
505 ;; Add queries.
506 (dolist (severity (if (consp severities) severities (list severities)))
507 (when (not (zerop (length severity)))
508 (when (string-equal severity "tagged")
509 (setq-default debbugs-gnu-current-suppress nil))
510 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
511 (dolist (package (if (consp packages) packages (list packages)))
512 (when (not (zerop (length package)))
513 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
514 (when archivedp
515 (setq-default debbugs-gnu-current-suppress nil)
516 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
517 (when suppress
518 (setq-default debbugs-gnu-current-suppress t)
519 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
520 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
521 (dolist (tag (if (consp tags) tags (list tags)))
522 (when (not (zerop (length tag)))
523 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
524
525 ;; Show result.
526 (debbugs-gnu-show-reports)
527
528 ;; Reset query and filter.
529 (setq debbugs-gnu-current-query nil
530 debbugs-gnu-current-filter nil))
531
532 (defun debbugs-gnu-get-bugs (query)
533 "Retrieve bugs numbers from debbugs.gnu.org according search criteria."
534 (let* ((debbugs-port "gnu.org")
535 (bugs (assoc 'bugs query))
536 (tags (assoc 'tag query))
537 (local-tags (and (member '(severity . "tagged") query) (not tags)))
538 (phrase (assoc 'phrase query))
539 args)
540 ;; Compile query arguments.
541 (unless (or query tags)
542 (dolist (elt debbugs-gnu-default-packages)
543 (setq args (append args (list :package elt)))))
544 (dolist (elt query)
545 (unless (equal elt '(severity . "tagged"))
546 (setq args
547 (append
548 args
549 (if phrase
550 (cond
551 ((eq (car elt) 'phrase)
552 (list (list :phrase (cdr elt) :max 500)))
553 ((eq (car elt) 'date)
554 (list (list :date (cddr elt) (cadr elt)
555 :operator "NUMBT")))
556 (t
557 (list (list (intern (concat ":" (symbol-name (car elt))))
558 (cdr elt) :operator "ISTRINC"))))
559 (list (intern (concat ":" (symbol-name (car elt))))
560 (cdr elt)))))))
561
562 (cond
563 ;; If the query is just a list of bug numbers, we return them.
564 (bugs (cdr bugs))
565 ;; If the query contains the pseudo-severity "tagged", we return
566 ;; just the local tagged bugs.
567 (local-tags (copy-sequence debbugs-gnu-local-tags))
568 ;; A full text query.
569 (phrase
570 (mapcar
571 (lambda (x) (cdr (assoc "id" x)))
572 (apply 'debbugs-search-est args)))
573 ;; User tags.
574 (tags
575 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
576 (apply 'debbugs-get-usertag args))
577 ;; Otherwise, we retrieve the bugs from the server.
578 (t (apply 'debbugs-get-bugs args)))))
579
580 (defun debbugs-gnu-show-reports ()
581 "Show bug reports."
582 (let ((inhibit-read-only t)
583 (debbugs-port "gnu.org")
584 (buffer-name "*Emacs Bugs*"))
585 ;; The tabulated mode sets several local variables. We must get
586 ;; rid of them.
587 (when (get-buffer buffer-name)
588 (kill-buffer buffer-name))
589 (switch-to-buffer (get-buffer-create buffer-name))
590 (debbugs-gnu-mode)
591
592 ;; Print bug reports.
593 (dolist (status
594 (apply 'debbugs-get-status
595 (debbugs-gnu-get-bugs debbugs-gnu-current-query)))
596 (let* ((id (cdr (assq 'id status)))
597 (words
598 (mapconcat
599 'identity
600 (cons (cdr (assq 'severity status))
601 (cdr (assq 'keywords status)))
602 ","))
603 (address (mail-header-parse-address
604 (decode-coding-string (cdr (assq 'originator status))
605 'utf-8)))
606 (owner (if (cdr (assq 'owner status))
607 (car (mail-header-parse-address
608 (decode-coding-string (cdr (assq 'owner status))
609 'utf-8)))))
610 (subject (decode-coding-string (cdr (assq 'subject status))
611 'utf-8))
612 merged)
613 (unless (equal (cdr (assq 'pending status)) "pending")
614 (setq words (concat words "," (cdr (assq 'pending status)))))
615 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
616 (when packages
617 (setq words (concat words "," (mapconcat 'identity packages ",")))))
618 (when (setq merged (cdr (assq 'mergedwith status)))
619 (setq words (format "%s,%s"
620 (if (numberp merged)
621 merged
622 (mapconcat 'number-to-string merged ","))
623 words)))
624 (when (or (not merged)
625 (not (let ((found nil))
626 (dolist (id (if (listp merged)
627 merged
628 (list merged)))
629 (dolist (entry tabulated-list-entries)
630 (when (equal id (cdr (assq 'id (car entry))))
631 (setq found t))))
632 found)))
633 (add-to-list
634 'tabulated-list-entries
635 (list
636 status
637 (vector
638 (propertize
639 (format "%5d" id)
640 'face
641 ;; Mark tagged bugs.
642 (if (memq id debbugs-gnu-local-tags)
643 'debbugs-gnu-tagged
644 'default))
645 (propertize
646 ;; Mark status and age.
647 words
648 'face
649 (cond
650 ((cdr (assq 'archived status))
651 'debbugs-gnu-archived)
652 ((equal (cdr (assq 'pending status)) "done")
653 'debbugs-gnu-done)
654 ((member "pending" (cdr (assq 'keywords status)))
655 'debbugs-gnu-pending)
656 ((= (cdr (assq 'date status))
657 (cdr (assq 'log_modified status)))
658 'debbugs-gnu-new)
659 ((< (- (float-time)
660 (cdr (assq 'log_modified status)))
661 (* 60 60 24 7 2))
662 'debbugs-gnu-handled)
663 (t
664 'debbugs-gnu-stale)))
665 (propertize
666 ;; Prefer the name over the address.
667 (or (cdr address)
668 (car address))
669 'face
670 ;; Mark own submitted bugs.
671 (if (and (stringp (car address))
672 (string-equal (car address) user-mail-address))
673 'debbugs-gnu-tagged
674 'default))
675 (propertize
676 subject
677 'face
678 ;; Mark owned bugs.
679 (if (and (stringp owner)
680 (string-equal owner user-mail-address))
681 'debbugs-gnu-tagged
682 'default))))
683 'append))))
684
685 (tabulated-list-init-header)
686 (tabulated-list-print)
687
688 (set-buffer-modified-p nil)
689 (goto-char (point-min))))
690
691 (defun debbugs-gnu-print-entry (list-id cols)
692 "Insert a debbugs entry at point.
693 Used instead of `tabulated-list-print-entry'."
694 (let ((beg (point))
695 (pos 0)
696 (case-fold-search t)
697 (id (aref cols 0))
698 (id-length (nth 1 (aref tabulated-list-format 0)))
699 (state (aref cols 1))
700 (state-length (nth 1 (aref tabulated-list-format 1)))
701 (submitter (aref cols 2))
702 (submitter-length (nth 1 (aref tabulated-list-format 2)))
703 (title (aref cols 3))
704 (title-length (nth 1 (aref tabulated-list-format 3))))
705 (when (and
706 ;; We may have a narrowing in effect.
707 (or (not debbugs-gnu-current-limit)
708 (memq (cdr (assq 'id list-id)) debbugs-gnu-current-limit))
709 ;; Filter suppressed bugs.
710 (or (not debbugs-gnu-current-suppress)
711 (not (catch :suppress
712 (dolist (check debbugs-gnu-default-suppress-bugs)
713 (when
714 (string-match
715 (cdr check)
716 (or (cdr (assq (car check) list-id)) ""))
717 (throw :suppress t))))))
718 ;; Filter search list.
719 (not (catch :suppress
720 (dolist (check debbugs-gnu-current-filter)
721 (let ((val (cdr (assq (car check) list-id))))
722 (if (stringp (cdr check))
723 ;; Regular expression.
724 (when (not (string-match (cdr check) (or val "")))
725 (throw :suppress t))
726 ;; Time value.
727 (when (or (and (numberp (cadr check))
728 (< (cadr check) val))
729 (and (numberp (cddr check))
730 (> (cddr check) val)))
731 (throw :suppress t))))))))
732
733 ;; Insert id.
734 (indent-to (- id-length (length id)))
735 (insert id)
736 ;; Insert state.
737 (indent-to (setq pos (+ pos id-length 1)) 1)
738 (insert (if (> (length state) state-length)
739 (propertize (substring state 0 state-length)
740 'help-echo state)
741 state))
742 ;; Insert submitter.
743 (indent-to (setq pos (+ pos state-length 1)) 1)
744 (insert "[" (if (> (length submitter) (- submitter-length 2))
745 (propertize (substring submitter 0 (- submitter-length 2))
746 'help-echo submitter)
747 submitter))
748 (indent-to (+ pos (1- submitter-length)))
749 (insert "]")
750 ;; Insert title.
751 (indent-to (setq pos (+ pos submitter-length 1)) 1)
752 (insert (propertize title 'help-echo title))
753 ;; Add properties.
754 (add-text-properties
755 beg (point)
756 `(tabulated-list-id ,list-id mouse-face highlight))
757 (insert ?\n))))
758
759 (defvar debbugs-gnu-mode-map
760 (let ((map (make-sparse-keymap))
761 (menu-map (make-sparse-keymap)))
762 (set-keymap-parent map tabulated-list-mode-map)
763 (define-key map "\r" 'debbugs-gnu-select-report)
764 (define-key map [mouse-1] 'debbugs-gnu-select-report)
765 (define-key map [mouse-2] 'debbugs-gnu-select-report)
766 (define-key map "s" 'debbugs-gnu-toggle-sort)
767 (define-key map "t" 'debbugs-gnu-toggle-tag)
768 (define-key map "d" 'debbugs-gnu-display-status)
769 (define-key map "g" 'debbugs-gnu-rescan)
770 (define-key map "x" 'debbugs-gnu-toggle-suppress)
771 (define-key map "/" 'debbugs-gnu-narrow-to-status)
772 (define-key map "w" 'debbugs-gnu-widen)
773 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
774 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
775 (define-key map "C" 'debbugs-gnu-send-control-message)
776 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
777
778 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
779 (define-key menu-map [debbugs-gnu-select-report]
780 '(menu-item "Show Reports" debbugs-gnu-select-report
781 :help "Show all reports belonging to this bug"))
782 (define-key-after menu-map [debbugs-gnu-rescan]
783 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
784 :help "Refresh bug list")
785 'debbugs-gnu-select-report)
786 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
787 '(menu-item "Show Release Blocking Bugs"
788 debbugs-gnu-show-all-blocking-reports
789 :help "Show all bugs blocking next Emacs release")
790 ;:enable '(assq 'phrase debbugs-gnu-current-query))
791 'debbugs-gnu-rescan)
792 (define-key-after menu-map [debbugs-gnu-separator]
793 '(menu-item "--") 'debbugs-gnu-show-all-blocking-reports)
794 (define-key-after menu-map [debbugs-gnu-search]
795 '(menu-item "Search Bugs" debbugs-gnu-search
796 :help "Search bugs on debbugs.gnu.org")
797 'debbugs-gnu-separator)
798 (define-key-after menu-map [debbugs-gnu]
799 '(menu-item "Retrieve Bugs" debbugs-gnu
800 :help "Retrieve bugs from debbugs.gnu.org")
801 'debbugs-gnu-search)
802 (define-key-after menu-map [debbugs-gnu-bugs]
803 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
804 :help "Retrieve selected bugs from debbugs.gnu.org")
805 'debbugs-gnu)
806 map))
807
808 (defun debbugs-gnu-rescan ()
809 "Rescan the current set of bug reports."
810 (interactive)
811 ;; Refresh the buffer. `save-excursion' does not work, so we
812 ;; remember the position.
813 (setq-default debbugs-gnu-current-suppress debbugs-gnu-current-suppress)
814 (let ((pos (point)))
815 (debbugs-gnu-show-reports)
816 (goto-char pos)))
817
818 (defvar debbugs-gnu-sort-state 'number)
819
820 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
821 "Major mode for listing bug reports.
822
823 All normal editing commands are switched off.
824 \\<debbugs-gnu-mode-map>
825
826 The following commands are available:
827
828 \\{debbugs-gnu-mode-map}"
829 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
830 (set (make-local-variable 'debbugs-gnu-current-limit) nil)
831 (set (make-local-variable 'debbugs-gnu-current-suppress)
832 debbugs-gnu-current-suppress)
833 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
834 ("State" 20 debbugs-gnu-sort-state)
835 ("Submitter" 25 t)
836 ("Title" 10 debbugs-gnu-sort-title)])
837 (setq tabulated-list-sort-key (cons "Id" nil))
838 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
839 (buffer-disable-undo)
840 (setq truncate-lines t)
841 (setq buffer-read-only t))
842
843 (defun debbugs-gnu-sort-id (s1 s2)
844 (> (cdr (assq 'id (car s1)))
845 (cdr (assq 'id (car s2)))))
846
847 (defconst debbugs-gnu-state-preference
848 '((debbugs-gnu-new . 1)
849 (debbugs-gnu-stale . 2)
850 (debbugs-gnu-handled . 3)
851 (debbugs-gnu-done . 4)
852 (debbugs-gnu-pending . 5)))
853
854 (defun debbugs-gnu-get-state-preference (face-string)
855 (or (cdr (assq (get-text-property 0 'face face-string)
856 debbugs-gnu-state-preference))
857 10))
858
859 (defconst debbugs-gnu-severity-preference
860 '(("serious" . 1)
861 ("important" . 2)
862 ("normal" . 3)
863 ("minor" . 4)
864 ("wishlist" . 5)))
865
866 (defun debbugs-gnu-get-severity-preference (state)
867 (or (cdr (assoc (cdr (assq 'severity state))
868 debbugs-gnu-severity-preference))
869 10))
870
871 (defun debbugs-gnu-sort-state (s1 s2)
872 (let ((id1 (cdr (assq 'id (car s1))))
873 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
874 (id2 (cdr (assq 'id (car s2))))
875 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
876 (cond
877 ;; Tagged bugs go to the end.
878 ((and (not (memq id1 debbugs-gnu-local-tags))
879 (memq id2 debbugs-gnu-local-tags))
880 t)
881 ((and (memq id1 debbugs-gnu-local-tags)
882 (not (memq id2 debbugs-gnu-local-tags)))
883 nil)
884 ;; Then, we check the age of the bugs.
885 ((< age1 age2)
886 t)
887 ((> age1 age2)
888 nil)
889 ;; If they have the same age, we check for severity.
890 ((< (debbugs-gnu-get-severity-preference (car s1))
891 (debbugs-gnu-get-severity-preference (car s2)))
892 t)
893 (t nil))))
894
895 (defun debbugs-gnu-sort-title (s1 s2)
896 (let ((owner (if (cdr (assq 'owner (car s1)))
897 (car (mail-header-parse-address
898 (decode-coding-string (cdr (assq 'owner (car s1)))
899 'utf-8))))))
900 (and (stringp owner)
901 (string-equal owner user-mail-address))))
902
903 (defun debbugs-gnu-toggle-sort ()
904 "Toggle sorting by age and by state."
905 (interactive)
906 (if (eq debbugs-gnu-sort-state 'number)
907 (progn
908 (setq debbugs-gnu-sort-state 'state)
909 (setq tabulated-list-sort-key (cons "Id" nil)))
910 (setq debbugs-gnu-sort-state 'number)
911 (setq tabulated-list-sort-key (cons "State" nil)))
912 (tabulated-list-init-header)
913 (tabulated-list-print))
914
915 (defun debbugs-gnu-widen ()
916 "Display all the currently selected bug reports."
917 (interactive)
918 (let ((id (debbugs-gnu-current-id t))
919 (inhibit-read-only t))
920 (setq debbugs-gnu-current-limit nil)
921 (tabulated-list-init-header)
922 (tabulated-list-print)
923 (when id
924 (debbugs-gnu-goto id))))
925
926 (defun debbugs-gnu-show-blocked-by-reports ()
927 "Display all bug reports this report is blocked by."
928 (interactive)
929 (let ((id (debbugs-gnu-current-id))
930 (status (debbugs-gnu-current-status)))
931 (if (null (cdr (assq 'blockedby status)))
932 (message "Bug %d is not blocked by any other bug" id)
933 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
934
935 (defun debbugs-gnu-show-blocking-reports ()
936 "Display all bug reports this report is blocking."
937 (interactive)
938 (let ((id (debbugs-gnu-current-id))
939 (status (debbugs-gnu-current-status)))
940 (if (null (cdr (assq 'blocks status)))
941 (message "Bug %d is not blocking any other bug" id)
942 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
943
944 (defun debbugs-gnu-show-all-blocking-reports ()
945 "Narrow the display to just the reports that are blocking a release."
946 (interactive)
947 (let ((blockers (cdr (assq 'blockedby
948 (car (debbugs-get-status
949 debbugs-gnu-blocking-report)))))
950 (id (debbugs-gnu-current-id t))
951 (inhibit-read-only t)
952 status)
953 (setq debbugs-gnu-current-limit nil)
954 (goto-char (point-min))
955 (while (not (eobp))
956 (setq status (debbugs-gnu-current-status))
957 (if (not (memq (cdr (assq 'id status)) blockers))
958 (delete-region (point) (progn (forward-line 1) (point)))
959 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
960 (forward-line 1)))
961 (when id
962 (debbugs-gnu-goto id))))
963
964 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
965 "Only display the bugs matching STRING.
966 If STATUS-ONLY (the prefix), ignore matches in the From and
967 Subject fields."
968 (interactive "sNarrow to: \nP")
969 (let ((id (debbugs-gnu-current-id t))
970 (inhibit-read-only t)
971 status)
972 (setq debbugs-gnu-current-limit nil)
973 (if (equal string "")
974 (debbugs-gnu-toggle-suppress)
975 (goto-char (point-min))
976 (while (not (eobp))
977 (setq status (debbugs-gnu-current-status))
978 (if (and (not (member string (assq 'keywords status)))
979 (not (equal string (cdr (assq 'severity status))))
980 (or status-only
981 (not (string-match
982 string (cdr (assq 'originator status)))))
983 (or status-only
984 (not (string-match string (cdr (assq 'subject status))))))
985 (delete-region (point) (progn (forward-line 1) (point)))
986 (push (cdr (assq 'id status)) debbugs-gnu-current-limit)
987 (forward-line 1)))
988 (when id
989 (debbugs-gnu-goto id)))))
990
991 (defun debbugs-gnu-goto (id)
992 "Go to the line displaying bug ID."
993 (goto-char (point-min))
994 (while (and (not (eobp))
995 (not (equal (debbugs-gnu-current-id t) id)))
996 (forward-line 1)))
997
998 (defun debbugs-gnu-toggle-tag ()
999 "Toggle the local tag of the report in the current line.
1000 If a report is tagged locally, it is presumed to be of little
1001 interest to you."
1002 (interactive)
1003 (save-excursion
1004 (beginning-of-line)
1005 (let ((inhibit-read-only t)
1006 (id (debbugs-gnu-current-id)))
1007 (if (memq id debbugs-gnu-local-tags)
1008 (progn
1009 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1010 (put-text-property (point) (+ (point) 5) 'face 'default))
1011 (add-to-list 'debbugs-gnu-local-tags id)
1012 (put-text-property
1013 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1014 'face 'debbugs-gnu-tagged))
1015 (debbugs-gnu--update-tag-face id)))
1016 (debbugs-gnu-dump-persistency-file))
1017
1018 (defun debbugs-gnu--update-tag-face (id)
1019 (dolist (entry tabulated-list-entries)
1020 (when (equal (cdr (assq 'id (car entry))) id)
1021 (aset (cadr entry) 0
1022 (propertize
1023 (format "%5d" id)
1024 'face
1025 ;; Mark tagged bugs.
1026 (if (memq id debbugs-gnu-local-tags)
1027 'debbugs-gnu-tagged
1028 'default))))))
1029
1030 (defun debbugs-gnu-toggle-suppress ()
1031 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1032 (interactive)
1033 (setq debbugs-gnu-current-suppress (not debbugs-gnu-current-suppress))
1034 (tabulated-list-init-header)
1035 (tabulated-list-print))
1036
1037 (defvar debbugs-gnu-bug-number nil)
1038 (defvar debbugs-gnu-subject nil)
1039
1040 (defun debbugs-gnu-current-id (&optional noerror)
1041 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1042 (and (not noerror)
1043 (error "No bug on the current line"))))
1044
1045 (defun debbugs-gnu-current-status ()
1046 (get-text-property (line-beginning-position) 'tabulated-list-id))
1047
1048 (defun debbugs-gnu-current-query ()
1049 debbugs-gnu-current-query)
1050
1051 (defun debbugs-gnu-display-status (query status)
1052 "Display the query and status of the report on the current line."
1053 (interactive (list (debbugs-gnu-current-query)
1054 (debbugs-gnu-current-status)))
1055 (switch-to-buffer "*Bug Status*")
1056 (let ((inhibit-read-only t))
1057 (erase-buffer)
1058 (when query (pp query (current-buffer)))
1059 (when status (pp status (current-buffer)))
1060 (goto-char (point-min)))
1061 (set-buffer-modified-p nil)
1062 (special-mode))
1063
1064 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1065 "Read email exchange for debbugs bug ID.
1066 STATUS is the bug's status list.
1067 MERGED is the list of bugs merged with this one."
1068 (let* ((mbox-dir (make-temp-file "debbugs" t))
1069 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1070 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1071 (rmail mbox-fname)
1072 ;; Download messages of all the merged bug reports and append them
1073 ;; to the mailbox of the requested bug.
1074 (when merged
1075 (dolist (bugno merged)
1076 (let ((fn (make-temp-file "url")))
1077 (debbugs-get-mbox bugno 'mboxmaint fn)
1078 (rmail-get-new-mail fn)
1079 (delete-file fn)
1080 ;; Remove the 'unseen' attribute from all the messages we've
1081 ;; just read, so that all of them appear in the summary with
1082 ;; the same face.
1083 (while (< rmail-current-message rmail-total-messages)
1084 (rmail-show-message (1+ rmail-current-message))))))
1085 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1086 (set (make-local-variable 'debbugs-gnu-subject)
1087 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1088 (rmail-summary)
1089 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1090 (set-window-text-height nil 10)
1091 (other-window 1)
1092 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1093 (rmail-show-message 1)))
1094
1095 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1096 "Read email exchange for debbugs bug ID.
1097 STATUS is the bug's status list.
1098 MERGED is the list of bugs merged with this one."
1099 (require 'gnus-dup)
1100 (setq gnus-suppress-duplicates t
1101 gnus-save-duplicate-list t)
1102 ;; Use Gnus.
1103 (gnus-read-ephemeral-emacs-bug-group
1104 (cons id (if (listp merged) merged (list merged)))
1105 (cons (current-buffer)
1106 (current-window-configuration)))
1107 (with-current-buffer (window-buffer (selected-window))
1108 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1109 (set (make-local-variable 'debbugs-gnu-subject)
1110 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1111 (debbugs-gnu-summary-mode 1)))
1112
1113 (defun debbugs-gnu-select-report ()
1114 "Select the report on the current line."
1115 (interactive)
1116 ;; We open the report messages.
1117 (let* ((status (debbugs-gnu-current-status))
1118 (id (cdr (assq 'id status)))
1119 (merged (cdr (assq 'mergedwith status))))
1120 (setq merged (if (listp merged) merged (list merged)))
1121 (cond
1122 ((not id)
1123 (message "No bug report on the current line"))
1124 ((eq debbugs-gnu-mail-backend 'rmail)
1125 (debbugs-read-emacs-bug-with-rmail id status merged))
1126 ((eq debbugs-gnu-mail-backend 'gnus)
1127 (debbugs-read-emacs-bug-with-gnus id status merged))
1128 (t (error "No valid mail backend specified")))))
1129
1130 (defvar debbugs-gnu-summary-mode-map
1131 (let ((map (make-sparse-keymap)))
1132 (define-key map "C" 'debbugs-gnu-send-control-message)
1133 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1134 map))
1135
1136 (define-minor-mode debbugs-gnu-summary-mode
1137 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1138
1139 \\{debbugs-gnu-summary-mode-map}"
1140 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1141 (set (make-local-variable 'gnus-posting-styles)
1142 `((".*"
1143 (eval
1144 (when (buffer-live-p gnus-article-copy)
1145 (with-current-buffer gnus-article-copy
1146 (set (make-local-variable 'message-prune-recipient-rules)
1147 '((".*@debbugs.*" "emacs-pretest-bug")
1148 (".*@debbugs.*" "bug-gnu-emacs")
1149 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1150 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1151 (set (make-local-variable 'message-alter-recipients-function)
1152 (lambda (address)
1153 (if (string-match "\\([0-9]+\\)@donarmstrong"
1154 (car address))
1155 (let ((new (format "%s@debbugs.gnu.org"
1156 (match-string 1 (car address)))))
1157 (cons new new))
1158 address)))
1159 ;; `gnus-posting-styles' is eval'ed after
1160 ;; `message-simplify-subject'. So we cannot use m-s-s.
1161 (setq subject ,debbugs-gnu-subject))))))))
1162
1163 (defun debbugs-gnu-guess-current-id ()
1164 "Guess the ID based on \"#23\"."
1165 (save-excursion
1166 (beginning-of-line)
1167 (and
1168 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1169 (progn
1170 (goto-char (point-min))
1171 (re-search-forward "#\\([0-9]+\\)" nil t)))
1172 (string-to-number (match-string 1)))))
1173
1174 (defun debbugs-gnu-send-control-message (message &optional reverse)
1175 "Send a control message for the current bug report.
1176 You can set the severity or add a tag, or close the report. If
1177 you use the special \"done\" MESSAGE, the report will be marked as
1178 fixed, and then closed.
1179
1180 If given a prefix, and given a tag to set, the tag will be
1181 removed instead."
1182 (interactive
1183 (list (completing-read
1184 "Control message: "
1185 '("serious" "important" "normal" "minor" "wishlist"
1186 "done" "donenotabug" "donewontfix" "doneunreproducible"
1187 "unarchive" "unmerge" "reopen" "close"
1188 "merge" "forcemerge"
1189 "block" "unblock"
1190 "owner" "noowner"
1191 "invalid"
1192 "reassign"
1193 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1194 "pending" "help" "security" "confirmed"
1195 "usertag")
1196 nil t)
1197 current-prefix-arg))
1198 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1199 (debbugs-gnu-guess-current-id)
1200 (debbugs-gnu-current-id)))
1201 (version
1202 (when (member message '("close" "done"))
1203 (read-string
1204 "Version: "
1205 (cond
1206 ;; Emacs development versions.
1207 ((string-match
1208 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1209 (format "%s.%d"
1210 (match-string 1 emacs-version)
1211 (1+ (string-to-number (match-string 2 emacs-version)))))
1212 ;; Emacs release versions.
1213 ((string-match
1214 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1215 (format "%s.%s"
1216 (match-string 1 emacs-version)
1217 (match-string 2 emacs-version)))
1218 (t emacs-version)))))
1219 (status (debbugs-gnu-current-status)))
1220 (with-temp-buffer
1221 (insert "To: control@debbugs.gnu.org\n"
1222 "From: " (message-make-from) "\n"
1223 (format "Subject: control message for bug #%d\n" id)
1224 "\n"
1225 (cond
1226 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1227 (format "%s %d\n" message id))
1228 ((member message '("merge" "forcemerge"))
1229 (format "%s %d %s\n" message id
1230 (read-string "Merge with bug #: ")))
1231 ((member message '("block" "unblock"))
1232 (format
1233 "%s %d by %s\n" message id
1234 (mapconcat
1235 'identity
1236 (completing-read-multiple
1237 (format "%s with bug(s) #: " (capitalize message))
1238 (if (equal message "unblock")
1239 (mapcar 'number-to-string
1240 (cdr (assq 'blockedby status))))
1241 nil (and (equal message "unblock") status))
1242 " ")))
1243 ((equal message "owner")
1244 (format "owner %d !\n" id))
1245 ((equal message "reassign")
1246 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1247 ((equal message "close")
1248 (format "close %d %s\n" id version))
1249 ((equal message "done")
1250 (format "tags %d fixed\nclose %d %s\n" id id version))
1251 ((member message '("donenotabug" "donewontfix"
1252 "doneunreproducible"))
1253 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1254 ((member message '("serious" "important" "normal"
1255 "minor" "wishlist"))
1256 (format "severity %d %s\n" id message))
1257 ((equal message "invalid")
1258 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1259 id id id))
1260 ((equal message "usertag")
1261 (format "user %s\nusertag %d %s\n"
1262 (completing-read
1263 "Package name or email address: "
1264 (append
1265 debbugs-gnu-all-packages (list user-mail-address))
1266 nil nil (car debbugs-gnu-default-packages))
1267 id (read-string "User tag: ")))
1268 (t
1269 (format "tags %d%s %s\n"
1270 id (if reverse " -" "")
1271 message))))
1272 (funcall send-mail-function)
1273 (message-goto-body)
1274 (message "Control message sent:\n%s"
1275 (buffer-substring-no-properties (point) (1- (point-max)))))))
1276
1277 (defvar debbugs-gnu-usertags-mode-map
1278 (let ((map (make-sparse-keymap)))
1279 (set-keymap-parent map tabulated-list-mode-map)
1280 (define-key map "\r" 'debbugs-gnu-select-usertag)
1281 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1282 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1283 map))
1284
1285 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1286 "Major mode for listing user tags.
1287
1288 All normal editing commands are switched off.
1289 \\<debbugs-gnu-usertags-mode-map>
1290
1291 The following commands are available:
1292
1293 \\{debbugs-gnu-usertags-mode-map}"
1294 (buffer-disable-undo)
1295 (setq truncate-lines t)
1296 (setq buffer-read-only t))
1297
1298 ;;;###autoload
1299 (defun debbugs-gnu-usertags (&rest users)
1300 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1301 (interactive
1302 (if current-prefix-arg
1303 (completing-read-multiple
1304 "Package name(s) or email address: "
1305 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1306 (mapconcat 'identity debbugs-gnu-default-packages ","))
1307 debbugs-gnu-default-packages))
1308
1309 (unwind-protect
1310 (let ((inhibit-read-only t)
1311 (debbugs-port "gnu.org")
1312 (buffer-name "*Emacs User Tags*")
1313 (user-tab-length
1314 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1315
1316 ;; Initialize variables.
1317 (when (and (file-exists-p debbugs-gnu-persistency-file)
1318 (not debbugs-gnu-local-tags))
1319 (with-temp-buffer
1320 (insert-file-contents debbugs-gnu-persistency-file)
1321 (eval (read (current-buffer)))))
1322
1323 ;; Create buffer.
1324 (when (get-buffer buffer-name)
1325 (kill-buffer buffer-name))
1326 (switch-to-buffer (get-buffer-create buffer-name))
1327 (debbugs-gnu-usertags-mode)
1328 (setq tabulated-list-format `[("User" ,user-tab-length t)
1329 ("Tag" 10 t)])
1330 (setq tabulated-list-sort-key (cons "User" nil))
1331 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1332
1333 ;; Retrieve user tags.
1334 (dolist (user users)
1335 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1336 (add-to-list
1337 'tabulated-list-entries
1338 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1339 `((("tagged") (,user) nil nil (,tag))
1340 ,(vector (propertize user 'mouse-face 'highlight)
1341 (propertize tag 'mouse-face 'highlight)))
1342 'append)))
1343
1344 ;; Add local tags.
1345 (when debbugs-gnu-local-tags
1346 (add-to-list
1347 'tabulated-list-entries
1348 `((("tagged"))
1349 ,(vector
1350 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1351
1352 ;; Show them.
1353 (tabulated-list-init-header)
1354 (tabulated-list-print)
1355
1356 (set-buffer-modified-p nil)
1357 (goto-char (point-min)))))
1358
1359 (defun debbugs-gnu-select-usertag ()
1360 "Select the user tag on the current line."
1361 (interactive)
1362 ;; We open the bug reports.
1363 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1364 (when args (apply 'debbugs-gnu args))))
1365
1366 ;;;###autoload
1367 (defun debbugs-gnu-bugs (&rest bugs)
1368 "List all BUGS, a list of bug numbers."
1369 (interactive
1370 (mapcar 'string-to-number
1371 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1372 (dolist (elt bugs)
1373 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1374 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1375 ;; We do not suppress bugs requested explicitely.
1376 (setq-default debbugs-gnu-current-suppress nil)
1377 (debbugs-gnu nil))
1378
1379 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1380 "The directory where the main source tree lives.")
1381
1382 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1383 "The directory where the previous source tree lives.")
1384
1385 (defun debbugs-gnu-apply-patch (&optional branch)
1386 "Apply the patch from the current message.
1387 If given a prefix, patch in the branch directory instead."
1388 (interactive "P")
1389 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1390 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1391 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1392 (let ((rej "/tmp/debbugs-gnu.rej")
1393 (output-buffer (get-buffer-create "*debbugs patch*"))
1394 (dir (if branch
1395 debbugs-gnu-branch-directory
1396 debbugs-gnu-trunk-directory))
1397 (patch-buffers nil))
1398 (when (file-exists-p rej)
1399 (delete-file rej))
1400 (with-current-buffer output-buffer
1401 (erase-buffer))
1402 (gnus-summary-select-article nil t)
1403 ;; The patches are either in MIME attachements or the main article
1404 ;; buffer. Determine which.
1405 (gnus-with-article-buffer
1406 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1407 (when (string-match "diff\\|patch" (mm-handle-media-type handle))
1408 (push (cons (mm-handle-encoding handle)
1409 (mm-handle-buffer handle))
1410 patch-buffers))))
1411 (unless patch-buffers
1412 (gnus-summary-show-article 'raw)
1413 (article-decode-charset)
1414 (push (cons nil gnus-article-buffer) patch-buffers))
1415 (dolist (elem patch-buffers)
1416 (with-temp-buffer
1417 (insert-buffer-substring (cdr elem))
1418 (cond ((eq (car elem) 'base64)
1419 (base64-decode-region (point-min) (point-max)))
1420 ((eq (car elem) 'qp)
1421 (quoted-printable-decode-region (point-min) (point-max))))
1422 (debbugs-gnu-fix-patch dir)
1423 (call-process-region (point-min) (point-max)
1424 "patch" nil output-buffer nil
1425 "-r" rej "--no-backup-if-mismatch"
1426 "-l" "-f"
1427 "-d" (expand-file-name dir)
1428 "-p1")))
1429 (set-buffer output-buffer)
1430 (when (file-exists-p rej)
1431 (goto-char (point-max))
1432 (insert-file-contents-literally rej))
1433 (goto-char (point-max))
1434 (save-some-buffers t)
1435 (require 'compile)
1436 (mapc 'kill-process compilation-in-progress)
1437 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1438 (vc-dir dir)
1439 (vc-dir-hide-up-to-date)
1440 (goto-char (point-min))
1441 (sit-for 1)
1442 (vc-diff)
1443 ;; All these commands are asynchronous, so just wait a bit. This
1444 ;; should be done properly a different way.
1445 (sit-for 2)
1446 ;; We've now done everything, so arrange the windows we need to see.
1447 (delete-other-windows)
1448 (switch-to-buffer output-buffer)
1449 (split-window)
1450 (split-window)
1451 (other-window 1)
1452 (switch-to-buffer "*compilation*")
1453 (goto-char (point-max))
1454 (other-window 1)
1455 (switch-to-buffer "*vc-diff*")
1456 (goto-char (point-min))))
1457
1458 (defun debbugs-gnu-fix-patch (dir)
1459 (setq dir (directory-file-name (expand-file-name dir)))
1460 (goto-char (point-min))
1461 (while (re-search-forward diff-file-header-re nil t)
1462 (goto-char (match-beginning 0))
1463 (let ((target-name (car (diff-hunk-file-names))))
1464 (when (and target-name
1465 (or (not (string-match "/" target-name))
1466 (and (string-match "^[ab]/" target-name)
1467 (not (file-exists-p
1468 (expand-file-name (substring target-name 2)
1469 dir))))
1470 (file-exists-p (expand-file-name target-name dir))))
1471 ;; We have a simple patch that refers to a file somewhere in the
1472 ;; tree. Find it.
1473 (when-let ((files (directory-files-recursively
1474 dir
1475 (concat "^" (regexp-quote
1476 (file-name-nondirectory target-name))
1477 "$"))))
1478 (when (re-search-forward (concat "^[+]+ "
1479 (regexp-quote target-name)
1480 "\\([ \t\n]\\)")
1481 nil t)
1482 (replace-match (concat "+++ a"
1483 (substring (car files) (length dir))
1484 (match-string 1))
1485 nil t)))))
1486 (forward-line 2)))
1487
1488 (defun debbugs-gnu-find-contributor (string)
1489 "Search through ChangeLogs to find contributors."
1490 (interactive "sContributor match: ")
1491 (let ((found 0)
1492 (match (concat "^[0-9].*" string)))
1493 (dolist (file (directory-files-recursively
1494 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1495 (with-temp-buffer
1496 (when (file-exists-p file)
1497 (insert-file-contents file))
1498 (goto-char (point-min))
1499 (while (and (re-search-forward match nil t)
1500 (not (looking-at ".*tiny change")))
1501 (cl-incf found))))
1502 (message "%s is a contributor %d times" string found)
1503 found))
1504
1505 (defun debbugs-gnu-insert-changelog ()
1506 "Add a ChangeLog from a recently applied patch from a third party."
1507 (interactive)
1508 (let (from subject)
1509 (gnus-with-article-buffer
1510 (widen)
1511 (goto-char (point-min))
1512 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1513 subject (gnus-fetch-field "subject")))
1514 (let ((add-log-full-name (car from))
1515 (add-log-mailing-address (cadr from)))
1516 (add-change-log-entry-other-window)
1517 (let ((point (point)))
1518 (when (string-match "\\(bug#[0-9]+\\)" subject)
1519 (insert " (" (match-string 1 subject) ")."))
1520 (when (zerop (debbugs-gnu-find-contributor
1521 (let ((bits (split-string (car from))))
1522 (cond
1523 ((>= (length bits) 2)
1524 (format "%s.*%s" (car bits) (car (last bits))))
1525 ((= (length bits) 1)
1526 (car bits))
1527 ;; Fall back on the email address.
1528 (t
1529 (cadr from))))))
1530 (goto-char (point-max))
1531 (end-of-line)
1532 (insert " (tiny change"))
1533 (goto-char point)))))
1534
1535 (defvar debbugs-gnu-lisp-mode-map
1536 (let ((map (make-sparse-keymap)))
1537 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1538 map))
1539
1540 (define-minor-mode debbugs-gnu-lisp-mode
1541 "Minor mode for providing a debbugs interface in Lisp buffers.
1542 \\{debbugs-gnu-lisp-mode-map}"
1543 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1544
1545 (defvar debbugs-gnu-diff-mode-map
1546 (let ((map (make-sparse-keymap)))
1547 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1548 map))
1549
1550 (define-minor-mode debbugs-gnu-diff-mode
1551 "Minor mode for providing a debbugs interface in diff buffers.
1552 \\{debbugs-gnu-diff-mode-map}"
1553 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1554
1555 (defun debbugs-gnu-diff-select ()
1556 "Select the diff under point."
1557 (interactive)
1558 (delete-other-windows)
1559 (diff-goto-source))
1560
1561 (defvar debbugs-gnu-change-mode-map
1562 (let ((map (make-sparse-keymap)))
1563 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1564 map))
1565
1566 (define-minor-mode debbugs-gnu-change-mode
1567 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1568 \\{debbugs-gnu-change-mode-map}"
1569 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1570
1571 (defun debbugs-gnu-change-checkin ()
1572 "Prepare checking in the current changes."
1573 (interactive)
1574 (save-some-buffers t)
1575 (when (get-buffer "*vc-dir*")
1576 (kill-buffer (get-buffer "*vc-dir*")))
1577 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1578 (if (equal (cl-subseq default-directory 0 (length trunk))
1579 trunk)
1580 (vc-dir debbugs-gnu-trunk-directory)
1581 (vc-dir debbugs-gnu-branch-directory)))
1582 (goto-char (point-min))
1583 (while (not (search-forward "edited" nil t))
1584 (sit-for 0.01))
1585 (beginning-of-line)
1586 (while (search-forward "edited" nil t)
1587 (vc-dir-mark)
1588 (beginning-of-line))
1589 (vc-diff nil)
1590 (vc-next-action nil)
1591 (log-edit-insert-changelog t)
1592 (delete-other-windows)
1593 (split-window)
1594 (other-window 1)
1595 (switch-to-buffer "*vc-diff*")
1596 (other-window 1))
1597
1598 (provide 'debbugs-gnu)
1599
1600 ;;; TODO:
1601
1602 ;; * Another random thought - is it possible to implement some local
1603 ;; cache, so only changed bugs are fetched? Glenn Morris.
1604
1605 ;;; debbugs-gnu.el ends here