]> git.donarmstrong.com Git - lilypond.git/blob - ly/init.ly
Issue 2872: Provide define-session and define-session-public commands
[lilypond.git] / ly / init.ly
1 %% Toplevel initialisation file. 
2
3 %% switch on debugging.
4 #(if (and #t (defined? 'set-debug-cell-accesses!))
5   (set-debug-cell-accesses! 5000))
6
7 \version "2.16.0"
8
9 #(session-initialize
10   (lambda ()
11    ;; we can't use ly:parser-include-string here since that does not
12    ;; actually do any parsing but merely switches inputs, so the
13    ;; session saved by the session initializer after calling this
14    ;; function has not actually started.  A parser clone, in contrast,
15    ;; can run and complete synchronously and shares the module with
16    ;; the current parser.
17    (ly:parser-parse-string (ly:parser-clone parser)
18     "\\include \"declarations-init.ly\"")))
19
20 #(note-names-language parser default-language)
21
22 #(ly:set-option 'old-relative #f)
23 #(define toplevel-scores (list))
24 #(define toplevel-bookparts (list))
25 #(define $defaultheader #f)
26 #(define $current-book #f)
27 #(define $current-bookpart #f)
28 #(define version-seen #f)
29 #(define expect-error #f)
30 #(define output-empty-score-list #f)
31 #(define output-suffix #f)
32 #(hash-clear! default-fret-table)
33 #(hash-clear! chord-shape-table)
34 #(hash-clear! musicQuotes)
35
36 #(use-modules (scm clip-region))
37 #(use-modules (srfi srfi-1))
38
39 $(if (ly:get-option 'include-settings)
40   (ly:parser-include-string parser
41     (format #f "\\include \"~a\"" (ly:get-option 'include-settings))))
42
43 \maininput
44 %% there is a problem at the end of the input file
45
46 %%
47 %% Above and below comments compensate for the parser's look-ahead.
48 %%
49
50 #(if (and (ly:get-option 'old-relative)
51       (defined? 'input-file-name)
52       (not (ly:get-option 'old-relative-used)))
53   (old-relative-not-used-message input-file-name))%% there is a problem at the end of the input file
54
55 #(if (and (not version-seen)
56       (defined? 'input-file-name))
57   (version-not-seen-message input-file-name))
58
59 #(ly:set-option 'protected-scheme-parsing #f)
60
61 #(let ((book-handler (if (defined? 'default-toplevel-book-handler)
62                          default-toplevel-book-handler
63                          toplevel-book-handler)))
64    (cond ((pair? toplevel-bookparts)
65           (let ((book (ly:make-book $defaultpaper $defaultheader)))
66             (map (lambda (part)
67                    (ly:book-add-bookpart! book part))
68                  (reverse! toplevel-bookparts))
69             (set! toplevel-bookparts (list))
70             ;; if scores have been defined after the last explicit \bookpart:
71             (if (pair? toplevel-scores)
72                 (map (lambda (score)
73                        (ly:book-add-score! book score))
74                      (reverse! toplevel-scores)))
75             (set! toplevel-scores (list))
76             (book-handler parser book)))
77          ((or (pair? toplevel-scores) output-empty-score-list)
78           (let ((book (apply ly:make-book $defaultpaper 
79                              $defaultheader toplevel-scores)))
80             (set! toplevel-scores (list))
81             (book-handler parser book)))))
82
83 #(if (eq? expect-error (ly:parser-has-error? parser))
84   (ly:parser-clear-error parser)
85   (if expect-error
86    (ly:parser-error parser (_ "expected error, but none found"))))