Nice job! One point where the docs are confusing: "line"s are soft-wrapped, not hard-wrapped lines. For code you want the methods with the word "paragraph" in the name instead of "line".
I'm not seeing why your code doesn't work at the beginning of the line, but if you start up drracket from the command-line and then put printfs into your functions, you should be able to see intermediate values and you can check what's going on. Or, if you're on windows, you might find it easier to call "message-box", ie: (define is-line-commented? (lambda (editor) (define ans (send editor find-string ";" 'forward (get-start-of-line editor) (get-end-of-line editor))) (message-box "hi" (format "ans ~s" ans)) ans)) Robby On Sat, Nov 23, 2013 at 9:42 AM, Colin Gan <gan.coli...@gmail.com> wrote: > Hi all, > > I have recently picked up Scheme and would like to customize the key > bindings in DrScheme. Specifically, I find the default binding for > commenting and uncommenting out to be cumbersome; on OSX it is esc;c:= and > esc;c:semicolon. > > What I would like to achieve is use one key to comment and uncomment, so > it comments an uncommented line, and vice versa. Unfortunately I'm finding > the documentation on key-binding a little sparse. Here's what I've been > working at: > > > (define get-start-of-line > (lambda (editor) > (send editor get-character (send editor line-start-position > (send editor position-line (send editor get-start-position)))))) > > (define is-line-commented? > (lambda (editor) > (cond > ((eq? ";" > (get-start-of-line editor) )#t) > (else #f)))) > > (keybinding "d:/" (λ (editor evt) (if (is-line-commented? editor) > (send editor uncomment-selection > (send editor get-start-position)) > (send editor comment-out-selection > (send editor get-start-position)) > ))) > > > I know it's not very well written; I've only just finished the recursion > section of The Little Schemer. I was going to leave it here, then I had > another look at the documentation and had another go: > > (define get-start-of-line > (lambda (editor) > (send editor line-start-position > (send editor position-line (send editor get-start-position))))) > > (define get-end-of-line > (lambda (editor) > (send editor line-end-position > (send editor position-line (send editor get-end-position))))) > > (define is-line-commented? > (lambda (editor) > (send editor find-string > ";" 'forward (get-start-of-line editor) (get-end-of-line > editor)))) > > > (keybinding "d:/" (λ (editor evt) (if (is-line-commented? editor) > (send editor uncomment-selection > (send editor get-start-position)) > (send editor comment-out-selection > (send editor get-start-position)) > ))) > > > This one actually works, but of course it is clumsy and dumb; it doesn't > work when the caret is at the start of each line, and doesn't know if the > semi-colon is escaped. I'm thrilled anyway. :) > > > Colin > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users > >
____________________ Racket Users list: http://lists.racket-lang.org/users