Re: indent-ly
Greetings, Martin Tarenskeen - I'd like to use your indent-ly. I copied and saved it from http://www.home.zonnet.nl/m.tarenskeen/tmp/indent-ly and named the new file indent-ly, but I'm not an experienced programmer, and I have some questions. Where should I put indent-ly? Does it need a file extension? What are the options, and how can I invoke them? I'm grateful for the work you've done on this and appreciate your sharing of the file. Ralph On Fri, Oct 23, 2009 at 7:57 AM, Martin Tarenskeen m.tarensk...@zonnet.nlwrote: Hi, I'm still working on indent-ly. New in current version as requested: - Backup files before overwriting. I'm giving these files names like infile.ly.1, infile.ly.2, etcetera. You don't loose files unless you delete them by hand. - Try to keep scheme stuff untouched ( needs improvement ) - Don't expand tabs in the middle of lines - Read from stdin if no inputfile specified You can find today's version here as usual: http://www.home.zonnet.nl/m.tarenskeen/tmp/indent-ly -- Martin ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user -- Ralph Palmer Montague City, MA USA palmer.r.vio...@gmail.com ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Hi, Op dinsdag 20 oktober 2009 schreef Martin: Would be nice if he could also integrate such functionality in Frescobaldi: Be able to re-indent a complete score with a mouseclick from inside the Frescobaldi screen would be great ! ( Just like indent-ly has been integrated into frescobaldi.) Or is it already possible ? Frescobaldi already has a LilyPond indenting command, using the indent.py script referred to in issue 777. The command is in menu LilyPond-Source document-Align. It works slightly better than the KatePart builtin indent at Tools-Align. My indent script can also be used standalone, with some work it could support multiple files, etc. It handles scheme code quite nice. best regards, Wilbert Berendsen -- Frescobaldi, LilyPond editor for KDE: http://www.frescobaldi.org/ Nederlands LilyPond forum: http://www.lilypondforum.nl/ ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Op donderdag 22 oktober 2009 schreef Bertalan: Now, the real problem I see with this approach is that no perfect formatting (which is not the same as indentation) can be done without actually parsing the input. I think this is true; my indent script[1] includes a basic parser. It knows when to switch from LilyPond to Scheme mode and back again and also supports LilyPond code in Scheme. It also has a nice feature that line-comments starting with three %%% or ;;; are not indented, because that comment style if often used to mark big sections of LilyPond or Scheme input. The scheme indenting currently works like this: If an opening parenthesis is found, the following 10 characters are searched for another one (before closing one or newline). If there is another opening parenthesis on the same line, the next line is aligned the same way. If none is found, the normal indent is used. (default 2). [1] http://code.google.com/p/lilykde/source/browse/trunk/frescobaldi/python/ly/indent.py best regards, Wilbert Berendsen -- Frescobaldi, LilyPond editor for KDE: http://www.frescobaldi.org/ Nederlands LilyPond forum: http://www.lilypondforum.nl/ ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Hi, I'm still working on indent-ly. New in current version as requested: - Backup files before overwriting. I'm giving these files names like infile.ly.1, infile.ly.2, etcetera. You don't loose files unless you delete them by hand. - Try to keep scheme stuff untouched ( needs improvement ) - Don't expand tabs in the middle of lines - Read from stdin if no inputfile specified You can find today's version here as usual: http://www.home.zonnet.nl/m.tarenskeen/tmp/indent-ly -- Martin ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Fri, 23 Oct 2009, eluze wrote: Also new in today's version: If no input file is specified indent-ly reads from stdin. works - how do you stop stdin? (i used ctrl+z) Ctrl + d ? -- Martin ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Fri, Oct 23, 2009 at 05:01:37PM +0200, Martin Tarenskeen wrote: works - how do you stop stdin? (i used ctrl+z) Ctrl + d ? You're both right. CTRL-z is Windows's way of signalling end-of-input; CTRL-d is likewise for POSIX-compliant systems. You can also do program file on both systems, and the contents of the file you name get to be the stdin of the program you name, without needing CTRL-anything. -- There is no such thing as a small specification change. http://surreal.istic.org/ The revolution will not be snowcloned. signature.asc Description: Digital signature ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Now, the real problem I see with this approach is that no perfect formatting (which is not the same as indentation) can be done without actually parsing the input. Complete parsing of LilyPond input is _impossible_ without LilyPond itself. For example you need to format LilyPond code _inside_ Scheme code (remember the #{ construct used in define-music-function) So a standard formatting engine can only be written inside LilyPond, or at least using LilyPond to generate metadata describing the structure of the input. Bert Martin Tarenskeen wrote: On Wed, 21 Oct 2009, Graham Percival wrote: - it would be nice to have an option to replace the file directly instead of having to copy/paste the resulting file Definitely! Done in latest version. Use -m (--modify) Be careful: This version overwrites the original file without making a backup ( infile.ly~ )first. Maybe I should add that in the next version. - scheme code is not handled (or indented uniformly) Yes, scheme code should be formatted in the scheme way. I know very very little about scheme. Some example lilypond files with much scheme code might help. - if within brackets there are tabs after the code and before the end-bracket they are replaced by a bunch of blanks Hmm, I'm not certain how often this would come into play. I use tabs sometimes for indenting lines, but I haven't seen anyone using tabs in the middle of a line of lilypond code - in my programming style i prefer to have the endbracket aligned with the code above - maybe with an additional option this could be solved!? I'd argue against this -- the point of a unified style / indentation scheme is that it's *standard*. ... I don't think we should have many options at all. I agree B One more item to consider: whitespace at the ends of lines should be stripped. I thought I already did that ? I'll look in to it. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Bertalan Fodor (LilyPondTool) lilypondt...@organum.hu writes: Now, the real problem I see with this approach is that no perfect formatting (which is not the same as indentation) can be done without actually parsing the input. I don't see that. Complete parsing of LilyPond input is _impossible_ without LilyPond itself. There are very few things actually affecting input syntax (redefining note names is one of those). Chord and lyrics mode, too, but I don't think that the subtleties are actually important for formatting and indentation. It is perfectly acceptable to just break on spaces, and indent according to } nesting. After discounting quoted strings, - \ \ and similar articulation. For example you need to format LilyPond code _inside_ Scheme code (remember the #{ construct used in define-music-function) Yes, but it is not like there are multiple arbitrary ways in which this can happen. It is actually just #{ IIRC. So a standard formatting engine can only be written inside LilyPond, or at least using LilyPond to generate metadata describing the structure of the input. I think that view is overly pessimistic. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
So a standard formatting engine can only be written inside LilyPond, or at least using LilyPond to generate metadata describing the structure of the input. I think that view is overly pessimistic. Ok, but I'm talking about a standard formatter, and not just indentation. But for that as well, you certainly need at least a limited parser, at least to find where Scheme parts start and begin. Bert ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Tue, 20 Oct 2009, Graham Percival wrote: On Tue, Oct 20, 2009 at 01:02:59PM +0200, Martin Tarenskeen wrote: On Tue, 20 Oct 2009, Graham Percival wrote: http://code.google.com/p/lilypond/issues/detail?id=777 Since you're somewhat interested in the area, could you compare the scripts? I will take a look. My first impression is that Wilbert's indent.py script is more advanced. I might learn something from it. The default for lilypond files is two-space indents. Is that official and written in the docs, or just common practice ? It's official for the docs and snippets. An official style OK. I changed the default to two-space indentation: http://www.home.zonnet.nl/m.tarenskeen/tmp/indent-ly -- Martin Tarenskeen ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Tue, 20 Oct 2009, Neil Puttock wrote: Apart from the lack of Scheme indentation, I've only noticed two cases where your script differs: single-line comments aren't indented to the same level as their surrounding environment, Changed that in my latest version. And I now leave block-comments %{ %} untouched. and texidoc strings in a header get re-indented if indentation has been left out (usually deliberately in the docs on a new line). Can you point me to an example ? I don't know what texidoc strings are. http://www.home.zonnet.nl/m.tarenskeen/tmp/indent-ly -- Martin ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Tue, 20 Oct 2009, Neil Puttock wrote: Be able to re-indent a complete score with a mouseclick from inside the Frescobaldi screen would be great ! ( Just like indent-ly has been integrated into frescobaldi.) Or is it already possible ? Alt-l s a does this rather nicely. I can't make this work. I have tried Alt and/or Ctrl + l, L, I or i (In case you made a typo). But I can only make all or selected lines move to the right, which is not what I mean or need when I have messed up the indentation in a larger score already and want to fix that. -- Martin ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Martin Tarenskeen wrote: I think it does a nice job, but comments are welcome. it does! a few remarks: - it would be nice to have an option to replace the file directly instead of having to copy/paste the resulting file - scheme code is not handled (or indented uniformly) - if within brackets there are tabs after the code and before the end-bracket they are replaced by a bunch of blanks - in my programming style i prefer to have the endbracket aligned with the code above - maybe with an additional option this could be solved!? - comments should also follow the indentation rules hope these comments are helpful - thanks! -- View this message in context: http://www.nabble.com/indent-ly-tp25971519p25993972.html Sent from the Gnu - Lilypond - User mailing list archive at Nabble.com. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Wed, Oct 21, 2009 at 07:47:01AM -0700, -Eluze wrote: Martin Tarenskeen wrote: I think it does a nice job, but comments are welcome. - it would be nice to have an option to replace the file directly instead of having to copy/paste the resulting file Definitely! - scheme code is not handled (or indented uniformly) Yes, scheme code should be formatted in the scheme way. - if within brackets there are tabs after the code and before the end-bracket they are replaced by a bunch of blanks Hmm, I'm not certain how often this would come into play. - in my programming style i prefer to have the endbracket aligned with the code above - maybe with an additional option this could be solved!? I'd argue against this -- the point of a unified style / indentation scheme is that it's *standard*. Now, if this program is just a random fun project, it doesn't matter what it does or how many options there are. But if this is going to turn into a standard script for formatting lilypond files, included in the main lilypond distributions (and I dearly hope it will, since it's an annoying problem that can be solved with an easy program), then I don't think we should have many options at all. One more item to consider: whitespace at the ends of lines should be stripped. Cheers, - Graham ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Martin Tarenskeen m.tarensk...@zonnet.nl writes: On Tue, 20 Oct 2009, Graham Percival wrote: The default for lilypond files is two-space indents. Is that official and written in the docs, or just common practice ? Lilypond itself does not write lilypond files, it just reads them. So it does not have a default indentation. Incorrect. Try { \displayLilyMusic { a b \\ c d | d e | } } which will produce { a b \\ c d | d e | } That _is_ an idea of indentation and line breaking written by Lilypond itself. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Wed, 21 Oct 2009, Graham Percival wrote: - it would be nice to have an option to replace the file directly instead of having to copy/paste the resulting file Definitely! Done in latest version. Use -m (--modify) Be careful: This version overwrites the original file without making a backup ( infile.ly~ )first. Maybe I should add that in the next version. - scheme code is not handled (or indented uniformly) Yes, scheme code should be formatted in the scheme way. I know very very little about scheme. Some example lilypond files with much scheme code might help. - if within brackets there are tabs after the code and before the end-bracket they are replaced by a bunch of blanks Hmm, I'm not certain how often this would come into play. I use tabs sometimes for indenting lines, but I haven't seen anyone using tabs in the middle of a line of lilypond code - in my programming style i prefer to have the endbracket aligned with the code above - maybe with an additional option this could be solved!? I'd argue against this -- the point of a unified style / indentation scheme is that it's *standard*. ... I don't think we should have many options at all. I agree B One more item to consider: whitespace at the ends of lines should be stripped. I thought I already did that ? I'll look in to it. -- Martin Tarenskeen ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Wed, Oct 21, 2009 at 08:49:33PM +0200, Martin Tarenskeen wrote: Be careful: This version overwrites the original file without making a backup ( infile.ly~ )first. Maybe I should add that in the next version. Yes, that would be good. What about a version that read from standard input and wrote to standard input? I'm thinking about the documentation -- we could automatically format all lilypond input syntax. The documentation _mostly_ follows our semi-defined style already, but I'm sure that there's a handful of places where it doesn't. It be nice if we could auto-format all 2143 portions of lilypond input in the docs. :) Yes, scheme code should be formatted in the scheme way. I know very very little about scheme. Some example lilypond files with much scheme code might help. The snippets-advanced scheme might help here, but I'm not certain if they're all formatted correctly. The definitive guide[1] would be whatever emacs does -- if you can install emacs and try its formatting on a few scheme files, you could satisfy all your questions about this. :) [1] I dislike installing 30 megs of programs just to have good indentation, which is why I consider this python indentation script such a great project. One more item to consider: whitespace at the ends of lines should be stripped. I thought I already did that ? I'll look in to it. Sorry, I still haven't looked at the program; I'm just commenting on the discussion. If you already do this, great! (BTW, this end-of-line whitespace-removal is a *huge* issue for the docs and our code. When the lilypond indenting script is done, it would be fantastic if you could write a similar program to help the documentation writers and programmers. :) Cheers, - Graham ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
2009/10/21 Martin Tarenskeen m.tarensk...@zonnet.nl: Can you point me to an example ? I don't know what texidoc strings are. Here's an example from the regression tests: http://git.savannah.gnu.org/gitweb/?p=lilypond.git;a=blob;f=input/regression/accidental-broken-tie-spacing.ly;h=6f4bc120affd5909bf32548d81fa8acf7247a6a9;hb=HEAD Regards, Neil ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
2009/10/21 Martin Tarenskeen m.tarensk...@zonnet.nl: I can't make this work. I have tried Alt and/or Ctrl + l, L, I or i (In case you made a typo). But I can only make all or selected lines move to the right, which is not what I mean or need when I have messed up the indentation in a larger score already and want to fix that. Alt-L S A or LilyPond - Source Document - Align Which version of Frescobaldi are you using? It was added in version 0.7.12. Regards, Neil ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
Graham Percival wrote: What about a version that read from standard input and wrote to standard input? I'm thinking about the documentation -- we could automatically format all lilypond input syntax. On unix a lot of tools default to input coming from one or more file(s) whose names are specified on the command line, and output going to standard output. They act as filters and you can put them in pipelines. Some specify one or more input filename(s) as the only non-option command line argument(s). Many of them have no facility to specify output filenames, requiring redirection if you want them to write to a file. Examples include sed, od, hd, col, cut, awk, indent, and bc. One variant you see a lot is that some programs will read a file list and after they're done they'll read from stdin until they run out of input. indent, which does for C programs what you're doing for lilypond programs has several syntaxes. indent [options] [input-files] This will create a backup of all the input files and then replace the original file with prettyfied versions. indent [options] [-o output-file] If no files are specified, it reads from standard in and then if there's no -o option it writes to standard out. If there is a -o option it writes to the specified file. indent [options] [single-input-file] [-o output-file] This will write to the output file if -o specified, backup and replace the original single-input-file if -o not specified. indent -st [input-file] the -st option means write to standard out, so writes the result of prettyfying the input-file to standard out. Hope this helps. Patrick ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Tue, Oct 20, 2009 at 10:31:15AM +0200, Martin Tarenskeen wrote: I have tried to write a tool in Python to (re-)indent lilypond source files. Something like indent ( for C/C++ ) or tidy ( for HTML ) but now with Lilypond in mind. Nice! If it works well, this would satisfy http://code.google.com/p/lilypond/issues/detail?id=777 The tool can handle multiple inputfiles, and there is a commandline option that lets you specify how much spacecharacters to use for indentation, or to use TAB characters for that (= default behaviour). The default for lilypond files is two-space indents. Cheers, - Graham ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Tue, 20 Oct 2009, Graham Percival wrote: On Tue, Oct 20, 2009 at 10:31:15AM +0200, Martin Tarenskeen wrote: I have tried to write a tool in Python to (re-)indent lilypond source files. Something like indent ( for C/C++ ) or tidy ( for HTML ) but now with Lilypond in mind. Nice! If it works well, this would satisfy http://code.google.com/p/lilypond/issues/detail?id=777 I also see there Wilbert Berendsen already wrote a similar, but more advanced, python script ( indent.py ). Might work better than mine. Give them both a try I would say to everyone. Would be nice if he could also integrate such functionality in Frescobaldi: Be able to re-indent a complete score with a mouseclick from inside the Frescobaldi screen would be great ! ( Just like indent-ly has been integrated into frescobaldi.) Or is it already possible ? The default for lilypond files is two-space indents. Is that official and written in the docs, or just common practice ? Lilypond itself does not write lilypond files, it just reads them. So it does not have a default indentation. I have tried different tools ( frescobaldi, lilypondtool, nted, noteedit, mscore, canorus, rosegarden, vim ) and they don't seem to agree when it comes to indenting style. -- Martin Tarenskeen ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
The default for lilypond files is two-space indents. Is that official and written in the docs, or just common practice ? Lilypond itself does not write lilypond files, it just reads them. So it does not have a default indentation. I have tried different tools ( frescobaldi, lilypondtool, nted, noteedit, mscore, canorus, rosegarden, vim ) and they don't seem to agree when it comes to indenting style. I agree. LilyPondTool relies on jEdit in this sense. JEdit doesn't provide advanced indentation by its own, and actually leaves it to the user the set up indent level, TAB vs Space etc. Though simple indentation can be done with Ctrl-I. Bert ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
On Tue, Oct 20, 2009 at 01:02:59PM +0200, Martin Tarenskeen wrote: On Tue, 20 Oct 2009, Graham Percival wrote: Nice! If it works well, this would satisfy http://code.google.com/p/lilypond/issues/detail?id=777 I also see there Wilbert Berendsen already wrote a similar, but more advanced, python script ( indent.py ). Might work better than mine. Give them both a try I would say to everyone. Don't ask everyone to investigate this, because they won't. The rule in open source is that you're lucky if you get one volunteer working on something. :( Since you're somewhat interested in the area, could you compare the scripts? The default for lilypond files is two-space indents. Is that official and written in the docs, or just common practice ? It's official for the docs and snippets. An official style recommended for users may be part of the Great Lilypond Input Syntax Standardization, but this project has not started yet. Cheers, - GRaham ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: indent-ly
2009/10/20 Martin Tarenskeen m.tarensk...@zonnet.nl: Would be nice if he could also integrate such functionality in Frescobaldi: Be able to re-indent a complete score with a mouseclick from inside the Frescobaldi screen would be great ! ( Just like indent-ly has been integrated into frescobaldi.) Or is it already possible ? Alt-l s a does this rather nicely. Apart from the lack of Scheme indentation, I've only noticed two cases where your script differs: single-line comments aren't indented to the same level as their surrounding environment, and texidoc strings in a header get re-indented if indentation has been left out (usually deliberately in the docs on a new line). Regards, Neil ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user