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