I'm not a big fan of counts of lines of code, but sometimes it's fun or otherwise useful. I didn't see a script to count the LOC in scripts.leo or PyLeoRef.leo, so I came up with one, but I wondered whether anyone else has a slicker one.
My script counts lines of code in a Leo subtree, not in external files. The subtree could be a file, but doesn't need to be. Of course, there's the question of what counts as a line of code. Part of that is whether a docstring counts. If it does, the code is way easier since you don't have to figure out where a docstring begins or ends. My version counts all non-blank, non-comment, non-directive lines. So it omits Python decorators, but there are unlikely to be enough of them to really matter. Here's my script: """Count non-blank, non-comment, non-directive lines in subtree.""" p = c.p nodes = p.self_and_subtree() cnt = 0 for n in nodes: lines = [l for l in n.b.split('\n') if l.strip()] lines = [l for l in lines if not l.lstrip()[0] in ('#', '@')] cnt += len(lines) g.es(cnt, f'lines of code in "{p.h}"') This executes pretty fast even on a large outline like PyLeoRef, which for the *Code* subtree outputs 154966 lines of code in "Code" -- 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/bcee2881-38ae-42bc-ac55-50d388537bc7n%40googlegroups.com.