diff options
| author | Stefan Monnier | 2007-10-20 02:02:22 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-10-20 02:02:22 +0000 |
| commit | 2659df6808566cdbfdeb00d1597a8eadf7d53c72 (patch) | |
| tree | 3f163e4a8ed21be122048938917f7f65448d23ff /lisp/diff-mode.el | |
| parent | 83ea55432c60c899ca7940219a62902d07b45a66 (diff) | |
| download | emacs-2659df6808566cdbfdeb00d1597a8eadf7d53c72.tar.gz emacs-2659df6808566cdbfdeb00d1597a8eadf7d53c72.zip | |
(diff-auto-refine): New var.
(diff-hunk): Use it.
(diff-ignore-whitespace-hunk): Rename diff-refine-ignore-spaces-hunk.
(diff-refine-change): Rename from diff-fine-change. Change it.
(diff-refine-preproc): Rename from diff-fine-highlight-preproc.
(diff-refine-hunk): Rename from diff-fine-highlight.
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index 972e7972e75..0208660c1a9 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -90,6 +90,9 @@ when editing big diffs)." | |||
| 90 | :type 'boolean | 90 | :type 'boolean |
| 91 | :group 'diff-mode) | 91 | :group 'diff-mode) |
| 92 | 92 | ||
| 93 | (defcustom diff-auto-refine t | ||
| 94 | "Automatically highlight changes in detail as the user visits hunks." | ||
| 95 | :type 'boolean) | ||
| 93 | 96 | ||
| 94 | (defcustom diff-mode-hook nil | 97 | (defcustom diff-mode-hook nil |
| 95 | "Run after setting up the `diff-mode' major mode." | 98 | "Run after setting up the `diff-mode' major mode." |
| @@ -149,14 +152,14 @@ when editing big diffs)." | |||
| 149 | ("\C-c\C-a" . diff-apply-hunk) | 152 | ("\C-c\C-a" . diff-apply-hunk) |
| 150 | ("\C-c\C-e" . diff-ediff-patch) | 153 | ("\C-c\C-e" . diff-ediff-patch) |
| 151 | ("\C-c\C-n" . diff-restrict-view) | 154 | ("\C-c\C-n" . diff-restrict-view) |
| 152 | ("\C-c\C-r" . diff-reverse-direction) | ||
| 153 | ("\C-c\C-s" . diff-split-hunk) | 155 | ("\C-c\C-s" . diff-split-hunk) |
| 154 | ("\C-c\C-t" . diff-test-hunk) | 156 | ("\C-c\C-t" . diff-test-hunk) |
| 157 | ("\C-c\C-r" . diff-reverse-direction) | ||
| 155 | ("\C-c\C-u" . diff-context->unified) | 158 | ("\C-c\C-u" . diff-context->unified) |
| 156 | ;; `d' because it duplicates the context :-( --Stef | 159 | ;; `d' because it duplicates the context :-( --Stef |
| 157 | ("\C-c\C-d" . diff-unified->context) | 160 | ("\C-c\C-d" . diff-unified->context) |
| 158 | ("\C-c\C-w" . diff-refine-ignore-spaces-hunk) | 161 | ("\C-c\C-w" . diff-ignore-whitespace-hunk) |
| 159 | ("\C-c\C-b" . diff-fine-highlight) ;No reason for `b' :-( | 162 | ("\C-c\C-b" . diff-refine-hunk) ;No reason for `b' :-( |
| 160 | ("\C-c\C-f" . next-error-follow-minor-mode)) | 163 | ("\C-c\C-f" . next-error-follow-minor-mode)) |
| 161 | "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") | 164 | "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") |
| 162 | 165 | ||
| @@ -174,8 +177,8 @@ when editing big diffs)." | |||
| 174 | ;;["Fixup Headers" diff-fixup-modifs (not buffer-read-only)] | 177 | ;;["Fixup Headers" diff-fixup-modifs (not buffer-read-only)] |
| 175 | "-----" | 178 | "-----" |
| 176 | ["Split hunk" diff-split-hunk (diff-splittable-p)] | 179 | ["Split hunk" diff-split-hunk (diff-splittable-p)] |
| 177 | ["Ignore whitespace changes" diff-refine-ignore-spaces-hunk t] | 180 | ["Ignore whitespace changes" diff-ignore-whitespace-hunk t] |
| 178 | ["Highlight fine changes" diff-fine-highlight t] | 181 | ["Highlight fine changes" diff-refine-hunk t] |
| 179 | ["Kill current hunk" diff-hunk-kill t] | 182 | ["Kill current hunk" diff-hunk-kill t] |
| 180 | ["Kill current file's hunks" diff-file-kill t] | 183 | ["Kill current file's hunks" diff-file-kill t] |
| 181 | "-----" | 184 | "-----" |
| @@ -458,7 +461,10 @@ but in the file header instead, in which case move forward to the first hunk." | |||
| 458 | 461 | ||
| 459 | ;; Define diff-{hunk,file}-{prev,next} | 462 | ;; Define diff-{hunk,file}-{prev,next} |
| 460 | (easy-mmode-define-navigation | 463 | (easy-mmode-define-navigation |
| 461 | diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk diff-restrict-view) | 464 | diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk diff-restrict-view |
| 465 | (if diff-auto-refine | ||
| 466 | (condition-case-no-debug nil (diff-refine-hunk) (error nil)))) | ||
| 467 | |||
| 462 | (easy-mmode-define-navigation | 468 | (easy-mmode-define-navigation |
| 463 | diff-file diff-file-header-re "file" diff-end-of-hunk) | 469 | diff-file diff-file-header-re "file" diff-end-of-hunk) |
| 464 | 470 | ||
| @@ -1604,8 +1610,8 @@ For use in `add-log-current-defun-function'." | |||
| 1604 | (goto-char (+ (car pos) (cdr src))) | 1610 | (goto-char (+ (car pos) (cdr src))) |
| 1605 | (add-log-current-defun)))))) | 1611 | (add-log-current-defun)))))) |
| 1606 | 1612 | ||
| 1607 | (defun diff-refine-ignore-spaces-hunk () | 1613 | (defun diff-ignore-whitespace-hunk () |
| 1608 | "Refine the current hunk by ignoring space differences." | 1614 | "Re-diff the current hunk, ignoring whitespace differences." |
| 1609 | (interactive) | 1615 | (interactive) |
| 1610 | (let* ((char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder) | 1616 | (let* ((char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder) |
| 1611 | (point)))) | 1617 | (point)))) |
| @@ -1651,12 +1657,20 @@ For use in `add-log-current-defun-function'." | |||
| 1651 | 1657 | ||
| 1652 | ;;; Fine change highlighting. | 1658 | ;;; Fine change highlighting. |
| 1653 | 1659 | ||
| 1654 | (defface diff-fine-change | 1660 | (defface diff-refine-change |
| 1655 | '((t :background "yellow")) | 1661 | '((((class color) (min-colors 88) (background light)) |
| 1656 | "Face used for char-based changes shown by `diff-fine-highlight'." | 1662 | :background "grey90") |
| 1663 | (((class color) (min-colors 88) (background dark)) | ||
| 1664 | :background "grey40") | ||
| 1665 | (((class color) (background light)) | ||
| 1666 | :background "yellow") | ||
| 1667 | (((class color) (background dark)) | ||
| 1668 | :background "green") | ||
| 1669 | (t :weight bold)) | ||
| 1670 | "Face used for char-based changes shown by `diff-refine-hunk'." | ||
| 1657 | :group 'diff-mode) | 1671 | :group 'diff-mode) |
| 1658 | 1672 | ||
| 1659 | (defun diff-fine-highlight-preproc () | 1673 | (defun diff-refine-preproc () |
| 1660 | (while (re-search-forward "^[+>]" nil t) | 1674 | (while (re-search-forward "^[+>]" nil t) |
| 1661 | ;; Remove spurious changes due to the fact that one side of the hunk is | 1675 | ;; Remove spurious changes due to the fact that one side of the hunk is |
| 1662 | ;; marked with leading + or > and the other with leading - or <. | 1676 | ;; marked with leading + or > and the other with leading - or <. |
| @@ -1668,7 +1682,7 @@ For use in `add-log-current-defun-function'." | |||
| 1668 | (replace-match (cdr (assq (char-before) '((?+ . "-") (?> . "<")))))) | 1682 | (replace-match (cdr (assq (char-before) '((?+ . "-") (?> . "<")))))) |
| 1669 | ) | 1683 | ) |
| 1670 | 1684 | ||
| 1671 | (defun diff-fine-highlight () | 1685 | (defun diff-refine-hunk () |
| 1672 | "Highlight changes of hunk at point at a finer granularity." | 1686 | "Highlight changes of hunk at point at a finer granularity." |
| 1673 | (interactive) | 1687 | (interactive) |
| 1674 | (require 'smerge-mode) | 1688 | (require 'smerge-mode) |
| @@ -1676,7 +1690,7 @@ For use in `add-log-current-defun-function'." | |||
| 1676 | (diff-beginning-of-hunk 'try-harder) | 1690 | (diff-beginning-of-hunk 'try-harder) |
| 1677 | (let* ((style (diff-hunk-style)) ;Skips the hunk header as well. | 1691 | (let* ((style (diff-hunk-style)) ;Skips the hunk header as well. |
| 1678 | (beg (point)) | 1692 | (beg (point)) |
| 1679 | (props '((diff-mode . fine) (face diff-fine-change))) | 1693 | (props '((diff-mode . fine) (face diff-refine-change))) |
| 1680 | (end (progn (diff-end-of-hunk) (point)))) | 1694 | (end (progn (diff-end-of-hunk) (point)))) |
| 1681 | 1695 | ||
| 1682 | (remove-overlays beg end 'diff-mode 'fine) | 1696 | (remove-overlays beg end 'diff-mode 'fine) |
| @@ -1688,7 +1702,7 @@ For use in `add-log-current-defun-function'." | |||
| 1688 | end t) | 1702 | end t) |
| 1689 | (smerge-refine-subst (match-beginning 0) (match-end 1) | 1703 | (smerge-refine-subst (match-beginning 0) (match-end 1) |
| 1690 | (match-end 1) (match-end 0) | 1704 | (match-end 1) (match-end 0) |
| 1691 | props 'diff-fine-highlight-preproc))) | 1705 | props 'diff-refine-preproc))) |
| 1692 | (context | 1706 | (context |
| 1693 | (let* ((middle (save-excursion (re-search-forward "^---"))) | 1707 | (let* ((middle (save-excursion (re-search-forward "^---"))) |
| 1694 | (other middle)) | 1708 | (other middle)) |
| @@ -1700,14 +1714,14 @@ For use in `add-log-current-defun-function'." | |||
| 1700 | (setq other (match-end 0)) | 1714 | (setq other (match-end 0)) |
| 1701 | (match-beginning 0)) | 1715 | (match-beginning 0)) |
| 1702 | other | 1716 | other |
| 1703 | props 'diff-fine-highlight-preproc)))) | 1717 | props 'diff-refine-preproc)))) |
| 1704 | (t ;; Normal diffs. | 1718 | (t ;; Normal diffs. |
| 1705 | (let ((beg1 (1+ (point)))) | 1719 | (let ((beg1 (1+ (point)))) |
| 1706 | (when (re-search-forward "^---.*\n" end t) | 1720 | (when (re-search-forward "^---.*\n" end t) |
| 1707 | ;; It's a combined add&remove, so there's something to do. | 1721 | ;; It's a combined add&remove, so there's something to do. |
| 1708 | (smerge-refine-subst beg1 (match-beginning 0) | 1722 | (smerge-refine-subst beg1 (match-beginning 0) |
| 1709 | (match-end 0) end | 1723 | (match-end 0) end |
| 1710 | props 'diff-fine-highlight-preproc)))))))) | 1724 | props 'diff-refine-preproc)))))))) |
| 1711 | 1725 | ||
| 1712 | 1726 | ||
| 1713 | ;; provide the package | 1727 | ;; provide the package |