Hi Nicolas

On Fri, Feb 5, 2016 at 9:33 AM, Michael Brand
<[email protected]> wrote:

> Due to lexical binding in org.el there was a change in
> `org-file-apps', see Org News for version 9.0 and e. g. this thread:
> http://thread.gmane.org/gmane.emacs.orgmode/104272
> I think the most convenient would be if `org-open-file' tries to find
> out that `cmd' in this case is a function with only one argument and
> call it with just `file'.

Only after a closer look I saw that the single parameter of
`org-pdfview-open' is not `file' but `link'. It is probably better for
`org-open-file' to not guess in case of `cmd' with a single parameter
whether it is meant to be `file' or `link'. That leads me to suggest
the attached patch to be reviewed that checks the function signature.

Michael
From 9788cb03d2714cde555fbe2abb55ddd383a885c1 Mon Sep 17 00:00:00 2001
From: Michael Brand <[email protected]>
Date: Fri, 5 Feb 2016 14:44:26 +0100
Subject: [PATCH] `org-file-apps' add migration hint for function signature

* lisp/org.el (org-open-file): Add an error when the function
signature does not match.
---
 lisp/org.el | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 5a6c74e..9ebabf8 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11323,6 +11323,18 @@ If the file does not exist, an error is thrown."
 		  (when (derived-mode-p 'org-mode) (org-reveal)))
 	    (search (org-link-search search))))
      ((functionp cmd)
+      ;; FIXME: Remove this check when most default installations of
+      ;; Emacs have at least Org 9.0.
+      (let ((arglist (help-function-arglist cmd)))
+	(when (or (memq '&optional arglist)
+		  (memq '&rest arglist)
+		  (/= 2 (length arglist)))
+	  (user-error
+	   (format
+	    "%s%s%S"
+	    "Please see Org News for version 9.0 about `org-file-apps', "
+	    "this function signature is wrong: "
+	    cmd))))
       (save-match-data
 	(set-match-data link-match-data)
 	(funcall cmd file link)))
@@ -11333,7 +11345,10 @@ If the file does not exist, an error is thrown."
       ;; `org-link-frame-setup' for an old usage of `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'"))
+       (format "%s%s%S"
+	       "Please see Org News for version 9.0 about `org-file-apps', "
+	       "this usage is wrong: "
+	       cmd)))
      (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
     (and (derived-mode-p 'org-mode)
 	 (eq old-mode 'org-mode)
-- 
2.1.3.dirty

Reply via email to