GNU bug report logs -
#25410
26.0.50; Refine an unified diff hunk only if adds lines
Previous Next
Reported by: Tino Calancha <tino.calancha <at> gmail.com>
Date: Tue, 10 Jan 2017 10:09:01 UTC
Severity: normal
Tags: fixed, patch
Found in version 26.0.50
Fixed in version 26.1
Done: npostavs <at> users.sourceforge.net
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
On Fri, 13 Jan 2017, Tino Calancha wrote:
> + (while (re-search-forward "^-" end t)
> + (let ((beg-del (progn (beginning-of-line) (point)))
> + (beg-add (diff--forward-while-leading-char ?- end 'no-lf-eol))
> + (end-add (diff--forward-while-leading-char ?+ end 'no-lf-eol)))
> + (when (and beg-add end-add)
> + (smerge-refine-subst beg-del beg-add beg-add end-add
> + nil 'diff-refine-preproc props-r props-a)))))
This is symmetrical respect beg-add/end-add but we could save a
`diff--forward-while-leading-char' call if beg-add is nil.
I think the following lazy version is better:
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 9dfcd944bb..d550a59d6d 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2062,6 +2062,19 @@ diff-refine-preproc
(declare-function smerge-refine-subst "smerge-mode"
(beg1 end1 beg2 end2 props-c &optional preproc props-r props-a))
+(defun diff--forward-while-leading-char (char bound &optional ok-no-lf-eol)
+ "Move point until reaching a line not starting with CHAR.
+Return new point, if it was moved.
+If optional arg OK-NO-LF-EOL is non-nil, then allow no newline at end of line."
+ (let ((orig (point)))
+ (cl-labels ((fn (ch limit)
+ (while (and (< (point) limit) (eql (following-char) ch))
+ (forward-line 1))))
+ (progn
+ (fn char bound)
+ (when ok-no-lf-eol (fn ?\\ bound))
+ (unless (= orig (point)) (point))))))
+
(defun diff-refine-hunk ()
"Highlight changes of hunk at point at a finer granularity."
(interactive)
@@ -2081,16 +2094,14 @@ diff-refine-hunk
(goto-char beg)
(pcase style
(`unified
- (while (re-search-forward
- (eval-when-compile
- (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?"))
- (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re
- "\\(\\)"
- "\\(?:\\+.*\n\\)+" no-LF-at-eol-re)))
- end t)
- (smerge-refine-subst (match-beginning 0) (match-end 1)
- (match-end 1) (match-end 0)
- nil 'diff-refine-preproc props-r props-a)))
+ (while (re-search-forward "^-" end t)
+ (let* ((beg-del (progn (beginning-of-line) (point)))
+ (beg-add (diff--forward-while-leading-char ?- end t))
+ (end-add (and beg-add
+ (diff--forward-while-leading-char ?+ end t))))
+ (when end-add
+ (smerge-refine-subst beg-del beg-add beg-add end-add
+ nil 'diff-refine-preproc props-r props-a)))))
(`context
(let* ((middle (save-excursion (re-search-forward "^---")))
(other middle))
This bug report was last modified 8 years and 124 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.