From: John Mandereau Date: Sat, 29 Dec 2007 22:49:07 +0000 (+0100) Subject: Add lilypond-book 'verbatim' option to 'lilypondfile' command X-Git-Tag: release/2.11.37-1~15 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=51c3823d581c9c9ea14b1653ce913891492df3bc;p=lilypond.git Add lilypond-book 'verbatim' option to 'lilypondfile' command --- diff --git a/Documentation/user/lilypond-book.itely b/Documentation/user/lilypond-book.itely index ef1176d435..f32e2d8844 100644 --- a/Documentation/user/lilypond-book.itely +++ b/Documentation/user/lilypond-book.itely @@ -655,6 +655,23 @@ enclosed in a verbatim block, followed by any text given with the displayed. This option does not work well with @code{\lilypond@{@}} if it is part of a paragraph. +If @code{verbatim} is used in a @code{lilypondfile} command, it is +possible to enclose verbatim only a part of the source file. If the +source file contain a comment containing @samp{begin verbatim} (without +quotes), quoting the source in the verbatim block will start after the +last occurence of such a comment; similarly, quoting the source verbatim +will stop just before the first occurence of a comment containing +@samp{end verbatim}, it there is any. In the following source file +example, the music will be interpreted in relative mode, but the +verbatim quote will not show the @code{relative} block. + +@example +\relative c' { % begin verbatim + c4 e2 g4 + f2 e % end verbatim +} +@end example + @item texidoc (Only for Texinfo output.) If @command{lilypond} is called with the @option{--header=@/texidoc} option, and the file to be processed is @@ -691,10 +708,11 @@ Most LilyPond test documents (in the @file{input} directory of the distribution) are small @file{.ly} files which look exactly like this. @item lilyquote -(Only for Texinfo output.) This is the same option as quote, but only -the music snippet is put into a quotation block. This option is useful -if you want to @code{quote} the music snippet but not the @code{texidoc} -documentation block. +(Only for Texinfo output.) This option is similar to quote, but only +the music snippet (and the optional verbatim block implied by +@code{verbatim} option) is put into a quotation block. This option is +useful if you want to @code{quote} the music snippet but not the +@code{texidoc} documentation block. @item printfilename If a LilyPond input file is included with @code{\lilypondfile}, print diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 7084350d5a..4e4c307782 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -875,6 +875,9 @@ class Lilypond_snippet (Snippet): os = match.group ('options') self.do_options (os, self.type) + def verb_ly (self): + return self.substring ('code') + def ly (self): contents = self.substring ('code') return ('\\sourcefileline %d\n%s' @@ -1169,7 +1172,7 @@ class Lilypond_snippet (Snippet): else: str = '' + str + '' if VERBATIM in self.option_dict: - verb = verbatim_html (self.substring ('code')) + verb = verbatim_html (self.verb_ly ()) str = output[DOCBOOK][VERBATIM] % vars () + str return str @@ -1179,7 +1182,7 @@ class Lilypond_snippet (Snippet): if global_options.format == HTML: str += self.output_print_filename (HTML) if VERBATIM in self.option_dict: - verb = verbatim_html (self.substring ('code')) + verb = verbatim_html (self.verb_ly ()) str += output[HTML][VERBATIM] % vars () if QUOTE in self.option_dict: str = output[HTML][QUOTE] % vars () @@ -1213,7 +1216,7 @@ class Lilypond_snippet (Snippet): if global_options.format == LATEX: str += self.output_print_filename (LATEX) if VERBATIM in self.option_dict: - verb = self.substring ('code') + verb = self.verb_ly () str += (output[LATEX][VERBATIM] % vars ()) str += (output[LATEX][OUTPUT] % vars ()) @@ -1251,16 +1254,16 @@ class Lilypond_snippet (Snippet): if os.path.exists (texidoc): str += '@include %(texidoc)s\n\n' % vars () + substr = '' if VERBATIM in self.option_dict: - verb = self.substring ('code') - str += output[TEXINFO][VERBATIM] % vars () + verb = self.verb_ly () + substr += output[TEXINFO][VERBATIM] % vars () if not QUOTE in self.option_dict: - str = output[TEXINFO][NOQUOTE] % vars () - + substr = output[TEXINFO][NOQUOTE] % {'str':substr} + substr += self.output_info () if LILYQUOTE in self.option_dict: - str += output[TEXINFO][QUOTE] % {'str':self.output_info ()} - else: - str += self.output_info () + substr = output[TEXINFO][QUOTE] % {'str':substr} + str += substr # str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n') # str += ('@tex\n' + self.output_latex () + '\n@end tex\n') @@ -1274,12 +1277,25 @@ class Lilypond_snippet (Snippet): return str +re_begin_verbatim = re.compile (r'\s+%.*?begin verbatim.*\n*', re.M) +re_end_verbatim = re.compile (r'\s+%.*?end verbatim.*$', re.M) + class Lilypond_file_snippet (Lilypond_snippet): + def __init__ (self, type, match, format, line_number): + Lilypond_snippet.__init__ (self, type, match, format, line_number) + self.contents = open (find_file (self.substring ('filename'))).read () + + def verb_ly (self): + s = self.contents + s = re_begin_verbatim.split (s)[-1] + s = re_end_verbatim.split (s)[0] + return s + def ly (self): name = self.substring ('filename') - contents = open (find_file (name)).read () return ('\\sourcefilename \"%s\"\n\\sourcefileline 0\n%s' - % (name, contents)) + % (name, self.contents)) + snippet_type_to_class = { 'lilypond_file': Lilypond_file_snippet,