1 %% -*- Mode: Scheme -*-
5 %%;; to be define later, in a closure
6 #(define-public toplevel-module-define-public
! #f)
7 #(define-public toplevel-module-ref
#f)
8 #(let
((toplevel-module
(current-module
)))
9 (set
! toplevel-module-define-public
!
10 (lambda
(symbol value
)
11 (module-define
! toplevel-module symbol value
)
12 (module-export
! toplevel-module
(list symbol
))))
13 (set
! toplevel-module-ref
15 (module-ref toplevel-module symbol
))))
17 #(defmacro-public define-public-toplevel
19 "Define a public variable or function in the toplevel module:
20 (define-public-toplevel variable-name value)
22 (define-public-toplevel (function-name . args)
24 (if
(symbol? first-arg
)
25 ;;
(define-public-toplevel symbol value
)
26 (let
((symbol first-arg
)
28 `
(toplevel-module-define-public
! ',symbol
,value
))
29 ;;
(define-public-toplevel
(function-name
. args
) . body
)
30 (let
((function-name
(car first-arg
))
31 (arg-list
(cdr first-arg
))
33 `
(toplevel-module-define-public
!
35 (let
((proc
(lambda
,arg-list
37 (set-procedure-property
! proc
42 #(defmacro-public define-markup-command
(command-and-args signature
. body
)
44 * Define a COMMAND-markup function after command-and-args and body,
45 register COMMAND-markup and its signature,
47 * add COMMAND-markup to markup-function-list,
49 * sets COMMAND-markup markup-signature and markup-keyword object properties,
51 * define a make-COMMAND-markup function.
54 (define-markup-command (COMMAND layout props arg1 arg2 ...)
55 (arg1-type? arg2-type? ...)
56 \"documentation string\"
59 (define-markup-command COMMAND (arg1-type? arg2-type? ...) function)
61 (let
* ((command
(if
(pair? command-and-args
)
62 (car command-and-args
)
64 (command-name
(string-
>symbol
(format
#f "~a-markup" command
)))
65 (make-markup-name
(string-
>symbol
(format
#f "make-~a-markup" command
))))
67 ;; define the COMMAND-markup procedure in toplevel module
68 ,(if
(pair? command-and-args
)
69 ;;
1/ (define
(COMMAND-markup layout props arg
1 arg
2 ...)
71 `
(define-public-toplevel
(,command-name
,@
(cdr command-and-args
))
73 ;;
2/ (define
(COMMAND-markup
. args
) (apply function args
))
74 (let
((args
(gensym
"args"))
76 `
(define-public-toplevel
(,command-name
. ,args
)
77 (apply
,command
,args
))))
78 (let
((command-proc
(toplevel-module-ref
',command-name
)))
79 ;; register its command signature
80 (set
! (markup-command-signature command-proc
)
82 ;; define the make-COMMAND-markup procedure in the toplevel module
83 (define-public-toplevel
(,make-markup-name
. args
)
84 (make-markup command-proc
85 ,(symbol-
>string make-markup-name
)
89 #(defmacro-public define-markup-list-command
(command-and-args signature
. body
)
90 "Same as `define-markup-command', but defines a command that, when interpreted,
91 returns a list of stencils, instead of a single one."
92 (let
* ((command
(if
(pair? command-and-args
)
93 (car command-and-args
)
95 (command-name
(string-
>symbol
(format
#f "~a-markup-list" command
)))
96 (make-markup-name
(string-
>symbol
(format
#f "make-~a-markup-list" command
))))
98 ;; define the COMMAND-markup-list procedure in toplevel module
99 ,(if
(pair? command-and-args
)
100 ;;
1/ (define
(COMMAND-markup-list layout props arg
1 arg
2 ...)
102 `
(define-public-toplevel
(,command-name
,@
(cdr command-and-args
))
104 ;;
2/ (define
(COMMAND-markup-list
. args
) (apply function args
))
105 (let
((args
(gensym
"args"))
106 (command
(car body
)))
107 `
(define-public-toplevel
(,command-name
. ,args
)
108 (apply
,command
,args
))))
109 (let
((command-proc
(toplevel-module-ref
',command-name
)))
110 ;; register its command signature
111 (set
! (markup-command-signature command-proc
)
113 ;; it
's a markup-list command
:
114 (set-object-property
! command-proc
'markup-list-command
#t
)
115 ;; define the make-COMMAND-markup-list procedure in the toplevel module
116 (define-public-toplevel
(,make-markup-name
. args
)
117 (list
(make-markup command-proc
118 ,(symbol-
>string make-markup-name
)