all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: "T.V Raman" <raman@google.com>
Cc: emacs-devel@gnu.org
Subject: Re: Need help with eldoc:
Date: Fri, 25 Mar 2022 10:03:10 +0000	[thread overview]
Message-ID: <87a6dee4dd.fsf@gmail.com> (raw)
In-Reply-To: <25149.10028.97873.940861@google.com> (T. V. Raman's message of "Thu, 24 Mar 2022 19:21:32 -0700")

"T.V Raman" <raman@google.com> writes:

> If I could be ensured of the eldoc always being in a buffer I could
> eliminate most of the above, but I am also afraid that  that will
> recreate the earlier async problem which is why I didn't go there.

Raman,

You are completely on the right track, and I'm very glad it was
reasonably straightforward.  And yes, "ensuring eldoc always being in a
buffer" is useful and possible -- if very slightly hacky, but read on.

Anyway, if you read the eldoc code and search for
eldoc--format-doc-buffer, you'll notice that the two members of
eldoc-display-functions by default already share "the eldoc doc buffer".
This avoids them repeating common needed work between themselves.  In
Emacsspeak, you have the same problem.

So you have two options:

1. Make use of the internal function eldoc--format-doc-buffer.  This has
   "ensure" semantics and returns the desired buffer.  Then your
   function will become:
  
   (defun emacspeak-speak-eldoc (docs interactive)
     "Speak eldoc."
     (emacspeak-auditory-icon 'help)
     (when interactive
       (with-current-buffer (eldoc--format-doc-buffer docs)
         (dtk-speak (buffer-string)))))

2. Make sure that the function eldoc-display-in-buffer is always present
   in eldoc-display-functions.  It will undertake to call
   eldoc--format-doc-buffer and place that work in the buffer that you
   can access with eldoc--doc-buffer.  Your function becomes:

   (defun emacspeak-speak-eldoc (docs interactive)
     "Speak eldoc."
     (emacspeak-auditory-icon 'help)
     (when interactive
       (with-current-buffer eldoc--doc-buffer
         (dtk-speak (buffer-string)))))

The reason I said before these solutions are slightly hacky is because
of the usage of "internal --" symbols.  But I guess it's reasonable to
make one of these symbols "external".  Or better yet, reuse the existing
external function eldoc-doc-buffer and re-purpose it for non-interactive
use.  This is done in a patch to eldoc.el added in PS, which I think is
reasonable.

Then your function would become more idiomatic:

(defun emacspeak-speak-eldoc (docs interactive)
  "Speak eldoc."
  (emacspeak-auditory-icon 'help)
  (when interactive
    (with-current-buffer (eldoc-doc-buffer)
      (dtk-speak (buffer-string)))))

Let me know what you think,
João


diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 74ffeb166d..2d0656fb41 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -464,19 +464,21 @@ eldoc--doc-buffer
 
 (defvar eldoc--doc-buffer-docs nil "Documentation items in `eldoc--doc-buffer'.")
 
-(defun eldoc-doc-buffer ()
+(defun eldoc-doc-buffer (&optional interactive)
   "Display ElDoc documentation buffer.
 
 This holds the results of the last documentation request."
-  (interactive)
+  (interactive (list t))
   (unless (buffer-live-p eldoc--doc-buffer)
     (user-error (format
                  "ElDoc buffer doesn't exist, maybe `%s' to produce one."
                  (substitute-command-keys "\\[eldoc]"))))
   (with-current-buffer eldoc--doc-buffer
-    (rename-buffer (replace-regexp-in-string "^ *" ""
-                                             (buffer-name)))
-    (display-buffer (current-buffer))))
+    (cond (interactive
+           (rename-buffer (replace-regexp-in-string "^ *" ""
+                                                    (buffer-name)))
+           (display-buffer (current-buffer)))
+          (t (current-buffer)))))
 
 (defun eldoc--format-doc-buffer (docs)
   "Ensure DOCS are displayed in an *eldoc* buffer."










  reply	other threads:[~2022-03-25 10:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 14:21 Need help with eldoc: T.V Raman
2022-03-24 23:28 ` João Távora
2022-03-24 23:39   ` T.V Raman
2022-03-25  0:16     ` João Távora
2022-03-25  2:21       ` T.V Raman
2022-03-25 10:03         ` João Távora [this message]
2022-03-25 14:03           ` T.V Raman
2022-03-25 22:52             ` João Távora
2022-03-25 14:27       ` T.V Raman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6dee4dd.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=raman@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.