diff --git a/inline-diff.el b/inline-diff.el index 9d1ab54..fb9da3a 100644 --- a/inline-diff.el +++ b/inline-diff.el @@ -52,8 +52,11 @@ If nil, the additions will be displayed via empty overlays." "Whether to refine diffs with finer changes." :type 'boolean) -(defcustom inline-diff-refine-similarity 0.5 - "The similarity threshold for refining diffs." +(defcustom inline-diff-refine-similarity 0.7 + "The similarity threshold for refining diffs, between 0.0 and 1.0. + +This is the proportion of characters that must remain in common between +the old and new versions in order for refinement highlighting to be shown." :type 'number) ;;;; Faces @@ -509,8 +512,9 @@ SO-FAR is a list of overlays already seen." (mapconcat #'cdr (cdar last-op-ov) nil)))) (new-chars (vconcat (inline-diff--char-positions (mapconcat #'cdr (cdar op-ov) nil)))) + (max-length (max (length old-chars) (length new-chars))) (char-diff (inline-diff--myers-diff old-chars new-chars :test #'eql :key #'cdr)) - deletions insertions del-ins-unique-points) + deletions insertions) (dolist (op char-diff) (pcase (car op) ('delete @@ -518,13 +522,15 @@ SO-FAR is a list of overlays already seen." ('insert (setq insertions (nconc insertions (cdr op)))))) (when (and deletions - (<= (length deletions) (* inline-diff-refine-similarity (length old-chars)))) + (<= (length deletions) (* (- 1 inline-diff-refine-similarity) (length old-chars))) + (<= (* inline-diff-refine-similarity max-length) (length old-chars))) (inline-diff--show-refinement (cdr last-op-ov) (inline-diff--seq-ranges deletions #'car) 'inline-diff-refine-removed)) (when (and insertions - (<= (length insertions) (* inline-diff-refine-similarity (length new-chars)))) + (<= (length insertions) (* (- 1 inline-diff-refine-similarity) (length new-chars))) + (<= (* inline-diff-refine-similarity max-length) (length new-chars))) (inline-diff--show-refinement (cdr op-ov) (inline-diff--seq-ranges insertions #'car)