lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chose module name instead of *anonymous-ly-NN*?


From: Jan Nieuwenhuizen
Subject: Re: chose module name instead of *anonymous-ly-NN*?
Date: Wed, 21 Apr 2004 10:58:55 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Nicolas Sceaux writes:

> Is it possible to specify the scheme module name used for declaring
> variables in a LilyPond file? Or is it possible to know what module
> name (the *anonymous-ly-NN*s) will be used the next time a Lily file
> will be parsed?

No, I don't think so, and I'm also not sure if or how we want to do that,
but I've added ly:parse-string (see CVS)


foe.ly:
#(use-modules (scm toetoe))

#(define (textoffset dx dy)
  #{ \override Voice.TextScript #'extra-offset = #(cons $dx $dy) #})

myoffset = #(textoffset 3 -4)

\score {
    \notes {
        c'^"normal text"
        %% uhrg, I cannot write scheme here
        %% #(textoffset 3 -4)

        \myoffset
        c'^"text with offset"
    }
}


;; toetoe.scm
(define-module (lily))

(define-module (scm toetoe))
(use-modules (ice-9 format) (lily))

(define-public (ly:parse-string-vartmp str)
    (ly:parse-string
     (format #f "
\\include \"declarations-init.ly\"
%% do nothing special with toplevel music
#(define (toplevel-music-handler x y) (display \"hi\") (newline))

vartmp = \\notes { ~a }

#(export vartmp)
#(define-module (scm toetoe))
#(use-modules (*anonymous-ly-15*))

~%" str))
    vartmp)

(define-public (read-lily-expression chr port)
  (let* ((format-args '())
         (lily-string (with-output-to-string
                        (lambda ()
                          (do ((c (read-char port) (read-char port)))
                              ((and (char=? c #\#)
                                    (char=? (peek-char port) #\}))
                               (read-char port))
                            (cond ((and (char=? c #\$)
                                        (not (char=? (peek-char port) #\$)))
                                   ;; a $variable
                                   (display "~a")
                                   (set! format-args (cons (read port) 
format-args)))
                                  ((and (char=? c #\$)
                                        (char=? (peek-char port) #\$))
                                   ;; just a $ character
                                   (display (read-char port)))
                                  (else
                                   ;; other caracters
                                   (display c))))))))
    `(ly:parse-string-vartmp (format #f ,lily-string ,@(reverse! 
format-args)))))

(read-hash-extend #\{ read-lily-expression)



-- 
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]