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