Skip to content

Commit

Permalink
chg: (-with-inhibit-read-only) Don't modify buffer-undo-list
Browse files Browse the repository at this point in the history
Resolves nobiot#177 by making `org-transclusion-add` and `org-transclusion-remove` not
affect the buffer undo history.
  • Loading branch information
josephmturner committed May 12, 2024
1 parent b23ead2 commit ac40d2a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions org-transclusion.el
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Org mode's caching relies upon modification hooks to function."
(declare (debug t) (indent 0))
(let ((modified (make-symbol "modified")))
`(let* ((,modified (buffer-modified-p))
(buffer-undo-list t)
(inhibit-read-only t))
(unwind-protect
(progn
Expand Down

7 comments on commit ac40d2a

@josephmturner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! This doesn't actually solve the problem.

@akashpal-21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be problematic because the user expects an undo operation to act as org-transclusion-remove somewhat -- although it doesn't function as such since org-transclusion-remove also does operations on the source buffer too -- removing overlays and so on;

I thought of this idea too - but abandoned it since this could result in problems elsewhere. Particularly in how user expects transclusions to function.

@josephmturner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akashpal-21 IMO undo and undo-redo should not act as org-transclusion-remove. I think transclusions should not be considered buffer modifications, but rather a different way to view the same buffer contents. What do you think?

@akashpal-21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you - but it won't be as direct as just blocking writing entries to the buffer-undo-list.

Transclusions are simply yanking text from another buffer with some extra steps -- which means they make buffer modifications - so we have to update the org environment nevertheless with the changes we have made else we would be corrupting positional pointers - if we have to really make transclusions invisible to the buffer-undo-list we have to block entries in strategic positions and not turn it off for the entire duration.

We could block entirely for the save-buffer protocol because we make changes and their inverses as part of the same operation, so it works there - but wouldn't work for org-transclusion-add and org-transclusion-remove so easily.

It could nevertheless be done if we desire as such.

@josephmturner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have to really make transclusions invisible to the buffer-undo-list we have to block entries in strategic positions and not turn it off for the entire duration

When adding/removing tranclusions, which buffer modifications need to be included in buffer-undo-list?

@akashpal-21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a simple example consider the text:

(position x-1) #+transclude: [[something]]
(position x) Here is some text

When we do (org-transclusion-add) "Here is some text" is moved from position (x) to (x+d) where d is some delta

In place of position x - there is now the transcluded text -- if we undo here - but this change is not recorded -- the undo will look for "Here is some text" in position x - but it doesn't exist here.

@josephmturner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akashpal-21 Thank you for explaining! This is why we get primitive-undo: Changes to be undone are outside visible portion of buffer when we exclude transclusions from the undo history.

Please sign in to comment.