emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eldoc recursion error


From: James N . V . Cash
Subject: Re: eldoc recursion error
Date: Sun, 20 Sep 2020 21:07:15 -0400

Kyle Meyer <kyle@kyleam.com> writes:

> All right, so we can't get by without using eldoc--make-callback here?
> Relying on a symbol marked with "--" makes me uneasy, and I'd like to
> avoid it if possible.

Yeah, good point. I was doing that so I could honour the setting of
eldoc-documentation-strategy. I don't know if that's going to be a
concern in practice though.

> Does your cider test case above break if we use
> eldoc-print-current-symbol-info without relaying the callback?  That is,
> this squashed into your patch:

My concern with using the eldoc-print-current-symbol-info is that it's
now somewhat subverting the actual eldoc documentation function -- i.e.
the invocation of org-eldoc-documentation-function now "fails" and
instead it prints out the actual documentation as a side-effect. Indeed,
applying that patch makes the eldoc for python code blocks not work
correctly.

The below patch which essentially just inlines the definition of
eldoc-documentation-default, so it's not messing around with any private
variables in eldoc, although it now won't honour the documentation
strategy. It remains to be seen if that will be an issue in practice,
but if necessary we could just check the value of
eldoc-documentation-strategy and behave appropriately.

>From 7d59ecadbea429626bae90464d76f01b60c8d67f Mon Sep 17 00:00:00 2001
From: "James N. V. Cash" <james.nvc@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 | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/contrib/lisp/org-eldoc.el b/contrib/lisp/org-eldoc.el
index 3b0999340..946a57273 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,18 @@
         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))
+                                    (run-hook-with-args-until-success
+                                     'eldoc-documentation-functions
+                                     callback))))
+                            (and eldoc-documentation-function
+                                 (symbol-value 
'eldoc-documentation-function))))
+           (puthash lang doc-func org-eldoc-local-functions-cache))
           doc-func)
       cached-func)))
 
@@ -127,7 +134,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 +167,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

[Prev in Thread] Current Thread [Next in Thread]