Skip to content

Commit c7f6aec

Browse files
Support newer eldoc API; closes greghendershott#716
1 parent b33940c commit c7f6aec

16 files changed

+406
-263
lines changed

doc/generate.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
racket-xp-after-change-refresh-delay
196196
racket-xp-highlight-unused-regexp
197197
racket-xp-add-binding-faces
198+
racket-xp-eldoc-level
198199
racket-documentation-search-location
199200
racket-expand-hiding
200201
"Hash lang variables"

doc/racket-mode.org

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
:COPYING: t
2525
:END:
2626

27-
Copyright (C) 2013-2022 by Greg Hendershott.
27+
Copyright (C) 2013-2024 by Greg Hendershott.
2828

2929
SPDX-License-Identifier: GPL-3.0-or-later
3030

@@ -366,15 +366,17 @@ You can customize where the REPL buffer is displayed by adding an item to the Em
366366

367367
** eldoc
368368

369-
By default Racket Mode sets ~eldoc-documentation-function~ to ~nil~ --- no ~eldoc-mode~ support. You may set it to ~racket-eldoc-function~ in a ~racket-mode-hook~ and ~racket-repl-mode-hook~ if you really want to use ~eldoc-mode~ with Racket. But it is not a very satisfying experience because Racket is not a very "eldoc-friendly" language. Although Racket Mode attempts to discover argument lists, contracts, or types this doesn't work in many common cases:
369+
Various modes add local hooks to ~eldoc-documentation-functions~.
370370

371-
- Many Racket primitives are defined in ~#%kernel~ or ~#%runtime~. There's no easy way to determine their argument lists. Most do not ~provide~ a contract.
371+
- The minor mode ~racket-xp-mode~ adds hooks to document the identifiers at point or at an apparent s-expression application head position. The identifiers are documented from check-syntax annotations. You may customize the variable {{{ref(racket-xp-eldoc-level)}}} to choose how much information is shown.
372372

373-
- Many of the interesting Racket forms are syntax (macros) not functions. There's no easy way to determine their "argument lists".
373+
- The major mode ~racket-repl-mode~ adds hooks to describe the namespace identifers at point or 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.
374374

375-
- When a form has documentation, Racket Mode can show the \"bluebox\" -- but often that does not fit in a single line as you would normally expect with eldoc.
375+
Tip: With an ~eldoc-documentation-strategy~ of ~eldoc-documentation-default~, these hooks show info about point when available, /or else/ for the s-expression application head. You may change that to ~eldoc-documentation-compose~ to show info for /both/ positions when available.
376376

377-
A more satisfying experience is to use {{{ref(racket-xp-describe)}}} or {{{ref(racket-xp-documentation)}}}.
377+
Tip: Some people use the third-party package ~eldoc-box~ to show information in a child frame (near point, or in a corner of the main frame) instead of the echo area.
378+
379+
Note: Racket Mode does not support the "old" eldoc API that uses ~eldoc-documentation-function~, singular.
378380

379381
** Start faster
380382

doc/racket-mode.texi

Lines changed: 84 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@c %**end of header
99

1010
@copying
11-
Copyright (C) 2013-2022 by Greg Hendershott.
11+
Copyright (C) 2013-2024 by Greg Hendershott.
1212

1313
SPDX-License-Identifier: GPL-3.0-or-later
1414
@end copying
@@ -215,6 +215,7 @@ General variables
215215
* racket-xp-after-change-refresh-delay::
216216
* racket-xp-highlight-unused-regexp::
217217
* racket-xp-add-binding-faces::
218+
* racket-xp-eldoc-level::
218219
* racket-documentation-search-location::
219220
* racket-expand-hiding::
220221
@@ -822,20 +823,21 @@ You can customize where the REPL buffer is displayed by adding an item to the Em
822823
@node eldoc
823824
@section eldoc
824825

