Vitalije's recent discussions of functional programming has indirectly lead 
me to a tentative plan to simplify Leo's undo logic.


*A thought experiment*
Suppose Leo outlines behaved kinda like Python strings.  You never actually 
change a Python string, you only compose new strings.

Of course, Leo would have to be super careful about how it composed new 
outlines. Rather than creating a new copy of the entire outline, there 
would have to be some kind of transaction-based mechanism behind the 
scenes.  Like a db.

I'm not keen to do this, perhaps for obvious reasons, but it did get me 
thinking about undo transactions.

*Transaction-based undo*

At present, Leo has several before and after undoer methods.  Instead, 
suppose there were only two public methods: undoer.before and undoer.after.

- undoer.start starts an undo transaction, which may consist of several 
parts.  For example:

data = c.undoer.start(undo_type) # data represents the transaction.

- undoer.end ends the transaction, and "commits" the transaction. 
undoer.after does nothing if the transaction is empty.

c.undoer.end(data)

This scheme can form the basis of an @undoable decorator.

Initially, a transaction is an empty container. Undoable commands would add 
to the transaction in one of several ways, much like the old begin/end 
methods of the present undoer.  Something like:

- data.change_headline(p, old, new)
- data.change_body(p, old, new)
- data.clone(p)
- data.mark(p)
- data.move(p1, p2)
- data.sort(p)

Unlike the old way, all transactions support multiple sub-transactions.  
For example,  a single transaction could handle the change-all command.

*Summary*

The new scheme is simpler for client (command) code, and behind the scenes 
as well.

The new scheme can be the basis for an @undoable decorator.

The new scheme would be a major change to Leo's code, but seems worth 
doing. I have just created #996.

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 https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to