Skip to content

fix: #177 Infinite loop when saving buffer with transclusions #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

nobiot
Copy link
Owner

@nobiot nobiot commented Dec 30, 2024

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 and org-transclusion-end-mkr. They are replaced with use of a new text-property org-transclusion-id and function org-transclusion-at-point. This new function uses text-property-search with org-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 and org-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).

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' and
`org-transclusion-end-mkr'. They are replaced with use of a new text-property
`org-transclusion-id' and function `org-transclusion-at-point'. This new
function uses `prop-match' with `org-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 and
org-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).

docs: Update NEWS
@nobiot nobiot merged commit f6fd666 into main Dec 30, 2024
1 check passed
@nobiot nobiot deleted the fix/inf-loop branch December 30, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant