Last active
October 21, 2021 02:49
-
-
Save Calvin-LL/8c463dac8e4167f67d543d954f5f48c8 to your computer and use it in GitHub Desktop.
DrRacket Code Formatting Keybinding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang s-exp framework/keybinding-lang | |
(require fmt) | |
(define (format editor event) | |
(define text (send editor get-text)) | |
;; for more options, see https://docs.racket-lang.org/fmt/ | |
(define formatted-text (program-format text #:max-blank-lines +inf.0)) | |
(send editor insert formatted-text 0 (string-length text) #f)) | |
(define (format-selection editor event) | |
(define start-pos (send editor get-start-position)) | |
(define end-pos (send editor get-end-position)) | |
(define text (send editor get-text start-pos end-pos)) | |
;; for more options, see https://docs.racket-lang.org/fmt/ | |
(define formatted-text (program-format text #:max-blank-lines +inf.0)) | |
(send editor insert formatted-text start-pos end-pos #f)) | |
;; d is for the command key on Macs | |
;; s is for the shift key | |
;; a is for the option key | |
;; f is for the f key | |
(keybinding "d:s:f" format) | |
(keybinding "d:s:g" format-selection) | |
;; use this keybinding instead if you're not using a Mac | |
;; c is for the control key | |
;; s is for the shift key | |
;; a is for the alt key | |
;; f is for the f key | |
; (keybinding "c:s:f" format) | |
; (keybinding "c:s:g" format-selection) | |
;; for more details, see https://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This keybinding formats the current Racket file when you press
control+shift+f
orcommand+shift+f
and formats the current selection withcontrol+shift+g
orcommand+shift+g
To add this binding
fmt