Skip to content

Commit

Permalink
Show help-echo as part of racket-xp-eldoc-{point sex-app}
Browse files Browse the repository at this point in the history
Previously it was a distinct hook that showed help-echo for point
only.
  • Loading branch information
greghendershott committed Sep 16, 2024
1 parent c0a39bd commit 85440fd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 41 deletions.
6 changes: 3 additions & 3 deletions doc/racket-mode.org
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ You can customize where the REPL buffer is displayed by adding an item to the Em

Various modes add local hooks to ~eldoc-documentation-functions~.

- ~racket-xp-mode~ adds hooks to document the identifier at point, show the help-echo at point, and to document identifier in an apparent s-expression application head position. The identifiers are documented from check-syntax annotations. The customization variable ~racket-xp-eldoc-full-docs~ to choose full documentation or just "bluebox" signatures.
- ~racket-xp-mode~ adds hooks to document the identifiers at point and at an apparent s-expression application head position. The identifiers are documented from check-syntax annotations. The customization variable ~racket-xp-eldoc-full-docs~ to choose full documentation or just "bluebox" signatures.

- ~racket-repl-mode~ adds hooks to describe the namespace identifer at point and in an apparent s-expression application head position. The description is a signature from surface syntax, or a Typed Racket type, or a bluebox for the namespace identifier.
- ~racket-repl-mode~ adds hooks to describe the namespace identifers at point and at an apparent s-expression application head position. The description is a signature from surface syntax, or a Typed Racket type, or a "bluebox" for the namespace identifier.

Note: Racket Mode does not support the "old" eldoc API that uses ~eldoc-documentation-function~, singular.

Also, ~eldoc-documentation-strategy~ is set to ~racket-eldoc-compose-unique~, which is like ~eldoc-documentation-default~ but filters duplicate values -- useful when point is at an application head position.

Some people use the third-party package ~eldoc-box~ to show information in a child frame (like a "tooltip") instead of the echo area. This is particularly useful when showing full documentation.
Some people use the third-party package ~eldoc-box~ to show information in a child frame instead of the echo area.

** Start faster

Expand Down
10 changes: 6 additions & 4 deletions doc/racket-mode.texi
Original file line number Diff line number Diff line change
Expand Up @@ -826,16 +826,18 @@ Various modes add local hooks to @code{eldoc-documentation-functions}.

@itemize
@item
@code{racket-eldoc-app} looks for function/macro application and returns information such as a signature or type. Added by @code{racket-mode}, @code{racket-repl-mode}, and @code{racket-hash-lang-mode} when the hash-lang appears to use s-expressions. Keep in mind that, because Racket is not a ``doc string'' system, these summaries are impoverished compared to the documentation you get from @ref{racket-xp-describe} or @ref{racket-xp-documentation}.
@code{racket-xp-mode} adds hooks to document the identifiers at point and at an apparent s-expression application head position. The identifiers are documented from check-syntax annotations. The customization variable @code{racket-xp-eldoc-full-docs} to choose full documentation or just ``bluebox'' signatures.

@item
@code{racket-xp-eldoc-help-echo} returns help-echo information added by @code{racket-xp-mode} from check-syntax annotations. This is lower precedence; @code{eldoc-documentation-strategy} determines whether or not it will be displayed.
@code{racket-repl-mode} adds hooks to describe the namespace identifers at point and at an apparent s-expression application head position. The description is a signature from surface syntax, or a Typed Racket type, or a ``bluebox'' for the namespace identifier.
@end itemize

Some people use the third-party package @code{eldoc-box} to show information in a child frame (like a ``tooltip'') instead of the echo area.

Note: Racket Mode does not support the ``old'' eldoc API that uses @code{eldoc-documentation-function}, singular.

Also, @code{eldoc-documentation-strategy} is set to @code{racket-eldoc-compose-unique}, which is like @code{eldoc-documentation-default} but filters duplicate values -- useful when point is at an application head position.

Some people use the third-party package @code{eldoc-box} to show information in a child frame instead of the echo area.

@node Start faster
@section Start faster

