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