From 4f4936aba13fe2156d74465e3f4e8df857cc6754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= 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. --- lisp/ol-gnus.el | 30 ++++++++++++++++++++++++------ lisp/ol.el | 4 +++- 2 files changed, 27 insertions(+), 7 deletions(-) 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 2365ca802..6cf3d92aa 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