18 drracket:rep

▼ |  | Dr Racket Plugins

1 | Tool 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 | drracket: init
27 | Backwards Compatibility
| Index

On this page:

drracket: rep: text<%>
drracket: rep: text%
make-object
after-delete
after-insert
display-results
evaluate-from-port
after-many-evals
on-execute
get-error-range
get-user-custodian
get-user-eventspace
get-user-language-settings
get-user-namespace
get-user-thread
highlight-errors
highlight-errors/ exn
on-highlighted-errors
initialize-console
insert-prompt
kill-evaluation
on-close
queue-output
reset-console
reset-highlighting
run-in-evaluation-thread
shutdown
wait-for-io-to-complete
wait-for-io-to-complete/ user
drracket: rep: drs-bindings-keymap-mixin
get-keymaps
drracket: rep: context<%>
clear-annotations
disable-evaluation
enable-evaluation
ensure-rep-shown
get-breakables
get-directory
needs-execution
reset-offer-kill
set-breakables
update-running
drracket: rep: get-welcome-delta
drracket: rep: get-dark-green-delta
drracket: rep: get-error-delta
drracket: rep: get-drs-bindings-keymap
drracket: rep: current-rep
drracket: rep: current-value-port
drracket: rep: after-expression
drracket: rep: current-language-settings
drracket: rep: module-language-initial-run

top contents ← prev up next →

### 18`` drracket:rep🔗ℹ

interface drracket:rep:text<%> : interface?

class drracket:rep:text% : class?
superclass: racket:text%
extends: | drracket:rep:text<%>

This class implements a read-eval-print loop for DrRacket. User submitted evaluations in DrRacket are evaluated asynchronously, in an eventspace created for the user. No evaluations carried out by this class affect the implementation that uses it.

> > constructor (make-object drracket:rep:text% context)
> > → (is-a?/c drracket:rep:text%)
> > context : (implements drracket:rep:context<%>)

> > method (send a-drracket:rep:text after-delete) → void?

> Overrides after-delete in mode:host-text-mixin.
> Resets any error highlighting in this editor.

> > method (send a-drracket:rep:text after-insert) → void?

> Overrides after-insert in mode:host-text-mixin.
> Resets any error highlighting in this editor.

> > method (send a-drracket:rep:text display-results results) → void?
> > results : (list-of TST)

> This displays each of the elements of results in the interactions window, expect those elements of results that are void. Those are just ignored.

> > > method
> > > (send a-drracket:rep:text evaluate-from-port |
> > > |  | port |
> > > |  | complete-program? |
> > > |  | cleanup) |
> > → any
> > port : input-port?
> > complete-program? : boolean?
> > cleanup : (-> void)

> Evaluates the program in the port argument. If complete-program? is #t, this method calls the front-end/complete-program to evaluate the program. If it is #f, it calls front-end/interaction method. When evaluation finishes, it calls cleanup on the user’s main thread.

> Just before calling cleanup, this invokes the thunk in drracket:rep:after-expression (if any). It takes the value of the drracket:rep:after-expression parameter on the DrRacket main thread, but invokes the thunk on the user’s thread.

> This method must be called from the DrRacket main thread.

> > method (send a-drracket:rep:text after-many-evals) → any

> Refine this method with augment.
> Called from the DrRacket main thread after evaluate-from-port finishes (no matter how it finishes).

> If the call to evaluate-from-port was from the call that sets up the initial read-eval-print loop, then the value of drracket:rep:module-language-initial-run will be #t; otherwise it will be #f.

> > method (send a-drracket:rep:text on-execute run-on-user-thread) → any
> > run-on-user-thread : (-> any)

> Use run-on-user-thread to initialize the user’s parameters, etc.

> Called from the DrRacket thread after the language’s on-execute method has been invoked, and after the special values have been setup (the ones registered via drracket:language:add-snip-value).

> Do not print to current-output-port or current-error-port during the dynamic extent of the thunk passed to run-on-user-thread because this can deadlock. IO is still, in general, fine, but the current-error-port and current-output-port are set to the user’s ports that print into the interactions window and are not in a good state during those calls.

> > method (send a-drracket:rep:text get-error-range)
> > → (or/c false/c (list/c (is-a?/c text:basic%) number? number?))

> Specification: Indicates the highlighted error range. The state for the error range is shared across all instances of this class, so there can only be one highlighted error region at a time.

> Default implementation: If #f, no region is highlighted. If a list, the first element is the editor where the range is highlighted and the second and third are the beginning and ending regions, respectively.

> > method (send a-drracket:rep:text get-user-custodian)
> > → (or/c false/c custodian?)

> This is the custodian controlling the user’s program.

> > method (send a-drracket:rep:text get-user-eventspace)
> > → (or/c false/c eventspace?)

> This is the user’s eventspace. The result of get-user-thread is the main thread of this eventspace.

> > method (send a-drracket:rep:text get-user-language-settings)
> > → language-settings

