aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/diff-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/diff-mode.el')
-rw-r--r--lisp/diff-mode.el89
1 files changed, 46 insertions, 43 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el
index 894a12b1193..972e7972e75 100644
--- a/lisp/diff-mode.el
+++ b/lisp/diff-mode.el
@@ -1657,54 +1657,57 @@ For use in `add-log-current-defun-function'."
1657 :group 'diff-mode) 1657 :group 'diff-mode)
1658 1658
1659(defun diff-fine-highlight-preproc () 1659(defun diff-fine-highlight-preproc ()
1660 (while (re-search-forward "^." nil t) 1660 (while (re-search-forward "^[+>]" nil t)
1661 ;; Replace the hunk's leading prefix (+, -, !, <, or >) on each line 1661 ;; Remove spurious changes due to the fact that one side of the hunk is
1662 ;; with something constant, otherwise it'll be flagged as changes 1662 ;; marked with leading + or > and the other with leading - or <.
1663 ;; (since it's typically "-" on one side and "+" on the other). 1663 ;; We used to replace all the prefix chars with " " but this only worked
1664 ;; Note that we keep the same number of chars: we treat the prefix 1664 ;; when we did char-based refinement (or when using
1665 ;; as part of the texts-to-diff, so that finding the right char 1665 ;; smerge-refine-weight-hack) since otherwise, the `forward' motion done
1666 ;; afterwards will be easier. This only makes sense because we make 1666 ;; in chopup do not necessarily do the same as the ones in highlight
1667 ;; diffs at char-granularity. 1667 ;; since the "_" is not treated the same as " ".
1668 (replace-match " "))) 1668 (replace-match (cdr (assq (char-before) '((?+ . "-") (?> . "<"))))))
1669 )
1669 1670
1670(defun diff-fine-highlight () 1671(defun diff-fine-highlight ()
1671 "Highlight changes of hunk at point at a finer granularity." 1672 "Highlight changes of hunk at point at a finer granularity."
1672 (interactive) 1673 (interactive)
1673 (require 'smerge-mode) 1674 (require 'smerge-mode)
1674 (diff-beginning-of-hunk 'try-harder) 1675 (save-excursion
1675 (let* ((style (diff-hunk-style)) ;Skips the hunk header as well. 1676 (diff-beginning-of-hunk 'try-harder)
1676 (beg (point)) 1677 (let* ((style (diff-hunk-style)) ;Skips the hunk header as well.
1677 (props '((diff-mode . fine) (face diff-fine-change))) 1678 (beg (point))
1678 (end (progn (diff-end-of-hunk) (point)))) 1679 (props '((diff-mode . fine) (face diff-fine-change)))
1679 1680 (end (progn (diff-end-of-hunk) (point))))
1680 (remove-overlays beg end 'diff-mode 'fine) 1681
1681 1682 (remove-overlays beg end 'diff-mode 'fine)
1682 (goto-char beg) 1683
1683 (case style 1684 (goto-char beg)
1684 (unified 1685 (case style
1685 (while (re-search-forward "^\\(?:-.*\n\\)+\\(\\)\\(?:\\+.*\n\\)+" end t) 1686 (unified
1686 (smerge-refine-subst (match-beginning 0) (match-end 1) 1687 (while (re-search-forward "^\\(?:-.*\n\\)+\\(\\)\\(?:\\+.*\n\\)+"
1687 (match-end 1) (match-end 0) 1688 end t)
1688 props 'diff-fine-highlight-preproc))) 1689 (smerge-refine-subst (match-beginning 0) (match-end 1)
1689 (context 1690 (match-end 1) (match-end 0)
1690 (let* ((middle (save-excursion (re-search-forward "^---"))) 1691 props 'diff-fine-highlight-preproc)))
1691 (other middle)) 1692 (context
1692 (while (re-search-forward "^\\(?:!.*\n\\)+" middle t) 1693 (let* ((middle (save-excursion (re-search-forward "^---")))
1693 (smerge-refine-subst (match-beginning 0) (match-end 0) 1694 (other middle))
1694 (save-excursion 1695 (while (re-search-forward "^\\(?:!.*\n\\)+" middle t)
1695 (goto-char other) 1696 (smerge-refine-subst (match-beginning 0) (match-end 0)
1696 (re-search-forward "^\\(?:!.*\n\\)+" end) 1697 (save-excursion
1697 (setq other (match-end 0)) 1698 (goto-char other)
1698 (match-beginning 0)) 1699 (re-search-forward "^\\(?:!.*\n\\)+" end)
1699 other 1700 (setq other (match-end 0))
1700 props 'diff-fine-highlight-preproc)))) 1701 (match-beginning 0))
1701 (t ;; Normal diffs. 1702 other
1702 (let ((beg1 (1+ (point)))) 1703 props 'diff-fine-highlight-preproc))))
1703 (when (re-search-forward "^---.*\n" end t) 1704 (t ;; Normal diffs.
1704 ;; It's a combined add&remove, so there's something to do. 1705 (let ((beg1 (1+ (point))))
1705 (smerge-refine-subst beg1 (match-beginning 0) 1706 (when (re-search-forward "^---.*\n" end t)
1706 (match-end 0) end 1707 ;; It's a combined add&remove, so there's something to do.
1707 props 'diff-fine-highlight-preproc))))))) 1708 (smerge-refine-subst beg1 (match-beginning 0)
1709 (match-end 0) end
1710 props 'diff-fine-highlight-preproc))))))))
1708 1711
1709 1712
1710;; provide the package 1713;; provide the package