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