Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active December 18, 2015 03:39
Show Gist options
  • Save Metaxal/5719809 to your computer and use it in GitHub Desktop.
Save Metaxal/5719809 to your computer and use it in GitHub Desktop.
Copy/paste example for keymap and text editors
#lang racket/gui
(require framework) ; for keymap:get-editor
(define keymap (keymap:get-editor))
#| ; Or define them yourself:
(define keymap (new keymap%))
(add-text-keymap-functions keymap)
(send keymap map-function "c:x" "cut-clipboard")
(send keymap map-function "c:c" "copy-clipboard")
(send keymap map-function "c:v" "paste-clipboard")
(send keymap map-function "middlebutton" "paste-x-selection")
|#
(define text (new text%))
(send text set-keymap keymap)
(define fr (new frame% [label ""]))
(define ed (new editor-canvas% [parent fr]
[editor text]
[min-width 400] [min-height 400]))
(send ed focus)
(send fr show #t)
@Metaxal
Copy link
Author

Metaxal commented Jun 7, 2013

Also possible:

#lang racket/gui

(define text (new text%))
((current-text-keymap-initializer) (send text get-keymap))

(define fr (new frame% [label ""]))
(define ed (new editor-canvas% [parent fr]
[editor text]
[min-width 400] [min-height 400]))

(send ed focus)
(send fr show #t)

but on Linux, the default bindings are then Emacs' ones (i.e., no Ctrl-x/c/v).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment