From: Tino Calancha <tino.calancha@gmail.com>
To: 25410@debbugs.gnu.org
Subject: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines
Date: Fri, 13 Jan 2017 21:11:20 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1701132104510.1874@calancha-pc> (raw)
In-Reply-To: <alpine.DEB.2.20.1701131510450.13494@calancha-pc>
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))
next prev parent reply other threads:[~2017-01-13 12:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 10:08 bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines Tino Calancha
2017-01-10 14:22 ` npostavs
2017-01-10 15:07 ` Tino Calancha
2017-01-11 2:49 ` Tino Calancha
2017-01-11 8:13 ` Tino Calancha
[not found] ` <87wpe0zz0s.fsf@users.sourceforge.net>
2017-01-12 5:32 ` Tino Calancha
2017-01-13 4:50 ` npostavs
2017-01-13 6:14 ` Tino Calancha
2017-01-13 12:11 ` Tino Calancha [this message]
2017-01-13 16:31 ` Noam Postavsky
2017-01-14 5:38 ` Tino Calancha
2017-01-19 1:55 ` npostavs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1701132104510.1874@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=25410@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).