From f0c1a065436911746e38d161fa497ff9350702fd Mon Sep 17 00:00:00 2001
From: Valentin Villenave <valentin@localhost.(none)>
Date: Wed, 8 Oct 2008 19:14:54 +0200
Subject: [PATCH] Added showFirstLength feature

This commits implements a showFirstLength property, that does
the opposite of showLastLength (both properties can't be set,
as showLastLength overrides showFirstLength).  This new feature
may be very convenient, e.g. to print the index of a book
containing only the beginning of each \score.
---
 Documentation/user/input.itely                     |    5 ++-
 Documentation/user/working.itely                   |    4 +-
 .../skiptypesetting-show-last-or-first.ly          |   23 +++++++++++++
 input/regression/skiptypesetting-show-last.ly      |   18 ----------
 scm/music-functions.scm                            |   34 +++++++++++++++++++-
 5 files changed, 62 insertions(+), 22 deletions(-)
 create mode 100644 input/regression/skiptypesetting-show-last-or-first.ly
 delete mode 100644 input/regression/skiptypesetting-show-last.ly

diff --git a/Documentation/user/input.itely b/Documentation/user/input.itely
index c5f7f55..3ca8018 100644
--- a/Documentation/user/input.itely
+++ b/Documentation/user/input.itely
@@ -1269,6 +1269,7 @@ For more information on output formats, see @rprogram{Invoking lilypond}.
 
 @funindex skipTypesetting
 @funindex showLastLength
+@funindex showFirstLength
 
 When entering or copying music, usually only the music near the end (where
 you
@@ -1285,7 +1286,9 @@ showLastLength = R1*5
 in your source file.  This will render only the last 5 measures
 (assuming 4/4 time signature) of every @code{\score} in the input
 file.  For longer pieces, rendering only a small part is often an order
-of magnitude quicker than rendering it completely
+of magnitude quicker than rendering it completely.  When working on the
+beginning of a score you have already typeset (e.g. to add a new part),
+the @code{showFirstLength} property may be useful as well.
 
 Skipping parts of a score can be controlled in a more fine-grained
 fashion with the property @code{Score.skipTypesetting}.  When it is
diff --git a/Documentation/user/working.itely b/Documentation/user/working.itely
index c6007c7..e24cc48 100644
--- a/Documentation/user/working.itely
+++ b/Documentation/user/working.itely
@@ -128,8 +128,8 @@ piece of existing sheet music),
 
 @item Enter one manuscript (the physical copy) system at a time (but still
 only one bar per line of text), and
-check each system when you finish it.  You may use the
-@code{showLastLength} command to speed up processing -- see
+check each system when you finish it.  You may define the
+@code{showLastLength} property to speed up processing -- see
 @ruser{Skipping corrected music}.
 
 @item Define @code{mBreak = @{ \break @}} and insert @code{\mBreak}
diff --git a/input/regression/skiptypesetting-show-last-or-first.ly b/input/regression/skiptypesetting-show-last-or-first.ly
new file mode 100644
index 0000000..f3e04e8
--- /dev/null
+++ b/input/regression/skiptypesetting-show-last-or-first.ly
@@ -0,0 +1,23 @@
+\header {
+
+  texidoc = "@code{showLastLength} will only show the last bit of a score;
+@code{showFirstLength} will only show the beginning."
+
+  }
+
+\version "2.11.62"
+
+music = {
+  c1 c1
+  c1 c1
+  c1 c1
+}
+
+showLastLength = R1*3
+
+\new Staff \music
+
+showLastLength = ""
+showFirstLength = R1
+
+\new Staff \music
\ No newline at end of file
diff --git a/input/regression/skiptypesetting-show-last.ly b/input/regression/skiptypesetting-show-last.ly
deleted file mode 100644
index def23fc..0000000
--- a/input/regression/skiptypesetting-show-last.ly
+++ /dev/null
@@ -1,18 +0,0 @@
-\header {
-
-  texidoc = "@code{showLastLength} will only show the last bit of a score"
-
-  }
-
-\version "2.11.51"
-
-showLastLength = R1*3
-\paper {
-  ragged-right = ##T
-}
-
-{
-  c1 c1
-  c1 c1
-  c1 c1
-}
diff --git a/scm/music-functions.scm b/scm/music-functions.scm
index 490cafe..d88a61f 100644
--- a/scm/music-functions.scm
+++ b/scm/music-functions.scm
@@ -823,6 +823,36 @@ Syntax:
 	(ly:music-length music))
   music)
 
+(define (skip-after-first music parser)
+  "Replace MUSIC by
+
+<< { LENGTHOF(\\showFirstLength)
+     \\set skipTypesetting = ##t }
+    MUSIC >>
+
+if appropriate.
+ "
+  (let*
+      ((show-first  (ly:parser-lookup parser 'showFirstLength)))
+    
+    (if (ly:music? show-first)
+	(let*
+	    ((skip-length (ly:music-length show-first)))
+
+	  (make-simultaneous-music
+	   (list
+	    (make-sequential-music
+	     (list
+	      (make-music 'SkipMusic 'duration
+			  (ly:make-duration
+			   0 0
+			   (ly:moment-main-numerator skip-length)
+			   (ly:moment-main-denominator skip-length)))
+	      (context-spec-music (make-property-set 'skipTypesetting #t)
+				  'Score)))
+	    music)))
+	music)))
+
 (define (skip-to-last music parser)
 
   "Replace MUSIC by
@@ -872,7 +902,9 @@ if appropriate.
    (lambda (x parser) (music-map cue-substitute x))
  
    (lambda (x parser)
-     (skip-to-last x parser)
+    (skip-after-first x parser))
+   (lambda (x parser)
+    (skip-to-last x parser)
    )))
 
 
-- 
1.6.0.2

