LilyPond comments
=================

LilyPond comments begin with the ``%`` sign.  Abjad models LilyPond comments as
marks.


Creating LilyPond comments
--------------------------

Use ``marktools`` to create LilyPond comments:

<abjad>
message_1 = 'This is a LilyPond comment before a note.'
comment_1 = marktools.LilyPondComment(message_1, 'before')
</abjad>

<abjad>
comment_1
</abjad>


Attaching LilyPond comments to leaves
-------------------------------------

Attach LilyPond comments to a note, rest or chord with ``attach()``:

<abjad>
note = Note("cs''4")
</abjad>

<abjad>
show(note)
</abjad>

<abjad>
comment_1.attach(note)
</abjad>

<abjad>
f(note)
</abjad>

You can add LilyPond comments before, after or to the right of any leaf.


Attaching LilyPond comments to containers
-----------------------------------------

Use ``attach()`` to attach LilyPond comments to a container:

<abjad>
staff = Staff("c'8 d'8 e'8 f'8")
</abjad>

<abjad>
show(staff)
</abjad>

<abjad>
message_1 = 'Here is a LilyPond comment before the staff.'
message_2 = 'Here is a LilyPond comment in the staff opening.'
message_3 = 'Here is another LilyPond comment in the staff opening.'
message_4 = 'LilyPond comment in the staff closing.'
message_5 = 'LilyPond comment after the staff.'
</abjad>

<abjad>
staff_comment_1 = marktools.LilyPondComment(message_1, 'before')
staff_comment_2 = marktools.LilyPondComment(message_2, 'opening')
staff_comment_3 = marktools.LilyPondComment(message_3, 'opening')
staff_comment_4 = marktools.LilyPondComment(message_4, 'closing')
staff_comment_5 = marktools.LilyPondComment(message_5, 'after')
</abjad>

<abjad>
staff_comment_1.attach(staff)
staff_comment_2.attach(staff)
staff_comment_3.attach(staff)
staff_comment_4.attach(staff)
staff_comment_5.attach(staff)
</abjad>

<abjad>
f(staff)
</abjad>

You can add LilyPond comments before, after, in the opening or in the closing
of any container.


Getting the LilyPond comments attached to a component
-----------------------------------------------------

Use the inspector to get the LilyPond comments attached to a component:

<abjad>
inspect(note).get_marks(marktools.LilyPondComment)
</abjad>


Detaching LilyPond comments from a component
--------------------------------------------

Use ``detach()`` to detach LilyPond comments from a component:

<abjad>
comment_1 = inspect(note).get_marks(marktools.LilyPondComment)[0]
</abjad>

<abjad>
comment_1.detach()
</abjad>

<abjad>
f(note)
</abjad>


Detaching all LilyPond comments attached to a component
-------------------------------------------------------

Write a loop to detach all LilyPond comments attached to a component:

<abjad>
comments = inspect(staff).get_marks(marktools.LilyPondComment)
for comment in comments:
    print comment
</abjad>

<abjad>
for comment in comments:
    comment.detach()
</abjad>

<abjad>
f(staff)
</abjad>


Inspecting the component to which a LilyPond comment is attached
----------------------------------------------------------------

Use ``start_component`` to inspect the component to which a LilyPond comment is
attached:

<abjad>
comment_1.attach(note)
</abjad>

<abjad>
comment_1.start_component
</abjad>


Inspecting the contents string of a LilyPond comment
----------------------------------------------------

Use ``contents_string`` to inspect the written contents of a LiliyPond comment:

<abjad>
comment_1.contents_string
</abjad>
