aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Kharlamov2019-10-13 05:52:21 +0200
committerLars Ingebrigtsen2019-10-13 05:52:21 +0200
commitf0002b2d84d7605d113b0b8124959e23f90d1b08 (patch)
tree0936e3f2ccbecdb947af996f17bab3429711c4a1
parent518ff50f7a245f437576c5f7e716be9cba336287 (diff)
downloademacs-f0002b2d84d7605d113b0b8124959e23f90d1b08.tar.gz
emacs-f0002b2d84d7605d113b0b8124959e23f90d1b08.zip
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).
-rw-r--r--lisp/vc/diff-mode.el23
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d40..c86f15cee00 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")
504(defconst diff-separator-re "^--+ ?$") 504(defconst diff-separator-re "^--+ ?$")
505 505
506(defvar diff-narrowed-to nil) 506(defvar diff-narrowed-to nil)
507(defvar diff-buffer-type nil)
507 508
508(defun diff-hunk-style (&optional style) 509(defun diff-hunk-style (&optional style)
509 (when (looking-at diff-hunk-header-re) 510 (when (looking-at diff-hunk-header-re)
@@ -511,6 +512,18 @@ See https://lists.gnu.org/r/emacs-devel/2007-11/msg01990.html")
511 (goto-char (match-end 0))) 512 (goto-char (match-end 0)))
512 style) 513 style)
513 514
515(defun diff-prev-line-if-patch-separator ()
516 "Return previous line if it has patch separator as produced by git."
517 (pcase diff-buffer-type
518 ('git
519 (save-excursion
520 (let ((old-point (point)))
521 (forward-line -1)
522 (if (looking-at "^-- $")
523 (point)
524 old-point))))
525 (_ (point))))
526
514(defun diff-end-of-hunk (&optional style donttrustheader) 527(defun diff-end-of-hunk (&optional style donttrustheader)
515 "Advance to the end of the current hunk, and return its position." 528 "Advance to the end of the current hunk, and return its position."
516 (let (end) 529 (let (end)
@@ -561,7 +574,8 @@ See https://lists.gnu.org/r/emacs-devel/2007-11/msg01990.html")
561 (goto-char (or end (point-max))) 574 (goto-char (or end (point-max)))
562 (while (eq ?\n (char-before (1- (point)))) 575 (while (eq ?\n (char-before (1- (point))))
563 (forward-char -1) 576 (forward-char -1)
564 (setq end (point))))) 577 (setq end (point))))
578 (setq end (diff-prev-line-if-patch-separator)))
565 ;; The return value is used by easy-mmode-define-navigation. 579 ;; The return value is used by easy-mmode-define-navigation.
566 (goto-char (or end (point-max))))) 580 (goto-char (or end (point-max)))))
567 581
@@ -1491,7 +1505,12 @@ a diff with \\[diff-reverse-direction].
1491 (add-function :filter-return (local 'filter-buffer-substring-function) 1505 (add-function :filter-return (local 'filter-buffer-substring-function)
1492 #'diff--filter-substring) 1506 #'diff--filter-substring)
1493 (unless buffer-file-name 1507 (unless buffer-file-name
1494 (hack-dir-local-variables-non-file-buffer))) 1508 (hack-dir-local-variables-non-file-buffer))
1509 (save-excursion
1510 (setq-local diff-buffer-type
1511 (if (re-search-forward "^diff --git" nil t)
1512 'git
1513 nil))))
1495 1514
1496;;;###autoload 1515;;;###autoload
1497(define-minor-mode diff-minor-mode 1516(define-minor-mode diff-minor-mode