Creating rest-delimited slurs
=============================

Take a look at the slurs in the following example and notice that
there is a pattern to how they arranged.

<abjad>[hide=true]
string = r"""
    \times 2/3 { c'4 d' r } 
    r8 e'4 <fs' a' c''>8 ~ q4 
    \times 4/5 { r16 g' r b' d'' } 
    df'4 c' ~ c'1
    """
staff = Staff(string)
leaves = iterationtools.iterate_leaves_in_expr(staff)
for group in iterationtools.iterate_runs_in_expr(leaves, (Note, Chord)):
    if 1 < len(group):
        slur = spannertools.SlurSpanner(group)

show(staff)
</abjad>

The pattern?  Slurs in the example span groups of notes and chords separated by rests.

Abjad makes it easy to create rest-delimited slurs in a structured way.


Entering input
--------------

Let's start with the note input like this:

<abjad>
string = r"""
    \times 2/3 { c'4 d' r } 
    r8 e'4 <fs' a' c''>8 ~ q4 
    \times 4/5 { r16 g' r b' d'' } 
    df'4 c' ~ c'1
    """
staff = Staff(string)
show(staff)
</abjad>


Grouping notes and chords
-------------------------

Next we'll group notes and chords together with one of the functions
available in the ``componenttools`` package.

We add slur spanners inside our loop:

<abjad>
leaves = iterationtools.iterate_leaves_in_expr(staff)
for group in iterationtools.iterate_runs_in_expr(leaves, (Note, Chord)):
    spannertools.SlurSpanner(group)

</abjad>

Here's the result:

<abjad>
show(staff)
</abjad>

But there's a problem.

Four slur spanners were generated but only three slurs are shown.

Why? Because LilyPond ignores one-note slurs.


Skipping one-note slurs
-----------------------

Let's rewrite our example to prevent that from happening:

<abjad>
staff = Staff(string)
leaves = iterationtools.iterate_leaves_in_expr(staff)
classes = (Note, Chord)
for group in iterationtools.iterate_runs_in_expr(leaves, classes):
    if 1 < len(group):
        spannertools.SlurSpanner(group)
</abjad>

And here's the corrected result:

<abjad>
show(staff)
</abjad>
