drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
271 stars 22 forks source link

Idempotence of null operations #98

Open countvajhula opened 1 year ago

countvajhula commented 1 year ago

Summary of Changes

Certain operations like I, A, O (among others) insert spaces or change the local region in the buffer in some way in preparation for the change we are about to make. This is typically desirable when we do actually continue. But sometimes we may do this accidentally or change our minds, and in these cases, the buffer is left in a changed state even though we didn't actually do anything. We call these "null" operations, and we'd like them to be idempotent in the sense that they should leave the buffer unchanged. See #92 for additional context.

At present this PR takes the approach of detecting that an edit was attempted but no change was made, and then inverting the preparatory change by using undo. This seems to work fairly well, but as it does invoke undo, any potential bugs in this area could be fraught with the risk of undoing actual user changes.

One improvement could be to, at the time of initiating the preparatory change, construct and store the inverse operation (e.g. as quoted code) in some kind of stack that could then be applied as a fresh change, which would undo the change without actually using undo. In this option, we'd also need to pop off the top two items on the actual undo stack so that they aren't encountered when the user actually attempts to undo (but this once again involves mutating the undo list!).

Another possibility is for these operations to not actually change the buffer to begin with, but only seem to, by showing some kind of preview of what the buffer would look like if the user continued with the change. I'm not sure if Emacs offers any facilities for this. Could overlays be used?

Public Domain Dedication

(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)