Leo's beautify-files command now uses the Orange class in leoAst.py. This class is a proof of concept for #1440 <https://github.com/leo-editor/leo-editor/issues/1440>, unify the ast and token worlds. I've been working on this project for almost four months. It is nearing completion. Further testing remains.
Yesterday the beautify-files command passed a major milestone: all of Leo's core files compile without syntax errors after being beautified :-) No, I haven't committed any of the changes: that will require careful perusal of diffs. *Commands* The beautify-files commands beautifies all @<file> nodes in the selected outline. The diff-beautify-files command (aka beautify-files-diff) reports the diffs (to the console) that would result from running the beautify-files command. *Settings* These commands take the following settings, with the indicated defaults: @bool beautify-allow-joined-strings = False By default, the beautifier will refrain from joining lines if they contain strings. This is my strong preference, because it suppresses rearranging of code such as: message = ( f"\n" f" contents: {contents!r}\n" f" expected: {expected!r}\n" f" got: {results!r}") I use this pattern all the time now. I would be most annoyed if some "helpful" beautifier collapsed it. @bool beautify-keep-blank-lines = True As I write this, I'm not sure this option works, or is even in effect. It's on the list of things to investigate. @int beautify-max-join-line-length = 80 @int beautify-max-split-line-length = 90 Notice: these two settings have different defaults. The beautifier will join lines only if they won't soon be candidates for being split. Zero suppresses splitting or joining.The beautifier ensures that the join length is no larger than the split length. In any case, the beautifier will join lines only if they have not just been split ;-) *Enabling and disabling beautification* Within Leo, @nobeautify suppresses all beautification until the end of the node. It's probably best to put this directive only a the start of a node. See below for an important warning. The beautifier supports two special comments: # pragma: no beautify # pragma: beautify These will allow a stand-alone version of the beautifier to suppress beautification in a range of lines. *Warning**:* Beautification catastrophes could occur if 'indent' and 'dedent' tokens are not matched within the "verbatim" range. It's probably best to use @nobeautify only at the start of a node. I might add support for @beautify, but that increases the danger. More noodling is required. *To do* 1. 100% coverage of all non-debugging code. Full coverage guarantees important properties. It will be an important advertising point when I announce this project. 2. Merge fstrings branch into devel. This will be done as soon as full coverage is achieved. 3. Beautify all of Leo's core files. This will be done in a separate branch. Imo, this work should be done before closing #1440. 4. Announce #1440 to the world. The core python devs should definitely know about this work. What they do with it is up to them. *Summary* Leo's new beautify-files command is now a worthy competitor to black. It contains important settings and features not found in black. Please feel free to play with the beautify-files command and report any problems. *Make sure you have backups of to-be-beautified files.* In particular, take care with @nobeautify. Unit tests guarantee that Leo's beautify works exactly like black for all of the pet peeves <https://www.python.org/dev/peps/pep-0008/#pet-peeves> listed in pep 8 <https://www.python.org/dev/peps/pep-0008/>. To do this, the beautifier must know which parse tree node corresponds to each ":" token. This single datum justifies using the entire TokenOrderGenerator class! Completing a major project such as #1440 is *itself* a significant project. Surely #1440 is much nearer completion than it was a few days ago ;-) Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/a709ea6f-75e7-4b6f-896f-67343e6e673d%40googlegroups.com.