825-
By default Racket Mode sets @code{eldoc-documentation-function} to @code{nil} --- no @code{eldoc-mode} support. You may set it to @code{racket-eldoc-function} in a @code{racket-mode-hook} and @code{racket-repl-mode-hook} if you really want to use @code{eldoc-mode} with Racket. But it is not a very satisfying experience because Racket is not a very ``eldoc-friendly'' language. Although Racket Mode attempts to discover argument lists, contracts, or types this doesn't work in many common cases:
826+
Various modes add local hooks to @code{eldoc-documentation-functions}.
826827

827828
@itemize
828829
@item
829-
Many Racket primitives are defined in @code{#%kernel} or @code{#%runtime}. There's no easy way to determine their argument lists. Most do not @code{provide} a contract.
830+
The minor mode @code{racket-xp-mode} adds hooks to document the identifiers at point or at an apparent s-expression application head position. The identifiers are documented from check-syntax annotations. You may customize the variable @ref{racket-xp-eldoc-level} to choose how much information is shown.
830831

831832
@item
832-
Many of the interesting Racket forms are syntax (macros) not functions. There's no easy way to determine their ``argument lists''.
833-
834-
@item
835-
When a form has documentation, Racket Mode can show the \``bluebox\'' -- but often that does not fit in a single line as you would normally expect with eldoc.
833+
The major mode @code{racket-repl-mode} adds hooks to describe the namespace identifers at point or 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.
836834
@end itemize
837835

838-
A more satisfying experience is to use @ref{racket-xp-describe} or @ref{racket-xp-documentation}.
836+
Tip: With an @code{eldoc-documentation-strategy} of @code{eldoc-documentation-default}, these hooks show info about point when available, @emph{or else} for the s-expression application head. You may change that to @code{eldoc-documentation-compose} to show info for @emph{both} positions when available.
837+
838+
Tip: Some people use the third-party package @code{eldoc-box} to show information in a child frame (near point, or in a corner of the main frame) instead of the echo area.
839+
840+
Note: Racket Mode does not support the ``old'' eldoc API that uses @code{eldoc-documentation-function}, singular.
839841

840842
@node Start faster
841843
@section Start faster
@@ -1298,21 +1300,6 @@ even ``let'' forms:
12981300

12991301
Minor mode to let you always type @code{[}' to insert @code{(} or @code{[} automatically.
13001302

1301-
This is a minor mode. If called interactively, toggle the
1302-
@code{Racket-Smart-Open-Bracket mode} mode. If the prefix argument is
1303-
positive, enable the mode, and if it is zero or negative, disable
1304-
the mode.
1305-
1306-
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
1307-
the mode if ARG is nil, omitted, or is a positive number.
1308-
Disable the mode if ARG is a negative number.
1309-
1310-
To check whether the minor mode is enabled in the current buffer,
1311-
evaluate @ref{racket-smart-open-bracket-mode}.
1312-
1313-
The mode's hook is called both when the mode is enabled and when
1314-
it is disabled.
1315-
13161303
Behaves like the ``Automatically adjust opening square brackets''
13171304
feature in Dr. Racket.
13181305

@@ -1355,6 +1342,21 @@ Tip: When using this with @ref{racket-hash-lang-mode}, you may want
13551342
to use @ref{racket-hash-lang-module-language-hook} to enable it IFF
13561343
the module langugage is something like ``racket''.
13571344

1345+
This is a minor mode. If called interactively, toggle the
1346+
@code{Racket-Smart-Open-Bracket mode} mode. If the prefix argument is
1347+
positive, enable the mode, and if it is zero or negative, disable
1348+
the mode.
1349+
1350+
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
1351+
the mode if ARG is nil, omitted, or is a positive number.
1352+
Disable the mode if ARG is a negative number.
1353+
1354+
To check whether the minor mode is enabled in the current buffer,
1355+
evaluate @ref{racket-smart-open-bracket-mode}.
1356+
1357+
The mode's hook is called both when the mode is enabled and when
1358+
it is disabled.
1359+
13581360
@node racket-insert-closing
13591361
@subsection racket-insert-closing
13601362

@@ -1724,20 +1726,6 @@ anything else, do @code{prog-indent-sexp}.
17241726

17251727
A minor mode that analyzes expanded code to explain and explore.
17261728

1727-
This is a minor mode. If called interactively, toggle the
1728-
@code{Racket-Xp mode} mode. If the prefix argument is positive,
1729-
enable the mode, and if it is zero or negative, disable the mode.
1730-
1731-
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
1732-
the mode if ARG is nil, omitted, or is a positive number.
1733-
Disable the mode if ARG is a negative number.
1734-
1735-
To check whether the minor mode is enabled in the current buffer,
1736-
evaluate @ref{racket-xp-mode}.
1737-
1738-
The mode's hook is called both when the mode is enabled and when
1739-
it is disabled.
1740-
17411729
This minor mode is an optional enhancement to @ref{racket-mode} edit
17421730
buffers. Like any minor mode, you can turn it on or off for a
17431731
specific buffer. If you always want to use it, put the following
@@ -1879,7 +1867,7 @@ will stop after the first syntax error, some like Typed Racket
18791867
will try to collect and report multiple errors.
18801868

18811869
You may use @code{xref-find-definitions} @kbd{M-.} ,
1882-
@code{xref-pop-marker-stack} @kbd{M-,} , and
1870+
@code{xref-pop-marker-stack} @kbd{M-x} @code{xref-pop-marker-stack}, and
18831871
@code{xref-find-references}: @ref{racket-xp-mode} adds a backend to the
18841872
variable @code{xref-backend-functions}. This backend uses information
18851873
from the drracket/check-syntax static analysis. Its ability to
@@ -1936,6 +1924,22 @@ commands directly to whatever keys you prefer.
19361924
@tab @ref{racket-xp-next-definition}
19371925
@end multitable
19381926

1927+
1928+
1929+
This is a minor mode. If called interactively, toggle the
1930+
@code{Racket-Xp mode} mode. If the prefix argument is positive,
1931+
enable the mode, and if it is zero or negative, disable the mode.
1932+
1933+
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
1934+
the mode if ARG is nil, omitted, or is a positive number.
1935+
Disable the mode if ARG is a negative number.
1936+
1937+
To check whether the minor mode is enabled in the current buffer,
1938+
evaluate @ref{racket-xp-mode}.
1939+
1940+
The mode's hook is called both when the mode is enabled and when
1941+
it is disabled.
1942+
19391943
@node racket-xp-describe
19401944
@subsection racket-xp-describe
19411945

@@ -2181,7 +2185,7 @@ Racket Describe buffer for that module's version of the thing.
21812185
Major mode for Racket REPL@.
21822186

21832187
You may use @code{xref-find-definitions} @kbd{M-.} and
2184-
@code{xref-pop-marker-stack} @kbd{M-,} :
2188+
@code{xref-pop-marker-stack} @kbd{M-x} @code{xref-pop-marker-stack}:
21852189
@ref{racket-repl-mode} adds a backend to the variable
21862190
@code{xref-backend-functions}. This backend uses information about
21872191
identifier bindings and modules from the REPL's namespace.
@@ -2547,20 +2551,6 @@ or penultimate step during initialization.
25472551

25482552
Minor mode for debug breaks.
25492553

2550-
This is a minor mode. If called interactively, toggle the
2551-
@code{Racket-Debug mode} mode. If the prefix argument is positive,
2552-
enable the mode, and if it is zero or negative, disable the mode.
2553-
2554-
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
2555-
the mode if ARG is nil, omitted, or is a positive number.
2556-
Disable the mode if ARG is a negative number.
2557-
2558-
To check whether the minor mode is enabled in the current buffer,
2559-
evaluate @ref{racket-debug-mode}.
2560-
2561-
The mode's hook is called both when the mode is enabled and when
2562-
it is disabled.
2563-
25642554
This feature is @strong{@strong{EXPERIMENTAL}}!!! It is likely to have
25652555
significant limitations and bugs. You are welcome to open an
25662556
issue to provide feedback. Please understand that this feature
@@ -2628,6 +2618,22 @@ provides shortcut keys:
26282618
@tab @code{racket-debug-step}
26292619
@end multitable
26302620

2621+
2622+
2623+
This is a minor mode. If called interactively, toggle the
2624+
@code{Racket-Debug mode} mode. If the prefix argument is positive,
2625+
enable the mode, and if it is zero or negative, disable the mode.
2626+
2627+
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
2628+
the mode if ARG is nil, omitted, or is a positive number.
2629+
Disable the mode if ARG is a negative number.
2630+
2631+
To check whether the minor mode is enabled in the current buffer,
2632+
evaluate @ref{racket-debug-mode}.
2633+
2634+
The mode's hook is called both when the mode is enabled and when
2635+
it is disabled.
2636+
26312637
@node racket-repl-clear
26322638
@subsection racket-repl-clear
26332639

@@ -3102,6 +3108,7 @@ Delete the ``compiled'' directories made by @ref{racket-mode-start-faster}.
31023108
* racket-xp-after-change-refresh-delay::
31033109
* racket-xp-highlight-unused-regexp::
31043110
* racket-xp-add-binding-faces::
3111+
* racket-xp-eldoc-level::
31053112
* racket-documentation-search-location::
31063113
* racket-expand-hiding::
31073114
@end menu
@@ -3246,6 +3253,29 @@ local definitions, using @ref{racket-xp-binding-local-face} and
32463253
This has a visible effect only when there is @emph{not} also a
32473254
'face property applied by the major mode's fontification.
32483255

3256+
@node racket-xp-eldoc-level
3257+
@subsection racket-xp-eldoc-level
3258+
3259+
How much documentation to show via @code{eldoc}.
3260+
3261+
Used by @code{racket-xp-eldoc-point} and @code{racket-xp-eldoc-sexp-app}.
3262+
3263+
@itemize
3264+
@item
3265+
Minimal: Only the help-echo string.
3266+
3267+
@item
3268+
Summary: Also the signature a.k.a. ``blubox'' from the
3269+
documentation.
3270+
3271+
@item
3272+
Complete: Also the complete prose documentation.
3273+
@end itemize
3274+
3275+
A third-party package like @code{eldoc-box} can be useful for all but
3276+
the minimal level. Even some bluebox signatures can take many
3277+
lines to show on screen.
3278+
32493279
@node racket-documentation-search-location
32503280
@subsection racket-documentation-search-location
32513281

@@ -4361,4 +4391,4 @@ Face @ref{racket-repl-mode} uses for output to current-error-port.
43614391

43624392
Face @ref{racket-hash-lang-mode} uses for text tokens.
43634393

4364-
@bye
4394+
@bye

racket-company-doc.el

Lines changed: 0 additions & 78 deletions
This file was deleted.

racket-custom.el

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; racket-custom.el -*- lexical-binding: t; -*-
22

3-
;; Copyright (c) 2013-2022 by Greg Hendershott.
3+
;; Copyright (c) 2013-2024 by Greg Hendershott.
44
;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.
55

66
;; Author: Greg Hendershott
@@ -160,6 +160,26 @@ This has a visible effect only when there is /not/ also a
160160
:type '(repeat symbol)
161161
:safe #'listp)
162162

163+
(defcustom racket-xp-eldoc-level 'summary
164+
"How much documentation to show via `eldoc'.
165+
166+
Used by `racket-xp-eldoc-point' and `racket-xp-eldoc-sexp-app'.
167+
168+
- Minimal: Only the help-echo string.
169+
170+
- Summary: Also the signature a.k.a. \"blubox\" from the
171+
documentation.
172+
173+
- Complete: Also the complete prose documentation.
174+
175+
A third-party package like `eldoc-box' can be useful for all but
176+
the minimal level. Even some bluebox signatures can take many
177+
lines to show on screen."
178+
:type '(radio (const :tag "Minimal" nil)
179+
(const :tag "Summary" summary)
180+
(const :tag "Complete" complete))
181+
:safe #'listp)
182+
163183
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164184
;;; racket-hash-lang group
165185

0 commit comments

Comments
 (0)