> Returns the user’s language-settings for the most recently run program. Consider using get-next-settings instead, since the user may have selected a new language since the program was last run.

> > method (send a-drracket:rep:text get-user-namespace)
> > → (or/c false/c namespace?)

> Returns the user’s namespace. This method returns a new namespace each time Run is clicked.

> > method (send a-drracket:rep:text get-user-thread)
> > → (or/c false/c thread?)

> This method returns the thread that the user’s code runs in. It returns a different result each time the user runs the program.

> It is #f before the first time the user click on the Run button or the evaluation has been killed.

> This thread has all of its parameters initialized according to the settings of the current execution. See Parameters for more information about parameters.

> > > method
> > > (send a-drracket:rep:text highlight-errors |  | locs |
> > > | [ | error-arrows]) |
> > → void?
> > locs : (listof srcloc?)
> > error-arrows : (or/c #f (listof srcloc?)) = #f

> Call this method to highlight errors associated with this repl. See also reset-highlighting, and highlight-errors/exn.

> This method highlights a series of dis-contiguous ranges in the editor.

> It puts the caret at the location of the first error.

> > method (send a-drracket:rep:text highlight-errors/exn exn) → void?
> > exn : exn

> Highlights the errors associated with the exn (only syntax and read errors – does not extract any information from the continuation marks)

> See also highlight-errors.

> > method (send a-drracket:rep:text on-highlighted-errors loc/s) → void?
> > loc/s : (or/c srcloc? (listof srcloc?))

> This method is called when an error is highlighted in a DrRacket window.

> If the input is a list of srcloc? objects, then all of them are highlighted, and they are all of the errors known to DrRacket at this point.

> If a single one is passed, then user probably typed the . menu shortcut to highlight a single error and there may be other errors known to DrRacket.

> Errors are made known to DrRacket via highlight-errors.

> > method (send a-drracket:rep:text initialize-console) → void?

> This inserts the “Welcome to DrRacket” message into the interactions buffer, calls reset-console, insert-prompt, and clear-undos.

> Once the console is initialized, this method calls first-opened. Accordingly, this method should not be called to initialize a REPL when the user’s evaluation is imminent. That is, this method should be called when new tabs or new windows are created, but not when the Run button is clicked.

> This method calls the first-opened from the user’s eventspace’s main thread and, when first-opened returns, it enqueue’s a callback that ends an edit sequence on the REPL and calls clear-undos. Accordingly, if the first-opened method does not return, the interactions text will be in an unclosed edit sequence.

> > method (send a-drracket:rep:text insert-prompt) → void?

> Inserts a new prompt at the end of the text.

> > method (send a-drracket:rep:text kill-evaluation) → void?

> This method is called when the user chooses the kill menu item.

> > method (send a-drracket:rep:text on-close) → void?

> Overrides on-close in editor:basic<%>.
> Calls shutdown.

> Calls the super method.

> > method (send a-drracket:rep:text queue-output thnk) → void?
> > thnk : (-> void?)

> Specification: This method queues thunks for DrRacket’s eventspace in a special output-related queue.

> > method (send a-drracket:rep:text reset-console) → void?

> Kills the old eventspace, and creates a new parameterization for it.

> > method (send a-drracket:rep:text reset-highlighting) → void?

> This method resets the highlighting being displayed for this repl. See also: highlight-errors, and highlight-errors/exn.

> > method (send a-drracket:rep:text run-in-evaluation-thread f) → void?
> > f : ( -> void)

> Specification: This function runs its arguments in the user evaluation thread. This thread is the same as the user’s eventspace main thread.

> Default implementation: Calls f, after switching to the user’s thread.

> > method (send a-drracket:rep:text shutdown) → void?

> Shuts down the user’s program and all windows. Reclaims any resources the program allocated. It is expected to be called from DrRacket’s main eventspace thread.

> > method (send a-drracket:rep:text wait-for-io-to-complete) → void?

> This waits for all pending IO in the rep to finish and then returns.

> This method must only be called from the main thread in DrRacket’s eventspace

> > method (send a-drracket:rep:text wait-for-io-to-complete/user)
> > → void?

> This waits for all pending IO in the rep to finish and then returns.

> This method must only be called from the main thread in the user’s eventspace

mixin drracket:rep:drs-bindings-keymap-mixin : (class? . -> . class?)
argument extends/implements: | editor:keymap<%>

This mixin adds some DrRacket-specific keybindings to the editor it is mixed onto.

> > method (send a-drracket:rep:drs-bindings-keymap get-keymaps)
> > → (listof (is-a?/c keymap%))

> Overrides get-keymaps in editor:keymap<%>.
> Calls the super method and adds in a keymap with the DrRacket-specific keybindings:

> - f5 - Run

> - c:x;o - toggles the focus between the definition and interactions windows.

interface drracket:rep:context<%> : interface?

Objects that match this interface provide all of the services that the drracket:rep:text% class needs to connect with its context.

> > method (send a-drracket:rep:context clear-annotations) → void?

> Specification: Call this method to clear any annotations in the text before executing or analyzing or other such activities that should process the program.

> Tools that annotate the program text should augment this method to clear their own annotations on the program text.

> DrRacket calls this method before a program is run (via the Run button).

> Default implementation: Clears any error highlighting in the definitions window.

> > method (send a-drracket:rep:context disable-evaluation) → void?

> Call this method to disable evaluation GUI evaluation while some evaluation (or expansion) is taking place on another thread.

> Override this method if you add a GUI-based mechanism for initiating evaluation in the frame.

> This method is also called when the user switches tabs.

> See also enable-evaluation.

> > method (send a-drracket:rep:context enable-evaluation) → void?

> This method must disable the GUI controls that start user-sponsored evaluation. It is called once the user starts some evaluation to ensure that only one evaluation proceeds at a time.

> It is also called when the user switches tabs.

> See also disable-evaluation.

> > method (send a-drracket:rep:context ensure-rep-shown rep) → void?
> > rep : (is-a?/c drracket:rep:text<%>)

> This method is called to force the rep window to be visible when, for example, an error message is put into the rep. Also ensures that the appropriate tab is visible, if necessary.

> > method (send a-drracket:rep:context get-breakables)
> > | → |  |
> > (or/c thread? false/c)
> > (or/c custodian? false/c)

> Returns the last values passed to set-breakables.

> > method (send a-drracket:rep:context get-directory) → path?

> The result of this method is used as the initial directory for the user’s program to be evaluated in.

> > method (send a-drracket:rep:context needs-execution)
> > → (or/c string? false/c)

> This method should return an explanatory string when the state of the program that the repl reflects has changed. It should return #f otherwise.

> > method (send a-drracket:rep:context reset-offer-kill) → void?

> The break button typically offers to kill if it has been pushed twice in a row. If this method is called, however, it ignores any prior clicks.

> > > method
> > > (send a-drracket:rep:context set-breakables |  | thread |  |  |  |
> > > |  | custodian) |  | → |  | void?
> > thread : (or/c thread false/c)
> > custodian : (or/c custodian false/c)

> Calling this method with a thread and a custodian means that the next time the break button is clicked, it will either break the thread or shutdown the custodian.

> See also get-breakables.

> > method (send a-drracket:rep:context update-running running?) → void?
> > running? : any/c

> This method should update some display in the gui that indicates whether or not evaluation is currently proceeding in the user’s world.

> procedure (drracket:rep:get-welcome-delta) → (is-a?/c style-delta%)

Returns a style delta that matches the style and color of the phrase “Welcome to” in the beginning of the interactions window.

> procedure (drracket:rep:get-dark-green-delta) → (is-a?/c style-delta%)

Returns a style delta that matches the style and color of the name of a language in the interactions window.

> procedure (drracket:rep:get-error-delta) → (is-a?/c style-delta%)

Returns a style delta that matches the style and color of errors that get shown in the interactions window.

> procedure (drracket:rep:get-drs-bindings-keymap) → (is-a?/c keymap%)

Returns a keymap that binds various DrRacket-specific keybindings. This keymap is used in the definitions and interactions window.

By default, binds C-x;o to a function that switches the focus between the definitions and interactions windows. Also binds f5 to Execute and f1 to Help Desk.

> procedure (drracket:rep:current-rep)
> → (or/c false/c (is-a?/c drracket:rep:text%))

This is a parameter whose value should not be set by tools. It is initialized to the repl that controls this evaluation in the user’s thread.

It only returns #f if the program not running in the context of a repl (eg, the test suite window).

> procedure (drracket:rep:current-value-port) → (or/c false/c port?)

This is a parameter whose value is a port that prints in the REPL in blue. It is used to print the values of toplevel expressions in the REPL.

It is only initialized on the user’s thread.

> parameter (drracket:rep:after-expression) → (or/c #f (-> any))
> (drracket:rep:after-expression top-level-expression) → void?
> top-level-expression : (or/c #f (-> any))

This parameter is used by evaluate-from-port. When it is a thunk, then DrRacket invokes the thunk on the user’s thread as the last thing it does (before cleaning up).

> parameter (drracket:rep:current-language-settings)
> → drracket:language-configuration:language-settings?
> (drracket:rep:current-language-settings language-settings)
> → void?
> language-settings : drracket:language-configuration:language-settings?

This parameter is set (on the user’s thread) to the drracket:language-configuration:language-settings for the currently running language.

> parameter (drracket:rep:module-language-initial-run) → boolean?
> (drracket:rep:module-language-initial-run initial-run?) → void?
> initial-run? : boolean?

The value of this parameter is #t in the dynamic extent of the call to evaluate-from-port that sets up the initial read-eval-print loop (which doesn’t run the user’s program)
top contents ← prev up next →