One note not related to what you ask: lines in editor<%> parlance are
soft-breaking; the methods about paragraphs are the ones you want.

Robby


On Tue, Jul 2, 2019 at 11:41 AM Jordan Johnson <j...@fellowhuman.com> wrote:

> Dear Racket folks,
>
> 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.)
>
> Here’s what I have so far:
>
> ;;;
> #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))))
> ;;;
>
> Two questions for those of you who know the editor toolkit well:
>
>    1. Given what’s in the tool-lib, what’d be the best way to approach
>    writing *go-to-end-of-code-on-line*? (I was thinking: save cursor
>    position & line no; move left/backward by one s-exp; then move
>    right/forward by one s-exp; then check if still on the same line, and if
>    not restore the cursor position from before the moves.)
>    2. Does it look like I’m on the right track, otherwise?
>
>
> Thanks,
> Jordan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/641F6290-D258-4D8D-B774-CAF5D9327204%40fellowhuman.com
> <https://groups.google.com/d/msgid/racket-users/641F6290-D258-4D8D-B774-CAF5D9327204%40fellowhuman.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAL3TdOO-1u_25gOUGjhQXdWii4jkyub9F1PfWH6wZ0kG%2BEtp%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to