[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I undo a change from a modification-hook?
From: |
Stefan Monnier |
Subject: |
Re: How can I undo a change from a modification-hook? |
Date: |
Wed, 26 Apr 2017 08:26:13 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
> (by raising an error), and to allow changes when in a comment. I can't
> find a good way to allow whitespace edits at the end of a line, though.
> I can detect such changes from the second call to the modification hook
> (during which it's easy to know whether the change is only adding or
> removing space at the end of a line), but I can't easily undo the changes
> and error out if they involve more than whitespace, can I?
Technically you can, but it's a bit messy and will likely not be
100% reliable. Personally, in your case, I wouldn't bother doing it,
but here's how I'd do it otherwise:
- in the before-hook stash the value of buffer-undo-list somewhere.
[ While you're at it, stash the beg/end there as well. ]
- in the after-hook check the change (using beg/end/len) [ and while
you're there, check that the beg/end/len is within the announces
beg/end stashed earlier, and if it's not just don't do anything
since it means the stash buffer-undo-list is likely unrelated. ]
and if it doesn't fit your criteria, call undo until you reach the
previously stashed value of buffer-undo-list, and then signal the error.
-- Stefan
- How can I undo a change from a modification-hook?, Clément Pit--Claudel, 2017/04/26
- Re: How can I undo a change from a modification-hook?,
Stefan Monnier <=
- Re: How can I undo a change from a modification-hook?, Clément Pit-Claudel, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Stefan Monnier, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Clément Pit-Claudel, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Stefan Monnier, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Clément Pit-Claudel, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Stefan Monnier, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Clément Pit-Claudel, 2017/04/26
- Re: How can I undo a change from a modification-hook?, Stefan Monnier, 2017/04/27
- Re: How can I undo a change from a modification-hook?, Clément Pit-Claudel, 2017/04/27
- Re: How can I undo a change from a modification-hook?, Stefan Monnier, 2017/04/27