​On Sat, May 16, 2015 at 3:58 PM, Edward K. Ream <[email protected]> 
wrote:

> Beautifying, reformatting or otherwise "improving" code could potentially 
change its meaning. 

​Now that Terry has put the code beautification problem in context, let's 
think about solving the original problem.  Here is a working prototype.  It 
could be an @button node, but running this Leo script on itself is good 
enough:

import ast
import hashlib
node = ast.parse(p.b,filename=p.h,mode='exec')
# Comments and whitespace do not affect the hash, but strings & docstrings 
do.
# Another comment.
if 0: return # Putting the return on another line does not affect the hash.
s = ast.dump(node,annotate_fields=False)
g.trace(hashlib.sha256(s).hexdigest(),len(s))

You can play with the code, adding blank lines, whitespace, etc.  Notice 
what does and does not change the hash.

Aha: We want diff that shows only changes that *do *change the hash.  This 
would be valuable when removing hangnails.  Such a diff would allow me, for 
example, to insert missing docstrings safely.  The diff would show *only *the 
inserted docstrings, and not all the completely benign changes.  Capiche?

The next step will be to look to see whether such a smart python diff 
already exists.

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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to