Skip to content

Instantly share code, notes, and snippets.



Last active Feb 1, 2021
What would you like to do?
Quickscript to open multiple files at once
#lang racket/base
;;; License: [Apache License, Version 2.0]( or
;;; [MIT license]( at your option.
(require quickscript
(script-help-string "Open multiple files at once")
;; Opens a file in a new tab and returns whether opening was successful.
;; Checks if the file exists and displays a message box otherwise and returns #f.
;; Opens the file in the first tab if drracket is still-untouched?
;; Changes to the corresponding tab if the file is already open.
;; TODO: Move this function to quickscript/utils (?) as it's quite useful!
;; appears also in quickscript-competition-2020/open-recent
(define (smart-open-file drfr f)
[(not (file-exists? f))
(message-box "Error"
(format "File not found: ~a" f)
'(ok stop))
[(send drfr still-untouched?)
(send drfr change-to-file f)
[(send drfr find-matching-tab f)
(λ (tab)
(send drfr change-to-tab tab)
(send drfr open-in-new-tab f)
(define-script open-multi
#:label "Open multiple files…"
(λ (selection #:frame fr)
(define files
(get-file-list "Select one or several Racket files"
'(("Racket Sources" "*.rkt;*.scm;*.scrbl;*.ss;*.rktd;*.rktl")
("Any" "*.*"))))
(when files
(for ([f (in-list files)])
(smart-open-file fr f)))
(module url2script-info racket/base
(provide url filename)
(define filename "open-multi.rkt")
(define url ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment