Subject: Re: bug#78864: Support for bookmarks in debbugs.el

From: Matthias Meulien <[email-masked]>
Date: Sun, 31 Aug 2025 15:18:47 +0200

Hi Michael,

This patch lies around in my workspace. Any News?

Sorry I still have two tasks on my todo list related to that patch but did
not spent time on those.

First, I want to propose an updated implementation of
debbugs-gnu-my-open-bugs with objective to have debbugs-gnu-local-query set
to the original query in the result buffer ; currently this variable is set
to a list of bugs which makes a bookmark to the result buffer not behaving
in the way we'd like to, I guess: The bookmark open to a fixed list of bugs.

Second, I want to write few words in the documentation.

Since holidays just finished, I'll spent more time in front of the
computer, so I might work on this soon but it's difficult to be precise.

I send the original patch in a private mail and it's not available from
that bug report so I attach it to this mail.

Best regards,
-- 
Matthias
From 684ecc25d9c143c6e00f5c24e6dde69f92311cb0 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <[email-masked]>
Date: Sun, 22 Jun 2025 17:45:38 +0200
Subject: [PATCH] Bookmarks support

---
 debbugs-gnu.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/debbugs-gnu.el b/debbugs-gnu.el
index c0ac0f8116..1f484a246a 100644
--- a/debbugs-gnu.el
+++ b/debbugs-gnu.el
@@ -1365,6 +1365,69 @@ Interactively, it is non-nil with the prefix argument."
   :type 'natnum
   :version "30.1")
 
+;;; Support for bookmark.el.
+
+(declare-function bookmark-make-record-default
+                  "bookmark" (&optional no-file no-context posn))
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-default-handler "bookmark" (bmk))
+(declare-function bookmark-get-bookmark-record "bookmark" (bmk))
+
+(defun debbugs-gnu-bookmark-name (query)
+  (let* ((bugs (cdr (assq 'bugs query)))
+	 (bug-count (length bugs))
+	 (packages (mapcar 'cdr
+			   (seq-filter
+			    (lambda (elt) (eq (car elt) 'package))
+			    query)))
+	 (package-count (length packages))
+	 (bugs-substring
+	  (cond
+	   ((eq bug-count 0) nil)
+	   ((eq bug-count 1) (concat "Bug #" (int-to-string (car bugs))))
+	   ((concat "Bugs " (string-join (mapcar (lambda (elt) (concat "#" (int-to-string elt))) bugs) ", ")))))
+	 (package-substring
+	  (cond
+	   ((eq package-count 0) nil)
+	   ((eq package-count 1) (concat "in " (car packages) " package"))
+	   (t (concat "in packages " (string-join packages ","))))))
+    (cond
+     (bugs-substring)
+     (package-substring (string-join (list "Bugs" package-substring) " "))
+     (t "Bugs"))))
+
+(defun debbugs-gnu-bookmark-make-record ()
+  "Make record used to bookmark a Debbugs buffer.
+This implements the `bookmark-make-record-function' type for
+such buffers."
+  (let ((bookmark-name (debbugs-gnu-bookmark-name debbugs-gnu-local-query)))
+    `(,bookmark-name
+      ,@(bookmark-make-record-default 'no-file)
+      (filename . nil)
+      (buf . ,(buffer-name))
+      (handler . debbugs-gnu-bookmark-jump)
+      (debbugs-gnu-current-filter . ,debbugs-gnu-local-filter)
+      (debbugs-gnu-current-print-function . ,debbugs-gnu-local-print-function)
+      (debbugs-gnu-current-query . ,debbugs-gnu-local-query)
+      (debbugs-gnu-current-suppress . ,debbugs-gnu-local-suppress))))
+
+(put 'debbugs-gnu-bookmark-jump 'bookmark-handler-type "Debbugs")
+
+;;;###autoload
+(defun debbugs-gnu-bookmark-jump (bmk)
+  "Provide the `bookmark-jump' behavior for a Debbugs buffer.
+This implements the `handler' function interface for the record
+type returned by `debbugs-gnu-bookmark-make-record'."
+  (let* ((debbugs-gnu-current-filter (bookmark-prop-get bmk 'debbugs-gnu-current-filter))
+	 (debbugs-gnu-current-print-function (bookmark-prop-get bmk 'debbugs-gnu-current-print-function))
+	 (debbugs-gnu-current-query (bookmark-prop-get bmk 'debbugs-gnu-current-query))
+	 (debbugs-gnu-current-suppress (bookmark-prop-get bmk 'debbugs-gnu-current-suppress))
+         (buf (progn ;; Don't use save-window-excursion (bug#39722)
+		(debbugs-gnu-show-reports)
+                debbugs-gnu-current-buffer)))
+    (bookmark-default-handler
+     `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
+
 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
   "Major mode for listing bug reports.
 The bugs are taken from the cache when the list is refreshed.
@@ -1383,6 +1446,7 @@ modified on the debbugs server, consider typing \\`C-u g'.
   (set (make-local-variable 'debbugs-gnu-local-print-function)
        debbugs-gnu-current-print-function)
   (set (make-local-variable 'tabulated-list-entries) nil)
+  (setq bookmark-make-record-function #'debbugs-gnu-bookmark-make-record)
   (setq tabulated-list-format
         `[("Id" ,debbugs-gnu-width-id debbugs-gnu-sort-id)
 	  ("State" ,debbugs-gnu-width-state debbugs-gnu-sort-state)
-- 
2.39.5