Skip to content

Instantly share code, notes, and snippets.

@Metaxal

Metaxal/open-multi.rkt

Last active Feb 1, 2021
Embed
What would you like to do?
Quickscript to open multiple files at once
#lang racket/base
;;; 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
racket/class
racket/string
racket/gui/base)
(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)
(cond
[(not (file-exists? f))
(message-box "Error"
(format "File not found: ~a" f)
drfr
'(ok stop))
#f]
[(send drfr still-untouched?)
(send drfr change-to-file f)
#t]
[(send drfr find-matching-tab f)
=>
(λ (tab)
(send drfr change-to-tab tab)
#t)]
[else
(send drfr open-in-new-tab f)
#t]))
(define-script open-multi
#:label "Open multiple files…"
(λ (selection #:frame fr)
(define files
(get-file-list "Select one or several Racket files"
fr
#f
#f
#f
'()
'(("Racket Sources" "*.rkt;*.scm;*.scrbl;*.ss;*.rktd;*.rktl")
("Any" "*.*"))))
(when files
(for ([f (in-list files)])
(smart-open-file fr f)))
#f))
(module url2script-info racket/base
(provide url filename)
(define filename "open-multi.rkt")
(define url "https://gist.github.com/Metaxal/3ed323747e1af0bd4df5acd56b03b45e/raw"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment