From: npostavs@users.sourceforge.net
To: Tino Calancha <tino.calancha@gmail.com>
Cc: 25410@debbugs.gnu.org
Subject: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines
Date: Thu, 12 Jan 2017 23:50:40 -0500 [thread overview]
Message-ID: <87inpjzhpb.fsf@users.sourceforge.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1701121429350.5813@calancha-pc> (Tino Calancha's message of "Thu, 12 Jan 2017 14:32:02 +0900 (JST)")
[-- Attachment #1: Type: text/plain, Size: 1015 bytes --]
tags 25410 patch
quit
>> (`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)
[...]
>> + (while (re-search-forward "^-" end t)
>> + (let ((beg-del (progn (beginning-of-line) (point)))
>> + beg-add end-add)
>> + (when (and (setq beg-add (diff--forward-while-leading-char ?- end))
>> + (or (diff--forward-while-leading-char ?\\ end) t)
>> + (setq end-add (diff--forward-while-leading-char ?+ end)))
Actually I made a mistake here, this doesn't allow for "\ No newline at
end of file" in the + part of the hunk. Here's v2 (seems I hit Reply
instead of Followup when sending v1, so it didn't reach the list).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2775 bytes --]
From dd49ab3921744930b422dc408f44206055c94cae Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Thu, 12 Jan 2017 23:32:44 -0500
Subject: [PATCH v2] Avoid inefficient regex in diff-refine-hunk (Bug#25410)
* lisp/vc/diff-mode.el (diff--forward-while-leading-char): New function.
(diff-refine-hunk): Use it instead of trying to match multiple lines
with a single lines.
---
lisp/vc/diff-mode.el | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 9dfcd94..b50b4a2 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2062,6 +2062,15 @@ 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)
+ "Move point until reaching a line not starting with CHAR.
+Return new point, if it was moved."
+ (let ((pt nil))
+ (while (and (< (point) bound) (eql (following-char) char))
+ (forward-line 1)
+ (setq pt (point)))
+ pt))
+
(defun diff-refine-hunk ()
"Highlight changes of hunk at point at a finer granularity."
(interactive)
@@ -2081,16 +2090,18 @@ 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 end-add)
+ (when (and (diff--forward-while-leading-char ?- end)
+ ;; Allow for "\ No newline at end of file".
+ (progn (diff--forward-while-leading-char ?\\ end)
+ (setq beg-add (point)))
+ (diff--forward-while-leading-char ?+ end)
+ (progn (diff--forward-while-leading-char ?\\ end)
+ (setq end-add (point))))
+ (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))
--
2.9.3
next prev parent reply other threads:[~2017-01-13 4:50 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 [this message]
2017-01-13 6:14 ` Tino Calancha
2017-01-13 12:11 ` Tino Calancha
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87inpjzhpb.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=25410@debbugs.gnu.org \
--cc=tino.calancha@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.