Last active
June 26, 2023 09:00
-
-
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
This file contains hidden or 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 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