[racket] How to check if a key is pressed within interaction block, and not declaration one.

From: Oleg Gunkin (oleg.gunkin at gmail.com)
Date: Wed Jul 11 16:02:16 EDT 2012

Basically, I want to change up/down key behaviour within interaction
window to "put-next-sexp"/ "put-previous-sexp" instead moving the
cursor, but only for interaction block.

This is what I came up with:

(require drracket/tool-lib)

(define (rebind key function original-function)
  (keybinding
   key
   (lambda (editor event)
     (send
      (send editor get-keymap)
      call-function
      (if (is-a? editor drracket:rep:text<%>)
          function
          original-function)
      editor event #t))))

(rebind "down" "put-next-sexp" "next-line")
(rebind "up" "put-previous-sexp" "previous-line")

However, (is-a? editor drracket:rep:text<%>) together with (require
drracket/tool-lib) crashes Dr. Racket. Is there an alternative way to
do this?

Posted on the users mailing list.