emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Unexpected error using org-gnus-follow-link
@ 2024-12-12 12:57 Fraga, Eric
  2024-12-12 15:02 ` Visuwesh
  0 siblings, 1 reply; 12+ messages in thread
From: Fraga, Eric @ 2024-12-12 12:57 UTC (permalink / raw)
  To: Emacs Org mode mailing list

Hello all,

I upgraded both Emacs (from git) and org (elpa) in the last couple of
days.  Today I find that I get the following error using
org-open-at-point:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (void-function nil)
  nil()
  org-gnus-follow-link("nnml+outlook:mail.dt2022" "[...]")
  org-gnus-open("nnml+outlook:mail.dt2022#[...]" nil)
  org-link-open((link (:standard-properties [1994 nil 2111 2179 2181 0 nil nil nil nil nil nil nil nil #<buffer todo.org> nil nil (paragraph (:standard-properties [1994 1994 1994 2182 2182 0 nil nil element t (3 . 1815) nil nil nil #<buffer todo.org> nil nil (item ...)]))] :type "gnus" :type-explicit-p t :path "nnml+outlook:mail.dt2022#[...]" :format bracket :raw-link "gnus:nnml+outlook:mail.dt2022#[...]" :application nil :search-option nil)) nil)
  org-open-at-point(nil)
  funcall-interactively(org-open-at-point nil)
  command-execute(org-open-at-point)
--8<---------------cut here---------------end--------------->8---

with message reference elided.

I cannot really reduce this to a minimal example or use -Q due to need
to have gnus configured.

Any suggestions on how to resolve this?  The vast majority of my TODO
entries have gnus email links and they have always worked just fine.
The problem could, of course, be with gnus but I cannot tell from the
above backtrace.

Thank you,
eric
-- 
: Eric S Fraga, with org 9.7.17-3ae179 in Emacs 31.0.50

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-12 12:57 Unexpected error using org-gnus-follow-link Fraga, Eric
@ 2024-12-12 15:02 ` Visuwesh
  2024-12-12 18:15   ` Fraga, Eric
  0 siblings, 1 reply; 12+ messages in thread
From: Visuwesh @ 2024-12-12 15:02 UTC (permalink / raw)
  To: Org Mode List

[வியாழன் டிசம்பர் 12, 2024] Fraga, Eric wrote:

> Hello all,
>
> I upgraded both Emacs (from git) and org (elpa) in the last couple of
> days.  Today I find that I get the following error using
> org-open-at-point:
>
> Debugger entered--Lisp error: (void-function nil)
>   nil()
>   org-gnus-follow-link("nnml+outlook:mail.dt2022" "[...]")
>   org-gnus-open("nnml+outlook:mail.dt2022#[...]" nil)
>   org-link-open((link (:standard-properties [1994 nil 2111 2179 2181 0 nil nil nil nil nil nil nil nil #<buffer todo.org> nil nil (paragraph (:standard-properties [1994 1994 1994 2182 2182 0 nil nil element t (3 . 1815) nil nil nil #<buffer todo.org> nil nil (item ...)]))] :type "gnus" :type-explicit-p t :path "nnml+outlook:mail.dt2022#[...]" :format bracket :raw-link "gnus:nnml+outlook:mail.dt2022#[...]" :application nil :search-option nil)) nil)
>   org-open-at-point(nil)
>   funcall-interactively(org-open-at-point nil)
>   command-execute(org-open-at-point)
>
> with message reference elided.
>
> I cannot really reduce this to a minimal example or use -Q due to need
> to have gnus configured.
>
> Any suggestions on how to resolve this?  The vast majority of my TODO
> entries have gnus email links and they have always worked just fine.
> The problem could, of course, be with gnus but I cannot tell from the
> above backtrace.

A shot in the dark after looking at org-gnus-follow-link: what is the
value of org-link-frame-setup?  Does it have the gnus entry?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-12 15:02 ` Visuwesh
@ 2024-12-12 18:15   ` Fraga, Eric
  2024-12-13  5:42     ` Visuwesh
  0 siblings, 1 reply; 12+ messages in thread
