aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2020-07-05 12:55:27 +0100
committerJoão Távora2020-07-08 11:25:33 +0100
commitbba3bea247675df234353f0c2cd8af7da23bc6b8 (patch)
treee03738dc3e3e0f753eadb6c5013e8e143a6dc638
parent1203626f472b0d99d2746f5999711137c0c1fd0c (diff)
downloademacs-bba3bea247675df234353f0c2cd8af7da23bc6b8.tar.gz
emacs-bba3bea247675df234353f0c2cd8af7da23bc6b8.zip
Adjust Eldoc documentation after Eli's review
* etc/NEWS (Eldoc): Adjust paragraphs. * lisp/emacs-lisp/eldoc.el (eldoc-prefer-doc-buffer): Adjust docstring. (eldoc--enthusiasm-curbing-timer, eldoc-documentation-strategy) (eldoc-documentation-functions): Adjust docstring. (eldoc--handle-docs): Adjust comments. (eldoc--documentation-compose-1): New helper. (eldoc-documentation-compose) (eldoc-documentation-compose-eagerly): Use it. (eldoc-print-current-symbol-info): Adjust comments.
-rw-r--r--etc/NEWS20
-rw-r--r--lisp/emacs-lisp/eldoc.el201
2 files changed, 120 insertions, 101 deletions
diff --git a/etc/NEWS b/etc/NEWS
index f5b9e5ed152..125457c609b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -247,17 +247,25 @@ supplied error message.
247+++ 247+++
248** ElDoc 248** ElDoc
249 249
250*** New hook 'eldoc-documentation-functions' to be used for registering 250*** New hook 'eldoc-documentation-functions' to be used for
251doc string functions. This makes the results of all doc string 251registering doc string functions. These functions don't need to
252functions accessible to the user through the existing single function hook 252produce the doc string right away, they may arrange for it to be
253'eldoc-documentation-function'. 253produced asynchronously. The results of all doc string functions
254accessible to the user through the existing single function hook
255'eldoc-documentation-strategy.
254 256
255*** New user option 'eldoc-documentation-strategy' 257*** New user option 'eldoc-documentation-strategy'
256The built-in choices available for this user option let users compose 258The built-in choices available for this user option let users compose
257the results of 'eldoc-documentation-functions' in various ways. The 259the results of 'eldoc-documentation-functions' in various ways, even
258user option replaces 'eldoc-documentation-function', which is now 260if some of those functions are sychronous and some asynchchronous.
261The user option replaces 'eldoc-documentation-function', which is now
259obsolete. 262obsolete.
260 263
264*** The user option 'eldoc-echo-area-use-multiline-p' is now handled
265by the Eldoc library itself. Functions in
266'eldoc-documentation-functions' don't need to worry about consulting
267it when producing a doc string.
268
261** Eshell 269** Eshell
262 270
263--- 271---
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index ab8dd6a73b5..1f7a29f9621 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -114,8 +114,9 @@ single line of display in the echo area."
114(defcustom eldoc-prefer-doc-buffer nil 114(defcustom eldoc-prefer-doc-buffer nil
115 "Prefer Eldoc's documentation buffer if it is showing in some frame. 115 "Prefer Eldoc's documentation buffer if it is showing in some frame.
116If this variable's value is t and a piece of documentation needs 116If this variable's value is t and a piece of documentation needs
117to be truncated to fit in the echo area, do so only if Eldoc's 117to be truncated to fit in the echo area, do so if Eldoc's
118documentation buffer is not already showing." 118documentation buffer is not already showing, since the buffer
119always holds the full documentation."
119 :type 'boolean) 120 :type 'boolean)
120 121
121(defface eldoc-highlight-function-argument 122(defface eldoc-highlight-function-argument
@@ -365,9 +366,9 @@ A doc string is typically relevant if point is on a function-like
365name, inside its arg list, or on any object with some associated 366name, inside its arg list, or on any object with some associated
366information. 367information.
367 368
368Each hook function is called with at least one argument CALLBACK 369Each hook function is called with at least one argument CALLBACK,
369and decides whether to display a doc short string about the 370a function, and decides whether to display a doc short string
370context around point. 371about the context around point.
371 372
372- If that decision can be taken quickly, the hook function may 373- If that decision can be taken quickly, the hook function may
373 call CALLBACK immediately following the protocol described 374 call CALLBACK immediately following the protocol described
@@ -381,10 +382,10 @@ context around point.
381 value and arrange for CALLBACK to be called at a later time, 382 value and arrange for CALLBACK to be called at a later time,
382 using asynchronous processes or other asynchronous mechanisms. 383 using asynchronous processes or other asynchronous mechanisms.
383 384
384Regardless of the context in which CALLBACK is called, it expects 385To call the CALLBACK function, the hook function must pass it an
385to be passed an argument DOCSTRING followed by an optional list 386obligatory argument DOCSTRING, a string containing the
386of keyword-value pairs of the form (:KEY VALUE :KEY2 VALUE2...). 387documentation, followed by an optional list of keyword-value
387KEY can be: 388pairs of the form (:KEY VALUE :KEY2 VALUE2...). KEY can be:
388 389
389* `:thing', VALUE is be a short string or symbol designating what 390* `:thing', VALUE is be a short string or symbol designating what
390 is being reported on; 391 is being reported on;
@@ -410,25 +411,24 @@ return any documentation.")
410(defun eldoc--handle-docs (docs) 411(defun eldoc--handle-docs (docs)
411 "Display multiple DOCS in echo area. 412 "Display multiple DOCS in echo area.
412DOCS is a list of (STRING PLIST...). It is already sorted. 413DOCS is a list of (STRING PLIST...). It is already sorted.
413Honour most of `eldoc-echo-area-use-multiline-p'." 414Honor most of `eldoc-echo-area-use-multiline-p'."
414 (if (null docs) (eldoc--message nil) ; if there's nothing to report 415 ;; If there's nothing to report clear the echo area, but don't erase
415 ; clear the echo area, but 416 ;; the last *eldoc* buffer.
416 ; don't erase the last *eldoc* 417 (if (null docs) (eldoc--message nil)
417 ; buffer. 418 (let*
418 ;; If there's something to report on, first establish some 419 ;; Otherwise, establish some parameters.
419 ;; parameterso 420 ((width (1- (window-width (minibuffer-window))))
420 (let* ((width (1- (window-width (minibuffer-window)))) 421 (val (if (and (symbolp eldoc-echo-area-use-multiline-p)
421 (val (if (and (symbolp eldoc-echo-area-use-multiline-p) 422 eldoc-echo-area-use-multiline-p)
422 eldoc-echo-area-use-multiline-p) 423 max-mini-window-height
423 max-mini-window-height 424 eldoc-echo-area-use-multiline-p))
424 eldoc-echo-area-use-multiline-p)) 425 (available (cl-typecase val
425 (available (cl-typecase val 426 (float (truncate (* (frame-height) val)))
426 (float (truncate (* (frame-height) val))) 427 (integer val)
427 (integer val) 428 (t 1)))
428 (t 1))) 429 (things-reported-on)
429 (things-reported-on) 430 single-sym-name)
430 single-sym-name) 431 ;; Then, compose the contents of the `*eldoc*' buffer.
431 ;; Then, compose the contents of the `*eldoc*' buffer
432 (with-current-buffer (eldoc-doc-buffer) 432 (with-current-buffer (eldoc-doc-buffer)
433 (let ((inhibit-read-only t)) 433 (let ((inhibit-read-only t))
434 (erase-buffer) (setq buffer-read-only t) 434 (erase-buffer) (setq buffer-read-only t)
@@ -446,55 +446,55 @@ Honour most of `eldoc-echo-area-use-multiline-p'."
446 this-doc)) 446 this-doc))
447 do (insert this-doc) 447 do (insert this-doc)
448 when rest do (insert "\n"))) 448 when rest do (insert "\n")))
449 ;; rename the buffer 449 ;; Rename the buffer.
450 (when things-reported-on 450 (when things-reported-on
451 (rename-buffer (format "*eldoc for %s*" 451 (rename-buffer (format "*eldoc for %s*"
452 (mapconcat (lambda (s) (format "%s" s)) 452 (mapconcat (lambda (s) (format "%s" s))
453 things-reported-on 453 things-reported-on
454 ", "))))) 454 ", ")))))
455 ;; Finally, output to the echo area. We currently do handling 455 ;; Finally, output to the echo area. We handle the
456 ;; the `truncate-sym-name-if-fit' special case first, then by 456 ;; `truncate-sym-name-if-fit' special case first, by selecting a
457 ;; selecting a top-section of the `*eldoc' buffer. I'm pretty 457 ;; top-section of the `*eldoc' buffer. I'm pretty sure nicer
458 ;; sure nicer strategies can be used here, probably by splitting 458 ;; strategies can be used here, probably by splitting this
459 ;; this pfunction into some `eldoc-display-functions' special 459 ;; function into some `eldoc-display-functions' special hook.
460 ;; hook.
461 (if (and (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p) 460 (if (and (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p)
462 (null (cdr docs)) 461 (null (cdr docs))
463 (setq single-sym-name 462 (setq single-sym-name
464 (format "%s" (plist-get (cdar docs) :thing))) 463 (format "%s" (plist-get (cdar docs) :thing)))
465 (> (+ (length (caar docs)) (length single-sym-name) 2) width)) 464 (> (+ (length (caar docs)) (length single-sym-name) 2) width))
466 (eldoc--message (caar docs)) 465 (eldoc--message (caar docs))
467 (with-current-buffer (eldoc-doc-buffer) 466 (with-current-buffer (eldoc-doc-buffer)
468 (goto-char (point-min)) 467 (goto-char (point-min))
469 (cond 468 (cond
470 ;; We truncate a long message 469 ;; Potentially truncate a long message into less lines,
471 ((> available 1) 470 ;; then display it in the echo area;
472 (cl-loop 471 ((> available 1)
473 initially (goto-char (line-end-position (1+ available))) 472 (cl-loop
474 for truncated = nil then t 473 initially (goto-char (line-end-position (1+ available)))
475 for needed 474 for truncated = nil then t
476 = (let ((truncate-lines message-truncate-lines)) 475 for needed
477 (count-screen-lines (point-min) (point) t (minibuffer-window))) 476 = (let ((truncate-lines message-truncate-lines))
478 while (> needed (if truncated (1- available) available)) 477 (count-screen-lines (point-min) (point) t (minibuffer-window)))
479 do (goto-char (line-end-position (if truncated 0 -1))) 478 while (> needed (if truncated (1- available) available))
480 (while (bolp) (goto-char (line-end-position 0))) 479 do (goto-char (line-end-position (if truncated 0 -1)))
481 finally 480 (while (bolp) (goto-char (line-end-position 0)))
482 (unless (and truncated 481 finally
483 eldoc-prefer-doc-buffer 482 (unless (and truncated
484 (get-buffer-window eldoc--doc-buffer)) 483 eldoc-prefer-doc-buffer
485 (eldoc--message 484 (get-buffer-window eldoc--doc-buffer))
486 (concat (buffer-substring (point-min) (point)) 485 (eldoc--message
487 (and truncated 486 (concat (buffer-substring (point-min) (point))
488 (format 487 (and truncated
489 "\n(Documentation truncated. Use `%s' to see rest)" 488 (format
490 (substitute-command-keys "\\[eldoc-doc-buffer]")))))))) 489 "\n(Documentation truncated. Use `%s' to see rest)"
491 ((= available 1) 490 (substitute-command-keys "\\[eldoc-doc-buffer]"))))))))
492 ;; truncate brutally ; FIXME: use `eldoc-prefer-doc-buffer' here, too? 491 ((= available 1)
493 (eldoc--message 492 ;; Truncate "brutally." ; FIXME: use `eldoc-prefer-doc-buffer' too?
494 (truncate-string-to-width 493 (eldoc--message
495 (buffer-substring (point-min) (line-end-position 1)) width))))))))) 494 (truncate-string-to-width
496 495 (buffer-substring (point-min) (line-end-position 1)) width)))))))))
497;; this variable should be unbound, but that confuses 496
497;; This variable should be unbound, but that confuses
498;; `describe-symbol' for some reason. 498;; `describe-symbol' for some reason.
499(defvar eldoc--make-callback nil "Helper for function `eldoc--make-callback'.") 499(defvar eldoc--make-callback nil "Helper for function `eldoc--make-callback'.")
500 500
@@ -506,11 +506,12 @@ Honour most of `eldoc-echo-area-use-multiline-p'."
506 "Show first doc string for item at point. 506 "Show first doc string for item at point.
507Default value for `eldoc-documentation-strategy'." 507Default value for `eldoc-documentation-strategy'."
508 (run-hook-with-args-until-success 'eldoc-documentation-functions 508 (run-hook-with-args-until-success 'eldoc-documentation-functions
509 (eldoc--make-callback :patient))) 509 (eldoc--make-callback :patient)))
510 510
511(defun eldoc-documentation-compose (&optional eagerlyp) 511(defun eldoc--documentation-compose-1 (eagerlyp)
512 "Show multiple doc strings at once after waiting for all. 512 "Helper function for composing multiple doc strings.
513Meant as a value for `eldoc-documentation-strategy'." 513If EAGERLYP is non-nil show documentation as soon as possible,
514else wait for all doc strings."
514 (run-hook-wrapped 'eldoc-documentation-functions 515 (run-hook-wrapped 'eldoc-documentation-functions
515 (lambda (f) 516 (lambda (f)
516 (let* ((callback (eldoc--make-callback 517 (let* ((callback (eldoc--make-callback
@@ -520,10 +521,15 @@ Meant as a value for `eldoc-documentation-strategy'."
520 nil))) 521 nil)))
521 t) 522 t)
522 523
524(defun eldoc-documentation-compose ()
525 "Show multiple doc strings at once after waiting for all.
526Meant as a value for `eldoc-documentation-strategy'."
527 (eldoc--documentation-compose-1 nil))
528
523(defun eldoc-documentation-compose-eagerly () 529(defun eldoc-documentation-compose-eagerly ()
524 "Show multiple doc strings at once as soon as possible. 530 "Show multiple doc strings at once as soon as possible.
525Meant as a value for `eldoc-documentation-strategy'." 531Meant as a value for `eldoc-documentation-strategy'."
526 (eldoc-documentation-compose 'eagerlyp)) 532 (eldoc--documentation-compose-1 t))
527 533
528(defun eldoc-documentation-enthusiast () 534(defun eldoc-documentation-enthusiast ()
529 "Show most important doc string produced so far. 535 "Show most important doc string produced so far.
@@ -546,25 +552,24 @@ specifies the sources of documentation, is queried and how its
546results are organized before being displayed to the user. The 552results are organized before being displayed to the user. The
547following values are allowed: 553following values are allowed:
548 554
549- `eldoc-documentation-default': queries the special hook for the 555- `eldoc-documentation-default': calls functions in the special
550 first function that produces a doc string value and displays 556 hook in order until one is found that produces a doc string
551 only that one; 557 value. Display only that value;
552 558
553- `eldoc-documentation-compose': queries the special hook for all 559- `eldoc-documentation-compose': calls all functions in the
554 functions that produce doc strings and displays all of them 560 special hook and displays all of the resulting doc strings
555 together as soon as all are ready, preserving the relative 561 together. Wait for all strings to be ready, and preserve their
556 order of doc strings as specified by the order of functions in 562 relative as specified by the order of functions in the hook;
557 the hook;
558 563
559- `eldoc-documentation-compose-eagerly': queries the special hook 564- `eldoc-documentation-compose-eagerly': calls all functions in
560 for all functions that produce doc strings and displays as many 565 the special hook and display as many of the resulting doc
561 as possible, as soon as possible, preserving the relative order 566 strings as possible, as soon as possibl. Preserving the
562 of doc strings; 567 relative order of doc strings;
563 568
564- `eldoc-documentation-enthusiast': queries the special hook for 569- `eldoc-documentation-enthusiast': calls all functions in the
565 all functions the produce doc strings but displays only the 570 special hook and displays only the most important resulting
566 most important one at any given time. A function appearing 571 docstring one at any given time. A function appearing first in
567 first in the special hook is considered more important. 572 the special hook is considered more important.
568 573
569This variable can also be set to a function of no args that 574This variable can also be set to a function of no args that
570allows for some or all of the special hook 575allows for some or all of the special hook
@@ -596,7 +601,11 @@ documentation themselves."
596 (local-variable-p 'eldoc-documentation-strategy)))) 601 (local-variable-p 'eldoc-documentation-strategy))))
597 602
598(defvar eldoc--enthusiasm-curbing-timer nil 603(defvar eldoc--enthusiasm-curbing-timer nil
599 "Timer used by `eldoc-documentation-enthusiast' to avoid blinking.") 604 "Timer used by the `eldoc-documentation-enthusiast' strategy.
605When a doc string is encountered, it must endure a certain amount
606of time unchallenged until it is displayed to the user. This
607prevents blinking if a lower priority docstring comes in shortly
608before a higher priority one.")
600 609
601(defalias 'eldoc #'eldoc-print-current-symbol-info) 610(defalias 'eldoc #'eldoc-print-current-symbol-info)
602 611
@@ -609,7 +618,8 @@ documentation themselves."
609 (eldoc--message nil)) 618 (eldoc--message nil))
610 (let ((non-essential t)) 619 (let ((non-essential t))
611 ;; Only keep looking for the info as long as the user hasn't 620 ;; Only keep looking for the info as long as the user hasn't
612 ;; requested our attention. This also locally disables inhibit-quit. 621 ;; requested our attention. This also locally disables
622 ;; inhibit-quit.
613 (while-no-input 623 (while-no-input
614 (let* ((howmany 0) (want 0) (docs-registered '())) 624 (let* ((howmany 0) (want 0) (docs-registered '()))
615 (cl-labels 625 (cl-labels
@@ -652,12 +662,13 @@ documentation themselves."
652 t)))))) 662 t))))))
653 (let* ((eldoc--make-callback #'make-callback) 663 (let* ((eldoc--make-callback #'make-callback)
654 (res (funcall eldoc-documentation-strategy))) 664 (res (funcall eldoc-documentation-strategy)))
655 (cond (;; old protocol: got string, output immediately 665 ;; Observe the old and the new protocol:
656 (stringp res) (register-doc 0 res nil) (display-doc)) 666 (cond (;; Old protocol: got string, output immediately;
657 (;; old protocol: got nil, clear the echo area 667 (stringp res) (register-doc 0 res nil) (display-doc))
658 (null res) (eldoc--message nil)) 668 (;; Old protocol: got nil, clear the echo area;
659 (;; got something else, trust callback will be called 669 (null res) (eldoc--message nil))
660 t))))))))) 670 (;; New protocol: trust callback will be called;
671 t)))))))))
661 672
662;; When point is in a sexp, the function args are not reprinted in the echo 673;; When point is in a sexp, the function args are not reprinted in the echo
663;; area after every possible interactive command because some of them print 674;; area after every possible interactive command because some of them print