>From b2da41327b717fbceed925a8062081af38165639 Mon Sep 17 00:00:00 2001 From: Davis Herring Date: Sun, 19 Jun 2016 02:00:50 -0600 Subject: [PATCH 2/6] Add constants for normal diff headers * lisp/vc/diff-mode.el (diff-hunk-header-re-normal, diff-normal-mid-hunk-header-re): New consts. (diff-font-lock-keywords, diff-hunk-header-re, diff-hunk-text, diff-refine-hunk): Use them. --- lisp/vc/diff-mode.el | 41 ++++++++++++++++++++--------------------- 1 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 10a2734..b859c5e 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -361,8 +361,12 @@ well." "^@@ -\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? \\+\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? @@") (defconst diff-hunk-header-re-context "\\*\\{15\\}\\(?: .*\\)?\n\\*\\*\\* \\(\\([0-9]+\\)\\(?:,\\(-?[0-9]+\\)\\)?\\) \\*\\*\\*\\*") +(defconst diff-hunk-header-re-normal + (let ((pair "\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?")) + (format "^%s\\([acd]\\)%s$" pair pair))) (defconst diff-context-mid-hunk-header-re "^--- \\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? ----$") +(defconst diff-normal-mid-hunk-header-re "^---$") (defvar diff-use-changed-face (and (face-differs-from-default-p 'diff-changed) (not (face-equal 'diff-changed 'diff-added)) @@ -378,8 +382,8 @@ and the face `diff-added' for added lines.") (1 'diff-hunk-header) (2 'diff-function)) ("^\\*\\*\\* .+ \\*\\*\\*\\*". 'diff-hunk-header) ;context (,diff-context-mid-hunk-header-re . 'diff-hunk-header) ;context - ("^[0-9,]+[acd][0-9,]+$" . 'diff-hunk-header) ;normal - ("^---$" . 'diff-hunk-header) ;normal + (,diff-hunk-header-re-normal . 'diff-hunk-header) + (,diff-normal-mid-hunk-header-re . 'diff-hunk-header) ;; For file headers, accept files with spaces, but be careful to rule ;; out false-positives when matching hunk headers. ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\([^\t\n]+?\\)\\(?:\t.*\\| \\(\\*\\*\\*\\*\\|----\\)\\)?\n" @@ -439,7 +443,7 @@ See http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01990.html") (defconst diff-hunk-header-re (concat "^\\(?:" diff-hunk-header-re-unified ".*\\|" diff-hunk-header-re-context - "\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$")) + "\\|" diff-hunk-header-re-normal "\\)$")) (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+ \\|\\*\\*\\* .+\n--- \\|[^-+!<>address@hidden \n]\\).+\n" (substring diff-hunk-header-re 1))) (defvar diff-narrowed-to nil) @@ -1582,23 +1586,18 @@ char-offset in TEXT." (setq divider-pos (point)) (forward-line 1) (setq dst-pos (point))) - ((looking-at "^[0-9]+a[0-9,]+$") - ;; normal diff, insert - (forward-line 1) - (setq dst-pos (point))) - ((looking-at "^[0-9,]+d[0-9]+$") - ;; normal diff, delete - (forward-line 1) - (setq src-pos (point))) - ((looking-at "^[0-9,]+c[0-9,]+$") - ;; normal diff, change - (forward-line 1) - (setq src-pos (point)) - (re-search-forward "^---$" nil t) - (forward-line 0) - (setq divider-pos (point)) - (forward-line 1) - (setq dst-pos (point))) + ((looking-at diff-hunk-header-re-normal) + (forward-line 1) + (pcase (match-string 3) + ("a" (setq dst-pos (point))) ; insert + ("d" (setq src-pos (point))) ; delete + (_ ; otherwise change + (setq src-pos (point)) + (re-search-forward diff-normal-mid-hunk-header-re nil t) + (forward-line 0) + (setq divider-pos (point)) + (forward-line 1) + (setq dst-pos (point))))) (t (error "Unknown diff hunk type"))) @@ -2014,7 +2013,7 @@ For use in `add-log-current-defun-function'." (unless diff-use-changed-face props-a))))) (_ ;; Normal diffs. (let ((beg1 (1+ (point)))) - (when (re-search-forward "^---.*\n" end t) + (when (re-search-forward diff-normal-mid-hunk-header-re end t) ;; It's a combined add&remove, so there's something to do. (smerge-refine-subst beg1 (match-beginning 0) (match-end 0) end -- 1.7.1