Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active June 26, 2023 09:00
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/2a57a6788028b98535ab1aabb0b3e1aa to your computer and use it in GitHub Desktop.
Save Metaxal/2a57a6788028b98535ab1aabb0b3e1aa to your computer and use it in GitHub Desktop.
A proof-of-concept quickscript to run the main file in the same directory
#lang racket/base
;;; 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.
(require quickscript
quickscript/utils
racket/file
racket/path
racket/class)
(define-script run-main-file
#:label "Run main file"
(λ (selection #:frame fr #:file f)
(when f
(define dir (path-only f))
(define main.rkt (build-path dir "main.rkt"))
(smart-open-file fr main.rkt)
(send fr execute-callback))
#f))
;=============;
;=== Tests ===;
;=============;
(define-script run-main-file-test
#:label "Run main file: create test case"
(λ (selection #:frame fr)
(define dir (make-temporary-directory))
(define a.rkt (build-path dir "a.rkt"))
(display-to-file "\
#lang racket
(provide foo)
(define (foo x)
(list x (+ x 10)))
;; Now click on \"Scripts|Run main file\"
"
a.rkt)
(define main.rkt (build-path dir "main.rkt"))
(display-to-file "\
#lang racket
(require \"a.rkt\")
(foo (random 100))
;; Look at the interactions, then go back to a.rkt, change something and
;; click on \"Scripts|Run main file\" again
"
main.rkt)
(smart-open-file fr a.rkt)
#f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment