I’m trying to implement a keybinding to get me more familiar with the editor toolkit. I’m working on modifying the Ctrl+E keybinding so it behaves more like the Ctrl+A keybinding (which, once at the beginning of the line, toggles between the true beginning of the line and the beginning of non-whitespace text on the line). The behavior I want is (I think) outlined pretty well in the code below, but to be clear: if the cursor is already at the line end, I want Ctrl+E to make the cursor jump to (right after) the end of the last s-exp that ends to the left of the cursor on the present line if there is such a s-exp. (The cursor can stay put if there is no such s-exp.)
#lang s-exp framework/keybinding-lang
(require drracket/tool-lib)
(define (at-EOL? ed) ; text% -> Boolean, #true iff cursor is right before newline
(define sp (send ed get-start-position))
(= sp
(send ed get-end-position)
(send ed line-end-position (send ed find-line sp))))
(define (go-to-eol ed evt)
(send (send ed get-keymap) call-function "end-of-line" ed evt #t))
(define (go-to-end-of-code-on-line ed) ;; text% -> void?
;; jump to the end of the code that is on the current line
(void)) ;; TODO
(keybinding "c:e" (λ (ed evt)
(if (at-EOL? ed)
(go-to-end-of-code-on-line ed)
(go-to-eol ed evt))))