From: Fraga, Eric @ 2024-12-12 18:15 UTC (permalink / raw)
  To: Visuwesh; +Cc: Org Mode List

Response below/inline for email Visuwesh wrote:
> (original email sent 12 Dec 2024 at 20:32)
> 
> A shot in the dark after looking at org-gnus-follow-link: what is the
> value of org-link-frame-setup?  Does it have the gnus entry?

Wow!  What an excellent shot in the dark. :-)

I happened to play with the orgrr package which unfortunately actually
changes that variable.  Resetting it to the default works just fine.

Many thanks.

It does beg the question: should org fail more gracefully and/or give an
error message in such a context?

Thanks again,
eric

-- 
: Eric S Fraga, with org 9.7.17-3ae179 in Emacs 31.0.50

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-12 18:15   ` Fraga, Eric
@ 2024-12-13  5:42     ` Visuwesh
  2024-12-13 10:46       ` Fraga, Eric
                         ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Visuwesh @ 2024-12-13  5:42 UTC (permalink / raw)
  To: Org Mode List

[வியாழன் டிசம்பர் 12, 2024] Fraga, Eric wrote:

> Response below/inline for email Visuwesh wrote:
>> (original email sent 12 Dec 2024 at 20:32)
>> 
>> A shot in the dark after looking at org-gnus-follow-link: what is the
>> value of org-link-frame-setup?  Does it have the gnus entry?
>
> Wow!  What an excellent shot in the dark. :-)
>
> I happened to play with the orgrr package which unfortunately actually
> changes that variable.  Resetting it to the default works just fine.
>
> Many thanks.

Glad to be of help.

> It does beg the question: should org fail more gracefully and/or give an
> error message in such a context?

I quickly checked the usage of that defcustom and Org does not fall back
gracefully in other places too.  While we can fix it, it would be good
to inform the maintainers of orgrr about this too.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-13  5:42     ` Visuwesh
@ 2024-12-13 10:46       ` Fraga, Eric
  2024-12-15 16:41       ` Max Nikulin
  2024-12-22 12:45       ` Ihor Radchenko
  2 siblings, 0 replies; 12+ messages in thread
From: Fraga, Eric @ 2024-12-13 10:46 UTC (permalink / raw)
  To: Visuwesh; +Cc: Org Mode List

Response below/inline for email Visuwesh wrote:
> (original email sent 13 Dec 2024 at 11:12)
> 
> While we can fix it, it would be good to inform the maintainers of
> orgrr about this too.

I intend to.  There are several bits of orgrr that stomp over the user's
preferences.  Otherwise, it's an interesting package.

Thanks again,
eric
-- 
: Eric S Fraga, with org 9.7.17-3ae179 in Emacs 31.0.50

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-13  5:42     ` Visuwesh
  2024-12-13 10:46       ` Fraga, Eric
@ 2024-12-15 16:41       ` Max Nikulin
  2024-12-22 12:45       ` Ihor Radchenko
  2 siblings, 0 replies; 12+ messages in thread
From: Max Nikulin @ 2024-12-15 16:41 UTC (permalink / raw)
  To: emacs-orgmode

On 13/12/2024 12:42, Visuwesh wrote:
> [வியாழன் டிசம்பர் 12, 2024] Fraga, Eric wrote:
>> Response below/inline for email Visuwesh wrote:
>>> (original email sent 12 Dec 2024 at 20:32)
>>>
>>> A shot in the dark after looking at org-gnus-follow-link: what is the
>>> value of org-link-frame-setup?  Does it have the gnus entry?
> 
>> It does beg the question: should org fail more gracefully and/or give an
>> error message in such a context?
> 
> I quickly checked the usage of that defcustom and Org does not fall back
> gracefully in other places too.

The question is if nil should mean "Do not call any setup function at 
all" or the default value should be used as a fallback.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-13  5:42     ` Visuwesh
  2024-12-13 10:46       ` Fraga, Eric
  2024-12-15 16:41       ` Max Nikulin
