22 drracket:modes

▼ |  | Dr Racket Plugins

1 | Dr Racket support for #lang-based Languages
2 | Implementing Dr Racket Plugins
3 | Adding Languages to Dr Racket
4 | Creating New Kinds of Dr Racket Frames
5 | Extending the Existing Dr Racket Classes
6 | Expanding the User’s Program Text and Breaking
7 | Editor Modes
8 | Plugin Capabilities
9 | Check Syntax
10 | Cooperating with Background Check Syntax
11 | Teaching Languages
12 | Signatures
13 | drracket: get/ extend
14 | drracket: unit
15 | drracket: language
16 | drracket: language-configuration
17 | drracket: debug
18 | drracket: rep
19 | drracket: frame
20 | drracket: help-desk
21 | drracket: eval
22 | drracket: modes
23 | drracket: module-language-tools
24 | drracket: module-language
25 | drracket: tracing
26 | Backwards Compatibility
| Index

On this page:

drracket: modes: add-mode
drracket: modes: mode
drracket: modes: struct: mode
drracket: modes: get-modes

top ← prev up next →

### 22`` drracket:modes

> > procedure
> > (drracket:modes:add-mode |
> > |  | name |
> > |  | surrogate |
> > |  | repl-submit |
> > |  | matches-language |
> > | [ | #:intended-to-edit-programs? intended-to-edit-programs?]) |
> → drracket:modes:mode?
> name : string?
> surrogate : (or/c #f (is-a?/c mode:surrogate-text<%>))
> repl-submit : (-> (is-a?/c drracket:rep:text%) number? boolean?)
> matches-language : (-> (or/c #f (listof string?)) boolean?)
> intended-to-edit-programs? : boolean? = #t

Adds a mode to DrRacket. Returns a mode value that identifies the mode.

The first argument, name, is the name of the mode, used in DrRacket’s GUI to allow the user to select this mode.

The surrogate argument is set to the definitions text and the interactions text (via the mode:host-text set-surrogate<%> method) whenever this mode is enabled.

The repl-submit procedure is called whenever the user types a return in the interactions window. It is passed the interactions editor and the position where the last prompt occurs. If it returns #t, the text after the last prompt is treated as a program fragment and evaluated, according to the language settings. If it returns #f, the text is assumed to be an incomplete program fragment, and the keystroke is not treated specially.

The matches-language predicate is called whenever the language changes. If it returns #t this mode is installed. It is passed the list of strings that correspond to the names of the language in the language dialog.

The intended-to-edit-programs? boolean indicates if this mode is intended to be for editing programs (as opposed to some other kind of file content). If it is #f, online expansion is disabled and DrRacket won’t look for (module at the front of the buffer to try to guess the intended filename.

Modes are tested in the opposite order that they are added. That is, the last mode to be added gets tested first when the filename changes or when the language changes.

See also drracket:modes:get-modes.

Changed in version 1.1 of package drracket: Added the intended-to-edit-programs? argument.

> > struct
> > (struct |  | drracket:modes:mode | ( | name
> > |  |  |  | surrogate
> > |  |  |  | repl-submit
> > |  |  |  | matches-language
> > |  |  |  | intended-to-edit-programs?))
> name : string?
> surrogate : (or/c #f (is-a?/c mode:surrogate-text<%>))
> repl-submit : (-> (is-a?/c drracket:rep:text%) number? boolean?)
> matches-language : (-> (or/c #f (listof string?)) boolean?)
> intended-to-edit-programs? : boolean?

See drracket:modes:add-mode for details on modes.

Changed in version 1.1 of package drracket: Added the intended-to-edit-programs? field.

> value drracket:modes:struct:mode : struct-type?

An alias for struct:drracket:modes:mode.

> procedure (drracket:modes:get-modes) → (listof drracket:modes:mode?)

Returns all of the modes currently added to DrRacket.

Note that the surrogate field of the mode corresponding to the module language does not take into account the definitions-text-surrogate, so it may not be the actual class used directly in DrRacket, even when the mode is active.

See also drracket:modes:add-mode.

top ← prev up next →