diff options
| author | Barry O'Reilly | 2014-03-24 22:47:39 -0400 |
|---|---|---|
| committer | Barry O'Reilly | 2014-03-24 22:47:39 -0400 |
| commit | 37ea8275f7faad1192ddaba9f4a0789580675e17 (patch) | |
| tree | cb6242b0298180f32d8c253c1b3aa8af3c6572fa /test | |
| parent | 3e2377ce2f4eeb141ffbd000723c55813f78b08f (diff) | |
| download | emacs-37ea8275f7faad1192ddaba9f4a0789580675e17.tar.gz emacs-37ea8275f7faad1192ddaba9f4a0789580675e17.zip | |
Undo in region after markers in undo history relocated
* simple.el (primitive-undo): Only process marker adjustments
validated against their corresponding (TEXT . POS). Issue warning
for lone marker adjustments in undo history. (Bug#16818)
(undo-make-selective-list): Add marker adjustments to selective
undo list based on whether their corresponding (TEXT . POS) is in
the region. Remove variable adjusted-markers, which was unused
and only non nil during undo-make-selective-list.
(undo-elt-in-region): Return nil when passed a marker adjustment
and explain in function doc.
Have (MARKER . ADJUSTMENT) undo records always be immediately
after their corresponding (TEXT . POS) record in undo list.
(Bug#16818)
* lisp.h (record-delete): New arg record_markers.
(record_marker_adjustment): No longer needed outside undo.c.
* insdel.c (adjust_markers_for_delete): Move calculation of marker
adjustments to undo.c's record_marker_adjustments. Note that
fileio.c's decide_coding_unwind is another caller to
adjust_markers_for_delete. Because it has undo list bound to t,
it does not rely on adjust_markers_for_delete to record marker
adjustments.
(del_range_2): Swap call to record_delete and
adjust_markers_for_delete so as undo marker adjustments are
recorded before current deletion's adjustments, as before.
(adjust_after_replace):
(replace_range): Pass value for new record_markers arg to
delete_record.
* undo.c (record_marker_adjustment): Renamed to
record_marker_adjustments and made static.
(record_delete): Check record_markers arg and call
record_marker_adjustments.
(record_change): Pass value for new record_markers arg to
delete_record.
(record_point): at_boundary calculation no longer needs to account
for marker adjustments.
* undo-tests.el (undo-test-marker-adjustment-nominal):
(undo-test-region-t-marker): New tests of marker adjustments.
(undo-test-marker-adjustment-moved):
(undo-test-region-mark-adjustment): New tests to demonstrate
bug#16818, which fail without the fix.
* markers.texi (Moving Marker Positions): The 2014-03-02 doc
change mentioning undo's inability to handle relocated markers no
longer applies. See bug#16818.
* text.texi (Undo): Expand documentation of (TEXT . POS) and
(MARKER . ADJUSTMENT) undo elements.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ChangeLog | 8 | ||||
| -rw-r--r-- | test/automated/undo-tests.el | 98 |
2 files changed, 106 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 15677e76468..e5df7536d0b 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2014-03-24 Barry O'Reilly <gundaetiapo@gmail.com> | ||
| 2 | |||
| 3 | * undo-tests.el (undo-test-marker-adjustment-nominal): | ||
| 4 | (undo-test-region-t-marker): New tests of marker adjustments. | ||
| 5 | (undo-test-marker-adjustment-moved): | ||
| 6 | (undo-test-region-mark-adjustment): New tests to demonstrate | ||
| 7 | bug#16818, which fail without the fix. | ||
| 8 | |||
| 1 | 2014-03-23 Daniel Colascione <dancol@dancol.org> | 9 | 2014-03-23 Daniel Colascione <dancol@dancol.org> |
| 2 | 10 | ||
| 3 | * automated/cl-lib.el (cl-lib-keyword-names-versus-values): New | 11 | * automated/cl-lib.el (cl-lib-keyword-names-versus-values): New |
diff --git a/test/automated/undo-tests.el b/test/automated/undo-tests.el index 8a963f10028..6ecac36b6b3 100644 --- a/test/automated/undo-tests.el +++ b/test/automated/undo-tests.el | |||
| @@ -268,6 +268,104 @@ | |||
| 268 | (should (string= (buffer-string) | 268 | (should (string= (buffer-string) |
| 269 | "This sentence corrupted?aaa")))) | 269 | "This sentence corrupted?aaa")))) |
| 270 | 270 | ||
| 271 | (ert-deftest undo-test-marker-adjustment-nominal () | ||
| 272 | "Test nominal behavior of marker adjustments." | ||
| 273 | (with-temp-buffer | ||
| 274 | (buffer-enable-undo) | ||
| 275 | (insert "abcdefg") | ||
| 276 | (undo-boundary) | ||
| 277 | (let ((m (make-marker))) | ||
| 278 | (set-marker m 2 (current-buffer)) | ||
| 279 | (goto-char (point-min)) | ||
| 280 | (delete-forward-char 3) | ||
| 281 | (undo-boundary) | ||
| 282 | (should (= (point-min) (marker-position m))) | ||
| 283 | (undo) | ||
| 284 | (undo-boundary) | ||
| 285 | (should (= 2 (marker-position m)))))) | ||
| 286 | |||
| 287 | (ert-deftest undo-test-region-t-marker () | ||
| 288 | "Test undo in region containing marker with t insertion-type." | ||
| 289 | (with-temp-buffer | ||
| 290 | (buffer-enable-undo) | ||
| 291 | (transient-mark-mode 1) | ||
| 292 | (insert "abcdefg") | ||
| 293 | (undo-boundary) | ||
| 294 | (let ((m (make-marker))) | ||
| 295 | (set-marker-insertion-type m t) | ||
| 296 | (set-marker m (point-min) (current-buffer)) ; m at a | ||
| 297 | (goto-char (+ 2 (point-min))) | ||
| 298 | (push-mark (point) t t) | ||
| 299 | (setq mark-active t) | ||
| 300 | (goto-char (point-min)) | ||
| 301 | (delete-forward-char 1) ;; delete region covering "ab" | ||
| 302 | (undo-boundary) | ||
| 303 | (should (= (point-min) (marker-position m))) | ||
| 304 | ;; Resurrect "ab". m's insertion type means the reinsertion | ||
| 305 | ;; moves it forward 2, and then the marker adjustment returns it | ||
| 306 | ;; to its rightful place. | ||
| 307 | (undo) | ||
| 308 | (undo-boundary) | ||
| 309 | (should (= (point-min) (marker-position m)))))) | ||
| 310 | |||
| 311 | (ert-deftest undo-test-marker-adjustment-moved () | ||
| 312 | "Test marker adjustment behavior when the marker moves. | ||
| 313 | Demonstrates bug 16818." | ||
| 314 | (with-temp-buffer | ||
| 315 | (buffer-enable-undo) | ||
| 316 | (insert "abcdefghijk") | ||
| 317 | (undo-boundary) | ||
| 318 | (let ((m (make-marker))) | ||
| 319 | (set-marker m 2 (current-buffer)) ; m at b | ||
| 320 | (goto-char (point-min)) | ||
| 321 | (delete-forward-char 3) ; m at d | ||
| 322 | (undo-boundary) | ||
| 323 | (set-marker m 4) ; m at g | ||
| 324 | (undo) | ||
| 325 | (undo-boundary) | ||
| 326 | ;; m still at g, but shifted 3 because deletion undone | ||
| 327 | (should (= 7 (marker-position m)))))) | ||
| 328 | |||
| 329 | (ert-deftest undo-test-region-mark-adjustment () | ||
| 330 | "Test that the mark's marker adjustment in undo history doesn't | ||
| 331 | obstruct undo in region from finding the correct change group. | ||
| 332 | Demonstrates bug 16818." | ||
| 333 | (with-temp-buffer | ||
| 334 | (buffer-enable-undo) | ||
| 335 | (transient-mark-mode 1) | ||
| 336 | (insert "First line\n") | ||
| 337 | (insert "Second line\n") | ||
| 338 | (undo-boundary) | ||
| 339 | |||
| 340 | (goto-char (point-min)) | ||
| 341 | (insert "aaa") | ||
| 342 | (undo-boundary) | ||
| 343 | |||
| 344 | (undo) | ||
| 345 | (undo-boundary) | ||
| 346 | |||
| 347 | (goto-char (point-max)) | ||
| 348 | (insert "bbb") | ||
| 349 | (undo-boundary) | ||
| 350 | |||
| 351 | (push-mark (point) t t) | ||
| 352 | (setq mark-active t) | ||
| 353 | (goto-char (- (point) 3)) | ||
| 354 | (delete-forward-char 1) | ||
| 355 | (undo-boundary) | ||
| 356 | |||
| 357 | (insert "bbb") | ||
| 358 | (undo-boundary) | ||
| 359 | |||
| 360 | (goto-char (point-min)) | ||
| 361 | (push-mark (point) t t) | ||
| 362 | (setq mark-active t) | ||
| 363 | (goto-char (+ (point) 3)) | ||
| 364 | (undo) | ||
| 365 | (undo-boundary) | ||
| 366 | |||
| 367 | (should (string= (buffer-string) "aaaFirst line\nSecond line\nbbb")))) | ||
| 368 | |||
| 271 | (defun undo-test-all (&optional interactive) | 369 | (defun undo-test-all (&optional interactive) |
| 272 | "Run all tests for \\[undo]." | 370 | "Run all tests for \\[undo]." |
| 273 | (interactive "p") | 371 | (interactive "p") |