@ 2024-12-22 12:45       ` Ihor Radchenko
       [not found]         ` <87pllic102.fsf@gmail.com>
  2 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-12-22 12:45 UTC (permalink / raw)
  To: Visuwesh; +Cc: Org Mode List

Visuwesh <visuweshm@gmail.com> writes:

>> It does beg the question: should org fail more gracefully and/or give an
>> error message in such a context?
>
> I quickly checked the usage of that defcustom and Org does not fall back
> gracefully in other places too...

Do you want to make a patch to that effect?

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
       [not found]           ` <87jzbqluk9.fsf@localhost>
@ 2024-12-26 12:50             ` Visuwesh
  2024-12-26 12:53             ` Visuwesh
  1 sibling, 0 replies; 12+ messages in thread
From: Visuwesh @ 2024-12-26 12:50 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]

[திங்கள் டிசம்பர் 23, 2024] Ihor Radchenko wrote:

> Visuwesh <visuweshm@gmail.com> writes:
>
>>> Do you want to make a patch to that effect?
>>
>> How about the attached?  It falls back to the default value if the key
>> is not found in the alist.
>
> I'd rather just throw an error. If the value is not right in the
> customization, the user likely tried to customize things but failed to
> follow the value format. Falling back in such situation will create a
> headache "why Org is doing not what I tell Org to do?".
>
> Also, (cdr (assq 'gnus org-link-frame-setup)) = nil is not the only
> possible incorrect customization. I'd rather check if the cdr is a
> function and throw a descriptive error otherwise asking to fix
> `org-link-frame-setup'.

How about the attached?

BTW, I hope the function would not erroneously signal an error when the
frame setup function isn't yet loaded because of the fboundp check (but
I guess the chances of that are quite slim).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Error-if-org-link-frame-setup-is-ill-defined.patch --]
[-- Type: text/x-diff, Size: 4083 bytes --]

From a12fc868aba018814be366594a21cad46827f05d Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 23 Dec 2024 11:59:16 +0530
Subject: [PATCH] Error if org-link-frame-setup is ill-defined

* lisp/ol.el (org-link-frame-setup-function): Define new helper
function get the frame-setup-function for the corresponding link-type.
* lisp/ol-gnus.el (org-gnus-follow-link):
* lisp/org.el (org-open-file): Use the new function to better inform
the user when the user option `org-link-frame-setup-function' is
ill-defined.

Reported-by: Eric Fraga <e.fraga@ucl.ac.uk>
Link: https://list.orgmode.org/874j39vz29.fsf@ucl.ac.uk/
---
 lisp/ol-gnus.el |  2 +-
 lisp/ol.el      | 10 ++++++++++
 lisp/org.el     | 12 ++++++------
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lisp/ol-gnus.el b/lisp/ol-gnus.el
index b9ee8683f..2b20e80b2 100644
--- a/lisp/ol-gnus.el
+++ b/lisp/ol-gnus.el
@@ -227,7 +227,7 @@ (defun org-gnus-open (path _)
 (defun org-gnus-follow-link (&optional group article)
   "Follow a Gnus link to GROUP and ARTICLE."
   (require 'gnus)
-  (funcall (cdr (assq 'gnus org-link-frame-setup)))
+  (funcall (org-link-frame-setup-function))
   (when gnus-other-frame-object (select-frame gnus-other-frame-object))
   (let ((group (org-no-properties group))
 	(article (org-no-properties article)))
diff --git a/lisp/ol.el b/lisp/ol.el
index fa16b5920..757f2b1fd 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1539,6 +1539,16 @@ (defun org-link-add-angle-brackets (s)
   (unless (equal (substring s -1) ">") (setq s (concat s ">")))
   s)
 
+(defun org-link-frame-setup-function (link-type)
+  "Return the frame setup function for the link type LINK-TYPE.
+This signals an error if the value of the key LINK-TYPE in
+`org-link-frame-setup' is not a function."
+  (let ((fun (cdr (assq link-type org-link-frame-setup))))
+    (if (fboundp fun)
+        fun
+      (error "The frame setup configuration for `%s' link type is ill-defined"
+             link-type))))
+
 \f
 ;;; Built-in link types
 
