Forgot to attach the updated patch.
See below.

>From 88c92d127b377ba8a296e54f760080bb779bc32c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bi...@thaodan.de>
Date: Tue, 21 Jan 2025 00:55:15 +0200
Subject: [PATCH] Ensure that gnus-other-frame-object is alive before selecting

* lisp/ol-gnus.el (org-gnus-follow-link): Ensure that
`gnus-other-frame-object' is active before selecting it.
Error out in case frame-object is dead, i.e. wasn't activated
by `org-link-frame-setup-function'.
(org-gnus-no-new-news): Take `gnus-other-frame-object' into account.
Call gnus-other-frame with chosen action instead without.
Ensures that previous behavior of `org-gnus-follow-link' is kept.
(org-gnus-no-new-news-other-frame): New function for users who choose
to call `gnus-other-frame' regardless if previous used or not.
* lisp/ol.el (org-link-frame-setup): Include
new `org-gnus-no-news-other-frame` function.
---
 etc/ORG-NEWS    | 17 +++++++++++++++++
 lisp/ol-gnus.el | 30 ++++++++++++++++++++++++------
 lisp/ol.el      |  4 +++-
 3 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index cb2c16da8..f3714212c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -211,6 +211,17 @@ retail 4-4-5 calendars, etc).
 # adding new customizations, or changing the interpretation of the
 # existing customizations.
 
+*** =org-link-gnus= Ensure that other frame is alive before selecting it
+Ensure that the Gnus frame is alive before selecting it if it was
+activated before.  If a Gnus frame existed before call it using
+~gnus-other-frame~. Using the function also ensures that
+~org-link-frame-setup~ no longer overrides the existing Gnus frame.
+
+Existing ~org-link-frame-setup~ functions for Gnus links have
+to be adjusted to ensure that ~gnus-other-frame-object~ contains
+a frame which is alive.  Check the default ~org-gnus-no-news~
+function for more.
+
 *** ox-odt: New export option ~org-odt-with-forbidden-chars~
 
 The new export option controls how to deal with characters that are forbidden
@@ -299,6 +310,12 @@ This text will be displayed on animation step 2 and later.
 
 # This also includes changes in function behavior from Elisp perspective.
 
+*** ~org-gnus-no-new-news-other-frame~ to open Gnus in other frame without fetching news
+New function to call ~org-gnusw-no-news~ to with ~t~ so it always will
+open Gnus with ~gnus-other-frame~ regardless if used previously or not.
+The function can be useful in a frame orientated setup to be used
+in ~org-link-frame-setup~.
+
 *** New command ~org-link-preview~ to preview Org links
 
 This command replaces ~org-toggle-inline-images~, which is now
diff --git a/lisp/ol-gnus.el b/lisp/ol-gnus.el
index 5cddc3790..65d77ea88 100644
--- a/lisp/ol-gnus.el
+++ b/lisp/ol-gnus.el
@@ -228,7 +228,12 @@ (defun org-gnus-follow-link (&optional group article)
   "Follow a Gnus link to GROUP and ARTICLE."
   (require 'gnus)
   (funcall (org-link-frame-setup-function 'gnus))
-  (when gnus-other-frame-object (select-frame gnus-other-frame-object))
+  (when gnus-other-frame-object
+    (if (not (frame-live-p gnus-other-frame-object))
+        ;; Error out in case org-link-frame-setup did not take care of setting up
+        ;; the gnus frame if was activate previously.
+        (error "Couldn't select \'gnus-other-frame-object\', make sure it is active"))
+    (select-frame gnus-other-frame-object))
   (let ((group (org-no-properties group))
 	(article (org-no-properties article)))
     (cond
@@ -260,11 +265,24 @@ (defun org-gnus-follow-link (&optional group article)
 	 (message "Couldn't follow Gnus link.  The linked group is empty."))))
      (group (gnus-group-jump-to-group group)))))
 
-(defun org-gnus-no-new-news ()
-  "Like `\\[gnus]' but doesn't check for new news."
-  (cond ((gnus-alive-p) nil)
-	(org-gnus-no-server (gnus-no-server))
-	(t (gnus))))
+(defun org-gnus-no-new-news (&optional other-frame)
+  "Like `\\[gnus]' but doesn't check for new news.
+In case of OTHER-FRAME or `gnus-other-frame-object' call `gnus-other-frame'.
+
+Ensures that `gnus-other-frame' is activated correctly if dead."
+  (let ((action (cond  (org-gnus-no-server #'gnus-no-server)
+	               (t #'gnus))))
+    (cond ((or other-frame gnus-other-frame-object)
+           (let ((gnus-other-frame-function action)
+                 (gnus-other-frame-resume-function action))
+             (gnus-other-frame)))
+          (t (if (not (gnus-alive-p))
+                 (funcall action))))))
+
+(defun org-gnus-no-new-news-other-frame ()
+  "Like `org-gnus-no-new-news' but always in another frame."
+    (org-gnus-no-new-news t))
+
 
 (provide 'ol-gnus)
 
diff --git a/lisp/ol.el b/lisp/ol.el
index 0429e257c..856a409d7 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -348,6 +348,7 @@ (defcustom org-link-frame-setup
     `gnus'
     `gnus-other-frame'
     `org-gnus-no-new-news'
+    `org-gnus-no-new-news-other-frame'
 For FILE, use any of
     `find-file'
     `find-file-other-window'
@@ -374,7 +375,8 @@ (defcustom org-link-frame-setup
 		(choice
 		 (const gnus)
 		 (const gnus-other-frame)
-		 (const org-gnus-no-new-news)))
+		 (const org-gnus-no-new-news)
+                 (const org-gnus-no-new-news-other-frame)))
 	  (cons (const file)
 		(choice
 		 (const find-file)
-- 
2.45.2

Reply via email to