diff options
| author | Po Lu | 2023-06-06 21:00:44 +0800 |
|---|---|---|
| committer | Po Lu | 2023-06-06 21:00:44 +0800 |
| commit | bf28b019a85fcc4e16bc7ecad6304c30e48a3223 (patch) | |
| tree | 0fc53c2707e0aab410ef20399fcc2ac1b2b71990 | |
| parent | 05c2be28a3e97bd920d0bf8c8b59ec682a420cce (diff) | |
| download | emacs-bf28b019a85fcc4e16bc7ecad6304c30e48a3223.tar.gz emacs-bf28b019a85fcc4e16bc7ecad6304c30e48a3223.zip | |
Fix problems resulting from modification of the undo list
* doc/lispref/text.texi (Atomic Changes): Describe what not to
do inside an atomic change group.
* lisp/elec-pair.el (electric-pair-inhibit-if-helps-balance):
Don't call `delete-char'; that edits the undo list by removing
boundary markers.
* lisp/subr.el (atomic-change-group, prepare-change-group): Warn
against modifying the undo list inside.
| -rw-r--r-- | doc/lispref/text.texi | 11 | ||||
| -rw-r--r-- | lisp/elec-pair.el | 4 | ||||
| -rw-r--r-- | lisp/subr.el | 9 |
3 files changed, 23 insertions, 1 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index f15b3c33e0c..dac8d0d8ce9 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -6181,6 +6181,17 @@ would expect. Non-nested use of change groups for the same buffer | |||
| 6181 | will get Emacs confused, so don't let it happen; the first change | 6181 | will get Emacs confused, so don't let it happen; the first change |
| 6182 | group you start for any given buffer should be the last one finished. | 6182 | group you start for any given buffer should be the last one finished. |
| 6183 | 6183 | ||
| 6184 | Emacs keeps track of change groups by assuming that by following | ||
| 6185 | each cdr in @code{buffer-undo-list}, it will eventually arrive at the | ||
| 6186 | cons it was set to at the time @code{prepare-change-group} was called. | ||
| 6187 | |||
| 6188 | If @code{buffer-undo-list} no longer contains that cons, Emacs will | ||
| 6189 | lose track of any change groups, resulting in an error when the change | ||
| 6190 | group is cancelled. To avoid this, do not call any functions which | ||
| 6191 | may edit the undo list in such a manner, when a change group is | ||
| 6192 | active: notably, ``amalgamating'' commands such as @code{delete-char}, | ||
| 6193 | which call @code{undo-auto-amalgamate}. | ||
| 6194 | |||
| 6184 | @node Change Hooks | 6195 | @node Change Hooks |
| 6185 | @section Change Hooks | 6196 | @section Change Hooks |
| 6186 | @cindex change hooks | 6197 | @cindex change hooks |
diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index b894965eae4..416c95e7a34 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el | |||
| @@ -439,7 +439,9 @@ happened." | |||
| 439 | ;; position some markers. The real fix would be to compute the | 439 | ;; position some markers. The real fix would be to compute the |
| 440 | ;; result without having to modify the buffer at all. | 440 | ;; result without having to modify the buffer at all. |
| 441 | (atomic-change-group | 441 | (atomic-change-group |
| 442 | (delete-char -1) | 442 | ;; Don't use `delete-char'; that may modify the head of the |
| 443 | ;; undo list. | ||
| 444 | (delete-region (point) (1- (point))) | ||
| 443 | (throw | 445 | (throw |
| 444 | 'done | 446 | 'done |
| 445 | (cond ((eq ?\( syntax) | 447 | (cond ((eq ?\( syntax) |
diff --git a/lisp/subr.el b/lisp/subr.el index cef631a69c3..1384215498b 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -3773,6 +3773,9 @@ This means that if BODY exits abnormally, | |||
| 3773 | all of its changes to the current buffer are undone. | 3773 | all of its changes to the current buffer are undone. |
| 3774 | This works regardless of whether undo is enabled in the buffer. | 3774 | This works regardless of whether undo is enabled in the buffer. |
| 3775 | 3775 | ||
| 3776 | Do not call functions which edit the undo list within BODY; see | ||
| 3777 | `prepare-change-group'. | ||
| 3778 | |||
| 3776 | This mechanism is transparent to ordinary use of undo; | 3779 | This mechanism is transparent to ordinary use of undo; |
| 3777 | if undo is enabled in the buffer and BODY succeeds, the | 3780 | if undo is enabled in the buffer and BODY succeeds, the |
| 3778 | user can undo the change normally." | 3781 | user can undo the change normally." |
| @@ -3839,6 +3842,12 @@ Once you finish the group, don't use the handle again--don't try to | |||
| 3839 | finish the same group twice. For a simple example of correct use, see | 3842 | finish the same group twice. For a simple example of correct use, see |
| 3840 | the source code of `atomic-change-group'. | 3843 | the source code of `atomic-change-group'. |
| 3841 | 3844 | ||
| 3845 | As long as this handle is still in use, do not call functions | ||
| 3846 | which edit the undo list: if it no longer contains its current | ||
| 3847 | value, Emacs will not be able to cancel the change group. This | ||
| 3848 | includes any \"amalgamating\" commands, such as `delete-char', | ||
| 3849 | which call `undo-auto-amalgamate'. | ||
| 3850 | |||
| 3842 | The handle records only the specified buffer. To make a multibuffer | 3851 | The handle records only the specified buffer. To make a multibuffer |
| 3843 | change group, call this function once for each buffer you want to | 3852 | change group, call this function once for each buffer you want to |
| 3844 | cover, then use `nconc' to combine the returned values, like this: | 3853 | cover, then use `nconc' to combine the returned values, like this: |