On this page:
racket:  sexp-snip<%>
get-saved-snips
racket:  sexp-snip%
get-text
copy
write
draw
get-extent
racket:  text<%>
get-limit
get-backward-navigation-limit
balance-parens
tabify-on-return?
tabify
tabify-selection
tabify-all
compute-racket-amount-to-indent
compute-amount-to-indent
insert-return
box-comment-out-selection
comment-out-selection
region-comment-out-selection
uncomment-box/  selection
uncomment-selection
uncomment-selection/  box
uncomment-selection/  line
uncomment-selection/  region
commented-out/  line?
commented-out/  region?
get-forward-sexp
remove-sexp
forward-sexp
flash-forward-sexp
get-backward-sexp
flash-backward-sexp
backward-sexp
find-up-sexp
up-sexp
find-down-sexp
down-sexp
remove-parens-forward
select-forward-sexp
select-backward-sexp
select-up-sexp
select-down-sexp
transpose-sexp
mark-matching-parenthesis
get-tab-size
set-tab-size
introduce-let-ans
move-sexp-out
racket:  text-mixin
get-word-at
get-start-of-line
racket:  text-mode<%>
racket:  text-mode-mixin
new
on-disable-surrogate
on-enable-surrogate
racket:  set-mode-mixin
racket:  text%
racket:  text-mode%
racket:  text-balanced?
racket:  default-paren-matches
racket:  add-preferences-panel
racket:  get-keymap
racket:  get-paren-keymap
racket:  get-non-paren-keymap
racket:  add-pairs-keybinding-functions
racket:  map-pairs-keybinding-functions
racket:  add-coloring-preferences-panel
racket:  get-color-prefs-table
racket:  get-white-on-black-color-prefs-table
racket:  short-sym->pref-name
racket:  short-sym->style-name
racket:  get-wordbreak-map
racket:  init-wordbreak-map
racket:  setup-keymap

29 Racket🔗ℹ

method

(send a-racket:sexp-snip get-saved-snips)

  (listof (is-a?/c snip%))
This returns the list of snips hidden by the sexp snip.

class

racket:sexp-snip% : class?

  superclass: snip%

  extends: racket:sexp-snip<%>
 readable-snip<%>

method

(send a-racket:sexp-snip get-text offset    
  num    
  [flattened?])  string?
  offset : number?
  num : number?
  flattened? : boolean? = #f
Overrides get-text in snip%.
Returns the concatenation of the text for all of the hidden snips.

method

(send a-racket:sexp-snip copy)  (is-a?/c racket:sexp-snip%)

Overrides copy in snip%.
Returns a copy of this snip that includes the hidden snips.

method

(send a-racket:sexp-snip write stream-out)  void?

  stream-out : (is-a?/c editor-stream-out%)
Overrides write in snip%.
Saves the embedded snips

method

(send a-racket:sexp-snip draw dc    
  x    
  y    
  left    
  top    
  right    
  bottom    
  dx    
  dy    
  draw-caret)  void?
  dc : dc<%>
  x : real?
  y : real?
  left : real?
  top : real?
  right : real?
  bottom : real?
  dx : real?
  dy : real?
  draw-caret : symbol?
Overrides draw in snip%.
Draws brackets with a centered ellipses between them.

method

