James N. V. Cash <james.c...@occasionallycogent.com> writes:

> I was just thinking more about this, and I'm concerned I might need to
> change things around a little bit more. The closure that
> org-eldoc-get-mode-local-documentation-function now returns under Emacs
> 28 doesn't take any arguments and instead lets the
> eldoc-documentation-strategy function create its own new callback.
>
> I think the current approach will appear to work when the documentation
> function returns a value directly, but if it uses the callback, then I
> think that it won't, since it invokes a new, separate callback.
>
> I will take another crack at addressing this and send another patch shortly.

Indeed, testing with an eldoc backend (a personally hacked-up version of
clojure's cider) that actually uses the callback, it wasn't working with
the previous approach. I've attached a patch that addresses the
previously-mentioned issues as well as this.

>From 028675e460d12711ba4b91bf576b35e307a0e640 Mon Sep 17 00:00:00 2001
From: "James N. V. Cash" <james....@gmail.com>
Date: Thu, 17 Sep 2020 10:51:13 -0400
Subject: [PATCH] Address org-eldoc-recursion issue

* org-eldoc.el (org-eldoc-get-mode-local-documentation-function,
org-eldoc-documentation-function): Support Emacs 28-style eldoc, where
instead of a single function, the eldoc-documentation-functions hook
has a list of functions, which may optionally take a callback.
---
 contrib/lisp/org-eldoc.el | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/contrib/lisp/org-eldoc.el b/contrib/lisp/org-eldoc.el
index 3b0999340..b86ad1f39 100644
--- a/contrib/lisp/org-eldoc.el
+++ b/contrib/lisp/org-eldoc.el
@@ -1,4 +1,4 @@
-;;; org-eldoc.el --- display org header and src block info using eldoc
+;;; org-eldoc.el --- display org header and src block info using eldoc -*- lexical-binding: t; -*-
 
 ;; Copyright (c) 2014-2020 Free Software Foundation, Inc.
 
@@ -114,11 +114,17 @@
         doc-func)
     (if (eq 'empty cached-func)
         (when (fboundp mode-func)
-          (with-temp-buffer
-            (funcall mode-func)
-            (setq doc-func (and eldoc-documentation-function
-                                (symbol-value 'eldoc-documentation-function)))
-            (puthash lang doc-func org-eldoc-local-functions-cache))
+	  (with-temp-buffer
+	    (funcall mode-func)
+	    (setq doc-func (if (boundp 'eldoc-documentation-functions)
+			       (let ((doc-funs eldoc-documentation-functions))
+				 (lambda (callback)
+				   (let ((eldoc-documentation-functions doc-funs)
+					 (eldoc--make-callback (lambda (_ignored) callback)))
+				     (funcall eldoc-documentation-strategy))))
+			     (and eldoc-documentation-function
+				  (symbol-value 'eldoc-documentation-function))))
+	    (puthash lang doc-func org-eldoc-local-functions-cache))
           doc-func)
       cached-func)))
 
@@ -127,7 +133,7 @@
 (declare-function php-eldoc-function "php-eldoc" ())
 (declare-function go-eldoc--documentation-function "go-eldoc" ())
 
-(defun org-eldoc-documentation-function (&rest _ignored)
+(defun org-eldoc-documentation-function (&rest args)
   "Return breadcrumbs when on a headline, args for src block header-line,
   calls other documentation functions depending on lang when inside src body."
   (or
@@ -160,8 +166,12 @@
              (string= lang "go")
              (string= lang "golang")) (when (require 'go-eldoc nil t)
                                         (go-eldoc--documentation-function)))
-           (t (let ((doc-fun (org-eldoc-get-mode-local-documentation-function lang)))
-                (when (functionp doc-fun) (funcall doc-fun))))))))
+           (t (let ((doc-fun (org-eldoc-get-mode-local-documentation-function lang))
+		    (callback (car args)))
+                (when (functionp doc-fun)
+		  (if (functionp callback)
+		      (funcall doc-fun callback)
+		    (funcall doc-fun)))))))))
 
 ;;;###autoload
 (defun org-eldoc-load ()
-- 
2.25.1

Reply via email to