[racket] Writing a single key binding in DrRacket for commenting/uncommenting

From: Laurent (laurent.orseau at gmail.com)
Date: Mon Nov 25 08:36:24 EST 2013

Not considering keybindings, you may also be interested in the various
commenting styles, in particular the "#|" and "|#" comments, that comment
several lines, and the "#;" comment which, if placed right before an
opening parenthesis, comments the following code up to the corresponding
closing parenthesis:
http://docs.racket-lang.org/reference/reader.html?q=%23%3B#%28idx._%28gentag._65._%28lib._scribblings%2Freference%2Freference..scrbl%29%29%29

Laurent


On Mon, Nov 25, 2013 at 2:23 PM, Robby Findler
<robby at eecs.northwestern.edu>wrote:

> 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.colin.e at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131125/ef11da03/attachment-0001.html>

Posted on the users mailing list.