(send a-racket:sexp-snip get-extent dc    
  x    
  y    
  [w    
  h    
  descent    
  space    
  lspace    
  rspace])  void?
  dc : (is-a?/c dc<%>)
  x : real?
  y : real?
  w : (or/c (box/c (and/c real? (not/c negative?))) #f) = #f
  h : (or/c (box/c (and/c real? (not/c negative?))) #f) = #f
  descent : (or/c (box/c (and/c real? (not/c negative?))) #f)
   = #f
  space : (or/c (box/c (and/c real? (not/c negative?))) #f) = #f
  lspace : (or/c (box/c (and/c real? (not/c negative?))) #f)
   = #f
  rspace : (or/c (box/c (and/c real? (not/c negative?))) #f)
   = #f
Overrides get-extent in snip%.
Returns a size corresponding to what this snip draws.

Texts matching this interface support Racket mode operations.

method

(send a-racket:text get-limit start)  exact-integer?

  start : exact-integer?
Returns a limit for backward-matching parenthesis starting at position start.

method

(send a-racket:text get-backward-navigation-limit start)

  exact-integer?
  start : exact-integer?
Calls get-limit.

method

(send a-racket:text balance-parens key-event)  void?

  key-event : (is-a?/c key-event%)
This function is called when the user types a close parenthesis in the text%. If the close parenthesis that the user inserted does not match the corresponding open parenthesis and the 'framework:fixup-parens preference is #t (see preferences:get) the correct closing parenthesis is inserted. If the 'framework:paren-match preference is #t (see preferences:get) the matching open parenthesis is flashed.

method

(send a-racket:text tabify-on-return?)  boolean?

The result of this method is used to determine if the return key automatically tabs over to the correct position.

Override it to change its behavior.

method

(send a-racket:text tabify [start-pos])  void?

  start-pos : exact-integer? = (send this get-start-position)
Tabs the line containing by start-pos

method

(send a-racket:text tabify-selection [start    
  end])  void?
  start : exact-integer? = (send this get-start-position)
  end : exact-integer? = (send this get-end-position)
Sets the tabbing for the lines containing positions start through end.

method

(send a-racket:text tabify-all)  void?

Tabs all lines.

Indentation results depend on the graphical context associated with the object; if there is not one, the indentation is based on the assumption that a fixed-width font is used. If the object is viewed in an editor-canvas% and top-level-window<%>, the actual font information is used to determine the initial number of spaces on a line.

method

(send a-racket:text compute-racket-amount-to-indent 
  pos 
  [get-head-sexp-type]) 
  exact-nonnegative-integer?
  pos : exact-nonnegative-integer?
  get-head-sexp-type : (-> string? (or/c #f 'lambda 'define 'begin 'for/fold 'other))
   = (λ (x) #f)
This method is final, so it cannot be overridden.
Computes the amount of space to indent the line containing pos, using the default s-expression indentation strategy.

The function get-head-sexp-type is consulted for each symbol/keyword that follows an open parenthesis. If it returns #f, then the user’s preferences (from the Indenting panel of the Editing panel in the preferences dialog) are used.

Indentation results depend on the graphical context associated with the object; if there is not one, the indentation is based on the assumption that a fixed-width font is used. If the object is viewed in an editor-canvas% and top-level-window<%>, the actual font information is used to determine the initial number of spaces on a line.

Added in version 1.9 of package gui-lib.
Changed in version 1.26: Added the get-head-sexp-type argument.

Refine this method with augment.
Computes the amount of space to indent the line containing pos.

Defaults to using using the default s-expression indentation strategy via compute-racket-amount-to-indent.

Added in version 1.9 of package gui-lib.

method

(send a-racket:text insert-return)  void?

Inserts a newline into the buffer. If tabify-on-return? returns #t, this will tabify the new line. Deletes any trailing whitespace from the old line.

method

(send a-racket:text box-comment-out-selection [start-pos    
  end-pos])  #t
  start-pos : (or/c 'start exact-integer?) = 'start
  end-pos : (or/c 'end exact-integer?) = 'end
This method comments out a selection in the text by putting it into a comment box.

Removes the region from start-pos to end-pos from the editor and inserts a comment box with that region of text inserted into the box.

If start-pos is 'start, the starting point of the selection is used. If end-pos is 'end, the ending point of the selection is used.

method

(send a-racket:text comment-out-selection [start-pos 
  end-pos 
  #:start start 
  #:padding padding]) 
  #t
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : (and/c string? (not/c #rx"[\r\n]")) = ";"
  padding : (and/c string? (not/c #rx"[\r\n]")) = ""
Comments the lines containing positions start-pos through end-pos by inserting a start followed by padding at the start of each paragraph.

method

(send a-racket:text region-comment-out-selection 
  [start-pos 
  end-pos 
  #:start start 
  #:end end 
  #:continue continue 
  #:padding padding]) 
  #t
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : (and/c string? (not/c #rx"[\r\n]")) = "#|"
  end : (and/c string? (not/c #rx"[\r\n]")) = "|#"
  continue : (and/c string? (not/c #rx"[\r\n]")) = ""
  padding : (and/c string? (not/c #rx"[\r\n]")) = "  "
Comments the region between start-pos and end-pos by inserting a start at start-pos, end at end-pos, and continue followed by padding at the start of each paragraph between start-pos and end-pos.

method

(send a-racket:text uncomment-box/selection [#:start start 
  #:padding padding]) 
  #t
  start : (and/c string? (not/c #rx"[\r\n]")) = ";"
  padding : (and/c string? (not/c #rx"[\r\n]")) = ""
If the result of get-focus-snip is a comment snip, then removes the comment snip. Otherwise, calls uncomment-selection with start and padding.

method

(send a-racket:text uncomment-selection [start-pos    
  end-pos    
  #:start start])  void?
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : string = ";"
Uncomments the paragraphs containing positions start-pos through end-pos if it has line-based comments or a box comment.

Specifically, checks for a box comment and, if present removes it. If a box comment is not present, then removes line-based comments (if any) on the paragraphs between start-pos and end-pos.

method

(send a-racket:text uncomment-selection/box [start-pos 
  end-pos]) 
  boolean?
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
Checks for a box comment and, if present removes it. Returns #t if it found (and removed) a box comment, and #f if it did not find a box comment.

method

(send a-racket:text uncomment-selection/line 
  [start-pos 
  end-pos 
  #:start start 
  #:padding padding]) 
  #t
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : (and/c string? (not/c #rx"[\r\n]")) = ";"
  padding : (and/c string? (not/c #rx"[\r\n]")) = ""
Removes each occurrence of start that appears (potentially following whitespace) at the start of each paragraph that enclose the range between start-pos and end-pos.

method

(send a-racket:text uncomment-selection/region 
  [start-pos 
  end-pos 
  #:start start 
  #:end end 
  #:continue continue 
  #:padding padding]) 
  #t
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : (and/c string? (not/c #rx"[\r\n]")) = "#|"
  end : (and/c string? (not/c #rx"[\r\n]")) = "|#"
  continue : (and/c string? (not/c #rx"[\r\n]")) = ""
  padding : (and/c string? (not/c #rx"[\r\n]")) = "  "
Removes the region comment on the paragraphs between start-pos and end-pos.

method

(send a-racket:text commented-out/line? [start-pos 
  end-pos 
  #:start start 
  #:padding padding]) 
  boolean?
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : (and/c string? (not/c #rx"[\r\n]")) = ";"
  padding : (and/c string? (not/c #rx"[\r\n]")) = ""
Considers each paragraph between start-pos and end-pos, returning #t if any of them have the line comment start commenting any portion of them out.

method

(send a-racket:text commented-out/region? [start-pos 
  end-pos 
  #:start start 
  #:end end 
  #:continue continue]) 
  boolean?
  start-pos : exact-nonnegative-integer? = (get-start-position)
  end-pos : exact-nonnegative-integer? = (get-end-position)
  start : (and/c string? (not/c #rx"[\r\n]")) = "#|"
  end : (and/c string? (not/c #rx"[\r\n]")) = "|#"
  continue : (and/c string? (not/c #rx"[\r\n]")) = ""
Returns #t if the paragraphs at start-pos and end-pos have start and end in them and the paragraphs in between start with continue.

method

(send a-racket:text get-forward-sexp start)

  (or/c #f exact-integer?)
  start : exact-integer?
Returns the position of the end of next S-expression after position start, or #f if there is no appropriate answer.

method

(send a-racket:text remove-sexp start)  void?

  start : exact-integer?
Forward-deletes the S-expression starting after the position start.

method

(send a-racket:text forward-sexp start)  void?

  start : exact-integer?
Moves forward over the S-expression starting at position start.

method

(send a-racket:text flash-forward-sexp start-pos)  void?

  start-pos : exact-integer?
Flashes the parenthesis that closes the sexpression at start-pos.

method

(send a-racket:text get-backward-sexp start)

  (or/c exact-integer? #f)
  start : exact-integer?
Returns the position of the start of the S-expression before or containing start, or #f if there is no appropriate answer.

method

(send a-racket:text flash-backward-sexp start-pos)  void?

  start-pos : exact-integer?
Flashes the parenthesis that opens the sexpression at start-pos.

method

(send a-racket:text backward-sexp start-pos)  void?

  start-pos : exact-integer?
Move the caret backwards one sexpression

Moves the caret to the beginning of the sexpression that ends at start-pos.

method

(send a-racket:text find-up-sexp start-pos)

  (or/c #f exact-integer?)
  start-pos : exact-integer?
Returns the position of the beginning of the next sexpression outside the sexpression that contains start-pos. If there is no such sexpression, it returns #f.

method

(send a-racket:text up-sexp start)  void?

  start : exact-integer?
Moves backward out of the S-expression containing the position start.

method

(send a-racket:text find-down-sexp start-pos)

  (or/c #f exact-integer?)
  start-pos : exact-integer?
Returns the position of the beginning of the next sexpression inside the sexpression that contains start-pos. If there is no such sexpression, it returns #f.

method

(send a-racket:text down-sexp start)  void?

  start : exact-integer?
Moves forward into the next S-expression after the position start.

method

(send a-racket:text remove-parens-forward start)  void?

  start : exact-integer?
Removes the parentheses from the S-expression starting after the position start.

method

(send a-racket:text select-forward-sexp)  void?

Selects the next S-expression, starting at the start of the current selection.

method

(send a-racket:text select-backward-sexp)  void?

Selects the previous S-expression, starting at the start of the current selection.

method

(send a-racket:text select-up-sexp)  void?

Selects the region to the enclosing S-expression, starting at the start of the current selection.

method

(send a-racket:text select-down-sexp)  void?

Selects the region to the next contained S-expression, starting at the start of the current selection.

method

(send a-racket:text transpose-sexp start)  void?

  start : exact-integer?
Swaps the S-expression beginning before the position start with the next S-expression following start.

method

(send a-racket:text mark-matching-parenthesis pos)  void?

  pos : exact-positive-integer?
If the paren after pos is matched, this method highlights it and its matching counterpart in dark green.

method

(send a-racket:text get-tab-size)  exact-integer?

This method returns the current size of the tabs for scheme mode. See also set-tab-size.

method

(send a-racket:text set-tab-size new-size)  void?

  new-size : exact-integer?
This method sets the tab size for this text.

method

(send a-racket:text introduce-let-ans start-pos)  void?

  start-pos : exact-integer?
Adds a let around the current s-expression and a printf into the body of the let.

method

(send a-racket:text move-sexp-out start-pos)  void?

  start-pos : exact-integer?
Replaces the sexpression surrounding the insertion point with the sexpression following the insertion point.

mixin

racket:text-mixin : (class? . -> . class?)

  argument extends/implements: text:basic<%>
 mode:host-text<%>
 color:text<%>
 text:autocomplete<%>
 editor:keymap<%>
  result implements: racket:text<%>
This mixin adds functionality for editing Racket files.
The result of this mixin uses the same initialization arguments as the mixin’s argument.

method

(send a-racket:text get-word-at pos)  string?

  pos : exact-positive-integer?
Returns the word just before pos, which is then used as the prefix for auto-completion.

method

(send a-racket:text get-start-of-line pos)

  exact-nonnegative-integer?
  pos : exact-nonnegative-integer?
Returns the first non-whitespace character in the paragraph containing pos, unless the position is already there, in which case it returns the first position of the paragraph.

The result of racket:text-mode-mixin implements this interface.

mixin

racket:text-mode-mixin : (class? . -> . class?)

  argument extends/implements: color:text-mode<%>
 mode:surrogate-text<%>
  result implements: racket:text-mode<%>
This mixin adds Racket mode functionality to the mode that it is mixed into. The resulting mode assumes that it is only set to an editor that is the result of racket:text-mixin.

constructor

(new racket:text-mode-mixin [[include-paren-keymap? include-paren-keymap?]])

  (is-a?/c racket:text-mode-mixin)
  include-paren-keymap? : boolean? = #t
If include-paren-keymap? is #f only the result of racket:get-non-paren-keymap is used by on-enable-surrogate; otherwise the result of racket:get-keymap is used.

Added in version 1.64 of package gui-lib.

method

(send a-racket:text-mode on-disable-surrogate)  void?

Removes the racket keymap (see also racket:get-keymap) and disables any parenthesis highlighting in the host editor.

method

(send a-racket:text-mode on-enable-surrogate)  void?

Adds the racket keymap (see also racket:get-keymap) and enables a parenthesis highlighting in the host editor.

mixin

racket:set-mode-mixin : (class? . -> . class?)

  argument extends/implements: racket:text<%>
 mode:host-text<%>
This mixin creates a new instance of racket:text-mode% and installs it, by calling its own set-surrogate method with the object.

procedure

(racket:text-balanced? text [start end])  boolean?

  text : (is-a?/c text%)
  start : number? = 0
  end : (or/c false/c number?) = #f
Determines if the range in the editor from start to end in text has at least one complete s-expression and there are no incomplete s-expressions. If end is #f, it defaults to the last position of the text. The designation “complete” is defined to be something that does not cause read to raise a exn:fail:read:eof? exception, so there may be all kinds of strange read-level (not to speak of parse level) errors in the expressions.

The implementation of this function creates a port with open-input-text-editor and then uses read to parse the range of the buffer.
The default parentheses that are matched when using racket:text-mode-mixin.

Added in version 1.60 of package gui-lib.

Adds a tabbing preferences panel to the preferences dialog.

procedure

(racket:get-keymap)  (is-a?/c keymap%)

Returns a keymap with binding suitable for Racket; the keymap is created with racket:setup-keymap where the paren-keymap is not #f but a keymap, and that keymap is added to the result of this function via chain-to-keymap. The paren-keymap argument is also the result of racket:get-paren-keymap.
Returns a keymap with binding suitable for the parentheses keystrokes in Racket; the keymap is created and passed to racket:setup-keymap as the paren-keymap argument. See also racket:get-keymap

Added in version 1.64 of package gui-lib.

Returns a keymap with all of the bindings in the keymap returned by racket:get-keymap except those in the keymap returned by racket:get-paren-keymap

Added in version 1.64 of package gui-lib.

procedure

(racket:add-pairs-keybinding-functions keymap)  void?

  keymap : (is-a?/c keymap%)
Adds keybindings that are intended to be bound to parenthesis characters to keymap. See racket:setup-keymap for more information.

Added in version 1.64 of package gui-lib.

procedure

(racket:map-pairs-keybinding-functions 
  keymap 
  open 
  close 
  [#:alt-as-meta-keymap alt-as-meta-keymap]) 
  void?
  keymap : (is-a?/c keymap%)
  open : char?
  close : char?
  alt-as-meta-keymap : (or/c #f (is-a?/c keymap%)) = #f
Binds a number of parenthesis-related keystrokes:

If any of these functions are no present in keymap, they are also added to it.

The alt-as-meta-keymap argument is treated as keymap:setup-global treats it.

Added in version 1.64 of package gui-lib.

Installs the “Racket” preferences panel in the “Syntax Coloring” section.
Returns a table mapping from symbols (naming the categories that the online colorer uses for Racket mode coloring) to their colors.

These symbols are suitable for input to racket:short-sym->pref-name and racket:short-sym->style-name.

Returns a table mapping from symbols (naming the categories that the online colorer uses for Racket mode coloring) to their colors when the user chooses the white-on-black mode in the preferences dialog.

procedure

(racket:short-sym->pref-name short-sym)  symbol?

  short-sym : symbol?
Builds the symbol naming the preference from one of the symbols in the table returned by racket:get-color-prefs-table.

procedure

(racket:short-sym->style-name short-sym)  string?

  short-sym : symbol?
Builds the symbol naming the editor style from one of the symbols in the table returned by racket:get-color-prefs-table. This style is a named style in the style list returned by editor:get-standard-style-list.
This method returns a editor-wordbreak-map% that is suitable for Racket.

procedure

(racket:init-wordbreak-map key)  void?

  key : (is-a?/c keymap%)
Initializes the workdbreak map for keymap.

procedure

(racket:setup-keymap 
  keymap 
  [#:alt-as-meta-keymap alt-as-meta-keymap 
  #:paren-keymap paren-keymap 
  #:paren-alt-as-meta-keymap paren-alt-as-meta-keymap]) 
  void?
  keymap : (is-a?/c keymap%)
  alt-as-meta-keymap : (or/c #f (is-a?/c keymap%)) = #f
  paren-keymap : (or/c #f (is-a?/c keymap%)) = #f
  paren-alt-as-meta-keymap : (or/c #f (is-a?/c keymap%)) = #f
Initializes keymap with Racket-mode keybindings.

The alt-as-meta-keymap argument is treated the same as for keymap:setup-global. The paren-alt-as-meta-keymap argument is similar, but matched up with paren-keymap and used only when paren-keymap is not #f.

The paren-keymap is filled with the keybindings that are bound to parentheses in the default racket keymap, which is done by calling racket:map-pairs-keybinding-functions with the keymap and the characters #\[ and #\], #\( and #\), #\{ and #\}, #\| and #\|, and #\" and #\".

Changed in version 1.40 of package gui-lib: Added the #:alt-as-meta-keymap argument.
Changed in version 1.64: Added the #:paren-keymap and paren-alt-as-meta-keymap arguments.