From 0d3b55f252945b45003c9d830406daebbabc4ef1 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Thu, 20 Aug 2026 23:21:43 +0200 Subject: [PATCH] Made it possible not to give a filename --- README.md | 12 +++++++++--- info.rkt | 2 +- main.rkt | 6 ++++-- scrbl/rkdt.scrbl | 32 +++++++++++++++++++++++--------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b5b82b9..28426bb 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,19 @@ # rackedit -`rackedit` opens a simple Racket editor window for a file. It can be used from -DrRacket, from a Racket program, or from the Racket command line. +`rackedit` opens a simple Racket editor window, optionally with a file. It can be +used from DrRacket, from a Racket program, or from the Racket command line. -The package exports one procedure: +The package exports one procedure. With no filename, `rkdt` opens an empty editor: ```racket (require rackedit) +(rkdt) +``` + +Pass a filename to open an existing file: + +```racket (rkdt "notes.rkt") ``` diff --git a/info.rkt b/info.rkt index ea9f66c..94c23fc 100644 --- a/info.rkt +++ b/info.rkt @@ -1,7 +1,7 @@ #lang info (define pkg-authors '(hnmdijkema)) -(define version "0.1.5") +(define version "0.1.7") (define license 'MIT) ; (define collection "rackedit") (define pkg-desc "rackedit exports the rkdt procedure, that can be used to open an editor window with a given file") diff --git a/main.rkt b/main.rkt index 1ab9a14..a4db70c 100644 --- a/main.rkt +++ b/main.rkt @@ -97,7 +97,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define (rkdt filename +(define (rkdt [filename #f] #:wait? [wait? #f] #:width [width 900] #:height [height 650] @@ -109,7 +109,9 @@ (closed (make-semaphore 0)) (frame (new (make-editor-frame% closed (λ (num x y w h) (store-cfg num x y w h))) - [filename (format "~a" filename)] + [filename (if (eq? filename #f) + #f + (format "~a" filename))] [editor% racket:text%] [width 900] [height 650] diff --git a/scrbl/rkdt.scrbl b/scrbl/rkdt.scrbl index 353ed89..b0fb6e1 100644 --- a/scrbl/rkdt.scrbl +++ b/scrbl/rkdt.scrbl @@ -2,6 +2,7 @@ @(require (for-label racket/base racket/class + racket/contract "../main.rkt")) @title{rackedit} @@ -11,12 +12,12 @@ @tt{rackedit} provides a small editor window based on Racket's GUI framework. It is intended for situations where a program, DrRacket interaction, or command -line session needs to open a file in a simple Racket editor without starting a -separate full editor application. +line session needs a simple Racket editor, optionally for a specific file, without +starting a separate full editor application. @section{Opening an editor} -@defproc[(rkdt [filename path-string?] +@defproc[(rkdt [filename (or/c path-string? #f) #f] [#:wait? wait? boolean? #f] [#:width width exact-positive-integer? 900] [#:height height exact-positive-integer? 650] @@ -26,11 +27,14 @@ separate full editor application. (λ (call-time frame) #t)]) void?]{ -@bold{Purpose.} Opens an editor window for @racket[filename]. +@bold{Purpose.} Opens an editor window. When @racket[filename] is a path or +string, that file is opened. When @racket[filename] is @racket[#f], which is the +default, an empty editor is opened. -@bold{Preconditions.} @racket[filename] identifies the file to open. -@racket[frame-cb] must accept two arguments: a lifecycle symbol and the editor -frame. The geometry arguments specify valid dimensions and screen coordinates. +@bold{Preconditions.} When supplied, @racket[filename] identifies the file to +open. @racket[frame-cb] must accept two arguments: a lifecycle symbol and the +editor frame. The geometry arguments specify valid dimensions and screen +coordinates. @bold{Postconditions.} An editor frame has been created and shown. When @racket[wait?] is @racket[#f], @racket[rkdt] returns after the frame has been @@ -40,7 +44,11 @@ shown and the @racket['after-show] callback has run. When @racket[wait?] is @bold{Result.} The procedure returns @racket[(void)]. The editor frame itself is made available to @racket[frame-cb] during its lifecycle callbacks. -@bold{Internal workings.} Each open editor receives an internal number. That +@bold{Internal workings.} A non-false @racket[filename] is converted to a +string before it is supplied to the Framework editor frame. A false filename is +passed through as @racket[#f], causing the frame to start without a file. + +Each open editor receives an internal number. That number is appended to the window title and is used to distinguish stored window geometry. Numbers belonging to closed editors are reused. On close, the current position and size are stored for that internal number and the current screen @@ -85,11 +93,17 @@ between @racket['after-show] and @racket['on-close]. @section{Examples} -The simplest use opens a file and returns immediately: +The simplest use opens an empty editor and returns immediately: @racketblock[ (require rackedit) +(rkdt) +] + +Supply a filename to open a file: + +@racketblock[ (rkdt "notes.rkt") ]