diff options
| author | Stefan Monnier | 2007-07-22 21:38:28 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-07-22 21:38:28 +0000 |
| commit | 3dc04e8360589cfdf59f6919ee38c0ec1b50c5fe (patch) | |
| tree | c586035b202c0eb0323dbe953ec69ae1065f86aa /lisp/diff-mode.el | |
| parent | e4456fdfc897d527b46cc5e10d357f99402da53b (diff) | |
| download | emacs-3dc04e8360589cfdf59f6919ee38c0ec1b50c5fe.tar.gz emacs-3dc04e8360589cfdf59f6919ee38c0ec1b50c5fe.zip | |
(diff-unified->context): Use the new `apply' undo entry kind
if applicable, so as to save undo-log space.
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index ecd32f4c331..3c0208d5b27 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -701,7 +701,12 @@ else cover the whole bufer." | |||
| 701 | (let ((line1 (match-string 4)) | 701 | (let ((line1 (match-string 4)) |
| 702 | (lines1 (match-string 5)) | 702 | (lines1 (match-string 5)) |
| 703 | (line2 (match-string 6)) | 703 | (line2 (match-string 6)) |
| 704 | (lines2 (match-string 7))) | 704 | (lines2 (match-string 7)) |
| 705 | ;; Variables to use the special undo function. | ||
| 706 | (old-undo buffer-undo-list) | ||
| 707 | (old-end (marker-position end)) | ||
| 708 | (start (match-beginning 0)) | ||
| 709 | (reversible t)) | ||
| 705 | (replace-match | 710 | (replace-match |
| 706 | (concat "***************\n*** " line1 "," | 711 | (concat "***************\n*** " line1 "," |
| 707 | (number-to-string (+ (string-to-number line1) | 712 | (number-to-string (+ (string-to-number line1) |
| @@ -743,6 +748,14 @@ else cover the whole bufer." | |||
| 743 | (if (not (save-excursion (re-search-forward "^+" nil t))) | 748 | (if (not (save-excursion (re-search-forward "^+" nil t))) |
| 744 | (delete-region (point) (point-max)) | 749 | (delete-region (point) (point-max)) |
| 745 | (let ((modif nil) (delete nil)) | 750 | (let ((modif nil) (delete nil)) |
| 751 | (if (save-excursion (re-search-forward "^\\+.*\n-" nil t)) | ||
| 752 | ;; Normally, lines in a substitution come with | ||
| 753 | ;; first the removals and then the additions, and | ||
| 754 | ;; the context->unified function follows this | ||
| 755 | ;; convention, of course. Yet, other alternatives | ||
| 756 | ;; are valid as well, but they preclude the use of | ||
| 757 | ;; context->unified as an undo command. | ||
| 758 | (setq reversible nil)) | ||
| 746 | (while (not (eobp)) | 759 | (while (not (eobp)) |
| 747 | (case (char-after) | 760 | (case (char-after) |
| 748 | (?\s (insert " ") (setq modif nil) (backward-char 1)) | 761 | (?\s (insert " ") (setq modif nil) (backward-char 1)) |
| @@ -761,7 +774,15 @@ else cover the whole bufer." | |||
| 761 | (forward-line 1) | 774 | (forward-line 1) |
| 762 | (when delete | 775 | (when delete |
| 763 | (delete-region last-pt (point)) | 776 | (delete-region last-pt (point)) |
| 764 | (setq delete nil))))))))))))))) | 777 | (setq delete nil))))))) |
| 778 | (unless (or (not reversible) (eq buffer-undo-list t)) | ||
| 779 | ;; Drop the many undo entries and replace them with | ||
| 780 | ;; a single entry that uses diff-context->unified to do | ||
| 781 | ;; the work. | ||
| 782 | (setq buffer-undo-list | ||
| 783 | (cons (list 'apply (- old-end end) start (point-max) | ||
| 784 | 'diff-context->unified start (point-max)) | ||
| 785 | old-undo))))))))))) | ||
| 765 | 786 | ||
| 766 | (defun diff-context->unified (start end &optional to-context) | 787 | (defun diff-context->unified (start end &optional to-context) |
| 767 | "Convert context diffs to unified diffs. | 788 | "Convert context diffs to unified diffs. |