[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master f0002b2: Make diff-mode understand git-format-patch
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master f0002b2: Make diff-mode understand git-format-patch separators |
Date: |
Sat, 12 Oct 2019 23:52:56 -0400 (EDT) |
branch: master
commit f0002b2d84d7605d113b0b8124959e23f90d1b08
Author: Konstantin Kharlamov <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Make diff-mode understand git-format-patch separators
* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
A 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
diff-buffer-type: whether a buffer is a git-diff
(define-derived-mode): set diff-buffer-type to appropriate
value (bug#37395).
---
lisp/vc/diff-mode.el | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c80..c86f15c 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -504,6 +504,7 @@ See
https://lists.gnu.org/r/emacs-devel/2007-11/msg01990.html")
(defconst diff-separator-re "^--+ ?$")
(defvar diff-narrowed-to nil)
+(defvar diff-buffer-type nil)
(defun diff-hunk-style (&optional style)
(when (looking-at diff-hunk-header-re)
@@ -511,6 +512,18 @@ See
https://lists.gnu.org/r/emacs-devel/2007-11/msg01990.html")
(goto-char (match-end 0)))
style)
+(defun diff-prev-line-if-patch-separator ()
+ "Return previous line if it has patch separator as produced by git."
+ (pcase diff-buffer-type
+ ('git
+ (save-excursion
+ (let ((old-point (point)))
+ (forward-line -1)
+ (if (looking-at "^-- $")
+ (point)
+ old-point))))
+ (_ (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 +574,8 @@ See
https://lists.gnu.org/r/emacs-devel/2007-11/msg01990.html")
(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)))))
@@ -1491,7 +1505,12 @@ a diff with \\[diff-reverse-direction].
(add-function :filter-return (local 'filter-buffer-substring-function)
#'diff--filter-substring)
(unless buffer-file-name
- (hack-dir-local-variables-non-file-buffer)))
+ (hack-dir-local-variables-non-file-buffer))
+ (save-excursion
+ (setq-local diff-buffer-type
+ (if (re-search-forward "^diff --git" nil t)
+ 'git
+ nil))))
;;;###autoload
(define-minor-mode diff-minor-mode
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master f0002b2: Make diff-mode understand git-format-patch separators,
Lars Ingebrigtsen <=