On 2017-01-08 6:01 PM, Thomas Morley wrote:
#(define my-settings
  '(
    (indent . 10)
    (short-indent . 10)
    (line-width . 80)
   ))

#(for-each
  (lambda (settings)
    (ly:output-def-set-variable! $defaultpaper (car settings) (cdr settings)))
  my-settings)

This works when copied and pasted into a test file, but when I try to apply the same thing to the test file with the -e command line argument I an error:

lilypond-dev -e="(define my-settings '((indent . 0)(line-width . 80)))" 
-e="(for-each (lambda (settings) (ly:output-def-set-variable! \$defaultpaper (car settings) 
(cdr settings))) my-settings)" test.ly
GNU LilyPond 2.19.53
<unnamed port>:3:5: While evaluating arguments to ly:output-def-set-variable! 
in expression (ly:output-def-set-variable! $defaultpaper (car settings) ...):
<unnamed port>:3:5: Unbound variable: $defaultpaper

It would appear that the Scheme expressions which are evaluated using `-e` are processed before the necessary variables are initialized.

Checking some of the other expressions I need to be able to manipulate, I get other errors:

lilypond-dev -e="(set-global-staff-size 11)" test.ly
GNU LilyPond 2.19.53
/Applications/LilyPond-dev.app/Contents/Resources/share/lilypond/current/scm/paper.scm:109:15:
 In procedure ly:parser-lookup in expression (ly:parser-lookup (quote 
$defaultpaper)):
/Applications/LilyPond-dev.app/Contents/Resources/share/lilypond/current/scm/paper.scm:109:15:
 Wrong type (expecting Lily_parser): #f

and for the lilypond-book-preamble:

lilypond-dev -e="(define default-toplevel-book-handler
  print-book-with-defaults-as-systems )" -e="(define 
toplevel-music-handlertest.ly
  (lambda ( . rest)
   (apply collect-music-for-book rest)))" -e="(define toplevel-score-handler
  (lambda ( . rest)
   (apply collect-scores-for-book rest)))" -e="(define toplevel-text-handler
  (lambda ( . rest)
   (apply collect-scores-for-book rest)))" -e="(set! output-empty-score-list #t)" -e="(ly:set-option 'backend 
'eps)" -e="(ly:set-option (quote no-point-and-click))" -e="(define inside-lilypond-book #t)" -e="(define 
version-seen #t)" test.ly
GNU LilyPond 2.19.53
<unnamed port>:8:44: In expression (set! output-empty-score-list #t):
<unnamed port>:8:44: Unbound variable: output-empty-score-list


I'm fairly certain both of these are due to the fact that the scheme expressions are being evaluated before LilyPond has initialized enough of the score herself for the code to make sense.

Given that there appears to be a timing issue, I thought I'd try the `--init` option with the following file:

%%%%% contents of file my_init.ly
\version "2.19.53"

\include "init.ly"


\version "2.16.0"

%% toplevel \book gets output per page,
%% everything else gets output per system/title
#(define default-toplevel-book-handler
  print-book-with-defaults-as-systems )

#(define toplevel-book-handler
  (lambda ( . rest)
  (set! output-empty-score-list #f)
  (apply print-book-with-defaults rest)))

#(define toplevel-music-handler
  (lambda ( . rest)
   (apply collect-music-for-book rest)))

#(define toplevel-score-handler
  (lambda ( . rest)
   (apply collect-scores-for-book rest)))

#(define toplevel-text-handler
  (lambda ( . rest)
   (apply collect-scores-for-book rest)))

#(set! output-empty-score-list #t)


#(ly:set-option 'backend 'eps)
#(ly:set-option (quote no-point-and-click))
#(define inside-lilypond-book #t)
#(define version-seen #t)

\paper{
    indent = 0\mm
    line-width = 4.3\in
}

%%%%% end my_init.ly

With this file saved to the same folder as my test score, `lilypond-dev --init="my_init.ly" test.ly` produces identical results to `lilypond-dev test.ly`. I would, therefore, guess that while LilyPond has initialized enough for the code to make sense (i.e. not cause errors the way putting this stuff in an `-e` argument on the command-line does), my_init.ly is still getting executed too early because the settings in it are being overwritten by their default values.

So, unless there is a hook somewhere accessible to either `-e` or `--init` that I can use to get the code executed at the right time (i.e. after LilyPond is finished setting the default values but before she actually starts interpreting test.ly), or some way to protect the settings in `my_init.ly` so that LilyPond doesn't/can't change them later, I'm going to have to do something that requires editing the source file before it can be used.

Here's hoping someone can prove me wrong.
--
✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝
Br. Samuel, OSB
St. Anselm’s Abbey
Washington, DC
(R. Padraic Springuel)

PAX ☧ ΧΡΙΣΤΟΣ

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to