Skip to content

Latest commit

 

History

History
762 lines (511 loc) · 22.3 KB

Reference.md

File metadata and controls

762 lines (511 loc) · 22.3 KB

Reference

Commands

Run

racket-run

C-c C-k or C-c C-c

Save and evaluate the buffer in REPL, much like DrRacket's Run.

When you run again, the file is evaluated from scratch -- the custodian releases resources like threads and the evaluation environment is reset to the contents of the file. In other words, like DrRacket, this provides the predictability of a "static" baseline, plus some interactive exploration.

See also racket-run-and-switch-to-repl, which is even more like DrRacket's Run because it selects the REPL window (gives it the focus), too.

With a C-u prefix, uses errortrace for improved stack traces. Otherwise follows the racket-error-context setting.

Output in the *Racket REPL* buffer that describes a file and position is automatically "linkified". To visit, move point there and press RET, mouse click, or use a Compilation mode command such as C-x ` (next error). Examples of such text include:

  • Racket error messages.
  • rackunit test failure location messages.
  • prints of #<path> objects.

In the *Racket REPL* buffer you can issue some special commands. Some of them are the foundation for Emacs commands. Others are available only as a command in the REPL.

  • ,help: See these commands.

  • ,top: Reset the REPL to an empty module (i.e. a racket/base namespace).

  • ,run <module> : What racket-run uses.

    • <module> = <file> | (<file> <submodule-id> ...)
    • <file> = file.rkt | /path/to/file.rkt | "file.rkt" | "/path/to/file.rkt"
  • ,exit: Exit Racket. Handy in a #lang like r5rs where the exit procedure is not available. (Regardless of how Racket exits, the *Racket REPL* buffer is not killed and is reused if you racket-run again.)

  • ,doc <symbol-or-string>: Look for <symbol-or-string> in Racket's documentation. What racket-doc uses.

  • ,cd, ,pwd: Change and show [current-directory].

  • ,log controls the log output level, overall, as well as for specific named loggers created with [define-logger].

    • ,log: Show the current levels.

    • ,log <logger> <level>: Set a logger to show at least level none, fatal, error, warning, info, or debug.

    • ,log <logger> <level>: Set a logger to use the default level.

    • ,log <level>: Set the default level for all other loggers not specified individually.

racket-racket

<C-M-f5>

Do racket <file> in *shell* buffer.

racket-profile

C-c C-l

Runs with profiling instrumentation and shows results.

Results are presented in a racket-profile-mode buffer, which also lets you quickly view the source code.

You may evaluate expressions in the REPL. They are also profiled. Use racket--profile-refresh to see the updated results. (In other words a possible workflow is: racket-profile a .rkt file, call one its functions in the REPL, and refresh the profile results.)

Caveat: Only source files are instrumented. You may need to delete compiled/*.zo files.

racket-profile-mode

M-x racket-profile-mode

Major mode for results of racket-profile.

key             binding
---             -------

RET		racket--profile-visit
,		racket--profile-sort
g		racket--profile-refresh
n		racket--profile-next
p		racket--profile-prev
q		racket--profile-quit
z		racket--profile-show-zero


In addition to any hooks its parent mode special-mode might have run, this mode runs the hook racket-profile-mode-hook, as the final step during initialization.

Test

racket-test

<C-f5> or C-c C-t

Run the test submodule.

With prefix, runs with coverage instrumentation and highlights uncovered code.

Put your tests in a test submodule. For example:

(module+ test
  (require rackunit)
  (check-true #t))

rackunit test failure messages show the location. You may use next-error to jump to the location of each failing test.

See also:

racket-raco-test

M-x racket-raco-test

Do raco test -x <file> in *shell* buffer. To run 's test submodule.

Eval

racket-send-region

C-c C-r

Send the current region (if any) to the Racket REPL.

racket-send-definition

C-M-x

Send the current definition to the Racket REPL.

racket-send-last-sexp

C-x C-e

Send the previous sexp to the Racket REPL.

When the previous sexp is a sexp comment the sexp itself is sent, without the #; prefix.

Visit

racket-visit-definition

M-.

Visit definition of symbol at point.

Use M-x racket-unvisit to return.

Note: Only finds symbols defined in the current namespace. You may need to invoke racket-run on the current buffer, first.

Note: Only visits the definition of module level identifiers (i.e. things for which Racket's identifier-binding function returns a list, as opposed to 'lexical).

Note: If the definition is from Racket's #%kernel module, it will tell you so but won't visit the definition site.

racket-visit-module

C-M-.

Visit definition of module at point, e.g. net/url or "file.rkt".

Use M-x racket-unvisit to return.

Note: Only works if you've racket-run the buffer so that its namespace is active.

See also: racket-find-collection.

racket-unvisit

M-,

Return from previous racket-visit-definition or racket-visit-module.

racket-open-require-path

C-c C-x C-f

Like Dr Racket's Open Require Path.

Type (or delete) characters that are part of a module path name. "Fuzzy" matches appear. For example try typing "t/t/r".

Choices are displayed in a vertical list. The current choice is at the top, marked with "->".

  • C-n and C-p move among the choices.
  • RET on a directory adds its contents to the choices.
  • RET on a file exits doing find-file.
  • C-g aborts.

Note: This requires Racket 6.1.1.6 or newer. Otherwise it won't error, it will just never return any matches.

racket-find-collection

M-x racket-find-collection

Given a collection name, try to find its directory and files.

Takes a collection name from point (or, with a prefix, prompts you).

If only one directory is found, ido-find-file-in-dir lets you pick a file there.

If more than one directory is found, ido-completing-read lets you pick one, then ido-find-file-in-dir lets you pick a file there.

Note: This requires the raco-find-collection package to be installed. To install it, in shell enter:

raco pkg install raco-find-collection

Tip: This works best with ido-enable-flex-matching set to t. Also handy is the flx-ido package from MELPA.

See also: racket-visit-module and racket-open-require-path.

Learn

racket-describe

C-c C-.

Describe the identifier at point in a *Racket Describe* buffer.

The intent is to give a quick reminder or introduction to something, regardless of whether it has installed documentation -- and to do so within Emacs, without switching to a web browser.

This buffer is also displayed when you use company-mode and press F1 or C-h in its pop up completion list.

  • If the identifier has installed Racket documentation, then a simplified version of the HTML is presented in the buffer, including the "blue box", documentation prose, and examples.

  • Otherwise, if the identifier is a function, then its signature is displayed, for example (name arg-1-name arg-2-name). If it has a Typed Racket type or a contract, that is also displayed.

You can quit the buffer by pressing q. Also, at the bottom of the buffer are Emacs buttons -- which you may navigate among using TAB, and activate using RET -- for racket-visit-definition and racket-doc.

racket-doc

C-c C-d

View documentation of the identifier or string at point.

Uses the default external web browser.

If point is an identifier required in the current namespace that has help, opens the web browser directly at that help topic. (i.e. Uses the identifier variant of racket/help.)

Otherwise, opens the 'search for a term' page, where you can choose among multiple possibilities. (i.e. Uses the string variant of racket/help.)

With a C-u prefix, prompts for the identifier or quoted string, instead of looking at point.

Edit

racket-fold-all-tests

C-c C-f

Fold (hide) all test submodules.

racket-unfold-all-tests

C-c C-u

Unfold (show) all test submodules.

racket-tidy-requires

M-x racket-tidy-requires

Make a single top-level require, modules sorted, one per line.

All top-level require forms are combined into a single form. Within that form:

  • A single subform is used for each phase level, sorted in this order: for-syntax, for-template, for-label, for-meta, and plain (phase 0).

    • Within each level subform, the modules are sorted:

      • Collection path modules -- sorted alphabetically.

      • Subforms such as only-in.

      • Quoted relative requires -- sorted alphabetically.

At most one module is listed per line.

Note: This only works for requires at the top level of a source file using #lang. It does not work for requires inside module forms.

See also: racket-trim-requires and racket-base-requires.

racket-trim-requires

M-x racket-trim-requires

Like racket-tidy-requires but also deletes unused modules.

Note: This only works when the source file can be evaluated with no errors.

Note: This only works for requires at the top level of a source file using #lang. It does not work for requires inside module forms.

See also: racket-base-requires.

racket-base-requires

M-x racket-base-requires

Change from #lang racket to #lang racket/base.

Adds explicit requires for modules that are provided by racket but not by racket/base.

This is a recommended optimization for Racket applications. Avoiding loading all of racket can reduce load time and memory footprint.

Also, as does racket-trim-requires, this removes unneeded modules and tidies everything into a single, sorted require form.

Note: This only works when the source file can be evaluated with no errors.

Note: This only works for requires at the top level of a source file using #lang. It does not work for requires inside module forms.

Note: Currently this only helps change #lang racket to #lang racket/base. It does not help with other similar conversions, such as changing #lang typed/racket to #lang typed/racket/base.

racket-indent-line

M-x racket-indent-line

Indent current line as Racket code.

This behaves like lisp-indent-line, except that whole-line comments are treated the same regardless of whether they start with single or double semicolons.

  • Automatically indents forms that start with begin in the usual way that begin is indented.

  • Automatically indents forms that start with def or with- in the usual way that define is indented.

  • Has rules for many specific standard Racket forms.

To extend, use your Emacs init file to

(put SYMBOL 'racket-indent-function INDENT)

where SYMBOL is the name of the Racket form (e.g. 'test-case) and INDENT is an integer or the symbol 'defun. When INDENT is an integer, the meaning is the same as for lisp-indent-function and scheme-indent-function: Indent the first n arguments specially and then indent any further arguments like a body.

For example in your .emacs file you could use:

(put 'test-case 'racket-indent-function 1)

to change the indent of test-case from this:

(test-case foo
           blah
           blah)

to this:

(test-case foo
  blah
  blah)

racket-smart-open-bracket

[

Automatically insert a ( or a [ as appropriate.

When racket-smart-open-bracket-enable is nil, this simply inserts [. Otherwise, this behaves like the "Automatically adjust opening square brackets" feature in Dr. Racket:

By default, inserts a (. Inserts a [ in the following cases:

  • let-like bindings -- forms with let in the name as well as things like parameterize, with-handlers, and with-syntax.

  • case, cond, match, syntax-case, syntax-parse, and syntax-rules clauses.

  • for-like bindings and for/fold accumulators.

When the previous s-expression in a sequence is a compound expression, uses the same kind of delimiter.

To force insert [, use quoted-insert: C-q [.

Combined with racket-insert-closing this means that you can press the unshifted [ and ] keys to get whatever delimiters follow the Racket conventions for these forms. (When electric-pair-mode or paredit-mode is active, you need not even press ].

racket-cycle-paren-shapes

C-c C-p

In an s-expression, move to the opening, and cycle the shape among () [] {}

racket-backward-up-list

C-M-u

Like backward-up-list but also works when point is in a string literal.

racket-check-syntax-mode

M-x racket-check-syntax-mode

Analyze the buffer and annotate with information.

The buffer becomes read-only until you exit this minor mode. However you may navigate the usual ways. When point is on a definition or use, related items are highlighted and information is displayed in the echo area. You may also use special commands to navigate among the definition and its uses.

key             binding
---             -------

TAB		racket-check-syntax-mode-goto-next-def
.		racket-check-syntax-mode-goto-def
h		racket-check-syntax-mode-help
j		racket-check-syntax-mode-goto-next-def
k		racket-check-syntax-mode-goto-prev-def
n		racket-check-syntax-mode-goto-next-use
p		racket-check-syntax-mode-goto-prev-use
q		racket-check-syntax-mode-quit
r		racket-check-syntax-mode-rename
S-TAB		racket-check-syntax-mode-goto-prev-def


racket-unicode-input-method-enable

M-x racket-unicode-input-method-enable

Set input method to racket-unicode.

The racket-unicode input method lets you easily type various Unicode symbols that might be useful when writing Racket code.

To automatically enable the racket-unicode input method in racket-mode buffers use M-x customize-variable <RET> racket-mode-hook or put the following code in your Emacs init file:

(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable)

Likewise for racket-repl-mode buffers:

(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable)

To temporarily enable this input method for a single buffer you can use M-x racket-unicode-input-method-enable.

Use C-\ to toggle the input method.

When the racket-unicode input method is active, you can for example type All and it is immediately replaced with . A few other examples:

omega     ω
x_1       x₁
x^1       x¹
|A|       𝔸
test-->>E test-->>∃ (racket/redex)

To see a table of all key sequences use M-x describe-input-method <RET> racket-unicode.

If you don’t like the highlighting of partially matching tokens you can turn it off by setting input-method-highlight-flag to nil via M-x customize-variable.

racket-align

M-x racket-align

Align values in the same column.

Useful for binding forms like let and parameterize, conditionals like cond and match, association lists, and any series of couples like the arguments to hash.

Before choosing this command, put point on the first of a series of "couples". A couple is:

  • A list of two or more sexprs: [sexpr val sexpr ...]
  • Two sexprs: sexpr val.

Each val moves to the same column and is indent-sexp-ed (in case it is a multi-line form).

For example with point on the [ before a:

Before             After

(let ([a 12]       (let ([a   12]
      [bar 23])          [bar 23])
  ....)              ....)

'([a . 12]         '([a   . 12]
  [bar . 23])        [bar . 23])

(cond [a? #t]      (cond [a?   #t]
      [b? (f x           [b?   (f x
             y)]                  y)]
      [else #f])         [else #f])

Or with point on the ' before a:

(list 'a 12        (list 'a   12
      'bar 23)           'bar 23)

If more than one couple is on the same line, none are aligned, because it is unclear where the value column should be. For example the following form will not change; racket-align will display an error message:

(let ([a 0][b 1]
      [c 2])       error; unchanged
  ....)

When a couple's sexprs start on different lines, that couple is ignored. Other, single-line couples in the series are aligned as usual. For example:

(let ([foo         (let ([foo
       0]                 0]
      [bar 1]            [bar 1]
      [x 2])             [x   2])
  ....)              ....)

See also: racket-unalign.

racket-unalign

M-x racket-unalign

The opposite of racket-align.

Effectively does M-x just-one-space and indent-sexp for each couple's value.

Macro expand

racket-expand-region

C-c C-e r

Like racket-send-region, but macro expand.

With C-u prefix, expands fully.

Otherwise, expands once. You may use racket-expand-again.

racket-expand-definition

C-c C-e x

Like racket-send-definition, but macro expand.

With C-u prefix, expands fully.

Otherwise, expands once. You may use racket-expand-again.

racket-expand-last-sexp

C-c C-e e

Like racket-send-last-sexp, but macro expand.

With C-u prefix, expands fully.

Otherwise, expands once. You may use racket-expand-again.

racket-expand-again

C-c C-e a

Macro expand again the previous expansion done by one of:

racket-gui-macro-stepper

M-x racket-gui-macro-stepper

Run the DrRacket GUI macro stepper.

Runs on the active region, if any, else the entire buffer.

EXPERIMENTAL: May be changed or removed.

BUGGY: The first-ever invocation might not display a GUI window. If so, try again.

Variables

Note: You may also set these via Customize.

General

racket-racket-program

Pathname of the racket executable.

racket-raco-program

Pathname of the raco executable.

racket-memory-limit

Terminate the Racket process if memory use exceeds this value in MB. Changes to this value take effect upon the next racket-run.

Caveat: This uses Racket's custodian-limit-memory, which does not enforce the limit exactly. Instead, the program will be terminated upon the first garbage collection where memory exceeds the limit (maybe by a significant amount).

racket-error-context

The level of context used for racket-run error stack traces.

Each level improves stack trace information, but causes your program to run more slowly.

  • 'low corresponds to compile-context-preservation-enabled #f.

  • 'medium corresponds to compile-context-preservation-enabled #t, which disables some optimizations like inlining.

  • 'high corresponds to compile-context-preservation-enabled #t and to use of errortrace, which heavily instruments your code and therefore may be significantly slower.

Tip: Regardless of this setting, you can enable 'high errortrace for a specific racket-run using a C-u prefix. This lets you normally run with a faster setting, and temporarily re-run to get a more-helpful error message.

REPL

racket-history-filter-regexp

Input matching this regexp are not saved on the history list. Defaults to a regexp ignoring all inputs of 0, 1, or 2 letters.

racket-images-inline

Whether to display inline images in the REPL.

racket-images-keep-last

How many images to keep in the image cache.

racket-images-system-viewer

Which system image viewer program to invoke upon M-x racket-view-last-image.

racket-pretty-print

Use pretty-print instead of print in REPL.

Other

racket-indent-curly-as-sequence

Indent {} with items aligned with the head item? This is indirectly disabled if racket-indent-sequence-depth is 0. This is safe to set as a file-local variable.

racket-indent-sequence-depth

To what depth should racket--align-sequence-to-head search. This affects the indentation of forms like '()` `() #() -- and {} if racket-indent-curly-as-sequence is t -- but not #'() #`() ,() ,@(). A zero value disables, giving the normal indent behavior of DrRacket or Emacs lisp-mode derived modes like scheme-mode. Setting this to a high value can make indentation noticeably slower. This is safe to set as a file-local variable.

racket-pretty-lambda

Display lambda keywords using λ. This is deprecated. Instead you can insert actual λ characters using C-M-y racket-insert-lambda.

racket-smart-open-bracket-enable

Use racket-smart-open-bracket when [ is pressed?

Faces

Note: You may also set these via Customize.

racket-keyword-argument-face

Face for #:keyword arguments.

racket-paren-face

Face for () [] {}.

racket-selfeval-face

Face for self-evaluating expressions like numbers, symbols, strings.