diff options
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 170 |
1 files changed, 89 insertions, 81 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index 7c7f7902d82..cc89aad6ca3 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, | 3 | ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
| 4 | ;; 2005, 2006 Free Software Foundation, Inc. | 4 | ;; 2005, 2006 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> | 6 | ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> |
| 7 | ;; Keywords: convenience patch diff | 7 | ;; Keywords: convenience patch diff |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| @@ -118,7 +118,8 @@ when editing big diffs)." | |||
| 118 | ("\C-m" . diff-goto-source) | 118 | ("\C-m" . diff-goto-source) |
| 119 | ([mouse-2] . diff-goto-source) | 119 | ([mouse-2] . diff-goto-source) |
| 120 | ;; From XEmacs' diff-mode. | 120 | ;; From XEmacs' diff-mode. |
| 121 | ("W" . widen) | 121 | ;; Standard M-w is useful, so don't change M-W. |
| 122 | ;; ("W" . widen) | ||
| 122 | ;;("." . diff-goto-source) ;display-buffer | 123 | ;;("." . diff-goto-source) ;display-buffer |
| 123 | ;;("f" . diff-goto-source) ;find-file | 124 | ;;("f" . diff-goto-source) ;find-file |
| 124 | ("o" . diff-goto-source) ;other-window | 125 | ("o" . diff-goto-source) ;other-window |
| @@ -127,14 +128,14 @@ when editing big diffs)." | |||
| 127 | ;;("h" . diff-show-header) | 128 | ;;("h" . diff-show-header) |
| 128 | ;;("j" . diff-show-difference) ;jump to Nth diff | 129 | ;;("j" . diff-show-difference) ;jump to Nth diff |
| 129 | ;;("q" . diff-quit) | 130 | ;;("q" . diff-quit) |
| 130 | (" " . scroll-up) | 131 | ;; Not useful if you have to metafy them. |
| 131 | ("\177" . scroll-down) | 132 | ;; (" " . scroll-up) |
| 132 | ;; Our very own bindings. | 133 | ;; ("\177" . scroll-down) |
| 133 | ("A" . diff-ediff-patch) | 134 | ;; Standard M-a is useful, so don't change M-A. |
| 134 | ("r" . diff-restrict-view) | 135 | ;; ("A" . diff-ediff-patch) |
| 135 | ("R" . diff-reverse-direction) | 136 | ;; Standard M-r is useful, so don't change M-r or M-R. |
| 136 | ("U" . diff-context->unified) | 137 | ;; ("r" . diff-restrict-view) |
| 137 | ("C" . diff-unified->context) | 138 | ;; ("R" . diff-reverse-direction) |
| 138 | ("q" . quit-window)) | 139 | ("q" . quit-window)) |
| 139 | "Basic keymap for `diff-mode', bound to various prefix keys.") | 140 | "Basic keymap for `diff-mode', bound to various prefix keys.") |
| 140 | 141 | ||
| @@ -143,10 +144,14 @@ when editing big diffs)." | |||
| 143 | ;; From compilation-minor-mode. | 144 | ;; From compilation-minor-mode. |
| 144 | ("\C-c\C-c" . diff-goto-source) | 145 | ("\C-c\C-c" . diff-goto-source) |
| 145 | ;; Misc operations. | 146 | ;; Misc operations. |
| 146 | ("\C-c\C-r" . diff-refine-hunk) | ||
| 147 | ("\C-c\C-s" . diff-split-hunk) | ||
| 148 | ("\C-c\C-a" . diff-apply-hunk) | 147 | ("\C-c\C-a" . diff-apply-hunk) |
| 148 | ("\C-c\C-e" . diff-ediff-patch) | ||
| 149 | ("\C-c\C-n" . diff-restrict-view) | ||
| 150 | ("\C-c\C-r" . diff-reverse-direction) | ||
| 151 | ("\C-c\C-s" . diff-split-hunk) | ||
| 149 | ("\C-c\C-t" . diff-test-hunk) | 152 | ("\C-c\C-t" . diff-test-hunk) |
| 153 | ("\C-c\C-u" . diff-context->unified) | ||
| 154 | ("\C-c\C-w" . diff-refine-hunk) | ||
| 150 | ("\C-c\C-f" . next-error-follow-minor-mode)) | 155 | ("\C-c\C-f" . next-error-follow-minor-mode)) |
| 151 | "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") | 156 | "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") |
| 152 | 157 | ||
| @@ -711,77 +716,80 @@ else cover the whole bufer." | |||
| 711 | (delete-region last-pt (point)) | 716 | (delete-region last-pt (point)) |
| 712 | (setq delete nil))))))))))))))) | 717 | (setq delete nil))))))))))))))) |
| 713 | 718 | ||
| 714 | (defun diff-context->unified (start end) | 719 | (defun diff-context->unified (start end &optional to-context) |
| 715 | "Convert context diffs to unified diffs. | 720 | "Convert context diffs to unified diffs. |
| 716 | START and END are either taken from the region (if a prefix arg is given) or | 721 | START and END are either taken from the region |
| 717 | else cover the whole bufer." | 722 | \(when it is highlighted) or else cover the whole buffer. |
| 718 | (interactive (if current-prefix-arg | 723 | With a prefix argument, convert unified format to context format." |
| 719 | (list (mark) (point)) | 724 | (interactive (if (and transient-mark-mode mark-active) |
| 720 | (list (point-min) (point-max)))) | 725 | (list (mark) (point) current-prefix-arg) |
| 721 | (unless (markerp end) (setq end (copy-marker end))) | 726 | (list (point-min) (point-max) current-prefix-arg))) |
| 722 | (let (;;(diff-inhibit-after-change t) | 727 | (if to-context |
| 723 | (inhibit-read-only t)) | 728 | (diff-unified->context start end) |
| 724 | (save-excursion | 729 | (unless (markerp end) (setq end (copy-marker end))) |
| 725 | (goto-char start) | 730 | (let ( ;;(diff-inhibit-after-change t) |
| 726 | (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\{15\\}.*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t) | 731 | (inhibit-read-only t)) |
| 727 | (< (point) end)) | 732 | (save-excursion |
| 728 | (combine-after-change-calls | 733 | (goto-char start) |
| 729 | (if (match-beginning 2) | 734 | (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\{15\\}.*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t) |
| 730 | ;; we matched a file header | 735 | (< (point) end)) |
| 731 | (progn | 736 | (combine-after-change-calls |
| 732 | ;; use reverse order to make sure the indices are kept valid | 737 | (if (match-beginning 2) |
| 733 | (replace-match "+++" t t nil 3) | 738 | ;; we matched a file header |
| 734 | (replace-match "---" t t nil 2)) | 739 | (progn |
| 735 | ;; we matched a hunk header | 740 | ;; use reverse order to make sure the indices are kept valid |
| 736 | (let ((line1s (match-string 4)) | 741 | (replace-match "+++" t t nil 3) |
| 737 | (line1e (match-string 5)) | 742 | (replace-match "---" t t nil 2)) |
| 738 | (pt1 (match-beginning 0))) | 743 | ;; we matched a hunk header |
| 739 | (replace-match "") | 744 | (let ((line1s (match-string 4)) |
| 740 | (unless (re-search-forward | 745 | (line1e (match-string 5)) |
| 741 | "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t) | 746 | (pt1 (match-beginning 0))) |
| 742 | (error "Can't find matching `--- n1,n2 ----' line")) | 747 | (replace-match "") |
| 743 | (let ((line2s (match-string 1)) | 748 | (unless (re-search-forward |
| 744 | (line2e (match-string 2)) | 749 | "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t) |
| 745 | (pt2 (progn | 750 | (error "Can't find matching `--- n1,n2 ----' line")) |
| 746 | (delete-region (progn (beginning-of-line) (point)) | 751 | (let ((line2s (match-string 1)) |
| 747 | (progn (forward-line 1) (point))) | 752 | (line2e (match-string 2)) |
| 748 | (point-marker)))) | 753 | (pt2 (progn |
| 749 | (goto-char pt1) | 754 | (delete-region (progn (beginning-of-line) (point)) |
| 750 | (forward-line 1) | 755 | (progn (forward-line 1) (point))) |
| 751 | (while (< (point) pt2) | 756 | (point-marker)))) |
| 752 | (case (char-after) | ||
| 753 | ((?! ?-) (delete-char 2) (insert "-") (forward-line 1)) | ||
| 754 | (?\s ;merge with the other half of the chunk | ||
| 755 | (let* ((endline2 | ||
| 756 | (save-excursion | ||
| 757 | (goto-char pt2) (forward-line 1) (point))) | ||
| 758 | (c (char-after pt2))) | ||
| 759 | (case c | ||
| 760 | ((?! ?+) | ||
| 761 | (insert "+" | ||
| 762 | (prog1 (buffer-substring (+ pt2 2) endline2) | ||
| 763 | (delete-region pt2 endline2)))) | ||
| 764 | (?\s ;FIXME: check consistency | ||
| 765 | (delete-region pt2 endline2) | ||
| 766 | (delete-char 1) | ||
| 767 | (forward-line 1)) | ||
| 768 | (?\\ (forward-line 1)) | ||
| 769 | (t (delete-char 1) (forward-line 1))))) | ||
| 770 | (t (forward-line 1)))) | ||
| 771 | (while (looking-at "[+! ] ") | ||
| 772 | (if (/= (char-after) ?!) (forward-char 1) | ||
| 773 | (delete-char 1) (insert "+")) | ||
| 774 | (delete-char 1) (forward-line 1)) | ||
| 775 | (save-excursion | ||
| 776 | (goto-char pt1) | 757 | (goto-char pt1) |
| 777 | (insert "@@ -" line1s "," | 758 | (forward-line 1) |
| 778 | (number-to-string (- (string-to-number line1e) | 759 | (while (< (point) pt2) |
| 779 | (string-to-number line1s) | 760 | (case (char-after) |
| 780 | -1)) | 761 | ((?! ?-) (delete-char 2) (insert "-") (forward-line 1)) |
| 781 | " +" line2s "," | 762 | (?\s ;merge with the other half of the chunk |
| 782 | (number-to-string (- (string-to-number line2e) | 763 | (let* ((endline2 |
| 783 | (string-to-number line2s) | 764 | (save-excursion |
| 784 | -1)) " @@")))))))))) | 765 | (goto-char pt2) (forward-line 1) (point))) |
| 766 | (c (char-after pt2))) | ||
| 767 | (case c | ||
| 768 | ((?! ?+) | ||
| 769 | (insert "+" | ||
| 770 | (prog1 (buffer-substring (+ pt2 2) endline2) | ||
| 771 | (delete-region pt2 endline2)))) | ||
| 772 | (?\s ;FIXME: check consistency | ||
| 773 | (delete-region pt2 endline2) | ||
| 774 | (delete-char 1) | ||
| 775 | (forward-line 1)) | ||
| 776 | (?\\ (forward-line 1)) | ||
| 777 | (t (delete-char 1) (forward-line 1))))) | ||
| 778 | (t (forward-line 1)))) | ||
| 779 | (while (looking-at "[+! ] ") | ||
| 780 | (if (/= (char-after) ?!) (forward-char 1) | ||
| 781 | (delete-char 1) (insert "+")) | ||
| 782 | (delete-char 1) (forward-line 1)) | ||
| 783 | (save-excursion | ||
| 784 | (goto-char pt1) | ||
| 785 | (insert "@@ -" line1s "," | ||
| 786 | (number-to-string (- (string-to-number line1e) | ||
| 787 | (string-to-number line1s) | ||
| 788 | -1)) | ||
| 789 | " +" line2s "," | ||
| 790 | (number-to-string (- (string-to-number line2e) | ||
| 791 | (string-to-number line2s) | ||
| 792 | -1)) " @@"))))))))))) | ||
| 785 | 793 | ||
| 786 | (defun diff-reverse-direction (start end) | 794 | (defun diff-reverse-direction (start end) |
| 787 | "Reverse the direction of the diffs. | 795 | "Reverse the direction of the diffs. |