Expand Down
6 changes: 2 additions & 4 deletions racket-eldoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Like `eldoc-documentation-compose', but filter redundant results.
A value for `eldoc-documentation-strategy', which is more
suitable because supply eldoc info for both point and the
suitable because we supply eldoc info for both point and the
application position, so when point is on the latter, they are
redundant."
(let* ((ord 0)
Expand Down Expand Up @@ -40,9 +40,7 @@ redundant."
(defun racket--eldoc-do-callback (callback thing str)
(if str
(funcall callback
(concat (when (string-match-p "\n" str)
"\n")
str)
str
:thing thing
:face 'font-lock-function-name-face)
(funcall callback "")))
Expand Down
6 changes: 5 additions & 1 deletion racket-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,11 @@ the surface syntax, or Typed Racket type information."
(racket--repl-session-id)
`(type namespace ,thing)
(lambda (str)
(racket--eldoc-do-callback callback thing str)))
(racket--eldoc-do-callback callback
thing
(if (and str (string-match-p "\n" str))
(concat "\n" str)
str))))
t))))

(defun racket-repl-eldoc-function ()
Expand Down
48 changes: 19 additions & 29 deletions racket-xp.el
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ commands directly to whatever keys you prefer.
nil t)
(add-hook 'eldoc-documentation-functions
#'racket-xp-eldoc-point
nil t)
(add-hook 'eldoc-documentation-functions
#'racket-xp-eldoc-help-echo
nil t)))
(t
(racket-show nil)
Expand All @@ -322,8 +319,7 @@ commands directly to whatever keys you prefer.
#'racket-xp-pre-redisplay
t)
(when (boundp 'eldoc-documentation-functions)
(dolist (hook (list #'racket-xp-eldoc-help-echo
#'racket-xp-eldoc-sexp-app
(dolist (hook (list #'racket-xp-eldoc-sexp-app
#'racket-xp-eldoc-point))
(remove-hook 'eldoc-documentation-functions
hook
Expand Down Expand Up @@ -615,24 +611,6 @@ point."
;; remove only those.
'font-lock-face nil)))))

(defun racket-xp-eldoc-help-echo (callback &rest _more)
"Show help-echo property at point.
By default this is /appended/ to `eldoc-documentation-functions',
therefore will have an effect only when the variable
`eldoc-documentation-strategy' is a value that composes more than
one function.
By default `racket-xp-mode' also shows help-echo strings using
the `racket-show-functions' mechanism. You may set that to
`ignore' if you get help-echo strings displayed both ways."
(when-let (str (get-text-property (point) 'help-echo))
(funcall callback
str
:thing (thing-at-point 'symbol t)
:face 'font-lock-variable-name-face)
t))

(defun racket-xp-eldoc-point (callback &rest _more)
"Call eldoc CALLBACK about the identifier at point.
First look for doc text property added by `racket-xp-mode'.
Expand Down Expand Up @@ -661,20 +639,32 @@ HOW and REPL-SESSION-ID are used."
(point)
(previous-single-property-change (point) 'racket-xp-doc)))
(end (next-single-property-change (point) 'racket-xp-doc))
(thing (buffer-substring-no-properties beg end)))
(thing (buffer-substring-no-properties beg end))
(help-echo (if-let (s (get-text-property (point) 'help-echo))
(concat s "\n")
"")))
(if racket-xp-eldoc-full-docs
(racket--eldoc-do-callback
callback
thing
(with-temp-buffer
(racket--scribble-path+anchor-insert path anchor)
(buffer-string)))
(concat
help-echo
(with-temp-buffer
(racket--scribble-path+anchor-insert path anchor)
(buffer-string))))
(racket--cmd/async
nil
`(bluebox ,tag)
(lambda (str)
(racket--eldoc-do-callback callback thing str))))
t))))
(racket--eldoc-do-callback callback
thing
(concat help-echo str)))))
t))
(_ (when-let (str (get-text-property (point) 'help-echo))
(racket--eldoc-do-callback callback
(thing-at-point 'symbol t)
str)
t))))

(defun racket-xp-eldoc-function ()
"A value for the obsolete variable `eldoc-documentation-function'.
Expand Down

0 comments on commit 85440fd

Please sign in to comment.