Compare commits
2 Commits
4e96ae7df8
...
96778ac47d
| Author | SHA1 | Date | |
|---|---|---|---|
| 96778ac47d | |||
| 86ebac5578 |
@@ -16,3 +16,6 @@ compiled/
|
|||||||
# Dependency tracking files
|
# Dependency tracking files
|
||||||
*.dep
|
*.dep
|
||||||
|
|
||||||
|
scrbl/*.html
|
||||||
|
scrbl/*.js
|
||||||
|
scrbl/*.css
|
||||||
@@ -1,3 +1,41 @@
|
|||||||
# rackedit
|
# rackedit
|
||||||
|
|
||||||
Starts a simple racket editor window from DrRacket or the racket command line, given a file to edit.
|
`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.
|
||||||
|
|
||||||
|
The package exports one procedure:
|
||||||
|
|
||||||
|
```racket
|
||||||
|
(require rackedit)
|
||||||
|
|
||||||
|
(rkdt "notes.rkt")
|
||||||
|
```
|
||||||
|
|
||||||
|
By default `rkdt` shows the editor and returns immediately. Use `#:wait? #t`
|
||||||
|
when execution should continue only after the editor is closed:
|
||||||
|
|
||||||
|
```racket
|
||||||
|
(rkdt "notes.rkt" #:wait? #t)
|
||||||
|
```
|
||||||
|
|
||||||
|
The initial window geometry can be specified with `#:width`, `#:height`, `#:x`,
|
||||||
|
and `#:y`. Window positions and sizes are remembered per internal editor number
|
||||||
|
and per screen configuration.
|
||||||
|
|
||||||
|
The frame can be customized with `#:frame-cb`. For example:
|
||||||
|
|
||||||
|
```racket
|
||||||
|
(require racket/class
|
||||||
|
rackedit)
|
||||||
|
|
||||||
|
(rkdt "notes.rkt"
|
||||||
|
#:frame-cb
|
||||||
|
(λ (frame)
|
||||||
|
(send frame set-label "Notes")))
|
||||||
|
```
|
||||||
|
|
||||||
|
The standard File menu does not contain the Exit/Quit command, so closing one
|
||||||
|
editor window does not imply exiting the application that opened it.
|
||||||
|
|
||||||
|
Full API documentation is included as Scribble documentation in
|
||||||
|
`scrbl/rkdt.scrbl`.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#lang info
|
#lang info
|
||||||
|
|
||||||
(define pkg-authors '(hnmdijkema))
|
(define pkg-authors '(hnmdijkema))
|
||||||
(define version "0.1.1")
|
(define version "0.1.5")
|
||||||
(define license 'MIT) ;
|
(define license 'MIT) ;
|
||||||
(define collection "rackedit")
|
(define collection "rackedit")
|
||||||
(define pkg-desc "rackedit exports the rkdt procedure, that can be used to open an editor window with a given file")
|
(define pkg-desc "rackedit exports the rkdt procedure, that can be used to open an editor window with a given file")
|
||||||
@@ -24,6 +24,4 @@
|
|||||||
"draw-doc"
|
"draw-doc"
|
||||||
"rackunit-lib"
|
"rackunit-lib"
|
||||||
"scribble-lib"
|
"scribble-lib"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
(super on-move x y)
|
(super on-move x y)
|
||||||
)
|
)
|
||||||
|
|
||||||
(define/override (on-size w h)
|
(define/override (on-size w h)
|
||||||
(set! my-w w)
|
(set! my-w w)
|
||||||
(set! my-h h)
|
(set! my-h h)
|
||||||
(super on-size w h)
|
(super on-size w h)
|
||||||
@@ -48,6 +48,12 @@
|
|||||||
(define/override (file-menu:create-quit?)
|
(define/override (file-menu:create-quit?)
|
||||||
#f)
|
#f)
|
||||||
|
|
||||||
|
(define cb (λ args #t))
|
||||||
|
|
||||||
|
(define/public (set-frame-cb! frame-cb)
|
||||||
|
(set! cb frame-cb)
|
||||||
|
)
|
||||||
|
|
||||||
(define/augment (on-close)
|
(define/augment (on-close)
|
||||||
(close-cb my-number my-x my-y my-w my-h)
|
(close-cb my-number my-x my-y my-w my-h)
|
||||||
(set! open-editor-use-list
|
(set! open-editor-use-list
|
||||||
@@ -58,6 +64,7 @@
|
|||||||
(not (= x my-number)))
|
(not (= x my-number)))
|
||||||
open-editor-use-list))
|
open-editor-use-list))
|
||||||
(semaphore-post closed)
|
(semaphore-post closed)
|
||||||
|
(cb 'on-close this)
|
||||||
(inner (void) on-close))
|
(inner (void) on-close))
|
||||||
|
|
||||||
(define/public (get-num)
|
(define/public (get-num)
|
||||||
@@ -96,7 +103,7 @@
|
|||||||
#:height [height 650]
|
#:height [height 650]
|
||||||
#:x [x 100]
|
#:x [x 100]
|
||||||
#:y [y 100]
|
#:y [y 100]
|
||||||
#:frame-cb [frame-cb (λ (frame) #t)])
|
#:frame-cb [frame-cb (λ (call-time frame) #t)])
|
||||||
|
|
||||||
(let* ((store-cfg #f)
|
(let* ((store-cfg #f)
|
||||||
(closed (make-semaphore 0))
|
(closed (make-semaphore 0))
|
||||||
@@ -140,17 +147,18 @@
|
|||||||
(send frame set-label (format "~a (~a)"
|
(send frame set-label (format "~a (~a)"
|
||||||
(send frame get-label)
|
(send frame get-label)
|
||||||
win-num))
|
win-num))
|
||||||
|
|
||||||
(string-append (send frame get-label)
|
(send frame set-frame-cb! frame-cb)
|
||||||
" - Rash"))
|
(frame-cb 'before-show frame)
|
||||||
|
|
||||||
(send frame show #t)
|
(send frame show #t)
|
||||||
|
(frame-cb 'after-show frame)
|
||||||
|
|
||||||
(when wait? (yield closed))
|
(when wait?
|
||||||
|
(frame-cb 'wait-for-close frame)
|
||||||
|
(yield closed)
|
||||||
|
)
|
||||||
|
|
||||||
(frame-cb frame)
|
(void))))
|
||||||
|
|
||||||
(void)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#lang scribble/manual
|
||||||
|
|
||||||
|
@(require (for-label racket/base
|
||||||
|
racket/class
|
||||||
|
"../main.rkt"))
|
||||||
|
|
||||||
|
@title{rackedit}
|
||||||
|
@author[@author+email["Hans Dijkema" "hans@dijkewijk.nl"]]
|
||||||
|
|
||||||
|
|
||||||
|
@defmodule[rackedit]
|
||||||
|
|
||||||
|
@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.
|
||||||
|
|
||||||
|
@section{Opening an editor}
|
||||||
|
|
||||||
|
@defproc[(rkdt [filename path-string?]
|
||||||
|
[#:wait? wait? boolean? #f]
|
||||||
|
[#:width width exact-positive-integer? 900]
|
||||||
|
[#:height height exact-positive-integer? 650]
|
||||||
|
[#:x x exact-integer? 100]
|
||||||
|
[#:y y exact-integer? 100]
|
||||||
|
[#:frame-cb frame-cb procedure? (λ (frame) #t)])
|
||||||
|
void?]{
|
||||||
|
|
||||||
|
Opens an editor window for @racket[filename]. The file name is passed to the
|
||||||
|
Racket editor frame and the editor is shown immediately.
|
||||||
|
|
||||||
|
The @racket[#:width], @racket[#:height], @racket[#:x], and @racket[#:y]
|
||||||
|
arguments specify the initial geometry for a window for which no stored geometry
|
||||||
|
is available. When an editor window is closed, @tt{rackedit} stores its position
|
||||||
|
and size. A later editor window with the same internal window number restores
|
||||||
|
that geometry.
|
||||||
|
|
||||||
|
Stored geometry is associated with the current screen configuration. The screen
|
||||||
|
configuration is derived from the number and dimensions of the displays visible
|
||||||
|
to Racket. Consequently, changing the monitor configuration causes the default
|
||||||
|
geometry, or geometry previously stored for that configuration, to be used.
|
||||||
|
|
||||||
|
If @racket[wait?] is @racket[#f], the procedure returns after the editor has
|
||||||
|
been shown. If @racket[wait?] is @racket[#t], the current event handler waits
|
||||||
|
until the editor window is closed before the procedure continues.
|
||||||
|
|
||||||
|
The @racket[frame-cb] procedure receives the editor frame. With the default
|
||||||
|
@racket[#:wait?] value it is called after the frame has been shown and can be
|
||||||
|
used to customize the frame, for example to change its title. When
|
||||||
|
@racket[wait?] is @racket[#t], the callback is called only after the window has
|
||||||
|
been closed. Its return value is ignored.
|
||||||
|
|
||||||
|
Each open editor has an internal number. That number is shown in the window
|
||||||
|
title and is also used to distinguish stored window geometries. Numbers of
|
||||||
|
closed editor windows are reused.
|
||||||
|
}
|
||||||
|
|
||||||
|
@section{Examples}
|
||||||
|
|
||||||
|
The simplest use opens a file and returns immediately:
|
||||||
|
|
||||||
|
@racketblock[
|
||||||
|
(require rackedit)
|
||||||
|
|
||||||
|
(rkdt "notes.rkt")
|
||||||
|
]
|
||||||
|
|
||||||
|
Use @racket[#:wait? #t] when execution should continue only after the editor is
|
||||||
|
closed:
|
||||||
|
|
||||||
|
@racketblock[
|
||||||
|
(rkdt "notes.rkt" #:wait? #t)
|
||||||
|
]
|
||||||
|
|
||||||
|
A frame callback can customize the editor frame:
|
||||||
|
|
||||||
|
@racketblock[
|
||||||
|
(require racket/class
|
||||||
|
rackedit)
|
||||||
|
|
||||||
|
(rkdt "notes.rkt"
|
||||||
|
#:frame-cb
|
||||||
|
(λ (frame)
|
||||||
|
(send frame set-label "Notes")))
|
||||||
|
]
|
||||||
|
|
||||||
|
The initial window geometry can be supplied explicitly:
|
||||||
|
|
||||||
|
@racketblock[
|
||||||
|
(rkdt "notes.rkt"
|
||||||
|
#:width 1200
|
||||||
|
#:height 800
|
||||||
|
#:x 50
|
||||||
|
#:y 50)
|
||||||
|
]
|
||||||
|
|
||||||
|
@section{Window behavior}
|
||||||
|
|
||||||
|
The editor uses Racket's standard editor menus, except that the standard
|
||||||
|
@onscreen{Exit} or @onscreen{Quit} command is not added to the File menu.
|
||||||
|
Closing an editor window closes only that window and releases its internal
|
||||||
|
window number for reuse by a later editor window.
|
||||||
Reference in New Issue
Block a user