aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2020-07-08 11:19:19 +0100
committerJoão Távora2020-07-08 11:23:29 +0100
commitb019a38b4f3d190a9b74af947bc1d678c127d177 (patch)
tree8d95ce8d64dd3d14f93483d3df35ef95fc8eb158
parent2866bbeb7d62ec6df05973e424bfaf198cfa44ca (diff)
downloademacs-scratch/eldoc-async.tar.gz
emacs-scratch/eldoc-async.zip
Improve Eldoc docstringsscratch/eldoc-async
* lisp/emacs-lisp/eldoc.el (eldoc-documentation-strategy): Improve docstring. (eldoc--make-callback): Improve docstring. (eldoc--invoke-strategy): New helper function. (eldoc-print-current-symbol-info): Call eldoc--invoke-strategy. (eldoc-documentation-functions): Improve docstring.
-rw-r--r--lisp/emacs-lisp/eldoc.el118
1 files changed, 87 insertions, 31 deletions
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 27daa7580e8..9efd770dca6 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -387,10 +387,12 @@ obligatory argument DOCSTRING, a string containing the
387documentation, followed by an optional list of keyword-value 387documentation, followed by an optional list of keyword-value
388pairs of the form (:KEY VALUE :KEY2 VALUE2...). KEY can be: 388pairs of the form (:KEY VALUE :KEY2 VALUE2...). KEY can be:
389 389
390* `:thing', VALUE is be a short string or symbol designating what 390* `:thing', VALUE is a short string or symbol designating what is
391 is being reported on; 391 being reported on. The documentation display engine can elect
392 to remove this information depending on space contraints;
392 393
393* `:face', VALUE is a symbol designating a face; 394* `:face', VALUE is a symbol designating a face to use when
395 displaying `:thing''s value.
394 396
395Major modes should modify this hook locally, for example: 397Major modes should modify this hook locally, for example:
396 (add-hook \\='eldoc-documentation-functions #\\='foo-mode-eldoc nil t) 398 (add-hook \\='eldoc-documentation-functions #\\='foo-mode-eldoc nil t)
@@ -494,14 +496,6 @@ Honor most of `eldoc-echo-area-use-multiline-p'."
494 (truncate-string-to-width 496 (truncate-string-to-width
495 (buffer-substring (point-min) (line-end-position 1)) width))))))))) 497 (buffer-substring (point-min) (line-end-position 1)) width)))))))))
496 498
497;; This variable should be unbound, but that confuses
498;; `describe-symbol' for some reason.
499(defvar eldoc--make-callback nil "Helper for function `eldoc--make-callback'.")
500
501(defun eldoc--make-callback (method)
502 "Make callback suitable for `eldoc-documentation-functions'."
503 (funcall eldoc--make-callback method))
504
505(defun eldoc-documentation-default () 499(defun eldoc-documentation-default ()
506 "Show first doc string for item at point. 500 "Show first doc string for item at point.
507Default value for `eldoc-documentation-strategy'." 501Default value for `eldoc-documentation-strategy'."
@@ -572,12 +566,16 @@ following values are allowed:
572 the special hook is considered more important. 566 the special hook is considered more important.
573 567
574This variable can also be set to a function of no args that 568This variable can also be set to a function of no args that
575allows for some or all of the special hook 569returns something other than a string or nil and allows for some
576`eldoc-documentation-functions' to be run. It should return nil, 570or all of the special hook `eldoc-documentation-functions' to be
577if no documentation is to be displayed at all, a string value 571run. In that case, the strategy function should follow that
578with the documentation to display, or any other non-nil value in 572other variable's protocol closely and endeavor to display the
579case the special hook functions undertake to display the 573resulting doc strings itself.
580documentation themselves." 574
575For backward compatibility to the \"old\" protocol, this variable
576can also be set to a function that returns nil or a doc string,
577depending whether or not there is documentation to display at
578all."
581 :link '(info-link "(emacs) Lisp Doc") 579 :link '(info-link "(emacs) Lisp Doc")
582 :type '(radio (function-item eldoc-documentation-default) 580 :type '(radio (function-item eldoc-documentation-default)
583 (function-item eldoc-documentation-compose) 581 (function-item eldoc-documentation-compose)
@@ -609,19 +607,63 @@ before a higher priority one.")
609 607
610(defalias 'eldoc #'eldoc-print-current-symbol-info) 608(defalias 'eldoc #'eldoc-print-current-symbol-info)
611 609
612(defun eldoc-print-current-symbol-info () 610;; This variable should be unbound, but that confuses
613 "Document thing at point." 611;; `describe-symbol' for some reason.
614 (interactive) 612(defvar eldoc--make-callback nil "Helper for function `eldoc--make-callback'.")
615 (if (not (eldoc-display-message-p)) 613
616 ;; Erase the last message if we won't display a new one. 614;; JT@2020-07-08: the below docstring for the internal function
617 (when eldoc-last-message 615;; `eldoc--invoke-strategy' could be moved to
618 (eldoc--message nil)) 616;; `eldoc-documentation-strategy' or thereabouts if/when we decide to
619 (let ((non-essential t)) 617;; extend or publish the `make-callback' protocol.
620 ;; Only keep looking for the info as long as the user hasn't 618(defun eldoc--make-callback (method)
621 ;; requested our attention. This also locally disables 619 "Make callback suitable for `eldoc-documentation-functions'.
622 ;; inhibit-quit. 620The return value is a function FN whose lambda list is (STRING
623 (while-no-input 621&rest PLIST) and can be called by those functions. Its
624 (let* ((howmany 0) (want 0) (docs-registered '())) 622responsibility is always to register the docstring STRING along
623with options specified in PLIST as the documentation to display
624for each particular situation.
625
626METHOD specifies how the callback behaves relative to other
627competing elements in `eldoc-documentation-functions'. It can
628have the following values:
629
630- `:enthusiast' says to display STRING as soon as possible if
631 there's no higher priority doc string;
632
633- `:patient' says to display STRING along with all other
634 competing strings but only when all of all
635 `eldoc-documentation-functions' have been collected;
636
637- `:eager' says to display STRING along with all other competing
638 strings so far, as soon as possible."
639 (funcall eldoc--make-callback method))
640
641(defun eldoc--invoke-strategy ()
642 "Invoke `eldoc-documentation-strategy' function.
643
644That function's job is to run the `eldoc-documentation-functions'
645special hook, using the `run-hook' family of functions. The way
646we invoke it here happens in a way strategy function can itself
647call `eldoc--make-callback' to produce values to give to the
648elements of the special hook `eldoc-documentation-functions'.
649
650For each element of `eldoc-documentation-functions' invoked a
651corresponding call to `eldoc--make-callback' must be made. See
652docstring of `eldoc--make-callback' for the types of callback
653that can be produced.
654
655If the strategy function does not use `eldoc--make-callback', it
656must find some alternate way to produce callbacks to feed to
657`eldoc-documentation-function', and those callbacks should
658endeavour to display the docstrings given to them."
659 (let* (;; how many docstrings callbaks have been
660 (howmany 0)
661 ;; how many calls to callbacks we're waiting on. Used by
662 ;; `:patient'.
663 (want 0)
664 ;; how many doc strings and corresponding options have been
665 ;; registered it.
666 (docs-registered '()))
625 (cl-labels 667 (cl-labels
626 ((register-doc (pos string plist) 668 ((register-doc (pos string plist)
627 (when (and string (> (length string) 0)) 669 (when (and string (> (length string) 0))
@@ -668,7 +710,21 @@ before a higher priority one.")
668 (;; Old protocol: got nil, clear the echo area; 710 (;; Old protocol: got nil, clear the echo area;
669 (null res) (eldoc--message nil)) 711 (null res) (eldoc--message nil))
670 (;; New protocol: trust callback will be called; 712 (;; New protocol: trust callback will be called;
671 t))))))))) 713 t))))))
714
715(defun eldoc-print-current-symbol-info ()
716 "Document thing at point."
717 (interactive)
718 (if (not (eldoc-display-message-p))
719 ;; Erase the last message if we won't display a new one.
720 (when eldoc-last-message
721 (eldoc--message nil))
722 (let ((non-essential t))
723 ;; Only keep looking for the info as long as the user hasn't
724 ;; requested our attention. This also locally disables
725 ;; inhibit-quit.
726 (while-no-input
727 (eldoc--invoke-strategy)))))
672 728
673;; When point is in a sexp, the function args are not reprinted in the echo 729;; When point is in a sexp, the function args are not reprinted in the echo
674;; area after every possible interactive command because some of them print 730;; area after every possible interactive command because some of them print