fix: #177 Infinite loop when saving buffer with transclusions #263
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixing a long-lasting (issue open since March 2023, but it had been an known issue before it) issue that was difficult to reproduce.
The fix is to stop using the text-properties of the transclusion that hold markers of beginning and ending points of itself, which is meant to remember and indicate its own the location; or the range of "this" transclusion at point. The text-properties are named
org-transclusion-beg-mkr
andorg-transclusion-end-mkr
. They are replaced with use of a new text-propertyorg-transclusion-id
and functionorg-transclusion-at-point
. This new function usestext-property-search
withorg-transclusion-id
to identify the range of "this" transclusion at point only when it is needed, thus eliminating the need for memorizing it as a pair of markers.Stable reproduction was achieved and recorded in a comment to the GitHub issue at #177 (comment).
A quick summary of the design hitherto and how the infinite loop occurs is as follows:
[Fact / design of org-transclusion]
Each transclusion has text-properties
org-transclusion-beg-mkr
andorg-transclusion-end-mkr
.They hold markers to keep track of where the transclusion begins and ends.
[Now what happens]
In some combination of undo and buffer-save with transclusions, the markers can temporarily point to non-existing locations in the buffer.
If the garbage collection happens to run at this moment, it will sweep these pointers. Now they end up pointing to start of the buffer (point 1).