Subject: Re: Base patch for bug #5975 (bookmarking from Gnus Article buffer).

From: Karl Fogel <[email-masked]>
Date: Tue, 13 Jul 2010 17:41:44 -0400

Karl Fogel <[email-masked]> writes:
>Just for reference, the current (preparatory) patch is below.  I will
>follow up separately with the gnus/* patch, so it's in the archives.

Here's that patch (still needs the C-w fix referred to in the bug, though).

=== modified file 'lisp/gnus/ChangeLog'
--- lisp/gnus/ChangeLog	2010-07-13 21:20:34 +0000
+++ lisp/gnus/ChangeLog	2010-07-13 21:39:19 +0000
@@ -1,5 +1,16 @@
 2010-07-13  Karl Fogel  <[email-masked]>
 
+	Allow bookmarks to be set from Gnus Article buffers.
+	Based on a patch by Thierry Volpiatto (Bug #5975).
+
+	* gnus-art.el (bookmark-make-record-function): New local variable.
+
+	* gnus-sum.el (gnus-summary-bookmark-make-record): Allow setting
+	from article buffer.
+	(gnus-summary-bookmark-jump): Maybe jump to article buffer.
+
+2010-07-13  Karl Fogel  <[email-masked]>
+
 	* gnus/gnus-sum.el (bookmark-make-record-default): Adjust
 	declaration, based on changes in bookmark.el.

=== modified file 'lisp/gnus/gnus-art.el'
--- lisp/gnus/gnus-art.el	2010-06-10 05:33:55 +0000
+++ lisp/gnus/gnus-art.el	2010-07-13 21:39:19 +0000
@@ -4452,6 +4452,8 @@
   (make-local-variable 'gnus-article-image-alist)
   (make-local-variable 'gnus-article-charset)
   (make-local-variable 'gnus-article-ignored-charsets)
+  (set (make-local-variable 'bookmark-make-record-function)
+       'gnus-summary-bookmark-make-record)
   ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
   ;; face.
   (set (make-local-variable 'nobreak-char-display) nil)

=== modified file 'lisp/gnus/gnus-sum.el'
--- lisp/gnus/gnus-sum.el	2010-07-13 21:20:34 +0000
+++ lisp/gnus/gnus-sum.el	2010-07-13 21:39:19 +0000
@@ -12629,18 +12629,24 @@
 
 (defun gnus-summary-bookmark-make-record ()
   "Make a bookmark entry for a Gnus summary buffer."
-  (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
-    (error "Please retry from the Gnus summary buffer")) ;[1]
-  (let* ((subject (elt (gnus-summary-article-header) 1))
-         (grp     (car gnus-article-current))
-         (art     (cdr gnus-article-current))
-         (head    (gnus-summary-article-header art))
-         (id      (mail-header-id head)))
-    `(,subject
-      ,@(bookmark-make-record-default 'point-only)
-      (location . ,(format "Gnus %s:%d:%s" grp art id))
-      (group . ,grp) (article . ,art)
-      (message-id . ,id) (handler . gnus-summary-bookmark-jump))))
+  (let (pos buf)
+    (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
+      (save-restriction ; FIXME is it necessary to widen?
+        (widen) (setq pos (point))) ; Set position in gnus-article buffer.
+      (setq buf "art") ; We are recording bookmark from article buffer.
+      (gnus-article-show-summary)) ; Go back in summary buffer.
+    ;; We are now recording bookmark from summary buffer.
+    (unless buf (setq buf "sum"))
+    (let* ((subject (elt (gnus-summary-article-header) 1))
+           (grp     (car gnus-article-current))
+           (art     (cdr gnus-article-current))
+           (head    (gnus-summary-article-header art))
+           (id      (mail-header-id head)))
+      `(,subject
+        ,@(bookmark-make-record-default 'no-file 'no-context pos)
+        (location . ,(format "Gnus-%s %s:%d:%s" buf grp art id))
+        (group . ,grp) (article . ,art)
+        (message-id . ,id) (handler . gnus-summary-bookmark-jump)))))
 
 ;;;###autoload
 (defun gnus-summary-bookmark-jump (bookmark)
@@ -12648,10 +12654,18 @@
 BOOKMARK is a bookmark name or a bookmark record."
   (let ((group    (bookmark-prop-get bookmark 'group))
         (article  (bookmark-prop-get bookmark 'article))
-        (id       (bookmark-prop-get bookmark 'message-id)))
+        (id       (bookmark-prop-get bookmark 'message-id))
+        (buf      (car (split-string (bookmark-prop-get bookmark 'location)))))
     (gnus-fetch-group group (list article))
     (gnus-summary-insert-cached-articles)
     (gnus-summary-goto-article id nil 'force)
+    ;; FIXME we have to wait article buffer is ready (only large buffer)
+    ;; Is there a better solution to know that?
+    ;; If we don't wait `bookmark-default-handler' will have no chance
+    ;; to set position. However there is no error, just wrong pos.
+    (sit-for 1)
+    (when (string= buf "Gnus-art")
+      (other-window 1))
     (bookmark-default-handler
      `(""
        (buffer . ,(current-buffer))