bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#37395: [PATCH v2] diff-mode.el: take into account patch separators


From: Konstantin Kharlamov
Subject: bug#37395: [PATCH v2] diff-mode.el: take into account patch separators
Date: Fri, 13 Sep 2019 12:19:21 +0300

* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
An inline function to return prev. line if it has
git-format-patch separator.
(diff-end-of-hunk): Make use of
diff-prev-line-if-patch-separator
---

v2:
* Start commit description with capital letter
* Limit commit description to 61 character line length
* Rename diff-goto-line-before-patch-separator, to
  diff-prev-line-if-patch-separator and rephrase the doc-string.
* diff-prev-line-if-patch-separator now does not mutate point.
* Make sure we're at line beginning before (looking-at …)

 lisp/vc/diff-mode.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..6702614472 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -511,6 +511,17 @@ diff-hunk-style
     (goto-char (match-end 0)))
   style)
 
+(defsubst diff-prev-line-if-patch-separator ()
+  "Return previous line if it has patch separator produced by
+git-format-patch."
+  (save-excursion
+    (let ((old-point (point)))
+      (previous-line)
+      (beginning-of-line)
+      (if (looking-at "^-- $")
+          (point)
+        old-point))))
+
 (defun diff-end-of-hunk (&optional style donttrustheader)
   "Advance to the end of the current hunk, and return its position."
   (let (end)
@@ -561,7 +572,8 @@ diff-end-of-hunk
         (goto-char (or end (point-max)))
         (while (eq ?\n (char-before (1- (point))))
           (forward-char -1)
-          (setq end (point)))))
+          (setq end (point))))
+      (setq end (diff-prev-line-if-patch-separator)))
     ;; The return value is used by easy-mmode-define-navigation.
     (goto-char (or end (point-max)))))
 
-- 
2.23.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]