Ihor Radchenko <yanta...@posteo.net> writes:

> Björn Bidar <bjorn.bi...@thaodan.de> writes:
>
>> +*** =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.
>
> This still feels confusing (sorry that I keep asking, but I need to
> make sure that the entry is useful for the existing users).
>
>> =org-link-gnus= Ensure that other frame is alive before selecting it
>
> By looking at this line, I feel like reading a commit log. It is not
> what we should put in ORG-NEWS. As a user, I expected ORG-NEWS heading
> to highlight what change has been introduced and why I need to care.
>
> "ensure that frame is alive" sounds like some bug being fixed, but not
> like a change to pay attention to.

> I actually doubt that we need to talk about `gnus-other-frame-object' at
> all. In the past, if `gnus-other-frame-object' were a dead frame, users
> would see an error. Now, we still show an error, albeit more
> descriptive. Nothing major to pay attention to.


Then no entry is necessary as there is nothing to pay attention too.
I removed the entry. 

> Isn't the potentially breaking change done in `org-gnus-no-new-news'
> behavior? The logic there is certainly changed, but it is hard to me to
> know how to explain it best to gnus users.

The logic hasn't changed the function which is invoked (see the action
variable) is still the same.
The only difference is that when gnus-other-frame should be used that
the function is called by gnus-other-frame after reactivating the Gnus
frame.


>> +*** ~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~.
>
> What about
>
> *** New function ~org-gnus-no-new-news-other-frame~ (to be used in 
> ~org-link-frame-setup~)
>
> The new function is like ~org-gnus-no-new-news~, but always opens the
> link in other frame.

Sounds fine.

>From 566117fabbe6fedd656ed9a4045b523bd7525c13 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    |  6 ++++++
 lisp/ol-gnus.el | 30 ++++++++++++++++++++++++------
 lisp/ol.el      |  4 +++-
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index cb2c16da8..63d9fcc33 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -299,6 +299,12 @@ This text will be displayed on animation step 2 and later.
 
 # This also includes changes in function behavior from Elisp perspective.
 
+*** New function ~org-gnus-no-new-news-other-frame~ (to be used in ~org-link-frame-setup~)
+
+The new function is like ~org-gnus-no-new-news~, but always opens the
+link in other frame.
+
+
 *** 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