Skip to content

save-restriction seems to fail in certain circumstances #5

Open
@telotortium

Description

@telotortium

When running code that uses save-restriction under ert, in certain circumstances an error is encountered. I don't have it at hand right now, but essentially, save-restriction attempts to restore point-max in the *ert* buffer, not the buffer I created for the test and in which I originally ran save-restriction, and that fails because my buffer is larger than the *ert* buffer.

In general, it seems like internally save-restriction, save-excursion, save-current-buffer are implemented essentially using unwind-protect (example). Basically, it seems like save-current-buffer just saves the current buffer, save-excursion saves instead a marker to the current point in the current buffer (as well as the current window), and save-restriction saves markers to the min and max points in the current buffer. iter2's save-restriction, however, does not restore the current buffer from the markers before calling narrow-to-region, which I believe causes the bug.

In general, it may be a better idea to manually convert these 3 macros to equivalent unwind-protect forms, following the Emacs source code, and then convert those.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions