Thanks Urs, Seeing how the Document and Cursor classes are used there was enough to put me on the right track. I've achieved what I was going for with this:
%%% begin test.py %%% import ly.document import ly.indent music = '''\\new Staff << \\relative c' { c4 c c c } | >>>''' d = ly.document.Document(music) c = ly.document.Cursor(d) i = ly.indent.Indenter() c.select_all() i.indent(c) print (d.plaintext()) %%% end test.py %%% $ python3 test.py \new Staff << \relative c' { c4 c c c } | >>> Best, Mason On 08/17, Urs Liska wrote: > Just shortly: does > > https://github.com/frescobaldi/python-ly/blob/master/ly/cli/main.py > > and > > https://github.com/frescobaldi/python-ly/blob/master/ly/cli/command.py#L116 > > help you further? I thought it would be best to look how the ly command line > program does it. > > Urs > > > Am 17. August 2019 03:00:47 MESZ schrieb ma...@masonhock.com: > >Hi all, > > > >The command line tools provided by python-ly are very > >convenient and easy to use, but I'm finding it a little harder to wrap > >my head around the Python module. > > > >For example, it is easy to automatically indent a file with > > > >$ ly "indent" file.ly > > > >or to indent the output of another command such as > > > >$ cat file.ly | ly "indent" > > > >I'd like to be able to do something similar in Python, using ly.indent > >to indent files or (preferably) strings. It seems that ly.indent might > >be what I want, but I'm having trouble figuring out how it works. The > >Indenter() class, with an indent() function, is defined here,[1] but > >I'm > >don't understand what a cursor object is or how to create and pass one. > >I next tried looking through Frescobaldi's code for example usage and > >found this,[2] but I think I would need to learn more about how > >Frescobaldi works in order to follow what's happening, which is deeper > >than I want to go to indent a string of Lilypond code. > > > >Is there a simple way to use ly.indent similarly to `ly "indent"`, or > >would I be better off invoking `ly "indent"` externally with > >os.system()? > > > >Thanks, > > > >Mason > > > >[1] > >https://github.com/frescobaldi/python-ly/blob/0d91ca2450ba01a8158f53ba05202af3e13bf78d/ly/indent.py > > > >[2] > >https://github.com/frescobaldi/frescobaldi/blob/09cae764126b505dedf0182beccd78d7934b2de4/frescobaldi_app/indent.py > > -- > Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet. > _______________________________________________ > lilypond-user mailing list > lilypond-user@gnu.org > https://lists.gnu.org/mailman/listinfo/lilypond-user
signature.asc
Description: PGP signature
_______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user