lilypond-user
[Top][All Lists]
Advanced

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

Re: Including only definitions from a Lilypond file


From: Aaron Hill
Subject: Re: Including only definitions from a Lilypond file
Date: Fri, 14 Aug 2020 06:35:52 -0700
User-agent: Roundcube Webmail/1.4.2

On 2020-08-14 4:48 am, David Kastrup wrote:
All of the elements in a score are routed through hooks you can
redefine. So you can just redefine your various hooks to do nothing and
then include the file.

Would something like this work?

%%%%
\version "2.20.0"

#(begin
  (use-modules (ice-9 regex))
  (let* ((symbols
           (map (lambda (m) (string->symbol (match:substring m 1)))
                (list-matches "define ([a-z-]+-handler)"
                  (ly:gulp-file "declarations-init.ly"))))
         (procs (map primitive-eval symbols))
         (null-proc (lambda args #f)))
    (ly:parser-define! 'disableHandlers
      (define-void-function () ()
        (for-each
          (lambda (sym) (primitive-eval `(set! ,sym ,null-proc)))
          symbols)))
    (ly:parser-define! 'restoreHandlers
      (define-void-function () ()
        (for-each
          (lambda (sym proc) (primitive-eval `(set! ,sym ,proc)))
          symbols procs)))))

assert =
#(define-void-function
  (expr)
  (scheme?)
  (or (primitive-eval expr)
      (ly:error "Assertion failed: ~s" expr)))

\disableHandlers

foo = { f'4 4 2 }
\assert #'(defined? 'foo)

\markup "Hidden"
{ \foo }
\assert #'(eq? 0 (length toplevel-scores))

\restoreHandlers

\markup "Visible"
{ \foo }
\assert #'(eq? 2 (length toplevel-scores))
%%%%


-- Aaron Hill



reply via email to

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