diff --git a/lisp/org.el b/lisp/org.el
index 2e91dd508..6af67359d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8489,7 +8489,7 @@ (defun org-open-file (path &optional in-emacs line search)
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))
-      (funcall (cdr (assq 'file org-link-frame-setup)) file)
+      (funcall (org-link-frame-setup-function 'file) file)
       (widen)
       (cond (line (org-goto-line line)
 		  (when (derived-mode-p 'org-mode) (org-fold-reveal)))
@@ -8517,7 +8517,7 @@ (defun org-open-file (path &optional in-emacs line search)
       ;; `org-file-apps' with sexp instead of a function for `cmd'.
       (user-error "Please see Org News for version 9.0 about \
 `org-file-apps'--Error: Deprecated usage of %S" cmd))
-     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
+     (t (funcall (org-link-frame-setup-function 'file) file)))
     (funcall save-position-maybe)))
 
 ;;;###autoload
@@ -15311,20 +15311,20 @@ (defun org-modify-ts-extra (ts-string pos nincrements increment-step)
 	(setq hour (mod hour 24))
 	(setq pos-match-group 1
               new (format "-%02d:%02d" hour minute)))
-       
+
        ((org-pos-in-match-range pos 6) ;; POS on "dmwy" repeater char.
 	(setq pos-match-group 6
               new (car (rassoc (+ nincrements (cdr (assoc (match-string 6 ts-string) idx))) idx))))
-       
+
        ((org-pos-in-match-range pos 5) ;; POS on X in "Xd" repeater.
 	(setq pos-match-group 5
               ;; Never drop below X=1.
               new (format "%d" (max 1 (+ nincrements (string-to-number (match-string 5 ts-string)))))))
-       
+
        ((org-pos-in-match-range pos 9) ;; POS on "dmwy" repeater in warning interval.
 	(setq pos-match-group 9
               new (car (rassoc (+ nincrements (cdr (assoc (match-string 9 ts-string) idx))) idx))))
-       
+
        ((org-pos-in-match-range pos 8) ;; POS on X in "Xd" in warning interval.
 	(setq pos-match-group 8
               ;; Never drop below X=0.
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
       [not found]           ` <87jzbqluk9.fsf@localhost>
  2024-12-26 12:50             ` Visuwesh
@ 2024-12-26 12:53             ` Visuwesh
  2024-12-26 13:22               ` Ihor Radchenko
  1 sibling, 1 reply; 12+ messages in thread
From: Visuwesh @ 2024-12-26 12:53 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]

[திங்கள் டிசம்பர் 23, 2024] Ihor Radchenko wrote:

> Visuwesh <visuweshm@gmail.com> writes:
>
>>> Do you want to make a patch to that effect?
>>
>> How about the attached?  It falls back to the default value if the key
>> is not found in the alist.
>
> I'd rather just throw an error. If the value is not right in the
> customization, the user likely tried to customize things but failed to
> follow the value format. Falling back in such situation will create a
> headache "why Org is doing not what I tell Org to do?".
>
> Also, (cdr (assq 'gnus org-link-frame-setup)) = nil is not the only
> possible incorrect customization. I'd rather check if the cdr is a
> function and throw a descriptive error otherwise asking to fix
> `org-link-frame-setup'.

How about the attached?

BTW, I hope the function would not erroneously signal an error when the
frame setup function isn't yet loaded because of the fboundp check (but
I guess the chances of that are quite slim).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Error-if-org-link-frame-setup-is-ill-defined.patch --]
[-- Type: text/x-diff, Size: 4083 bytes --]

From a12fc868aba018814be366594a21cad46827f05d Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 23 Dec 2024 11:59:16 +0530
Subject: [PATCH] Error if org-link-frame-setup is ill-defined

* lisp/ol.el (org-link-frame-setup-function): Define new helper
function get the frame-setup-function for the corresponding link-type.
* lisp/ol-gnus.el (org-gnus-follow-link):
* lisp/org.el (org-open-file): Use the new function to better inform
the user when the user option `org-link-frame-setup-function' is
ill-defined.

Reported-by: Eric Fraga <e.fraga@ucl.ac.uk>
Link: https://list.orgmode.org/874j39vz29.fsf@ucl.ac.uk/
---
 lisp/ol-gnus.el |  2 +-
 lisp/ol.el      | 10 ++++++++++
 lisp/org.el     | 12 ++++++------
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lisp/ol-gnus.el b/lisp/ol-gnus.el
index b9ee8683f..2b20e80b2 100644
--- a/lisp/ol-gnus.el
+++ b/lisp/ol-gnus.el
@@ -227,7 +227,7 @@ (defun org-gnus-open (path _)
 (defun org-gnus-follow-link (&optional group article)
   "Follow a Gnus link to GROUP and ARTICLE."
   (require 'gnus)
-  (funcall (cdr (assq 'gnus org-link-frame-setup)))
+  (funcall (org-link-frame-setup-function))
   (when gnus-other-frame-object (select-frame gnus-other-frame-object))
   (let ((group (org-no-properties group))
 	(article (org-no-properties article)))
diff --git a/lisp/ol.el b/lisp/ol.el
index fa16b5920..757f2b1fd 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1539,6 +1539,16 @@ (defun org-link-add-angle-brackets (s)
   (unless (equal (substring s -1) ">") (setq s (concat s ">")))
   s)
 
+(defun org-link-frame-setup-function (link-type)
+  "Return the frame setup function for the link type LINK-TYPE.
+This signals an error if the value of the key LINK-TYPE in
+`org-link-frame-setup' is not a function."
+  (let ((fun (cdr (assq link-type org-link-frame-setup))))
+    (if (fboundp fun)
+        fun
+      (error "The frame setup configuration for `%s' link type is ill-defined"
+             link-type))))
+
 \f
 ;;; Built-in link types
 
diff --git a/lisp/org.el b/lisp/org.el
index 2e91dd508..6af67359d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8489,7 +8489,7 @@ (defun org-open-file (path &optional in-emacs line search)
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))
-      (funcall (cdr (assq 'file org-link-frame-setup)) file)
+      (funcall (org-link-frame-setup-function 'file) file)
       (widen)
       (cond (line (org-goto-line line)
 		  (when (derived-mode-p 'org-mode) (org-fold-reveal)))
@@ -8517,7 +8517,7 @@ (defun org-open-file (path &optional in-emacs line search)
       ;; `org-file-apps' with sexp instead of a function for `cmd'.
       (user-error "Please see Org News for version 9.0 about \
 `org-file-apps'--Error: Deprecated usage of %S" cmd))
-     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
+     (t (funcall (org-link-frame-setup-function 'file) file)))
     (funcall save-position-maybe)))
 
 ;;;###autoload
@@ -15311,20 +15311,20 @@ (defun org-modify-ts-extra (ts-string pos nincrements increment-step)
 	(setq hour (mod hour 24))
 	(setq pos-match-group 1
               new (format "-%02d:%02d" hour minute)))
-       
+
        ((org-pos-in-match-range pos 6) ;; POS on "dmwy" repeater char.
 	(setq pos-match-group 6
               new (car (rassoc (+ nincrements (cdr (assoc (match-string 6 ts-string) idx))) idx))))
-       
+
        ((org-pos-in-match-range pos 5) ;; POS on X in "Xd" repeater.
 	(setq pos-match-group 5
               ;; Never drop below X=1.
               new (format "%d" (max 1 (+ nincrements (string-to-number (match-string 5 ts-string)))))))
-       
+
        ((org-pos-in-match-range pos 9) ;; POS on "dmwy" repeater in warning interval.
 	(setq pos-match-group 9
               new (car (rassoc (+ nincrements (cdr (assoc (match-string 9 ts-string) idx))) idx))))
-       
+
        ((org-pos-in-match-range pos 8) ;; POS on X in "Xd" in warning interval.
 	(setq pos-match-group 8
               ;; Never drop below X=0.
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-26 12:53             ` Visuwesh
@ 2024-12-26 13:22               ` Ihor Radchenko
  2024-12-26 14:45                 ` Visuwesh
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-12-26 13:22 UTC (permalink / raw)
  To: Visuwesh; +Cc: Org Mode List

Visuwesh <visuweshm@gmail.com> writes:

>> Also, (cdr (assq 'gnus org-link-frame-setup)) = nil is not the only
>> possible incorrect customization. I'd rather check if the cdr is a
>> function and throw a descriptive error otherwise asking to fix
>> `org-link-frame-setup'.
>
> How about the attached?

You still do not check if the value is a function.
Consider totally wrong values like '(wrong). `fboundp' will then throw
an error.  You may consider `functionp' instead.

> +(defun org-link-frame-setup-function (link-type)
> +  "Return the frame setup function for the link type LINK-TYPE.
> +This signals an error if the value of the key LINK-TYPE in
> +`org-link-frame-setup' is not a function."
> +  (let ((fun (cdr (assq link-type org-link-frame-setup))))
> +    (if (fboundp fun)
> +        fun
> +      (error "The frame setup configuration for `%s' link type is ill-defined"
> +             link-type))))

In the error, we can also show the problematic value to aid the user.

> @@ -15311,20 +15311,20 @@ (defun org-modify-ts-extra (ts-string pos nincrements increment-step)
>  	(setq hour (mod hour 24))
>  	(setq pos-match-group 1
>                new (format "-%02d:%02d" hour minute)))
> -       
> +
> ...

Please remove irrelevant whitespace-only changes.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-26 13:22               ` Ihor Radchenko
@ 2024-12-26 14:45                 ` Visuwesh
  2024-12-27 17:10                   ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Visuwesh @ 2024-12-26 14:45 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1572 bytes --]

[வியாழன் டிசம்பர் 26, 2024] Ihor Radchenko wrote:

> Visuwesh <visuweshm@gmail.com> writes:
>
>>> Also, (cdr (assq 'gnus org-link-frame-setup)) = nil is not the only
>>> possible incorrect customization. I'd rather check if the cdr is a
>>> function and throw a descriptive error otherwise asking to fix
>>> `org-link-frame-setup'.
>>
>> How about the attached?
>
> You still do not check if the value is a function.
> Consider totally wrong values like '(wrong). `fboundp' will then throw
> an error.  You may consider `functionp' instead.

Ah, I wasn't aware that functionp also returned t if you gave a symbol.
Thanks for the hint.

>> +(defun org-link-frame-setup-function (link-type)
>> +  "Return the frame setup function for the link type LINK-TYPE.
>> +This signals an error if the value of the key LINK-TYPE in
>> +`org-link-frame-setup' is not a function."
>> +  (let ((fun (cdr (assq link-type org-link-frame-setup))))
>> +    (if (fboundp fun)
>> +        fun
>> +      (error "The frame setup configuration for `%s' link type is ill-defined"
>> +             link-type))))
>
> In the error, we can also show the problematic value to aid the user.

Now done.

>> @@ -15311,20 +15311,20 @@ (defun org-modify-ts-extra (ts-string pos nincrements increment-step)
>>  	(setq hour (mod hour 24))
>>  	(setq pos-match-group 1
>>                new (format "-%02d:%02d" hour minute)))
>> -       
>> +
>> ...
>
> Please remove irrelevant whitespace-only changes.

Done.  Please find attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Error-if-org-link-frame-setup-is-ill-defined.patch --]
[-- Type: text/x-diff, Size: 3036 bytes --]

From ee57860915308dc9bf30172cfd94f8985b536361 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 23 Dec 2024 11:59:16 +0530
Subject: [PATCH] Error if org-link-frame-setup is ill-defined

* lisp/ol.el (org-link-frame-setup-function): Define new helper
function get the frame-setup-function for the corresponding link-type.
* lisp/ol-gnus.el (org-gnus-follow-link):
* lisp/org.el (org-open-file): Use the new function to better inform
the user when the user option `org-link-frame-setup-function' is
ill-defined.

Reported-by: Eric Fraga <e.fraga@ucl.ac.uk>
Link: https://list.orgmode.org/874j39vz29.fsf@ucl.ac.uk/
---
 lisp/ol-gnus.el |  2 +-
 lisp/ol.el      | 10 ++++++++++
 lisp/org.el     |  4 ++--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/ol-gnus.el b/lisp/ol-gnus.el
index b9ee8683f..2b20e80b2 100644
--- a/lisp/ol-gnus.el
+++ b/lisp/ol-gnus.el
@@ -227,7 +227,7 @@ (defun org-gnus-open (path _)
 (defun org-gnus-follow-link (&optional group article)
   "Follow a Gnus link to GROUP and ARTICLE."
   (require 'gnus)
-  (funcall (cdr (assq 'gnus org-link-frame-setup)))
+  (funcall (org-link-frame-setup-function))
   (when gnus-other-frame-object (select-frame gnus-other-frame-object))
   (let ((group (org-no-properties group))
 	(article (org-no-properties article)))
diff --git a/lisp/ol.el b/lisp/ol.el
index fa16b5920..102b68bab 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1539,6 +1539,16 @@ (defun org-link-add-angle-brackets (s)
   (unless (equal (substring s -1) ">") (setq s (concat s ">")))
   s)
 
+(defun org-link-frame-setup-function (link-type)
+  "Return the frame setup function for the link type LINK-TYPE.
+This signals an error if the value of the key LINK-TYPE in
+`org-link-frame-setup' is not a function."
+  (let ((fun (cdr (assq link-type org-link-frame-setup))))
+    (if (functionp fun)
+        fun
+      (error "The frame setup configuration `%S' for `%s' link type is ill-defined"
+             fun link-type))))
+
 \f
 ;;; Built-in link types
 
diff --git a/lisp/org.el b/lisp/org.el
index 2e91dd508..2c35bed5f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8489,7 +8489,7 @@ (defun org-open-file (path &optional in-emacs line search)
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))
-      (funcall (cdr (assq 'file org-link-frame-setup)) file)
+      (funcall (org-link-frame-setup-function 'file) file)
       (widen)
       (cond (line (org-goto-line line)
 		  (when (derived-mode-p 'org-mode) (org-fold-reveal)))
@@ -8517,7 +8517,7 @@ (defun org-open-file (path &optional in-emacs line search)
       ;; `org-file-apps' with sexp instead of a function for `cmd'.
       (user-error "Please see Org News for version 9.0 about \
 `org-file-apps'--Error: Deprecated usage of %S" cmd))
-     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
+     (t (funcall (org-link-frame-setup-function 'file) file)))
     (funcall save-position-maybe)))
 
 ;;;###autoload
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Unexpected error using org-gnus-follow-link
  2024-12-26 14:45                 ` Visuwesh
@ 2024-12-27 17:10                   ` Ihor Radchenko
  0 siblings, 0 replies; 12+ messages in thread
From: Ihor Radchenko @ 2024-12-27 17:10 UTC (permalink / raw)
  To: Visuwesh; +Cc: Org Mode List

Visuwesh <visuweshm@gmail.com> writes:

> From ee57860915308dc9bf30172cfd94f8985b536361 Mon Sep 17 00:00:00 2001
> From: Visuwesh <visuweshm@gmail.com>
> Date: Mon, 23 Dec 2024 11:59:16 +0530
> Subject: [PATCH] Error if org-link-frame-setup is ill-defined

Thanks!
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=5099091118

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-12-27 17:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-12 12:57 Unexpected error using org-gnus-follow-link Fraga, Eric
2024-12-12 15:02 ` Visuwesh
2024-12-12 18:15   ` Fraga, Eric
2024-12-13  5:42     ` Visuwesh
2024-12-13 10:46       ` Fraga, Eric
2024-12-15 16:41       ` Max Nikulin
2024-12-22 12:45       ` Ihor Radchenko
     [not found]         ` <87pllic102.fsf@gmail.com>
     [not found]           ` <87jzbqluk9.fsf@localhost>
2024-12-26 12:50             ` Visuwesh
2024-12-26 12:53             ` Visuwesh
2024-12-26 13:22               ` Ihor Radchenko
2024-12-26 14:45                 ` Visuwesh
2024-12-27 17:10                   ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).