Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active August 19, 2022 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Metaxal/f45ea1a893a1bdedaadbeafd11144e3d to your computer and use it in GitHub Desktop.
Save Metaxal/f45ea1a893a1bdedaadbeafd11144e3d to your computer and use it in GitHub Desktop.
Quickscript for sorawee's `fmt`
#lang racket/base
(require quickscript
fmt ; needs to be installed first
racket/class)
;;; Author: Laurent Orseau
;;; License: [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or
;;; [MIT license](http://opensource.org/licenses/MIT) at your option.
(script-help-string "Format the selection or the whole program using `fmt`")
(define-script fmt
#:label "fmt"
#:menu-path ("Re&factor")
(λ (selection #:definitions defs)
(cond
[(equal? selection "")
(define txt (send defs get-text))
(define new-txt (program-format txt))
(send defs begin-edit-sequence)
(send defs erase)
(send defs insert new-txt)
(send defs end-edit-sequence)
#f]
[else (program-format selection)])))
(module url2script-info racket/base
(provide filename url)
(define filename "fmt.rkt")
(define url "https://gist.github.com/Metaxal/f45ea1a893a1bdedaadbeafd11144e3d"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment